:root {
  color-scheme: dark;
  --bg: #070b14;
  --panel: #0e1624;
  --panel-2: #111c2d;
  --line: #27344a;
  --line-bright: #3d4d67;
  --text: #edf4ff;
  --muted: #94a3b9;
  --dim: #687892;
  --accent: #f2a65a;
  --accent-soft: rgba(242, 166, 90, .13);
  --blue: #8eb9ee;
  --good: #71d7a1;
  --bad: #ee8176;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; overflow-x: hidden; color: var(--text); background: radial-gradient(circle at 28% -20%, #172640 0, var(--bg) 44%); font: 16px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }

.app-shell { width: min(1540px, 100%); margin: 0 auto; padding: 0 clamp(16px, 3vw, 44px) 38px; }
.topbar { min-height: 92px; display: grid; grid-template-columns: 1fr minmax(220px, 360px) 1fr; align-items: center; gap: 30px; border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; width: fit-content; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 38px; height: 38px; color: #201207; background: var(--accent); border-radius: 50%; font-size: 1.1rem; }
.brand strong, .brand small { display: block; }
.brand strong { font: 600 1rem/1.2 Georgia, serif; letter-spacing: .015em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; }
.round-meter { display: grid; gap: 9px; justify-self: center; width: min(100%, 360px); color: var(--muted); font-size: .76rem; letter-spacing: .1em; text-align: center; text-transform: uppercase; }
.meter-track { height: 2px; overflow: hidden; background: var(--line); }
.meter-track span { display: block; width: 10%; height: 100%; background: var(--accent); transition: width .35s ease; }
.score-box { justify-self: end; display: flex; align-items: baseline; gap: 10px; }
.score-box small { color: var(--muted); font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; }
.score-box strong { font: 500 2rem/1 Georgia, serif; font-variant-numeric: tabular-nums; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(320px, .75fr); min-height: calc(100vh - 132px); border-bottom: 1px solid var(--line); }
.sky-panel { display: grid; grid-template-rows: 44px minmax(480px, 1fr) 44px; min-width: 0; padding-right: clamp(20px, 3vw, 46px); border-right: 1px solid var(--line); }
.sky-toolbar, .sky-footer { display: flex; align-items: center; justify-content: space-between; color: var(--dim); font: 650 .69rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .08em; text-transform: uppercase; }
.status { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.status i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }
.canvas-wrap { position: relative; min-height: 480px; overflow: hidden; border: 1px solid #25334a; border-radius: 3px; background: #000; box-shadow: 0 24px 80px rgba(0,0,0,.24); }
.canvas-wrap:fullscreen { width: 100vw; height: 100vh; min-height: 100vh; border: 0; }
#skyCanvas { display: block; width: 100%; height: 100%; touch-action: none; }
.canvas-wrap::after { content: none; }
.reticle { position: absolute; inset: 50% auto auto 50%; width: 20px; height: 20px; opacity: .22; transform: translate(-50%, -50%); pointer-events: none; }
.reticle span { position:absolute; background: var(--blue); }
.reticle span:nth-child(1), .reticle span:nth-child(2) { width: 6px; height: 1px; top: 50%; }
.reticle span:nth-child(1) { left: 0; } .reticle span:nth-child(2) { right: 0; }
.reticle span:nth-child(3), .reticle span:nth-child(4) { width: 1px; height: 6px; left: 50%; }
.reticle span:nth-child(3) { top: 0; } .reticle span:nth-child(4) { bottom: 0; }
.loading-state, .error-state { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; gap: 14px; padding: 30px; color: var(--muted); background: #050a13; text-align: center; }
.loading-state p, .error-state p { margin: 0; }
.loader { width: 28px; height: 28px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(1turn); } }
.error-state strong { color: var(--text); font-size: 1.05rem; }
.error-state code { color: var(--accent); }
[hidden] { display: none !important; }
.feedback-card { position: absolute; z-index: 3; left: 22px; bottom: 22px; max-width: min(360px, calc(100% - 44px)); padding: 18px 20px; border: 1px solid rgba(142,185,238,.36); background: rgba(8,14,25,.9); box-shadow: 0 16px 50px rgba(0,0,0,.35); backdrop-filter: blur(12px); }
.feedback-card span { display: block; margin-bottom: 4px; color: var(--good); font-size: .7rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.feedback-card.incorrect span { color: var(--bad); }
.feedback-card strong { display: block; font: 500 1.65rem/1.15 Georgia, serif; }
.feedback-card p { margin: 5px 0 0; color: var(--muted); font-size: .85rem; }
.icon-button { width: 32px; height: 32px; padding: 0; color: var(--muted); border: 0; background: transparent; cursor: pointer; font-size: 1.1rem; }
.icon-button:hover { color: var(--text); }

.control-panel { padding: clamp(28px, 4vw, 56px) 0 28px clamp(24px, 4vw, 56px); }
.control-panel section + section { margin-top: 48px; padding-top: 42px; border-top: 1px solid var(--line); }
.section-index { color: var(--accent); font: 750 .68rem/1 ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .14em; }
h1, h2 { margin: 13px 0 22px; font-family: Georgia, "Times New Roman", serif; font-weight: 500; letter-spacing: -.025em; }
h1 { max-width: 380px; font-size: clamp(1.65rem, 2.5vw, 2.35rem); line-height: 1.12; }
h2 { font-size: clamp(1.4rem, 2.1vw, 1.9rem); }
.mode-switch { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode { min-width: 0; padding: 13px 9px 12px; color: var(--muted); border: 1px solid var(--line); border-radius: 2px; background: rgba(15,24,39,.64); cursor: pointer; text-align: left; transition: color .18s,border-color .18s,background .18s; }
.mode:hover { border-color: var(--line-bright); }
.mode.active { color: var(--text); border-color: var(--accent); background: var(--accent-soft); }
.mode span, .mode small { display: block; overflow: hidden; text-overflow: ellipsis; }
.mode span { font-size: .82rem; font-weight: 700; }
.mode small { margin-top: 3px; color: var(--dim); font-size: .66rem; white-space: nowrap; }
.mode.active small { color: #cda77e; }
.answers { display: grid; gap: 10px; }
.instructions { color: var(--muted); margin: 0 0 28px; font-size: 1rem; }
.answer { position: relative; display: grid; grid-template-columns: 30px 1fr auto; align-items: center; gap: 10px; width: 100%; min-height: 55px; padding: 10px 14px; color: var(--text); border: 1px solid var(--line); border-radius: 2px; background: rgba(15,24,39,.66); cursor: pointer; text-align: left; transition: transform .15s,border-color .15s,background .15s; }
.answer:hover:not(:disabled), .answer:focus-visible { transform: translateX(3px); border-color: #60708c; outline: none; }
.answer .key { display: grid; place-items: center; width: 25px; height: 25px; color: var(--muted); border: 1px solid var(--line); font: 700 .7rem/1 ui-monospace, monospace; }
.answer .name { font-weight: 650; }
.answer .mark { color: transparent; font-size: 1.1rem; }
.answer.correct { border-color: var(--good); background: rgba(113,215,161,.08); }
.answer.correct .mark { color: var(--good); }
.answer.wrong { border-color: var(--bad); background: rgba(238,129,118,.08); }
.answer.wrong .mark { color: var(--bad); }
.answer:disabled { cursor: default; }
.next-button, .result-panel button { display: flex; align-items: center; justify-content: space-between; width: 100%; margin-top: 16px; padding: 15px 17px; color: #211306; border: 1px solid var(--accent); border-radius: 2px; background: var(--accent); cursor: pointer; font-weight: 800; }
.next-button:hover, .result-panel button:hover { background: #ffc17b; }
.key-hint { margin: 18px 0 0; color: var(--dim); font-size: .72rem; }
kbd { display: inline-grid; place-items: center; min-width: 20px; min-height: 20px; padding: 0 4px; border: 1px solid var(--line); border-radius: 3px; background: #101827; font: 700 .65rem/1 ui-monospace, monospace; }

.result-overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: rgba(3,6,12,.82); backdrop-filter: blur(13px); }
.result-panel { width: min(430px,100%); padding: 42px; border: 1px solid var(--line-bright); background: linear-gradient(145deg,#111b2b,#0b111d); box-shadow: 0 28px 100px rgba(0,0,0,.55); text-align: center; }
.result-label { margin: 28px 0 0; color: var(--muted); }
.result-score { display: flex; justify-content: center; align-items: baseline; gap: 8px; margin: 4px 0 18px; font: 500 6rem/1 Georgia, serif; }
.result-score small { color: var(--muted); font: 500 1.5rem/1 Georgia, serif; }
.result-panel > p:last-of-type { color: var(--muted); }
.result-panel button { margin-top: 28px; }
.result-panel a { display: inline-block; margin-top: 22px; color: var(--muted); font-size: .85rem; }

@media (max-width: 980px) {
  .topbar { grid-template-columns: 1fr auto; }
  .round-meter { grid-column: 1 / -1; grid-row: 2; width: 100%; padding-bottom: 17px; }
  .game-layout { grid-template-columns: 1fr; }
  .sky-panel { min-height: min(72vh, 700px); padding-right: 0; border-right: 0; }
  .control-panel { padding-left: 0; }
  .control-panel section + section { margin-top: 34px; padding-top: 34px; }
}

@media (max-width: 600px) {
  .app-shell { padding-inline: 12px; }
  .topbar { min-height: 78px; gap: 16px; }
  .brand small { display: none; }
  .brand-mark { width: 34px; height: 34px; }
  .sky-panel { grid-template-rows: 38px minmax(410px, 58vh) 38px; min-height: 0; }
  .canvas-wrap { min-height: 410px; }
  .sky-toolbar span:last-child { display: none; }
  .mode-switch { grid-template-columns: 1fr; }
  .mode { display: grid; grid-template-columns: 1fr auto; align-items: center; }
  .mode small { margin: 0; }
  .feedback-card { left: 12px; bottom: 12px; max-width: calc(100% - 24px); }
  .key-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; } }


/* ===== Player, timer, points and leaderboard ===== */

.hud-stats {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 26px;
}

.timer-box,
.score-box {
  display: flex;
  align-items: baseline;
  gap: 9px;
}

.timer-box small,
.score-box small {
  color: var(--muted);
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
}

.timer-box strong,
.score-box strong {
  font: 500 2rem/1 Georgia, serif;
  font-variant-numeric: tabular-nums;
}

.timer-unit {
  margin-left: 2px;
  color: var(--dim);
  font: 600 .72rem/1 ui-sans-serif, system-ui, sans-serif;
}

.timer-box.warning strong { color: var(--accent); }
.timer-box.danger strong { color: var(--bad); }

.leaderboard-section {
  margin-top: 48px;
  padding-top: 42px;
  border-top: 1px solid var(--line);
}

.leaderboard-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 14px;
}

.leaderboard-heading h2 {
  margin: 7px 0 0;
}

.leaderboard-heading > span,
.leaderboard-heading.compact span {
  color: var(--dim);
  font-size: .72rem;
  text-align: right;
}

.leaderboard-heading.compact {
  align-items: baseline;
  margin-bottom: 10px;
}

.leaderboard-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  border-bottom: 1px solid rgba(39,52,74,.72);
}

.leaderboard-rank {
  color: var(--dim);
  font: 700 .7rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-points {
  font-variant-numeric: tabular-nums;
}

.leaderboard-list li.current-player {
  color: var(--accent);
}

.leaderboard-empty {
  display: block !important;
  padding: 9px 0;
  color: var(--muted);
  font-size: .85rem;
}

.result-leaderboard {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  text-align: left;
}

.result-leaderboard .leaderboard-list {
  max-height: 185px;
  overflow-y: auto;
}

.player-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(3,6,12,.9);
  backdrop-filter: blur(13px);
}

.player-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: clamp(28px, 5vw, 44px);
  border: 1px solid var(--line-bright);
  background: linear-gradient(145deg,#111b2b,#0b111d);
  box-shadow: 0 28px 100px rgba(0,0,0,.55);
}

.player-card h1 {
  max-width: none;
  margin-bottom: 12px;
}

.player-card > p {
  margin: 0 0 26px;
  color: var(--muted);
}

.player-card label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.player-form-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.player-form-row input,
.player-form-row button {
  min-height: 48px;
  border-radius: 2px;
  font: inherit;
}

.player-form-row input {
  min-width: 0;
  padding: 0 14px;
  color: var(--text);
  border: 1px solid var(--line-bright);
  background: #080e19;
  outline: none;
}

.player-form-row input:focus {
  border-color: var(--accent);
}

.player-form-row button {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  color: #211306;
  border: 1px solid var(--accent);
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

.player-form-row button:hover {
  background: #ffc17b;
}

.form-error {
  margin: 8px 0 0 !important;
  color: var(--bad) !important;
  font-size: .82rem;
}

.start-leaderboard {
  margin-top: 30px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

@media (max-width: 980px) {
  .hud-stats { grid-column: 2; grid-row: 1; }
}

@media (max-width: 600px) {
  .hud-stats { gap: 14px; }
  .timer-box, .score-box { display: grid; gap: 1px; text-align: right; }
  .timer-box small, .score-box small { display: block; font-size: .62rem; }
  .timer-box strong, .score-box strong { font-size: 1.42rem; }
  .player-form-row { grid-template-columns: 1fr; }
  .leaderboard-heading { align-items: baseline; }
}


/* ===== Language switch ===== */

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.language-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 10px 6px;
  color: var(--muted);
  border: 1px solid var(--line-bright);
  border-radius: 999px;
  background: rgba(15,24,39,.62);
  text-decoration: none;
  font: 600 .78rem/1.1 Tahoma, Arial, sans-serif;
  white-space: nowrap;
  transition: color .18s, border-color .18s, background .18s;
}

.language-button:hover,
.language-button:focus-visible {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

@media (max-width: 600px) {
  .brand-group { gap: 8px; }
  .language-button {
    min-height: 28px;
    padding: 4px 8px 5px;
    font-size: .72rem;
  }
}


/* Language switch visible on the opening player panel */
.player-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}

.player-topline .language-button {
  flex: 0 0 auto;
}
