:root {
  --bg: #0f1115;
  --panel: rgba(20, 23, 30, 0.88);
  --panel-solid: #171a21;
  --line: rgba(255, 255, 255, 0.07);
  --hover: rgba(255, 255, 255, 0.04);
  --text: #e8e8ec;
  --muted: #8b919c;
  --dim: #5c626d;
  --accent: #f0a24b;
  --accent-soft: rgba(240, 162, 75, 0.14);
  --accent-ring: rgba(240, 162, 75, 0.35);
  --good: #4caf7d;
  --good-soft: rgba(76, 175, 125, 0.14);
  --bad: #e0625f;
  /* score levels 0-5: distinct tier hues, bad -> good (violet = mastered) */
  --lvl-0: #e5534b;
  --lvl-1: #f08a3a;
  --lvl-2: #e3c243;
  --lvl-3: #6fbf5a;
  --lvl-4: #38b2c2;
  --lvl-5: #9b86f5;
  --lvl-5-soft: rgba(155, 134, 245, 0.14);
  --radius: 0;
  --sidebar: 264px;
  --pad: 10px;
  --globe-w: 312px;
  --globe-h: 187px;
  --osk-h: 0px; /* screen height covered by the on-screen keyboard (phones) */
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body {
  position: relative;
}

button, input {
  font: inherit;
  color: inherit;
}

/* ---------- map ---------- */

.map-box {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  /* Phones: taller than the screen by the keyboard's height and slid up so
     the map centres above the keyboard (see slideMap in app.js). */
  height: calc(100% + var(--osk-h));
  transform: translateY(calc(-1 * var(--map-shift, 0px)));
  transition: transform var(--map-slide-ms, 0ms) ease-in-out;
  touch-action: none;
}

#map-canvas {
  position: absolute;
  inset: 0;
  display: block;
}

/* Labels only; the geometry is on the canvas underneath. */
#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  pointer-events: none;
}

.globe-sphere {
  fill: #1c2029;
  stroke: none;
}

/* Fills are drawn as lon/lat tiles; a same-colour hairline stroke hides the
   anti-aliasing seams between adjacent tiles. */
.country {
  fill: #3a4050;
  stroke: #3a4050;
  stroke-width: 0.7;
  stroke-linejoin: round;
}

.country.target {
  fill: var(--accent);
  stroke: var(--accent);
}

.borders {
  fill: none;
  stroke: #0f1115;
  stroke-width: 0.6;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.country-label {
  fill: var(--muted);
  font-size: 11px;
  text-anchor: middle;
  dominant-baseline: middle;
  paint-order: stroke;
  stroke: var(--bg);
  stroke-width: 3px;
  stroke-linejoin: round;
  pointer-events: none;
}

/* the correct answer, shown after a wrong guess */
.country-label.reveal {
  fill: #fff;
  font-size: 15px;
  font-weight: 700;
  stroke: rgba(15, 17, 21, 0.85);
  stroke-width: 4px;
}

/* ---------- sidebars ---------- */

.continents {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar);
  /* No backdrop blur: the compositor would re-blur this strip on every
     map frame during flights. */
  background: var(--panel);
  z-index: 10;
  padding: var(--pad);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.section-title {
  margin: 0 0 8px;
  padding: 5px 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.06);
}

/* ---------- packs ---------- */

.continent-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.continent-row {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  column-gap: 8px;
  width: 100%;
  padding: 4px 10px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  text-align: left;
  cursor: pointer;
  transition: background 120ms ease, color 120ms ease;
}

.continent-row:hover {
  background: var(--hover);
  color: var(--text);
}

.continent-row.selected {
  background: var(--accent-soft);
  color: var(--text);
}

.continent-row.selected::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--accent);
}

.continent-row:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-ring);
}

.continent-name {
  font-weight: 500;
}

.continent-score {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* pack at 100% */
.continent-row.complete {
  color: var(--lvl-5);
}

.continent-row.complete.selected {
  background: var(--lvl-5-soft);
  color: var(--lvl-5);
}

.continent-row.complete.selected::before {
  background: var(--lvl-5);
}

.progress-stat {
  margin-bottom: 8px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: center;
}


/* ---------- chart ---------- */

.chart-section {
  margin-top: 0;
}

.score-chart {
  width: 100%;
  height: 125px;
  display: block;
  overflow: visible;
}

.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-label {
  fill: var(--dim);
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.chart-area {
  opacity: 0.12;
}

.chart-line {
  fill: none;
  stroke-width: 1.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-dot {
  stroke: var(--bg);
  stroke-width: 1.5;
}


/* ---------- buttons & input ---------- */

.btn {
  padding: 9px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  line-height: 1.2;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
}

.btn:active {
  background: rgba(255, 255, 255, 0.12);
}

.btn:disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--accent-ring);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1a1206;
}

.btn.primary:hover {
  background: #f5b064;
  border-color: #f5b064;
}

.btn.quiet {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  padding-left: 8px;
  padding-right: 8px;
}

.btn.quiet:hover {
  background: var(--hover);
  color: var(--text);
}

.btn.danger {
  background: rgba(224, 98, 95, 0.1);
  border-color: rgba(224, 98, 95, 0.3);
  color: #f0a09d;
}

.btn.danger:hover {
  background: rgba(224, 98, 95, 0.18);
  border-color: rgba(224, 98, 95, 0.5);
  color: #f7b8b6;
}

.btn.danger:active {
  background: rgba(224, 98, 95, 0.26);
}

/* Menu + Reset, pinned to the bottom of the sidebar */
.sidebar-actions {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: auto;
}

/* World view: only the pack list (pick one to start). Pack view: the
   pack's progress and answers; Menu goes back to the world view. */
body.globe-mode .globe-box,
body.globe-mode .chart-section,
body.globe-mode .answers-section,
body.globe-mode .sidebar-actions,
body:not(.globe-mode) .pack-section {
  display: none;
}

/* ---------- mini globe (floats over the map, bottom right) ---------- */

.globe-box {
  position: absolute;
  bottom: 12px;
  right: 12px;
  width: var(--globe-w);
  height: var(--globe-h);
  z-index: 10;
  pointer-events: none;
}

/* Drawn on a canvas; colours live in app.js (MINI_COLORS). No CSS filter:
   a per-frame drop-shadow on a changing canvas is a hidden compositor cost. */
#mini-map {
  width: 100%;
  height: 100%;
  display: block;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  min-height: 123px; /* room for 4 rows so the layout doesn't shift */
}

.history-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius);
}

.history-mark {
  width: 6px;
  height: 6px;
  flex-shrink: 0;
  font-size: 0; /* hide the glyph; the dot carries the meaning */
}

.history-row.good .history-mark { background: var(--good); }
.history-row.bad .history-mark { background: var(--bad); }

.history-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delta {
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 2.4em;
  text-align: right;
}

.history-delta.up { color: var(--good); }
.history-delta.down { color: var(--bad); }
.history-delta.flat { color: var(--dim); }

/* score pips: filled ones take the level colour via currentColor */
.history-pips {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.pip {
  width: 5px;
  height: 10px;
  background: rgba(255, 255, 255, 0.08);
}

.pip.on {
  background: currentColor;
}

.history-row.flash {
  animation: history-flash 1s ease-out forwards;
}

.history-row.good.flash { --flash: rgba(76, 175, 125, 0.28); }
.history-row.bad.flash { --flash: rgba(224, 98, 95, 0.28); }

@keyframes history-flash {
  from { background: var(--flash); }
  to { background: transparent; }
}

/* ---------- bottom bar ---------- */

.bottom-bar {
  position: absolute;
  bottom: 0;
  left: var(--sidebar);
  right: calc(var(--globe-w) + 12px); /* keep clear of the mini globe */
  z-index: 10;
  padding: 24px 16px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.bottom-bar > * {
  pointer-events: auto;
}

.answer-form {
  display: flex;
  gap: 6px;
  width: 100%;
  max-width: 460px;
}

.answer-input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-solid);
  color: var(--text);
  font-size: 14px;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}

.answer-input::placeholder {
  color: var(--dim);
}

.answer-input:focus {
  outline: none;
  border-color: var(--accent);
}

.answer-input:disabled {
  opacity: 0.6;
}

.warning {
  font-size: 12px;
  color: var(--accent);
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

.warning:empty {
  display: none;
}

/* ---------- responsive ---------- */

@media (max-width: 800px) {
  :root {
    --sidebar: 160px;
    --pad: 10px;
  }
  body {
    font-size: 12px;
  }
  :root {
    --globe-w: 180px;
    --globe-h: 108px;
  }
}

@media (max-width: 560px) {
  /* The globe is a circle the box's height across, centred in a 5:3 box;
     the negative right offset makes its visible gap at the side match the
     top one. */
  :root {
    --globe-w: 156px;
    --globe-h: 94px;
  }
  .section-title,
  .score-chart,
  .menu-text,
  #reset {
    display: none;
  }

  /* No sidebar column: its sections float over the full-width map. */
  .continents {
    width: auto;
    right: 0;
    background: none;
    padding: 0;
    pointer-events: none;
  }
  .continents > * {
    pointer-events: auto;
  }

  /* World view: the region list, centred and larger; no answer box. */
  body.globe-mode .continents {
    justify-content: center;
    align-items: center;
  }
  body.globe-mode .bottom-bar {
    display: none;
  }
  .continent-list {
    gap: 8px;
  }
  .continent-row {
    min-width: 220px;
    font-size: 18px;
    padding: 11px 18px;
    column-gap: 24px;
    align-items: center;
    border: 1px solid var(--line);
    background: rgba(28, 32, 41, 0.85);
    color: var(--text);
  }
  .continent-row:active {
    background: rgba(58, 64, 80, 0.95);
  }
  .continent-score {
    font-size: 15px;
  }

  /* Map view: hamburger + score top left, globe top right. */
  .sidebar-actions {
    position: absolute;
    top: 10px;
    left: 10px;
    margin: 0;
  }
  #menu {
    padding: 6px 10px;
    font-size: 18px;
    line-height: 1;
    background: rgba(15, 17, 21, 0.6);
  }
  .chart-section {
    position: absolute;
    top: 10px;
    left: 58px;
    height: 32px;
    display: flex;
    align-items: center;
  }
  .progress-stat {
    margin: 0;
    font-size: 18px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  }
  .globe-box {
    top: 10px;
    bottom: auto;
    right: calc(10px - (var(--globe-w) - var(--globe-h)) / 2);
  }
  /* Map labels are in viewBox units, which a phone shrinks a lot. */
  .country-label {
    font-size: 16.5px;
    stroke-width: 4px;
  }
  .country-label.reveal {
    font-size: 22.5px;
    stroke-width: 5px;
  }

  /* Recent answers float bottom left, above the answer box, and fade out
     5s after they're added. */
  .answers-section {
    position: absolute;
    left: 6px;
    bottom: calc(var(--osk-h) + 58px);
    width: 60%;
  }
  .history-list {
    min-height: 0;
    flex-direction: column-reverse;
  }
  .history-row {
    padding: 3px 6px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
    animation: history-fade 5.4s linear calc(-1 * var(--age, 0ms)) forwards;
  }
  .history-row.flash {
    animation: history-flash 1s ease-out forwards,
      history-fade 5.4s linear calc(-1 * var(--age, 0ms)) forwards;
  }

  /* Answer box floats over the map, right above the on-screen keyboard,
     whose height is fixed (--osk-h) so the map can centre above it. */
  :root {
    --osk-h: 206px;
  }
  .bottom-bar {
    left: 0;
    right: 0;
    padding: 0;
    gap: 8px;
  }
  .answer-form {
    max-width: none;
    padding: 0 8px;
  }
  .answer-input {
    background: rgba(28, 32, 41, 0.72);
  }
  .osk {
    height: var(--osk-h);
    padding: 8px 4px calc(6px + env(safe-area-inset-bottom));
    justify-content: center;
    background: #0f1115;
  }
  .submit-btn {
    display: none;
  }
  .answer-input {
    caret-color: transparent;
  }
  .warning:not(:empty) {
    position: absolute;
    top: -22px;
  }
}

@keyframes history-fade {
  0%, 92% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------- score level colours (last, so they win over base colours) ---------- */

.lvl-0 { color: var(--lvl-0); }
.lvl-1 { color: var(--lvl-1); }
.lvl-2 { color: var(--lvl-2); }
.lvl-3 { color: var(--lvl-3); }
.lvl-4 { color: var(--lvl-4); }
.lvl-5 { color: var(--lvl-5); }
.lvl-none { color: var(--dim); }

/* iOS zooms the page in on any text field under 16px when it's focused */
@media (max-width: 800px) {
  .answer-input {
    font-size: 16px;
  }
}

.menu-icon {
  display: none;
}
@media (max-width: 560px) {
  .menu-icon {
    display: inline;
  }
}

/* ---------- on-screen keyboard (phones) ---------- */

.osk {
  display: none;
  position: relative;
  flex-direction: column;
  gap: 7px;
  width: 100%;
  user-select: none;
  -webkit-user-select: none;
}

.osk-row {
  /* iOS geometry: every letter key is the same width (2 of 20 columns);
     row 2 is inset half a key, row 3 a key and a half (so z sits under s),
     with backspace filling the end. */
  display: grid;
  grid-template-columns: repeat(20, 1fr);
}

.osk-key {
  grid-column: span 2;
  margin: 0 3px;
  min-width: 0;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: #3a4050;
  color: var(--text);
  font-size: 19px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
}

/* each key's hidden haptic switch (see makeKey in app.js) */
.osk-key input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  pointer-events: none;
}

.osk-bubble {
  display: none;
  position: absolute;
  z-index: 2;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #555d70;
  color: #fff;
  font-size: 30px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

/* blinking caret for the read-only answer box on phones */
.answer-form {
  position: relative;
}

.fake-caret {
  display: none;
  position: absolute;
  top: 50%;
  width: 2px;
  height: 20px;
  margin-top: -10px;
  background: var(--accent);
  pointer-events: none;
  animation: caret-blink 1s steps(1) infinite;
}

@keyframes caret-blink {
  50% { opacity: 0; }
}

.osk-row:nth-child(2) .osk-key:first-child {
  grid-column: 2 / span 2;
}

.osk-row:nth-child(3) .osk-key:first-child {
  grid-column: 4 / span 2;
}

.osk-key.wide {
  grid-column: span 3;
  margin-left: 10px;
  font-size: 18px;
  background: #2a2f3b;
}

.osk-key.space {
  grid-column: 1 / span 14;
  font-size: 15px;
  color: var(--muted);
}

.osk-key.enter {
  grid-column: span 6;
  font-size: 15px;
  font-weight: 600;
  background: var(--accent);
  color: #1a1206;
}


.osk-key.down {
  background: #555d70;
}

.osk-key.enter.down {
  background: #f5b064;
}

@media (max-width: 560px) {
  .osk {
    display: flex;
  }
  .fake-caret {
    display: block;
  }
}
