:root {
  --bg: #0b1020;
  --bg2: #121a33;
  --panel: rgba(20, 28, 52, 0.86);
  --border: #26345c;
  --text: #e7ecf5;
  --muted: #8e9ab3;
  --accent: #35d6ff;
  --current: #ff4fd8;
  --goal: #35f2a0;
  --error: #ff5c6c;
  --warn: #ffb547;
  --gold: #ffd166;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace;
  --sans: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: radial-gradient(1200px 700px at 70% -10%, #1b2a55 0%, var(--bg) 60%);
  color: var(--text);
  font-family: var(--sans);
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; }

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---- barre du haut ---- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: rgba(10, 15, 32, 0.7);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(6px);
  position: relative;
  z-index: 20; /* reste accessible (langue, son) même quand une fenêtre est ouverte */
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; letter-spacing: 0.3px; white-space: nowrap; }
.logo { font-size: 22px; }
.chip {
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--bg2);
  border: 1px solid var(--border);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:empty { display: none; }
.spacer { flex: 1; }

.progress { display: flex; gap: 4px; }
.pip {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  font-size: 12px;
  font-weight: 700;
  padding: 0;
  transition: transform 0.15s, background 0.15s;
}
.pip.done { background: #14494f; border-color: #1f8f9c; }
.pip.open { border-color: var(--accent); }
.pip.current { background: var(--accent); color: #05202a; border-color: var(--accent); transform: scale(1.12); }
.pip.locked { opacity: 0.35; }
.pip:not(:disabled):hover { transform: scale(1.12); }

.stat { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.1; }
.stat .label { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.stat strong { font-size: 20px; font-variant-numeric: tabular-nums; }
.combo {
  padding: 3px 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ff8a3d, #ff4fd8);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
  animation: pop 0.3s;
}
.combo[hidden] { display: none; }
.icon-btn {
  min-width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg2);
  font-size: 15px;
  font-weight: 700;
}
.icon-btn:hover { border-color: var(--accent); }

.chrono-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg2);
  font-weight: 800;
  color: var(--muted);
}
.chrono-btn:hover { border-color: var(--gold); }
.chrono-btn.on {
  color: #2a1c00;
  border-color: transparent;
  background: linear-gradient(90deg, #ffd166, #ff8a3d);
  box-shadow: 0 0 14px rgba(255, 170, 60, 0.55);
}

/* ---- scène ---- */
#stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
#canvas { position: absolute; inset: 0; display: block; }

#coach {
  position: absolute;
  top: 14px;
  left: 14px;
  width: min(340px, calc(100% - 28px));
  padding: 12px 16px 14px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(6px);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}
.coach-head { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.8px; }
.dots { display: flex; gap: 5px; }
.dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--border); }
.dot.now { border-color: var(--accent); }
.dot.done { background: var(--goal); border-color: var(--goal); }
#coach h2 { margin: 6px 0 4px; font-size: 17px; }
#coach p { margin: 0; font-size: 14px; line-height: 1.45; color: #c9d3e8; white-space: pre-line; }

#legend {
  position: absolute;
  left: 14px;
  bottom: 12px;
  margin: 0;
  padding: 8px 12px;
  list-style: none;
  display: flex;
  gap: 14px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
}
#legend li { display: flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; }
.swatch.current { background: var(--current); box-shadow: 0 0 8px var(--current); }
.swatch.goal { border: 2px dashed var(--goal); }
.swatch.path { background: var(--accent); box-shadow: 0 0 8px var(--accent); }

#toast {
  position: absolute;
  top: 18px;
  left: 50%;
  transform: translate(-50%, -20px);
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 800;
  background: var(--bg2);
  border: 1px solid var(--border);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.gold { color: #2a1c00; background: var(--gold); border-color: var(--gold); }
#toast.error { color: #fff; background: #6b1f2b; border-color: var(--error); }

/* ---- zone de saisie ---- */
#prompt {
  padding: 12px 16px 14px;
  background: rgba(8, 12, 26, 0.92);
  border-top: 1px solid var(--border);
}
.promptline {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 12px;
  background: #050813;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 20px;
  max-width: 900px;
  margin: 0 auto;
}
.promptline:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(53, 214, 255, 0.18); }
.ps1 { color: var(--current); }
.ps1:empty { display: none; }
.dollar { color: var(--goal); white-space: nowrap; }
#answer {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: 0;
  outline: 0;
  color: var(--text);
  font: inherit;
  caret-color: var(--accent);
}
#answer.invalid { color: var(--error); }
#answer:read-only { opacity: 0.6; }
.enter {
  border: 1px solid var(--border);
  background: var(--bg2);
  border-radius: 8px;
  width: 34px;
  height: 30px;
  font-size: 16px;
}
.enter:hover { border-color: var(--accent); }

.prompt-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  max-width: 900px;
  margin: 8px auto 0;
  min-height: 22px;
  font-size: 14px;
}
#feedback.error { color: var(--error); }
#feedback.warn { color: var(--warn); }
#feedback.cheer { color: var(--goal); font-weight: 700; }
.hints { display: flex; gap: 14px; color: var(--muted); font-size: 12px; text-align: right; }
#parInfo { color: var(--gold); font-weight: 700; }

/* ---- minuteur du mode chrono ---- */
#timer {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 900px;
  margin: 0 auto 10px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
#timer[hidden] { display: none; }
#timerText { min-width: 62px; color: var(--gold); }
#timerPts { min-width: 88px; text-align: right; color: var(--muted); font-size: 13px; }
#timer .track { flex: 1; height: 10px; border-radius: 999px; background: #0a1024; border: 1px solid var(--border); overflow: hidden; }
#timerFill { height: 100%; width: 100%; border-radius: 999px; background: linear-gradient(90deg, #35f2a0, #35d6ff); transition: width 0.1s linear; }
#timerFill.mid { background: linear-gradient(90deg, #ffd166, #ffb547); }
#timerFill.low { background: linear-gradient(90deg, #ff8a3d, #ff5c6c); }
#timer.urgent #timerText { color: var(--error); animation: throb 0.5s infinite alternate; }
@keyframes throb { to { transform: scale(1.18); } }

/* ---- fenêtres modales ---- */
#modalRoot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 76px 16px 16px; /* laisse la barre du haut (langue, son) accessible */
  background: rgba(4, 7, 18, 0.66);
  backdrop-filter: blur(4px);
  z-index: 10;
}
#modalRoot[hidden] { display: none; }
.modal {
  width: min(520px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 24px 26px 22px;
  border-radius: 18px;
  background: linear-gradient(180deg, #17224a, #101835);
  border: 1px solid var(--border);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
  animation: pop 0.25s;
}
.modal h2 { margin: 0 0 12px; font-size: 22px; }
.modal h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }
.modal p { line-height: 1.5; }
.modal .intro { font-size: 17px; white-space: pre-line; }
.muted { color: var(--muted); }
.actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin: 22px -26px -22px;
  padding: 16px 26px 22px;
  position: sticky; /* les boutons restent visibles quand la fenêtre défile */
  bottom: -22px;
  background: linear-gradient(180deg, rgba(16, 24, 53, 0), #101835 35%);
}
.btn {
  padding: 10px 18px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg2);
  font-weight: 700;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(90deg, #1fb6e0, #4d7cff); border-color: transparent; color: #fff; }
.btn.primary:focus-visible, .btn:focus-visible, .pip:focus-visible, .icon-btn:focus-visible { outline: 3px solid rgba(53, 214, 255, 0.5); outline-offset: 2px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.name-input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #050813;
  color: var(--text);
  font-size: 18px;
  outline: 0;
}
.name-input:focus { border-color: var(--accent); }

.stars { display: flex; justify-content: center; gap: 8px; font-size: 46px; margin: 4px 0 2px; }
.star { color: #2b3760; }
.star.on { color: var(--gold); text-shadow: 0 0 16px rgba(255, 209, 102, 0.6); animation: pop 0.5s; }
.summary { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; margin: 14px 0 0; }
.summary dt { color: var(--muted); }
.summary dd { margin: 0; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.modal p.muted { text-align: center; margin: 0; }

.modal.wide { width: min(660px, 100%); }
.level-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
@media (max-width: 560px) { .level-list { grid-template-columns: 1fr; } }
.level-row {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  min-width: 0;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg2);
  text-align: left;
}
.level-row:not(:disabled):hover { border-color: var(--accent); }
.level-row.current { border-color: var(--accent); background: #10345a; }
.level-row:disabled { opacity: 0.45; }
.level-row .num { font-weight: 800; color: var(--accent); }
.level-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-stars { color: var(--gold); letter-spacing: 2px; font-size: 13px; }
.scores { margin: 0; padding: 0; list-style: none; }
.scores li { display: grid; grid-template-columns: 34px 1fr auto; gap: 8px; padding: 5px 8px; border-radius: 8px; }
.scores li.me { background: rgba(53, 214, 255, 0.14); outline: 1px solid rgba(53, 214, 255, 0.4); }
.scores .medal { text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }
.scores .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scores li.muted { display: block; }
.credit { margin: 18px 0 0; font-size: 13px; color: var(--muted); text-align: center; }
.credit a { color: var(--accent); }
.field-error { min-height: 20px; margin: 8px 0 0; color: var(--error); font-size: 14px; }
.field + .field { margin-top: 14px; }
.rank {
  padding: 3px 10px;
  border-radius: 999px;
  background: #10345a;
  border: 1px solid var(--accent);
  font-weight: 800;
  font-size: 13px;
  white-space: nowrap;
}
.rank[hidden], .class-chip[hidden] { display: none; }
.class-chip { color: var(--gold); border-color: rgba(255, 209, 102, 0.4); }

@keyframes pop {
  0% { transform: scale(0.85); opacity: 0.4; }
  100% { transform: scale(1); opacity: 1; }
}

/* ---- petits écrans ---- */
@media (max-width: 720px) {
  .brand span:last-child, #levelChip, .class-chip, .progress, .chrono-label { display: none; }
  #legend { display: none; }
  #coach { padding: 8px 12px 10px; }
  #coach p { font-size: 13px; }
  .promptline { font-size: 17px; }
  .hints #input-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
