/* Language Quest — interface.
   Le canvas occupe tout l'écran et le jeu se dessine à la résolution native ;
   cette couche HTML se pose par-dessus pour tout ce qui est texte, panneaux et
   saisie. */

:root {
  --ink: #0a0d14;
  --panel: rgba(16, 19, 30, 0.95);
  --line: rgba(240, 210, 150, 0.22);
  --gold: #f0c04a;
  --gold-soft: #ffe49a;
  --text: #efe9dc;
  --muted: #9b98a6;
  --green: #5fc16a;
  --red: #e2564c;
  --radius: 10px;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: #05070c;
  color: var(--text);
  font-family: var(--sans);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

#stage { position: relative; width: 100vw; height: 100vh; height: 100dvh; }
#game { display: block; width: 100%; height: 100%; }

#ui {
  position: absolute; inset: 0;
  pointer-events: none;
  font-size: clamp(13px, 1.05vw, 18px);
  line-height: 1.4;
}
#ui button, #ui input, #ui .pointer { pointer-events: auto; }
.hidden { display: none !important; }

/* ------------------------------------------------------------- chargement */

#boot {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 45%, #141a2c 0%, #05070c 70%);
  z-index: 80;
  transition: opacity 0.6s ease;
}
#boot.done { opacity: 0; pointer-events: none; }
.boot-inner { text-align: center; }
#boot h1 {
  margin: 0 0 1.2rem;
  font-family: var(--serif);
  font-size: clamp(1.8rem, 5vw, 3rem);
  letter-spacing: 0.18em;
}
#boot em { color: var(--gold); font-style: normal; }
.boot-track {
  width: min(70vw, 340px); height: 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  margin: 0 auto;
}
#boot-bar { width: 0%; height: 100%; background: linear-gradient(90deg, var(--gold), var(--gold-soft)); transition: width 0.15s linear; }
#boot p { margin-top: 0.8rem; color: var(--muted); font-family: var(--mono); font-size: 0.8rem; }

/* ---------------------------------------------------------------- briques */

.btn {
  display: inline-flex; align-items: center; gap: 0.5em;
  padding: 0.55em 1.1em;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(62, 70, 104, 0.6), rgba(22, 26, 42, 0.9));
  color: var(--text);
  font: inherit; font-size: 0.95em;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: linear-gradient(180deg, rgba(84, 94, 138, 0.75), rgba(30, 36, 56, 0.95)); border-color: var(--gold-soft); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #f5d36a, #cf9a22); border-color: #ffe9a8; color: #221a06; font-weight: 700; }
.btn.primary:hover { background: linear-gradient(180deg, #ffe07c, #e0a92a); }
.btn.ghost { background: rgba(12, 15, 24, 0.75); }
.btn.danger { border-color: rgba(226, 86, 76, 0.7); color: #ffbdb7; }
.btn.danger:hover { background: rgba(120, 30, 26, 0.6); }
.btn.next { padding: 0.3em 1em; font-size: 1.05em; }
.btn:disabled { opacity: 0.45; cursor: default; }

kbd {
  display: inline-block; min-width: 1.6em;
  padding: 0.15em 0.4em;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.1);
  font-family: var(--mono); font-size: 0.72em;
  text-align: center; color: #fff; letter-spacing: 0.04em;
}

.bar { height: 6px; border-radius: 4px; background: rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.3s ease; }

.stars { display: inline-flex; gap: 3px; }
.stars i {
  width: 1.05em; height: 1.05em; background: rgba(255, 255, 255, 0.18);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}
.stars i.on { background: #f7d24a; filter: drop-shadow(0 0 5px rgba(247, 210, 74, 0.6)); }

.medal { display: inline-block; width: 0.9em; height: 0.9em; border-radius: 50%; background: var(--medal);
  box-shadow: inset 0 -0.15em 0 rgba(0, 0, 0, 0.3); margin-right: 0.4em; vertical-align: -0.08em; }

.foot-note { color: var(--muted); font-size: 0.78em; font-family: var(--mono); }
.muted { color: var(--muted); }

/* -------------------------------------------------------------------- HUD */

.hud { position: absolute; inset: 0; }

.hud-esc {
  pointer-events: auto;
  position: absolute; top: 14px; left: 14px;
  display: flex; align-items: center; gap: 0.4em;
  padding: 0.35em 0.7em;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: rgba(10, 13, 22, 0.72);
  color: var(--text); font: inherit; font-size: 0.85em; cursor: pointer;
  backdrop-filter: blur(6px);
}
.hud-esc:hover { border-color: var(--gold-soft); }

.hud-right { position: absolute; top: 14px; right: 14px; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }

.quest-track {
  min-width: 11em; padding: 0.5em 0.85em;
  border: 1px solid var(--line); border-left: 3px solid var(--accent, var(--gold));
  border-radius: var(--radius);
  background: rgba(10, 13, 22, 0.76);
  text-align: right; backdrop-filter: blur(6px);
}
.qt-count { font-family: var(--mono); font-size: 1em; color: var(--accent, var(--gold)); font-weight: 700; }
.qt-label { font-size: 0.78em; color: #ded8cc; }

.badge-strip { display: flex; gap: 6px; }
.badge-chip {
  width: 1.7em; height: 1.7em; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 50%;
  background: rgba(10, 13, 22, 0.72);
}
.badge-chip i { width: 0.8em; height: 0.8em; border-radius: 50%; background: rgba(255, 255, 255, 0.12); }
.badge-chip.owned { border-color: var(--accent); box-shadow: 0 0 10px rgba(255, 220, 140, 0.35); }
.badge-chip.owned i { background: var(--accent); }
.badge-chip.gold { box-shadow: 0 0 14px rgba(240, 180, 41, 0.6); }

.hud-keys { position: absolute; right: 14px; bottom: 14px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.keyrow {
  pointer-events: auto; display: flex; align-items: center; gap: 0.45em;
  padding: 0.18em 0.5em; border-radius: 7px;
  background: rgba(10, 13, 22, 0.55); font-size: 0.78em; cursor: pointer;
}
.keyrow:hover { background: rgba(32, 38, 62, 0.8); }
.keyrow .kl { color: #cfc9bd; }

.prompt {
  position: absolute; left: 50%; bottom: 26px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.45em 1em; border: 1px solid var(--line); border-radius: 2em;
  background: rgba(10, 13, 22, 0.88); font-size: 0.88em; white-space: nowrap;
}
.prompt .p-main { color: #fff; }
.prompt .p-sub { color: var(--muted); font-size: 0.85em; }

.toasts { position: absolute; left: 14px; bottom: 14px; display: flex; flex-direction: column-reverse; gap: 7px; max-width: 46%; }
.toast {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.55em 0.9em;
  border: 1px solid var(--line); border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  background: rgba(12, 15, 26, 0.92);
  backdrop-filter: blur(6px);
  opacity: 0; transform: translateX(-10px);
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.toast.in { opacity: 1; transform: none; }
.toast.word { border-left-color: var(--green); }
.toast.locked { border-left-color: var(--red); }
.toast.gold { border-left-color: var(--gold); box-shadow: 0 0 26px rgba(240, 192, 74, 0.22); }
.toast-icon { font-size: 1.1em; }
.toast-title { font-size: 0.88em; color: #fff; }
.toast-sub { font-size: 0.74em; color: var(--muted); font-family: var(--mono); }

/* --------------------------------------------------------------- dialogue */

.dialogue {
  pointer-events: auto;
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  width: min(92%, 640px);
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(10px);
  cursor: pointer;
}
.dlg-inner { display: flex; gap: 0.9em; padding: 0.9em 1.1em; }
.dlg-portrait {
  flex: none; width: 3.2em; height: 3.2em; border-radius: 10px;
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 32%, var(--accent, var(--gold)) 0%, transparent 62%),
    linear-gradient(180deg, rgba(62, 70, 104, 0.6), rgba(18, 22, 36, 0.9));
}
.dlg-col { flex: 1; min-width: 0; }
.dlg-name { font-size: 0.74em; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); margin-bottom: 0.25em; }
.dlg-text { font-size: 0.95em; min-height: 3em; color: #ece7dc; }
.dlg-actions { display: flex; gap: 0.5em; justify-content: flex-end; margin-top: 0.5em; }

/* -------------------------------------------------------------- panneaux */

.panel-wrap {
  pointer-events: auto; position: absolute; inset: 0;
  display: grid; place-items: center;
  background: rgba(4, 6, 12, 0.62);
  backdrop-filter: blur(4px);
}
.panel {
  width: min(94%, 720px); max-height: 90%;
  display: flex; flex-direction: column;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.75);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 0.7em;
  padding: 0.8em 1em; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(52, 60, 96, 0.45), transparent);
}
.panel-head h2 { flex: 1; margin: 0; font-family: var(--serif); font-size: 1.05em; letter-spacing: 0.12em; text-transform: uppercase; color: var(--gold); }
.head-count { font-family: var(--mono); font-size: 0.85em; color: var(--muted); }
.panel-body { padding: 0.9em 1em; overflow-y: auto; }
.panel-body h3 { margin: 1.1em 0 0.5em; font-size: 0.72em; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.panel-body h3:first-child { margin-top: 0; }
.panel-foot { display: flex; align-items: center; gap: 0.8em; padding: 0.7em 1em; border-top: 1px solid var(--line); }
.panel-foot .bar { flex: 1; }

.tabs { display: flex; gap: 4px; padding: 0.7em 1em 0; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 0.45em 0.5em;
  border: 1px solid var(--line); border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: rgba(10, 13, 22, 0.6); color: var(--muted);
  font: inherit; font-size: 0.82em; cursor: pointer;
}
.tab em { font-family: var(--mono); font-size: 0.8em; font-style: normal; }
.tab:hover { color: var(--text); }
.tab.active { color: #fff; border-bottom-color: var(--accent); background: rgba(42, 48, 78, 0.7); }

.word-grid {
  padding: 0.8em 1em; overflow-y: auto;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 2px 1em;
}
.word-row { display: flex; align-items: center; gap: 0.45em; padding: 0.3em 0.4em; border-radius: 6px; font-size: 0.85em; border-bottom: 1px dashed rgba(255, 255, 255, 0.08); }
.word-row.unknown { color: #5f5c6a; }
.word-row .w-native { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.word-row .w-target { flex: 1; min-width: 0; color: var(--gold-soft); overflow: hidden; text-overflow: ellipsis; }
.word-row.unknown .w-target { color: #4e4b58; }
.word-row .w-arrow { color: var(--muted); }
.word-row .swatch { width: 0.85em; height: 0.85em; border-radius: 3px; border: 1px solid rgba(255, 255, 255, 0.35); flex: none; }
.w-say { border: 0; background: none; cursor: pointer; padding: 0 0.15em; font-size: 0.9em; opacity: 0.55; }
.w-say:hover { opacity: 1; }

.quest { display: flex; align-items: center; gap: 0.7em; padding: 0.5em 0.2em; border-bottom: 1px solid rgba(255, 255, 255, 0.06); }
.q-check { flex: none; width: 1.1em; height: 1.1em; border: 1px solid var(--line); border-radius: 4px; }
.quest.done .q-check { background: var(--green); border-color: var(--green); }
.quest.done .q-label { color: var(--muted); text-decoration: line-through; }
.q-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.q-label { font-size: 0.88em; }
.q-count { font-family: var(--mono); font-size: 0.78em; color: var(--muted); }

.student-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 6px; }
.student-cell { display: flex; flex-direction: column; gap: 3px; padding: 0.45em 0.6em; border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 7px; background: rgba(255, 255, 255, 0.03); font-size: 0.78em; }
.sc-id { font-family: var(--mono); color: var(--muted); text-transform: uppercase; }
.sc-time { font-family: var(--mono); color: var(--muted); font-size: 0.85em; }

.badge-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.8em; padding: 1em; overflow-y: auto; }
.badge-card { display: flex; flex-direction: column; align-items: center; gap: 0.45em; padding: 1em 0.6em; border: 1px solid var(--line); border-radius: 12px; background: rgba(255, 255, 255, 0.03); text-align: center; }
.badge-emblem { width: 4em; height: 4em; display: grid; place-items: center; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.12); background: radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.08), transparent 70%); }
.badge-emblem i { width: 2.1em; height: 2.1em; border-radius: 50%; background: rgba(255, 255, 255, 0.1); }
.badge-card.owned .badge-emblem { border-color: var(--accent); box-shadow: 0 0 26px rgba(255, 220, 140, 0.25); }
.badge-card.owned .badge-emblem i { background: var(--accent); box-shadow: inset 0 -0.3em 0 rgba(0, 0, 0, 0.25); }
.badge-card.locked { opacity: 0.6; }
.badge-name { font-size: 0.88em; color: #fff; }
.badge-stats { font-family: var(--mono); font-size: 0.7em; color: var(--muted); display: grid; gap: 2px; }

.set-row { display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: 0.55em 0.2em; border-bottom: 1px solid rgba(255, 255, 255, 0.06); font-size: 0.88em; }
.slider { width: 12em; accent-color: var(--gold); }
.toggle { width: 2.9em; height: 1.5em; border: 1px solid var(--line); border-radius: 1em; background: rgba(255, 255, 255, 0.08); cursor: pointer; padding: 0; position: relative; }
.toggle i { position: absolute; top: 3px; left: 4px; width: 1em; height: 1em; border-radius: 50%; background: #8b8a95; transition: left 0.15s ease, background 0.15s ease; }
.toggle.on { background: rgba(240, 192, 74, 0.25); border-color: var(--gold); }
.toggle.on i { left: 1.55em; background: var(--gold); }
.set-langs { display: flex; justify-content: space-between; padding: 0.7em 0.2em 0; }
.set-actions { display: flex; gap: 0.6em; justify-content: flex-end; padding-top: 0.7em; }

/* ---------------------------------------------------------------- écrans */

.screen-layer { pointer-events: auto; position: absolute; inset: 0; display: grid; opacity: 0; transition: opacity 0.35s ease; }
.screen-layer.in { opacity: 1; }

.title-screen {
  display: grid; grid-template-rows: 1fr auto auto; justify-items: center;
  padding: 3vh 1rem 2vh;
  background: linear-gradient(180deg, rgba(5, 7, 14, 0.2) 0%, rgba(5, 7, 14, 0.7) 55%, rgba(5, 7, 14, 0.92) 100%);
}
.title-logo { text-align: center; align-self: center; }
.title-logo h1 {
  margin: 0; font-family: var(--serif);
  font-size: clamp(2.2rem, 7vw, 4.6rem);
  letter-spacing: 0.2em; line-height: 0.98;
  display: flex; flex-direction: column;
  text-shadow: 0 4px 0 rgba(0, 0, 0, 0.55), 0 0 40px rgba(240, 192, 74, 0.28);
}
.title-logo h1 em { font-style: normal; color: var(--gold); letter-spacing: 0.34em; }
.tagline { margin: 0.7em 0 0; color: #cdc6b8; font-size: 0.95em; }

.title-card {
  width: min(96%, 520px); display: grid; gap: 0.8em;
  padding: 1.2em 1.4em;
  border: 1px solid var(--line); border-radius: 16px;
  background: var(--panel);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
}
.lang-block h3 { margin: 0 0 0.45em; font-size: 0.74em; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.lang-row { display: flex; gap: 0.5em; }
.lang {
  flex: 1; display: flex; align-items: center; gap: 0.5em;
  padding: 0.55em 0.7em; border: 1px solid var(--line); border-radius: 9px;
  background: rgba(255, 255, 255, 0.04); color: var(--text);
  font: inherit; font-size: 0.88em; cursor: pointer;
}
.lang:hover { background: rgba(255, 255, 255, 0.09); }
.lang.on { border-color: var(--gold); background: rgba(240, 192, 74, 0.16); color: #fff; }
.lang-flag { font-family: var(--mono); font-size: 0.78em; font-weight: 700; padding: 0.15em 0.35em; border-radius: 4px; background: rgba(255, 255, 255, 0.12); }
.title-actions { display: flex; gap: 0.6em; justify-content: center; margin-top: 0.2em; }
.title-note { margin: 0; text-align: center; font-family: var(--mono); font-size: 0.75em; color: var(--muted); }
.title-foot { display: flex; flex-direction: column; align-items: center; gap: 3px; margin-top: 1em; font-size: 0.75em; color: var(--muted); text-align: center; }
.title-foot .keys { font-family: var(--mono); opacity: 0.8; }

.intro-screen { display: grid; align-content: end; justify-items: center; padding: 0 2rem 3rem; background: linear-gradient(180deg, transparent 45%, rgba(5, 7, 14, 0.85) 100%); }
.intro-lines { text-align: center; }
.intro-line { margin: 0.35em 0; font-size: clamp(1rem, 2vw, 1.4rem); color: #fff; text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9); opacity: 0; animation: introIn 1s ease forwards; }
.intro-line:first-child { font-family: var(--mono); color: var(--gold); letter-spacing: 0.12em; font-size: 0.9em; }
@keyframes introIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.intro-skip { position: absolute; right: 18px; bottom: 18px; }

/* ------------------------------------------------------------------ duels */

.quiz-screen { display: grid; grid-template-rows: auto auto 1fr auto; padding: 1rem 1.2rem; gap: 0.6em; }
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8em; font-family: var(--mono); font-size: 0.82em; }
.quiz-prog { color: var(--gold); font-weight: 700; }
.quiz-cat { color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; }
.quiz-timer { color: #fff; }
.quiz-q { text-align: center; }
.quiz-q h2 {
  display: inline-block; margin: 0.2em 0; padding: 0.45em 1.2em;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(8, 10, 18, 0.82); backdrop-filter: blur(6px);
  font-family: var(--serif); font-size: clamp(1.1rem, 2.4vw, 1.7rem); font-weight: 600;
}
.quiz-grid { align-self: end; display: grid; grid-template-columns: 1fr 1fr; gap: 0.7em; width: min(100%, 640px); margin: 0 auto; }
.quiz-choice {
  display: flex; align-items: center; gap: 0.6em;
  padding: 0.85em 1.1em;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(14, 18, 32, 0.9); backdrop-filter: blur(6px);
  color: var(--text); font: inherit; font-size: 1em; cursor: pointer;
  transition: transform 0.08s ease, border-color 0.15s ease, background 0.15s ease;
}
.quiz-choice:hover { border-color: var(--gold); background: rgba(40, 46, 74, 0.95); transform: translateY(-2px); }
.quiz-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.8em; }
.quiz-screen.wrong { animation: shakeX 0.35s ease; }
.quiz-screen.wrong .quiz-choice { border-color: rgba(226, 86, 76, 0.7); }
@keyframes shakeX { 0%, 100% { transform: none; } 25% { transform: translateX(-9px); } 75% { transform: translateX(9px); } }

.master-screen { display: grid; grid-template-rows: auto auto auto 1fr auto; padding: 1rem 1.2rem; gap: 0.5em; }
.master-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8em; font-family: var(--mono); font-size: 0.82em; }
.m-prog { color: var(--gold); font-weight: 700; }
.m-name { color: var(--muted); text-transform: uppercase; letter-spacing: 0.14em; }
.m-time { color: #fff; }
.m-track { display: flex; gap: 2px; height: 5px; }
.m-track .seg { flex: 1; background: rgba(255, 255, 255, 0.12); border-radius: 3px; }
.m-track .seg.done { background: var(--accent); }
.m-track .seg.cur { background: #fff; }
.m-q { align-self: start; text-align: center; margin-top: 0.4em; }
.m-q h2 {
  display: inline-block; margin: 0; padding: 0.45em 1.2em;
  border: 1px solid var(--line); border-radius: 12px;
  background: rgba(8, 10, 18, 0.82); backdrop-filter: blur(6px);
  font-family: var(--serif); font-size: clamp(1.1rem, 2.4vw, 1.7rem); font-weight: 600;
}
.m-input-wrap { display: grid; place-items: center; align-self: end; }
.master-input {
  width: min(100%, 420px); padding: 0.7em 1.1em;
  border: 1px solid var(--gold); border-radius: 12px;
  background: rgba(8, 10, 18, 0.92); color: #fff;
  font-family: var(--mono); font-size: 1.15em; text-align: center; outline: none;
}
.master-input::placeholder { color: #5f5c6a; }
.master-input:focus { box-shadow: 0 0 26px rgba(240, 192, 74, 0.35); }
.master-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.8em; font-family: var(--mono); font-size: 0.76em; color: var(--muted); }
.master-screen.wrong .master-input { border-color: var(--red); animation: shakeX 0.3s ease; }

.quiz-screen.result, .master-screen.result {
  grid-template-rows: none; align-content: center; justify-items: center;
  gap: 0.7em; padding: 1.5rem; background: rgba(5, 7, 14, 0.7); backdrop-filter: blur(3px);
}
.res-title { margin: 0; font-family: var(--serif); font-size: clamp(1.4rem, 3vw, 2.1rem); letter-spacing: 0.08em; color: var(--gold); text-shadow: 0 3px 16px rgba(0, 0, 0, 0.9); }
.res-stars { font-size: 1.8em; }
.res-name { font-size: 1em; color: #fff; }
.res-medal { display: flex; align-items: center; font-size: 0.9em; color: var(--gold-soft); }
.res-stats { display: flex; gap: 2em; padding: 0.8em 1.4em; border: 1px solid var(--line); border-radius: 12px; background: rgba(10, 13, 22, 0.88); }
.res-stats div { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.res-stats span { font-size: 0.68em; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.res-stats b { font-family: var(--mono); font-size: 1em; color: #fff; }
.res-actions { display: flex; gap: 0.7em; margin-top: 0.5em; }
.master-screen.result.lost .res-title { color: var(--red); }

.badge-big {
  width: 5.5em; height: 5.5em; display: grid; place-items: center; border-radius: 50%;
  border: 2px solid var(--accent);
  background: radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.16), transparent 70%);
  box-shadow: 0 0 45px rgba(255, 220, 140, 0.45);
  animation: badgePop 0.55s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.badge-big i { width: 2.8em; height: 2.8em; border-radius: 50%; background: var(--accent); box-shadow: inset 0 -0.35em 0 rgba(0, 0, 0, 0.25); }
@keyframes badgePop { from { transform: scale(0.2); opacity: 0; } to { transform: none; opacity: 1; } }

.end-screen {
  align-content: start; justify-items: center; gap: 0.6em; padding: 2rem 1rem;
  overflow-y: auto; text-align: center;
  background: linear-gradient(180deg, rgba(5, 7, 14, 0.5), rgba(5, 7, 14, 0.9));
}
.end-title { margin: 0; font-family: var(--serif); font-size: clamp(1.6rem, 4vw, 2.6rem); letter-spacing: 0.12em; color: var(--gold); }
.end-body { margin: 0; max-width: 42em; font-size: 0.92em; color: #d6d0c3; }
.end-screen h3 { margin: 0.6em 0 0; font-size: 0.7em; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); }
.end-grid { display: flex; gap: 1em; flex-wrap: wrap; justify-content: center; }
.end-cell { display: flex; flex-direction: column; align-items: center; padding: 0.6em 1.2em; border: 1px solid var(--line); border-radius: 10px; background: rgba(10, 13, 22, 0.8); }
.end-cell b { font-family: var(--mono); font-size: 1.15em; color: #fff; }
.end-cell span { font-size: 0.66em; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.end-badges { display: flex; gap: 0.8em; flex-wrap: wrap; justify-content: center; }
.end-badge { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 0.7em 1em; border: 1px solid var(--accent); border-radius: 12px; background: rgba(255, 255, 255, 0.04); font-size: 0.8em; }
.end-badge i { width: 2.2em; height: 2.2em; border-radius: 50%; background: var(--accent); box-shadow: inset 0 -0.3em 0 rgba(0, 0, 0, 0.25), 0 0 20px rgba(255, 220, 140, 0.3); }
.end-badge em { font-style: normal; font-family: var(--mono); font-size: 0.8em; color: var(--muted); }
.end-students { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.end-student { display: flex; align-items: center; gap: 5px; padding: 0.25em 0.6em; border-radius: 6px; background: rgba(255, 255, 255, 0.05); font-family: var(--mono); font-size: 0.72em; color: var(--muted); text-transform: uppercase; }

@media (max-width: 680px) {
  .badge-grid { grid-template-columns: 1fr; }
  .word-grid { grid-template-columns: 1fr; }
  .hud-keys { display: none; }
  .quiz-grid { grid-template-columns: 1fr; }
  .res-stats { flex-wrap: wrap; justify-content: center; gap: 1em; }
}

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