/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-dark:     #0a0a12;
  --bg-panel:    #10101e;
  --bg-card:     #16162a;
  --border:      #2a2a45;
  --text-primary:#e8e8f0;
  --text-muted:  #7878a0;
  --accent:      #5b7fff;
  --accent-glow: rgba(91,127,255,0.25);
  --radius:      12px;
  --panel-w:     280px;
  --transition:  0.25s ease;
}

html, body {
  width: 100%; height: 100%;
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  overflow: hidden;
  user-select: none;
}

/* ===== SCREEN SYSTEM ===== */
.screen { display: none; width: 100%; height: 100%; }
.screen.active { display: flex; }

/* ===== WELCOME SCREEN (M2) ===== */
#screen-welcome {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, #1a1040 0%, #0a0a12 70%);
  position: relative;
  overflow: hidden;
}

#screen-welcome canvas#stars-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
}

.welcome-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 40px 24px 32px;
}

.welcome-content h1 {
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #fff 30%, #a0b4ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.welcome-content p {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 40px;
}

.discipline-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 18px;
  max-width: 920px;
  margin: 0 auto;
}

.disc-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 16px 22px;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.disc-card:hover {
  transform: translateY(-6px);
  border-color: var(--accent);
  box-shadow: 0 8px 32px var(--accent-glow);
}

.disc-card .disc-icon {
  font-size: 2.6rem;
  line-height: 1;
  filter: drop-shadow(0 0 12px currentColor);
}

.disc-card .disc-label {
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.disc-card .disc-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.4;
}

/* ===== LAB SCREEN (M4) ===== */
#screen-lab {
  flex-direction: row;
  height: 100vh;
}

/* ===== LEFT PANEL ===== */
#panel-left {
  width: var(--panel-w);
  min-width: var(--panel-w);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.28s ease, min-width 0.28s ease;
  flex-shrink: 0;
}

#panel-left.collapsed {
  width: 0;
  min-width: 0;
}

/* Bouton toggle — fine bande entre panel gauche et canvas */
.panel-toggle {
  flex-shrink: 0;
  width: 18px;
  background: var(--bg-panel);
  border: none;
  border-right: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
  user-select: none;
}

.panel-toggle:hover {
  color: var(--text-primary);
  background: var(--bg-card);
}

/* Filtre de classe dans le panneau gauche */
.panel-class-filter {
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  flex-shrink: 0;
}

.panel-class-filter:empty {
  display: none;
}

.class-pill {
  padding: 3px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
}

.class-pill:hover {
  background: rgba(91,127,255,0.12);
  border-color: var(--accent);
  color: var(--text-primary);
}

.class-pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.panel-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-header .back-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  cursor: pointer;
  padding: 4px 0;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  transition: color var(--transition);
}

.panel-header .back-btn:hover { color: var(--text-primary); }

.panel-header .disc-name {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-header .disc-name span { font-size: 1.4rem; }

.panel-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-search input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.82rem;
  padding: 7px 10px;
  outline: none;
  transition: border-color var(--transition);
}

.panel-search input:focus { border-color: var(--accent); }
.panel-search input::placeholder { color: var(--text-muted); }

.exp-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.exp-list::-webkit-scrollbar { width: 4px; }
.exp-list::-webkit-scrollbar-track { background: transparent; }
.exp-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.exp-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 12px 10px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}

.exp-item:hover { border-color: var(--accent); background: #1c1c34; }
.exp-item.active { border-color: var(--accent); background: #1c1c34; box-shadow: 0 0 12px var(--accent-glow); }

.exp-item .exp-name {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 4px;
}

.exp-item .exp-level {
  font-size: 0.72rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.05);
  border-radius: 4px;
  padding: 2px 6px;
  display: inline-block;
}

/* ===== CENTER CANVAS AREA ===== */
#panel-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#lab-canvas {
  display: block;
  width: 100%;
  flex: 1;
}

/* ===== RIGHT PANEL ===== */
#panel-right {
  width: var(--panel-w);
  min-width: var(--panel-w);
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-right-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 700;
  flex-shrink: 0;
}

.right-section {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.right-section h3 {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 0.82rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.metric-row:last-child { border-bottom: none; }
.metric-row .metric-label { color: var(--text-muted); }
.metric-row .metric-value { font-weight: 600; color: var(--accent); }

.btn-action {
  display: block;
  width: 100%;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.82rem;
  cursor: pointer;
  margin-top: 6px;
  transition: border-color var(--transition), background var(--transition);
  text-align: center;
}

.btn-action:hover { border-color: var(--accent); background: #1c1c34; }
.btn-action.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-action.primary:hover { filter: brightness(1.15); }

#log-panel {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px;
}

#log-panel::-webkit-scrollbar { width: 4px; }
#log-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.log-entry {
  font-size: 0.76rem;
  padding: 5px 0;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  color: var(--text-muted);
  line-height: 1.4;
}

.log-entry .log-time { color: rgba(255,255,255,0.2); margin-right: 6px; }
.log-entry.log-info { color: #a0c4ff; }
.log-entry.log-success { color: #7fff9a; }
.log-entry.log-warn { color: #ffd07f; }

/* ===== COSMIC ENTRY ANIMATION OVERLAY ===== */
#cosmic-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
}

#cosmic-overlay.active {
  pointer-events: all;
  opacity: 1;
}

#cosmic-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

/* ===== EXPERIMENT INFO TOAST ===== */
#exp-toast {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 20px;
  max-width: 420px;
  font-size: 0.82rem;
  line-height: 1.5;
  opacity: 0;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 10;
  pointer-events: none;
  text-align: center;
}

#exp-toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== AUTH SCREEN ===== */
#screen-auth {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 10%, #1a1040 0%, #0a0a12 65%);
  position: relative;
}

.auth-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
  max-width: 420px;
  padding: 24px;
}

.auth-brand { text-align: center; }

.auth-logo { font-size: 3rem; margin-bottom: 10px; filter: drop-shadow(0 0 20px rgba(91,127,255,0.5)); }

.auth-brand h1 {
  font-size: 1.7rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff 30%, #a0b4ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 6px;
}

.auth-brand p { color: var(--text-muted); font-size: 0.88rem; }

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-panel);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}

.auth-tab {
  flex: 1;
  padding: 8px;
  border-radius: 7px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-family: inherit;
}

.auth-tab.active { background: var(--accent); color: #fff; }

.auth-panel { display: none; }
.auth-panel.active { display: block; }

.auth-field { margin-bottom: 14px; }

.auth-field label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.auth-field input {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}

.auth-field input:focus { border-color: var(--accent); }
.auth-field input::placeholder { color: rgba(120,120,160,0.5); }

.auth-error { font-size: 0.8rem; color: #ff7f7f; min-height: 18px; margin-bottom: 10px; }

.btn-auth {
  display: block;
  width: 100%;
  padding: 11px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), filter var(--transition);
  font-family: inherit;
}

.btn-auth:hover { border-color: var(--accent); background: var(--bg-card); }
.btn-auth.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-auth.primary:hover { filter: brightness(1.12); }

/* ===== USER BADGE (welcome screen) ===== */
.user-badge {
  position: absolute;
  top: 20px;
  right: 24px;
  z-index: 2;
  align-items: center;
  gap: 6px;
  background: rgba(16,16,30,0.85);
  border: 1px solid var(--border);
  border-radius: 40px;
  padding: 6px 8px 6px 14px;
  backdrop-filter: blur(8px);
}

.user-badge-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.user-badge button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}

.user-badge button:hover { color: var(--text-primary); background: rgba(255,255,255,0.08); }

/* ===== TUTORIAL MODAL ===== */
#tutorial-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#tutorial-overlay.visible { opacity: 1; pointer-events: all; }

#tutorial-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 640px;
  max-width: 92vw;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  overflow: hidden;
}

#tutorial-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
  font-weight: 700;
}

#tutorial-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px 7px;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}

#tutorial-close:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }

#tutorial-iframe { width: 100%; height: 280px; border: none; display: block; background: #000; }

#tutorial-no-video {
  width: 100%;
  height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.85rem;
  background: var(--bg-panel);
}

#tutorial-no-video span { font-size: 2rem; }

#tutorial-desc {
  padding: 14px 20px;
  font-size: 0.87rem;
  color: var(--text-muted);
  line-height: 1.6;
  min-height: 20px;
}

#tutorial-footer {
  display: flex;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

#tutorial-footer button {
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: inherit;
  transition: border-color var(--transition), color var(--transition);
}

#tutorial-footer button:hover { border-color: var(--accent); color: var(--text-primary); }
#tutorial-footer button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
#tutorial-footer button.primary:hover { filter: brightness(1.12); }

/* ===== PROFILE MODAL ===== */
#profile-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0,0,0,0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

#profile-overlay.visible { opacity: 1; pointer-events: all; }

#profile-modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 480px;
  max-width: 92vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
  overflow: hidden;
}

#profile-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
  font-weight: 700;
  flex-shrink: 0;
}

#profile-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.95rem;
  padding: 4px 7px;
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}

#profile-close:hover { background: rgba(255,255,255,0.08); color: var(--text-primary); }

#profile-body { flex: 1; overflow-y: auto; }
#profile-body::-webkit-scrollbar { width: 4px; }
#profile-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.profile-section { padding: 14px 20px; border-bottom: 1px solid var(--border); }
.profile-section:last-child { border-bottom: none; }

.profile-section h3 {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;
  font-size: 0.84rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.stat-row:last-child { border-bottom: none; }
.stat-row span:first-child { color: var(--text-muted); }
.stat-row span:last-child { font-weight: 600; color: var(--accent); }

.top-exp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 0;
  font-size: 0.84rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.top-exp-row:last-child { border-bottom: none; }
.top-rank { color: var(--text-muted); font-weight: 700; min-width: 18px; }
.top-visits { margin-left: auto; color: var(--accent); font-weight: 600; font-size: 0.78rem; }

.profile-empty { font-size: 0.84rem; color: var(--text-muted); font-style: italic; }

.reward-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 0.79rem;
  margin: 3px;
  border: 1px solid transparent;
}

.reward-badge.earned {
  background: rgba(91,127,255,0.14);
  border-color: rgba(91,127,255,0.3);
  color: var(--text-primary);
}

.reward-badge.locked {
  background: rgba(255,255,255,0.03);
  border-color: var(--border);
  color: var(--text-muted);
  opacity: 0.55;
  filter: grayscale(1);
}

#profile-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ===== REWARD TOAST ===== */
.reward-toast {
  position: fixed;
  bottom: 80px;
  right: 24px;
  z-index: 3000;
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.84rem;
  box-shadow: 0 8px 24px rgba(91,127,255,0.22);
  transform: translateX(130%);
  transition: transform 0.4s ease;
  max-width: 280px;
  line-height: 1.4;
}

.reward-toast.visible { transform: translateX(0); }
.reward-toast > span:first-child { font-size: 1.6rem; flex-shrink: 0; }

/* ===== AUTH — champs supplémentaires ===== */
.auth-required { color: #ff7f7f; font-size: 0.7rem; }
.auth-optional { color: var(--text-muted); font-size: 0.7rem; font-weight: 400; }

.auth-field select {
  width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.9rem;
  padding: 10px 12px;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
  font-family: inherit;
}

.auth-field select:focus { border-color: var(--accent); }

.auth-field select option,
.auth-field select optgroup {
  background: #1a1a2e;
  color: var(--text-primary);
}

/* ===== SYNC DOT (indicateur connexion) ===== */
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.4s ease;
}

.sync-dot.online { background: #4caf82; box-shadow: 0 0 6px rgba(76,175,130,0.5); }

/* ===== PROFIL — header enrichi ===== */
#profile-title-block {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

#profile-displayname {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
}

#profile-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.top-label { flex: 1; font-size: 0.83rem; }
.top-time  { font-size: 0.76rem; color: var(--text-muted); margin-right: 6px; }

/* ===== PROFIL — catégories récompenses ===== */
.rewards-category-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin: 10px 0 4px;
}
