/* ==========================================================================
   Atlas — a night-sky palette, laid out for a phone first and widened for
   larger screens at 900px.
   ========================================================================== */

:root {
  --bg: #070b16;
  --bg-raise: #0e1527;
  --bg-sunken: #060a14;
  --line: #1f2b45;
  --line-soft: #16203a;

  --ink: #eef3ff;
  --ink-dim: #93a1c0;
  --ink-faint: #5f6d8c;

  --land: #1b2440;
  --land-edge: #2c3a5c;
  --land-region: #27345a;
  --ocean-edge: #16233f;

  --gold: #ffc24b;
  --flame: #ff7a45;
  --mint: #34e5a0;
  --rose: #ff4d6d;

  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-full: 999px;

  --pad: clamp(16px, 4vw, 28px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  --font-display: "Space Grotesk", ui-sans-serif, system-ui, sans-serif;
  --font-ui: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

/* Pinned so the iOS keyboard slides over a fixed page instead of scrolling it. */
body {
  position: fixed;
  inset: 0;
  width: 100%;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* A slow wash of colour behind everything. */
.aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(42% 38% at 18% 12%, rgba(84, 120, 255, 0.22), transparent 70%),
    radial-gradient(46% 40% at 86% 8%, rgba(255, 122, 69, 0.14), transparent 70%),
    radial-gradient(60% 50% at 50% 104%, rgba(52, 229, 160, 0.12), transparent 72%);
  filter: blur(14px);
  animation: drift 26s ease-in-out infinite alternate;
}
@keyframes drift {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to   { transform: translate3d(2%, 2%, 0) scale(1.08); }
}

/* ── Screens ─────────────────────────────────────────────────────────── */

.screen {
  position: relative;
  z-index: 1;
  display: none;
  height: var(--app-h, 100dvh);
  max-height: var(--app-h, 100dvh);
}
.screen.is-active { display: grid; }

/* ── Start ───────────────────────────────────────────────────────────── */

#screen-start {
  grid-template-rows: auto 1fr auto;
  gap: clamp(14px, 2.4vh, 26px);
  padding: calc(var(--safe-t) + var(--pad)) var(--pad) 0;
  overflow-y: auto;
  justify-items: center;
}
#screen-start > * { width: min(860px, 100%); }

.masthead { text-align: center; }

.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.6rem, 11vw, 4.6rem);
  letter-spacing: -0.04em;
  line-height: 0.95;
  background: linear-gradient(135deg, #ffffff 10%, var(--gold) 55%, var(--flame) 95%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline {
  margin: 0.5rem 0 0;
  color: var(--ink-dim);
  font-size: clamp(0.95rem, 3.4vw, 1.1rem);
}

.section-label {
  margin: 0 0 0.6rem;
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.mode-card {
  position: relative;
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 6px;
  min-height: 112px;
  padding: 10px 12px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: linear-gradient(170deg, var(--bg-raise), var(--bg-sunken));
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.18s, transform 0.18s, background 0.18s;
}
.mode-card:hover { border-color: #38496f; }
.mode-card:active { transform: scale(0.985); }

.mode-card.is-on {
  border-color: var(--gold);
  background: linear-gradient(170deg, rgba(255, 194, 75, 0.14), rgba(255, 122, 69, 0.05));
  box-shadow: 0 0 0 1px rgba(255, 194, 75, 0.35), 0 10px 30px -14px rgba(255, 150, 60, 0.6);
}
.mode-card.is-on .mode-thumb path { fill: var(--gold); opacity: 0.95; }

.mode-thumb {
  width: 100%;
  height: 100%;
  min-height: 44px;
  overflow: visible;
}
.mode-thumb path {
  fill: #44557e;
  opacity: 0.75;
  transition: fill 0.18s, opacity 0.18s;
}

.mode-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
  line-height: 1.2;
}
.mode-blurb {
  font-size: 0.75rem;
  color: var(--ink-faint);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--bg-sunken);
}
.seg {
  min-height: 46px;
  border: 0;
  border-radius: var(--r-full);
  background: transparent;
  color: var(--ink-dim);
  font: 600 0.95rem/1 var(--font-ui);
  cursor: pointer;
  transition: background 0.18s, color 0.18s;
}
.seg.is-on {
  background: linear-gradient(135deg, var(--gold), var(--flame));
  color: #2a1403;
}

.start-dock {
  position: sticky;
  bottom: 0;
  display: grid;
  gap: 8px;
  padding: 16px 0 calc(var(--safe-b) + 16px);
  background: var(--bg);
}
/* A short fade above the solid dock, so cards scroll out rather than collide. */
.start-dock::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 28px;
  background: linear-gradient(to top, var(--bg), transparent);
  pointer-events: none;
}
.start-dock .section-label { margin: 0; text-align: center; }

/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5ch;
  min-height: 48px;
  padding: 0 1.3rem;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  font: 600 1rem/1 var(--font-ui);
  cursor: pointer;
  transition: transform 0.14s, filter 0.18s, background 0.18s, border-color 0.18s;
}
.btn:active { transform: scale(0.97); }
.btn-lg { width: 100%; min-height: 56px; font-size: 1.05rem; }

.btn-primary {
  background: linear-gradient(135deg, var(--gold), var(--flame));
  color: #2a1403;
  box-shadow: 0 12px 34px -16px rgba(255, 140, 60, 0.9);
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-primary:disabled { opacity: 0.45; box-shadow: none; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink-dim);
}
.btn-ghost:hover { border-color: #3a4a70; color: var(--ink); }

.btn-detail { font-weight: 500; opacity: 0.72; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  background: var(--bg-raise);
  color: var(--ink-dim);
  cursor: pointer;
}
.icon-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:hover { color: var(--ink); border-color: #3a4a70; }

:where(button, input):focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ── Game ────────────────────────────────────────────────────────────── */

.game {
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 0;
}

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--safe-t) + 10px) var(--pad) 10px;
}
.hud-progress { flex: 1; min-width: 0; }
.progress-track {
  height: 5px;
  border-radius: var(--r-full);
  background: var(--line-soft);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0;
  border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--gold), var(--flame));
  transition: width 0.4s cubic-bezier(0.22, 1, 0.36, 1);
}
.hud-count {
  display: block;
  margin-top: 5px;
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.hud-score { display: flex; align-items: center; gap: 8px; flex: none; }
.score-num {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.streak {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  background: rgba(255, 122, 69, 0.16);
  color: var(--gold);
  font-size: 0.8rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.map-stage {
  position: relative;
  min-height: 0;
  padding: 0 clamp(6px, 2vw, 16px);
}
.map { display: block; width: 100%; height: 100%; }

.graticule path {
  fill: none;
  stroke: #1b2744;
  stroke-width: 0.6;
  opacity: 0.6;
}
#layer-sphere path {
  fill: url(#ocean);
  stroke: var(--ocean-edge);
  stroke-width: 1;
}
.context path {
  fill: var(--land);
  stroke: var(--land-edge);
  stroke-width: 0.5;
  stroke-linejoin: round;
}
.region path {
  fill: var(--land-region);
  stroke: #3d5080;
  stroke-width: 0.65;
  stroke-linejoin: round;
}
.target path {
  fill: url(#targetFill);
  stroke: #fff3d6;
  stroke-width: 0.9;
  stroke-linejoin: round;
  filter: url(#glow);
  animation: throb 2.4s ease-in-out infinite;
}
@keyframes throb {
  0%, 100% { opacity: 0.88; }
  50%      { opacity: 1; }
}
.map.is-right .target path { fill: url(#rightFill); stroke: #d6fff0; animation: none; }
.map.is-wrong .target path { fill: url(#wrongFill); stroke: #ffe1e8; animation: none; }

/* The loupe magnifies targets too small to read at the region's zoom. */
.loupe-ring {
  fill: none;
  stroke: rgba(255, 194, 75, 0.55);
  stroke-width: 1.5;
}
.loupe-bg { fill: #0a1120; }
.loupe-tether {
  stroke: rgba(255, 194, 75, 0.38);
  stroke-width: 1;
  stroke-dasharray: 3 3;
  fill: none;
}
.locator {
  fill: none;
  stroke: var(--gold);
  stroke-width: 1.5;
  opacity: 0.9;
  animation: ping 1.9s ease-out infinite;
  transform-box: fill-box;
  transform-origin: center;
}
@keyframes ping {
  0%   { opacity: 0.9; transform: scale(0.7); }
  70%  { opacity: 0;   transform: scale(1.5); }
  100% { opacity: 0;   transform: scale(1.5); }
}

/* ── Answer console ──────────────────────────────────────────────────── */

.console {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 12px var(--pad) calc(var(--safe-b) + 14px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}

.verdict {
  min-height: 1.5rem;
  font-family: var(--font-display);
  font-size: clamp(1rem, 4.4vw, 1.25rem);
  font-weight: 600;
  letter-spacing: -0.01em;
  text-align: center;
}
.verdict.is-right { color: var(--mint); }
.verdict.is-wrong { color: var(--rose); }
.verdict .answer-name { color: var(--ink); }

.answer { display: grid; gap: 10px; }
.field { position: relative; }

.answer-input {
  width: 100%;
  min-height: 54px;
  padding: 0 1rem;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-sunken);
  color: var(--ink);
  /* 16px keeps iOS from zooming the viewport on focus. */
  font: 500 1.05rem/1 var(--font-ui);
  transition: border-color 0.18s, box-shadow 0.18s;
}
.answer-input::placeholder { color: var(--ink-faint); }
.answer-input:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(255, 194, 75, 0.16);
}

/* Opens upward so the on-screen keyboard never covers it. */
.suggestions {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 20;
  max-height: min(46vh, 320px);
  margin: 0;
  padding: 6px;
  list-style: none;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: #0c1326;
  box-shadow: 0 24px 50px -20px #000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.suggestion {
  padding: 11px 12px;
  border-radius: var(--r-sm);
  font-size: 0.98rem;
  cursor: pointer;
}
.suggestion mark {
  background: none;
  color: var(--gold);
  font-weight: 600;
}
.suggestion.is-active,
.suggestion:hover { background: #16203a; }

/* Flex, not grid: when Skip hides after an answer, the primary button
   takes the whole row on its own. */
.answer-actions {
  display: flex;
  gap: 10px;
}
.answer-actions .btn-ghost { flex: 0 0 auto; }
.answer-actions .btn-primary { flex: 1; }

/* ── Results ─────────────────────────────────────────────────────────── */

.done {
  place-items: center;
  padding: calc(var(--safe-t) + var(--pad)) var(--pad) calc(var(--safe-b) + var(--pad));
  overflow-y: auto;
}
.done-card {
  width: min(560px, 100%);
  display: grid;
  gap: 14px;
  text-align: center;
}
.done-grade {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}
.done-score {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.6rem, 13vw, 4rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1;
}
.done-sub { margin: 0; color: var(--ink-dim); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 4px 0 0;
}
.stat {
  padding: 12px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--bg-raise);
}
.stat dt {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.stat dd {
  margin: 4px 0 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.missed { text-align: left; }
.missed-list {
  display: grid;
  gap: 6px;
  max-height: 34vh;
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}
.missed-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: var(--r-sm);
  background: var(--bg-raise);
  font-size: 0.92rem;
}
.missed-list .said {
  color: var(--ink-faint);
  font-size: 0.82rem;
  text-align: right;
}
.done-actions { display: grid; gap: 8px; margin-top: 4px; }

/* ── Loading ─────────────────────────────────────────────────────────── */

.loading {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  background: var(--bg);
  color: var(--ink-dim);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  transition: opacity 0.4s;
}
.loading.is-gone { opacity: 0; pointer-events: none; }
.spinner {
  width: 30px;
  height: 30px;
  border: 2px solid var(--line);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.shake { animation: shake 0.42s cubic-bezier(0.36, 0.07, 0.19, 0.97); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-7px); }
  40%, 60% { transform: translateX(7px); }
}

/* ── Landscape phones: the map needs the height more than the chrome ─── */

@media (max-height: 520px) and (orientation: landscape) and (max-width: 899px) {
  .game { grid-template-columns: 1fr minmax(260px, 34%); grid-template-rows: auto 1fr; }
  .hud { grid-column: 1 / -1; padding-top: calc(var(--safe-t) + 6px); padding-bottom: 6px; }
  .console {
    padding-top: 0;
    align-content: center;
    background: none;
  }
  .verdict { min-height: 0; }
}

/* ── Desktop ─────────────────────────────────────────────────────────── */

@media (min-width: 900px) {
  .mode-grid { grid-template-columns: repeat(4, 1fr); gap: 12px; }
  .mode-card { min-height: 142px; }

  #screen-start {
    align-content: center;
    gap: 26px;
    padding-bottom: var(--pad);
  }
  .start-dock {
    position: static;
    background: none;
    gap: 10px;
    padding: 0;
    background: none;
    justify-self: center;
    width: min(380px, 100%);
  }
  #screen-start .picker { justify-self: center; }
  .section-label { text-align: center; }
  .start-dock::before { content: none; }

  .game {
    grid-template-columns: minmax(0, 1fr) 390px;
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas:
      "hud hud"
      "map console";
    column-gap: 8px;
  }
  .hud { grid-area: hud; padding-inline: clamp(20px, 3vw, 40px); }
  .map-stage { grid-area: map; padding: 0 0 20px clamp(20px, 3vw, 40px); }
  .console {
    grid-area: console;
    align-content: center;
    gap: 16px;
    padding: 0 clamp(20px, 3vw, 40px) 20px 0;
    background: none;
  }
  .verdict { min-height: 3.2rem; text-align: left; display: grid; align-content: center; }

  /* Space below in the sidebar, so the list reads better dropping down. */
  .suggestions { bottom: auto; top: calc(100% + 8px); max-height: 330px; }

  .done-actions { grid-template-columns: 1fr 1fr; }
}

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

/* Card text stacks; the silhouette is clipped to its box. */
.mode-name, .mode-blurb { display: block; }
.mode-thumb { overflow: hidden; }

/* Class-level `display` would otherwise beat the UA rule for [hidden]. */
[hidden] { display: none !important; }
