/* ===== Design system multicodesandbox ===== */
:root {
  --bg: #FAFAFA;
  --surface: #FFFFFF;
  --border: #E4E4E7;
  --text: #18181B;
  --text-muted: #71717A;
  --accent: #6366F1;
  --accent-hover: #4F52E0;
  --accent-soft: #EEF0FE;
  --success: #16A34A;
  --danger: #DC2626;
  --warn-bg: #FEF3C7;
  --warn-text: #92400E;
  --radius: 8px;
  --font-ui: system-ui, -apple-system, sans-serif;
  --font-code: "JetBrains Mono", monospace;
}

/* ===== Thème sombre : on ne redéfinit QUE les variables ===== */
[data-theme="dark"] {
  --bg: #131316;
  --surface: #1B1B1F;
  --border: #2A2A30;
  --text: #F4F4F5;
  --text-muted: #A1A1AA;
  --accent: #818CF8;
  --accent-hover: #6A76F5;
  --accent-soft: #26264A;
  --success: #4ADE80;
  --danger: #F87171;
  --warn-bg: #3B2F0B;
  --warn-text: #FCD34D;
}

* { box-sizing: border-box; margin: 0; }

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
}

/* ===== Navigation entre écrans ===== */
.screen { display: none; }
.screen.active { display: block; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 13px; }
.spacer { flex: 1; }

/* ===== Écran d'accueil ===== */
#screen-home.active {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}

.home-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.logo { font-size: 22px; font-weight: 600; text-align: center; }
.tagline { text-align: center; color: var(--text-muted); font-size: 14px; margin-top: -12px; }

.home-section { display: flex; flex-direction: column; gap: 10px; }
.home-section h2 { font-size: 13px; font-weight: 500; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--text-muted); font-size: 12px;
}
.divider::before, .divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

/* ===== Contrôles ===== */
.btn {
  font: inherit; font-size: 14px;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s;
}
.btn:hover { background: var(--bg); }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

input[type="text"], select {
  font: inherit; font-size: 14px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
}
input[type="text"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
#input-code { font-family: var(--font-code); text-transform: uppercase; }

.error { color: var(--danger); font-size: 13px; }

/* ===== Barre du haut ===== */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.logo-small { font-size: 14px; font-weight: 600; }
.badge {
  font-family: var(--font-code); font-size: 12px;
  background: var(--accent-soft); color: var(--accent);
  padding: 4px 12px; border-radius: 999px;
}

/* ===== Bandeau du code de room (hôte) ===== */
.room-banner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 24px 16px 8px;
}
.room-banner-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.room-banner-code {
  font-family: var(--font-code);
  font-size: 44px;
  font-weight: 500;
  letter-spacing: 0.18em;
  color: var(--accent);
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 16px;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.room-banner-code:hover { background: var(--accent-soft); }
.copy-feedback {
  opacity: 0;
  transition: opacity 0.2s;
}
.copy-feedback.visible { opacity: 1; }

/* ===== Espace de travail ===== */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
  height: calc(100vh - 53px);
}

#editor, #focus-editor { min-width: 0; }

.console-panel {
  border-left: 1px solid var(--border);
  background: var(--surface);
  display: flex; flex-direction: column;
}
.console-header {
  font-size: 12px; color: var(--text-muted);
  padding: 10px 14px 6px;
}
.console-output {
  font-family: var(--font-code); font-size: 13px;
  padding: 4px 14px;
  flex: 1;
  overflow: auto;
  white-space: pre-wrap;
  color: var(--text);
}
.console-footer {
  font-size: 12px; color: var(--text-muted);
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
}

/* ===== Dashboard hôte ===== */
.participants-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  padding: 16px;
}
.empty-msg { grid-column: 1 / -1; text-align: center; padding: 60px 0; }

.participant-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
}
.participant-card:hover { border-color: var(--accent); }
.participant-card-header {
  display: flex; align-items: center; gap: 8px;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px; font-weight: 500;
}
.participant-card-editor { height: 240px; }

.focus-hint {
  font-weight: 400;
  opacity: 0;
  transition: opacity 0.15s;
}
.participant-card:hover .focus-hint { opacity: 1; }

/* ===== Reconnexion : participants hors ligne ===== */
.participant-card.offline { opacity: 0.55; }
.offline-pill {
  font-size: 11px;
  background: var(--warn-bg);
  color: var(--warn-text);
  padding: 2px 8px;
  border-radius: 999px;
}

/* ===== Sortie d'exécution ===== */
.preview {
  flex: 1;
  border: 0;
  width: 100%;
  background: #FFFFFF; /* l'aperçu HTML reste blanc : c'est une "vraie page" */
}
.log-error { color: var(--danger); }
.log-warn { color: var(--warn-text); }

/* ===== Bouton de thème ===== */
.theme-toggle {
  position: fixed;
  bottom: 16px;
  right: 16px;
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  z-index: 100;
  transition: border-color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); }