/* Wine Guesser - dark by default, with a light theme for bright rooms. */
:root {
  --bg: #0d1420;
  --bg-raised: #151e2d;
  --line: #24314a;
  --text: #e8eef7;
  --text-dim: #93a3bb;
  --accent: #e3879e;
  --bad: #ef5f6b;

  --ocean: #0f2639;
  --ocean-edge: #31506b;
  --graticule: #1b3b55;
  --land: #566374;
  --land-edge: #7c8b9d;
  --inert: #39424e;
  --inert-edge: #4d5867;
  --river: #6fa9d8;
  --border: #d3c88f;
  --admin: #8fa3cf;
  --label: #ffffff;
  --label-halo: #0b1724;
  --label-missed: #ffd9dd;
  --unknown: #ffd93d;
  --unknown-halo: #3a2b00;
  --pick: #ffd93d;
  --go: #3ddc84;

  --africa: #f0a34b;
  --asia: #ef6f6c;
  --europe: #9d8df1;
  --north-america: #4fbf8b;
  --south-america: #5fd0d8;
  --oceania: #ea7cc0;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #eef2f7;
    --bg-raised: #ffffff;
    --line: #d4dde8;
    --text: #16202e;
    --text-dim: #5d6b7d;
    --ocean: #cadff0;
    --ocean-edge: #8badc9;
    --graticule: #b3cfe4;
    --land: #aab6c4;
    --land-edge: #7b8899;
    --inert: #ccd4de;
    --inert-edge: #aab4c0;
    --river: #3f7fb8;
    --border: #9c8a3c;
    --admin: #5f74ad;
    --label: #10192a;
    --label-halo: #ffffff;
    --label-missed: #7d1420;
    --unknown: #b45309;
    --unknown-halo: #fff6e5;
    --pick: #c2410c;
    --go: #0a8f4d;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow: hidden;
}

.app { display: flex; flex-direction: column; height: 100%; }

/* ------------------------------------------------------------------ header */
.bar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  padding: 12px 18px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
}

/* Daily or practice, named for the length of the run: the splash is gone
   by the time it matters, and the score only makes sense against it. */
.mode-tag { flex: 0 0 auto; }
.mode-tag:empty { display: none; }

.bar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
}

.readout { display: flex; align-items: center; gap: 18px; margin-left: auto; }

.score { font-size: 13px; color: var(--text-dim); }
.score b {
  font-size: 22px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  margin-right: 4px;
}


.actions { display: flex; gap: 8px; }

button {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 11px;
  cursor: pointer;
}
button:hover { border-color: var(--text-dim); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button:disabled:hover { border-color: var(--line); }
button:disabled:active { transform: none; }

/* -------------------------------------------------------------------- body */
main { flex: 1; display: flex; min-height: 0; }

.stage { position: relative; flex: 1; min-width: 0; background: var(--bg); touch-action: none; }

/* The globe is a canvas (js/app.js draws it, with the palette above read
   from these custom properties); pins and labels are an SVG laid over it,
   which also takes the pointer. */
#globe, #map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#map { touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }

.dot {
  fill: var(--land);
  stroke: var(--label-halo);
  stroke-width: .5;
  vector-effect: non-scaling-stroke;
  pointer-events: all;
}
#dots g[data-region] .dot.found { fill: var(--region); }
.dot.missed { fill: var(--bad); }
.dot.hidden, .label.hidden { display: none; }

/* Sizes come from app.js, in screen pixels: the map scales to its container,
   so anything sized in map units turns to dust on a phone. */
.label {
  fill: var(--label);
  stroke: var(--label-halo);
  paint-order: stroke;
  stroke-linejoin: round;
  font-weight: 600;
  text-anchor: middle;
  pointer-events: none;
  user-select: none;
}
.label.missed { fill: var(--label-missed); }   /* red on red is unreadable */

/* ------------------------------------------------------------------ overlays */
.zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom button {
  width: 34px;
  height: 34px;
  font-size: 16px;
  background: var(--bg-raised);
  display: grid;
  place-items: center;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  font-size: 12px;
  color: var(--text-dim);
  background: color-mix(in srgb, var(--bg-raised) 85%, transparent);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  font-variant-numeric: tabular-nums;
}

/* Under the map: how the round stands, and the one button that moves it on
   - lock in, next region, see results. */
.round {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
  align-items: center;
  max-width: calc(100% - 140px);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 8px 7px 18px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
}
.round[hidden] { display: none; }
.round-line { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.round button {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 700;
  background: var(--accent);
  border-color: var(--accent);
  color: #2a0612;
}
.round button:disabled { background: var(--bg); border-color: var(--line); color: var(--text-dim); }

/* Over the top of the map: the region asked for, and a fact about it as the
   hint, so the player reads both in one place. */
.target {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(640px, calc(100% - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 20px 12px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  text-align: center;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.target[hidden] { display: none; }
.target-count {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.target-name { font-size: 26px; line-height: 1.2; letter-spacing: -.01em; }
.hint {
  margin: 4px 0 0;
  font-size: 16px;
  line-height: 1.4;
  color: var(--text);
  text-wrap: balance;
}
.hint[hidden] { display: none; }

.toast {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  opacity: 0;
  transition: opacity .2s;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 8px 6px 14px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast button { border-radius: 999px; padding: 4px 10px; }

/* -------------------------------------------------------------------- panel */
.panel {
  width: 268px;
  flex: 0 0 268px;
  border-left: 1px solid var(--line);
  background: var(--bg-raised);
  padding: 14px 16px 24px;
  overflow-y: auto;
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}

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

.regions li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
}
.regions li:hover { background: var(--bg); }

.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--region); }

.regions .count {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
  color: var(--text-dim);
}
.regions .done .count { color: var(--region); }

.meter {
  grid-column: 2 / -1;
  height: 3px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.meter i { display: block; height: 100%; background: var(--region); width: 0; transition: width .3s ease; }

.note { font-size: 12px; color: var(--text-dim); margin: 14px 2px 0; }

.missed { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 16px; }
.missed h3 {
  margin: 12px 0 4px;
  font-size: 12px;
  color: var(--region, var(--text-dim));
}
.missed ul { list-style: none; margin: 0; padding: 0; font-size: 13px; color: var(--text-dim); }
.missed li { padding: 1px 0; }

@media (prefers-reduced-motion: reduce) {
  .country.flash { animation: none; }
  .meter i, .country { transition: none; }
}

@media (max-width: 820px) {
  main { flex-direction: column; }
  .panel {
    width: auto;
    flex: 0 0 auto;
    border-left: 0;
    border-top: 1px solid var(--line);
    max-height: 32%;
    padding: 10px 12px 16px;
  }
  .panel h2 { margin-bottom: 6px; }
  .regions { display: grid; grid-template-columns: 1fr 1fr; column-gap: 10px; }
  .regions li { padding: 5px 6px; font-size: 13px; }
  .note { display: none; }
  .bar { gap: 12px; }
  .bar h1 { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .target { top: 10px; padding: 8px 14px 10px; }
  .target-name { font-size: 21px; }
  /* Clear of the zoom buttons, and free to wrap. */
  .round {
    left: 12px;
    right: 58px;
    transform: none;
    max-width: none;
    border-radius: 14px;
    padding-left: 14px;
    font-size: 13px;
  }
  .round-line { white-space: normal; flex: 1; }
  .hint { font-size: 14px; }
}

/* ------------------------------------------------------- unguessed markers */
.label.unknown {
  fill: var(--unknown);
  stroke: var(--unknown-halo);
  font-weight: 800;
}

/* ------------------------------------------------ hard mode: picked country */
#dots g[data-region] .dot.selected,
.dot.selected { fill: var(--pick); stroke: var(--label-halo); stroke-width: 1; }
.label.selected { fill: var(--pick); }

/* Sized in app.js, in screen pixels: a picked speck has to be findable at
   any zoom, so the ring is the same size whether it rings Russia or Nauru. */
#pick-ring {
  fill: none;
  stroke: var(--pick);
  stroke-width: 2.4;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
  transform-box: fill-box;
  transform-origin: center;
  animation: ping 1.5s ease-in-out infinite;
}
#pick-ring.hidden { display: none; }

/* Breathing, never gone: a ring that blinks out leaves you hunting again. */
@keyframes ping {
  0%, 100% { transform: scale(.9); opacity: 1; }
  50% { transform: scale(1.2); opacity: .45; }
}

/* ------------------------------------------------------ the dropped pin */
/* Where the last click landed. Sized in app.js, in screen pixels, like the
   pick ring: the map scales, the pin should not. */
#pin-dot {
  fill: var(--pick);
  stroke: var(--label-halo);
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}
#pin-dot.hidden { display: none; }

/* A round once its guess is in: the pin, the region, and the line between.
   Earlier rounds are hidden until the run is over. Sized in app.js. */
#marks { pointer-events: none; }
.mark-line {
  fill: none;
  stroke: var(--text);
  stroke-width: 1.6;
  stroke-dasharray: 5 4;
  vector-effect: non-scaling-stroke;
}
.mark-guess { fill: var(--pick); stroke: var(--label-halo); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.mark-wine { fill: var(--go); stroke: var(--label-halo); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.mark.past { display: none; }

/* Over a region once it is found: where it is and what grows there.
   Placed by app.js at the region, every frame; the tail points down at it,
   or up when the card has dropped below. */
.place {
  position: absolute;
  left: 0;
  top: 0;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  max-width: 280px;
  padding: 8px 14px 9px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 10px;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  pointer-events: none;
}
.place[hidden] { display: none; }
.place::after {
  content: "";
  position: absolute;
  left: var(--tail, 50%);
  top: 100%;
  width: 10px;
  height: 10px;
  background: var(--bg-raised);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  transform: translate(-50%, -50%) rotate(45deg);
}
.place.below::after { top: 0; transform: translate(-50%, -50%) rotate(225deg); }
.place-name { font-size: 15px; }
.place-where { color: var(--text); }
.place-grapes { color: var(--text-dim); }
.place-grapes[hidden] { display: none; }

/* --------------------------------------------------------- correct-guess pop */
.country.pop,
.dot.pop {
  transform-box: fill-box;
  transform-origin: center;
  animation: pop .42s cubic-bezier(.34, 1.56, .64, 1), flash .9s ease-out;
}
.dot.pop { animation: pop .42s cubic-bezier(.34, 1.56, .64, 1); }

/* --pop is set per element when the guess lands: a country should swell by
   about the same number of pixels whatever its size, so the United States
   does not heave across the Atlantic while Monaco barely twitches. */
@keyframes pop {
  0% { transform: scale(1); }
  38% { transform: scale(var(--pop, 1.08)); }
  100% { transform: scale(1); }
}

/* ----------------------------------------------------------- results sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(4px);
}
.sheet[hidden] { display: none; }

.card {
  width: min(540px, 100%);
  max-height: min(86vh, 820px);
  overflow-y: auto;
  padding: 24px 26px 20px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
  animation: rise .24s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.card h2 {
  margin: 0;
  font-size: 23px;
  letter-spacing: -.01em;
  text-transform: none;
  color: var(--text);
}

.sheet-line { margin: 5px 0 18px; color: var(--text-dim); font-size: 13.5px; }

.sheet-mode { margin: 0 0 8px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
}
.sheet-mode .badge + .badge { margin-left: 7px; }
.badge[hidden] { display: none; }

/* Hardcore's rule, under the reason it ended the run. */
.sheet-rule { margin: -12px 0 18px; color: var(--text-dim); font-size: 12.5px; }
.sheet-rule[hidden] { display: none; }

.badge.plain {
  color: var(--text-dim);
  background: transparent;
  border-color: var(--line);
}

.badge.hard {
  color: var(--unknown);
  background: color-mix(in srgb, var(--unknown) 14%, transparent);
  border-color: color-mix(in srgb, var(--unknown) 40%, transparent);
}

.final {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.final b { font-size: 44px; font-variant-numeric: tabular-nums; line-height: 1; }
.final span { color: var(--text-dim); font-size: 13.5px; }

.final .percent {
  margin-left: auto;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.breakdown { list-style: none; margin: 16px 0 0; padding: 0; }
.breakdown li {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
  font-size: 13.5px;
}
.breakdown .count { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 12.5px; }
.breakdown .meter { grid-column: 2 / -1; }

/* The run, region by region. */
.tally { list-style: none; margin: 14px 0 0; padding: 0; counter-reset: tally; }
.tally li {
  display: grid;
  grid-template-columns: 22px 1fr auto 52px;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
  counter-increment: tally;
}
.tally li::before { content: counter(tally); color: var(--text-dim); font-size: 12px; font-variant-numeric: tabular-nums; }
.tally .km { color: var(--text-dim); font-size: 13px; font-variant-numeric: tabular-nums; }
.tally .points { text-align: right; font-variant-numeric: tabular-nums; }

.sheet-missed { margin-top: 20px; border-top: 1px solid var(--line); padding-top: 14px; }
.sheet-missed h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.sheet-missed h4 { margin: 10px 0 3px; font-size: 12px; color: var(--region, var(--text-dim)); }
.sheet-missed ul {
  list-style: none;
  margin: 0;
  padding: 0;
  columns: 2;
  font-size: 13px;
  color: var(--text-dim);
}
.sheet-missed li { break-inside: avoid; padding: 1px 0; }

.sheet-actions {
  position: sticky;
  bottom: -20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
  padding: 14px 0 4px;
  background: linear-gradient(to top, var(--bg-raised) 72%, transparent);
}
.sheet-actions button { padding: 9px 16px; font-size: 13.5px; }
.sheet-actions .share { margin-right: auto; }
.sheet-actions .share.done { border-color: var(--go); color: var(--go); }

/* Back to the results after "Look at the map". */
.results-again { border-color: var(--accent); color: var(--accent); }
.results-again[hidden] { display: none; }
.sheet-actions .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #2a0612;
  font-weight: 600;
}

/* ------------------------------------------------------ splash and countdown */
/* Every run opens behind this, and is set up here: today's daily regions or
   a practice run. Nothing has started while it is up, and it counts down
   into the first region. */
.splash {
  position: fixed;
  inset: 0;
  z-index: 25;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(5px);
}
.splash[hidden] { display: none; }

.splash-card { position: relative; width: min(720px, 100%); text-align: center; }

.splash-card h2 { margin: 0; font-size: 29px; }
.splash-card .sheet-line { margin: 9px 0 0; font-size: 14.5px; }

.splash-go {
  margin-top: 20px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}
.splash-go button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 220px;
  padding: 11px 24px 12px;
  font-size: 15px;
  border-radius: 12px;
}
.splash-go button b { font-size: 17px; }
.splash-go button span { font-size: 12.5px; color: var(--text-dim); }
.splash-go .primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #2a0612;
}
.splash-go .primary span { color: inherit; opacity: .8; }
.splash-go button:not(.primary):hover { border-color: var(--text-dim); }
.splash-go button[aria-expanded="true"] { border-color: var(--accent); }
/* The two kinds of practice, a size down from the choice that opened them. */
.splash-kinds { margin-top: 12px; }
.splash-kinds[hidden] { display: none; }
.splash-kinds button { min-width: 200px; padding: 8px 18px 9px; }
.splash-kinds button b { font-size: 15px; }
.splash-go button:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

/* Counting: the card goes, and the number has the screen to itself. */
.splash.counting { backdrop-filter: blur(3px); }
.splash.counting .splash-card { display: none; }

.countdown {
  font-size: clamp(110px, 26vw, 260px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.05em;
  color: var(--accent);
  text-shadow: 0 0 70px color-mix(in srgb, var(--accent) 45%, transparent);
}
.countdown:empty { display: none; }

/* Re-added per number, so each one lands with its own beat. The duration is
   a touch under COUNT_STEP: the number has faded before the next arrives. */
.countdown.tick { animation: countdown .74s ease-out both; }

@keyframes countdown {
  0% { opacity: 0; transform: scale(.5); }
  20% { opacity: 1; transform: scale(1.09); }
  62% { opacity: 1; transform: scale(1); }
  100% { opacity: .1; transform: scale(.88); }
}

@media (prefers-reduced-motion: reduce) {
  .country.pop, .dot.pop { animation: none; }
  .card { animation: none; }
  #pick-ring { animation: none; }
  .countdown.tick { animation: none; }
}
