/* Every Country — a school-atlas map that colours in as you learn.
   One typeface, Overpass, descended from the lettering on North American highway signs. */

:root {
  --ocean: #cfe2ea;
  --land: #f4f5f2;
  --border: #8d9ca4;
  --context: #e2e5e1;
  --ink: #14232b;
  --muted: #56666e;
  --panel: #fbfcfb;
  --rule: #d6dee2;
  --right: #1d8a4f;
  --wrong: #c63a3a;
  --target: #14232b;
  /* atlas colours: neighbours never share one */
  --atlas-0: #f0a7b6;
  --atlas-1: #f3d36b;
  --atlas-2: #a6d48c;
  --atlas-3: #bfa9e4;
  --atlas-4: #f4b47c;
  --atlas-5: #dcc39c;
  --font: "Overpass", system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ocean: #0f2531;
    --land: #23353f;
    --border: #5b7380;
    --context: #1b2b33;
    --ink: #e9eff2;
    --muted: #9fb1ba;
    --panel: #12232c;
    --rule: #2c414c;
    --right: #4cc283;
    --wrong: #ef7067;
    --target: #f3f7f9;
    --atlas-0: #c97a8c;
    --atlas-1: #c9a944;
    --atlas-2: #7fae67;
    --atlas-3: #9682c0;
    --atlas-4: #c98a54;
    --atlas-5: #ad9773;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ocean: #0f2531; --land: #23353f; --border: #5b7380; --context: #1b2b33; --ink: #e9eff2;
  --muted: #9fb1ba; --panel: #12232c; --rule: #2c414c; --right: #4cc283; --wrong: #ef7067; --target: #f3f7f9;
  --atlas-0: #c97a8c; --atlas-1: #c9a944; --atlas-2: #7fae67; --atlas-3: #9682c0; --atlas-4: #c98a54; --atlas-5: #ad9773;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--panel);
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }

.app {
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto minmax(44svh, 1fr) auto;
}

/* on phones, the world map gets a box its own shape instead of a tall one full of ocean */
@media (max-width: 899px) { .app.world { grid-template-rows: auto calc(100vw * 0.56) auto; } }

/* ---------- top bar ---------- */
.bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 16px 10px;
  background: var(--ocean);
}
.title { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -0.01em; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tally { margin: 0; font-size: 14px; color: var(--muted); white-space: nowrap; }
.bar-btn {
  border: 1.5px solid var(--ink);
  background: transparent;
  border-radius: 999px;
  padding: 4px 14px 2px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
}
.bar-btn.round { width: 34px; height: 34px; padding: 2px 0 0; }

/* ---------- map ---------- */
.map-wrap { position: relative; background: var(--ocean); min-height: 0; }
.map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: manipulation; }
.ocean { fill: var(--ocean); }
.context path { fill: var(--context); stroke: var(--border); stroke-width: 0.5px; vector-effect: non-scaling-stroke; }
.hatch-ground { fill: var(--land); }

.c {
  fill: var(--land);
  stroke: var(--border);
  stroke-width: 0.6px;
  vector-effect: non-scaling-stroke;
  cursor: pointer;
  transition: fill 300ms ease;
}
.c.s2 { fill: color-mix(in srgb, var(--fill) 50%, var(--land)); }
.c.s3 { fill: var(--fill); }
.c.target { stroke: var(--target); stroke-width: 2.5px; animation: pulse 1.6s ease-in-out infinite; }
.c.right { fill: var(--right) !important; stroke: var(--target); stroke-width: 1.5px; animation: none; }
.c.wrong { fill: var(--wrong) !important; stroke: var(--target); stroke-width: 1.5px; }
@keyframes pulse { 50% { stroke-width: 1px; } }

/* the end-of-session moment: countries that moved up fill in one after another */
.c.fresh {
  transform-box: fill-box;
  transform-origin: center;
  animation: fill-in 800ms cubic-bezier(.2, .9, .3, 1.2) both;
  animation-delay: calc(var(--i) * 140ms + 450ms);
}
@keyframes fill-in { from { opacity: 0.15; transform: scale(1.25); } to { opacity: 1; transform: none; } }

/* while you look for a country, the map shows no progress colours */
.map.plain .c:not(.right):not(.wrong),
.map.plain .dot:not(.right):not(.wrong) { fill: var(--land) !important; }

.dot { fill: var(--land); stroke: var(--ink); stroke-width: 1.2px; vector-effect: non-scaling-stroke; cursor: pointer; }
.dot.s1 { fill: color-mix(in srgb, var(--fill) 45%, var(--land)); }
.dot.s2 { fill: color-mix(in srgb, var(--fill) 65%, var(--land)); }
.dot.s3 { fill: var(--fill); }
.dot.target { stroke: var(--target); stroke-width: 3px; animation: dot-pulse 1.6s ease-in-out infinite; }
@keyframes dot-pulse { 50% { stroke-width: 1.5px; } }
.dot.right { fill: var(--right); }
.dot.wrong { fill: var(--wrong); }

.label {
  font-family: var(--font);
  font-weight: 800;
  font-size: calc(var(--u) * 14px);
  text-anchor: middle;
  dominant-baseline: middle;
  fill: var(--ink);
  paint-order: stroke;
  stroke: var(--panel);
  stroke-width: calc(var(--u) * 4px);
  stroke-linejoin: round;
  pointer-events: none;
}
.label.right { fill: var(--right); }
.label.wrong { fill: var(--wrong); }

.map-caption {
  position: absolute;
  left: 16px;
  bottom: 8px;
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  pointer-events: none;
}

/* ---------- panel ---------- */
.panel {
  padding: 16px 16px max(24px, env(safe-area-inset-bottom));
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}
.progress { height: 4px; background: var(--rule); border-radius: 2px; margin-bottom: 14px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--ink); transition: width 300ms ease; }
.lede { margin: 0 0 14px; font-size: 18px; color: var(--muted); }
.ask { margin: 0; font-size: 16px; color: var(--muted); }
.big { margin: 0 0 12px; font-size: clamp(30px, 8vw, 40px); line-height: 1.08; font-weight: 800; letter-spacing: -0.02em; }
.facts { margin: 0 0 14px; }
.verdict { margin: 12px 0 8px; font-weight: 800; font-size: 18px; }
.verdict.good { color: var(--right); }
.verdict.bad { color: var(--wrong); }

.flag { display: block; height: 72px; width: auto; aspect-ratio: 4 / 3; border-radius: 4px; box-shadow: 0 0 0 1px var(--rule); margin: 4px 0 12px; }
.flag.big-flag { height: 120px; margin: 10px 0 16px; }
.flag.small { height: 44px; margin: 2px 0 0; flex: none; }
.hook { display: flex; gap: 12px; align-items: flex-start; }

.continents { list-style: none; margin: 0 0 16px; padding: 0; }
.continent {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  padding: 12px 0;
  border: 0;
  border-bottom: 1px solid var(--rule);
  background: none;
  text-align: left;
  cursor: pointer;
}
.c-name { font-weight: 800; font-size: 19px; }
.c-status { font-size: 15px; color: var(--muted); align-self: center; }
.has-due .c-status { color: var(--ink); font-weight: 600; }
.meter { grid-column: 1 / -1; display: flex; height: 6px; border-radius: 3px; background: var(--rule); overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; transition: width 900ms cubic-bezier(.2, .8, .2, 1) 400ms; }
.c-pct { margin-left: 4px; font-size: 15px; font-weight: 600; color: var(--muted); }
.world-row, .gain { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.world-row { padding: 0 0 14px; margin-bottom: 4px; border-bottom: 1px solid var(--rule); }
.world-row .meter { height: 8px; }

/* after a game: the continent's or the world's bar growing, with the change */
.gain { margin: 4px 0 18px; }
.gain .meter { height: 10px; border-radius: 5px; }
.gain-pct { font-weight: 800; font-size: 19px; }
.gain-pct .up { color: var(--right); }
.gain-pct .down { color: var(--wrong); }
.gain-note { grid-column: 1 / -1; margin: 8px 0 0; font-size: 15px; color: var(--muted); }

/* practice: the game, skill and area pickers, typed answers, the race */
.seg { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 0; }
.seg-btn { flex: 1 1 auto; padding: 9px 14px 7px; border-radius: 999px; border: 1.5px solid var(--rule); background: transparent; font-weight: 700; font-size: 15px; cursor: pointer; }
.seg-btn:hover { border-color: var(--ink); }
.seg-btn[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--panel); }
.hint { margin-top: 10px; }
.typed { display: flex; gap: 8px; margin-top: 10px; }
.typed .btn { flex: none; }
.typed-input { flex: 1; min-width: 0; font: inherit; font-size: 18px; padding: 12px 14px 10px; border-radius: 12px; border: 1.5px solid var(--rule); background: var(--panel); color: var(--ink); }
.typed-input:focus { outline: none; border-color: var(--ink); }
.typed-input:disabled { opacity: 0.6; }
.typed-input.wide { width: 100%; margin-top: 10px; }
.race-score { display: flex; justify-content: space-between; align-items: baseline; margin-top: 4px; }
.race-score .big { margin: 0; }
.race-clock { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); }
.race-last { min-height: 1.4em; margin: 8px 0 0; color: var(--muted); }
.meter .m3 { background: var(--atlas-2); }
.meter .m2 { background: color-mix(in srgb, var(--atlas-2) 50%, var(--rule)); }
.meter .m1 { background: repeating-linear-gradient(45deg, var(--atlas-2) 0 2px, transparent 2px 5px); }

.options { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.opt {
  min-height: 56px;
  padding: 10px 12px 8px;
  border: 1.5px solid var(--rule);
  border-radius: 12px;
  background: var(--panel);
  font-weight: 600;
  font-size: 16px;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
}
.opt:hover:not(:disabled) { border-color: var(--ink); }
.opt .key { display: none; font-size: 12px; color: var(--muted); border: 1px solid var(--rule); border-radius: 4px; padding: 1px 5px 0; }
@media (pointer: fine) { .opt .key { display: inline-block; } }
.opt.right { border-color: var(--right); background: color-mix(in srgb, var(--right) 14%, var(--panel)); }
.opt.wrong { border-color: var(--wrong); background: color-mix(in srgb, var(--wrong) 14%, var(--panel)); }
.opt:disabled { cursor: default; }
.opt:disabled:not(.right):not(.wrong) { opacity: 0.55; }

.btn {
  padding: 13px 18px 11px;
  border-radius: 12px;
  border: 1.5px solid var(--ink);
  background: var(--ink);
  color: var(--panel);
  font-weight: 800;
  font-size: 17px;
  cursor: pointer;
}
.btn.quiet { background: transparent; color: var(--ink); }
.btn.wide { width: 100%; margin-top: 8px; }
.extras { display: flex; gap: 10px; flex-wrap: wrap; }
.extras .btn { flex: 1 1 160px; }

.squares { font-size: 24px; letter-spacing: 2px; margin: 0 0 12px; }
.next-daily { color: var(--muted); text-align: center; margin: 12px 0 4px; font-variant-numeric: tabular-nums; }
.share-text { white-space: pre-wrap; background: var(--rule); padding: 10px; border-radius: 8px; font-family: var(--font); user-select: all; }

.help {
  max-width: 440px;
  border: 0;
  border-radius: 16px;
  padding: 20px 20px 16px;
  background: var(--panel);
  color: var(--ink);
}
.help::backdrop { background: rgb(10 20 26 / 0.45); }
.help h2 { margin: 0 0 8px; font-size: 24px; font-weight: 800; }
.help p { margin: 0 0 10px; }

/* ---------- desktop: map beside the panel ---------- */
@media (min-width: 900px) {
  .app { grid-template-columns: 1fr 420px; grid-template-rows: auto 1fr; height: 100svh; }
  .bar { grid-column: 1 / -1; }
  .map-wrap { grid-row: 2; }
  .panel { grid-row: 2; grid-column: 2; overflow-y: auto; max-width: none; padding: 24px; border-left: 1px solid var(--rule); }
}

@media (prefers-reduced-motion: reduce) {
  .c, .progress i, .meter i { transition: none; }
  .c.target, .c.fresh, .dot.target { animation: none; }
}
