/* Globe Game — sunny light theme by default, deep-space dark theme as an option ([data-theme="dark"]). */

:root {
  --bg: #e6f3ff;
  --bg-2: #fbf6ea;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-solid: #ffffff;
  --panel-border: rgba(24, 56, 110, 0.10);
  --text: #14223b;
  --muted: #52627d;
  --accent: #1a6fd6;
  --accent-2: #c2410c;
  --accent-ink: #ffffff;
  --danger: #d12a45;
  --success: #0b7f56;
  --field: #ffffff;
  --field-border: rgba(24, 56, 110, 0.22);
  --hover: rgba(26, 111, 214, 0.07);
  --shadow: 0 12px 32px rgba(28, 64, 120, 0.12), 0 2px 6px rgba(28, 64, 120, 0.06);
  --backdrop: rgba(20, 40, 80, 0.32);
  --dock-shadow: 0 -8px 24px rgba(28, 64, 120, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #050b1a;
  --bg-2: #0a1630;
  --panel: rgba(13, 24, 48, 0.78);
  --panel-solid: #0d1830;
  --panel-border: rgba(120, 170, 255, 0.16);
  --text: #e8efff;
  --muted: #93a4c6;
  --accent: #5cc8ff;
  --accent-2: #ff7a45;
  --accent-ink: #04101f;
  --danger: #ff6b7d;
  --success: #2fe6a7;
  --field: rgba(6, 14, 32, 0.85);
  --field-border: rgba(120, 170, 255, 0.25);
  --hover: rgba(120, 170, 255, 0.10);
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --backdrop: rgba(2, 6, 18, 0.62);
  --dock-shadow: 0 -10px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { background-color: var(--bg); }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background-color: var(--bg);
  /* Sunny sky: warm sun glow top-right, soft white clouds, sky blue fading to warm cream. */
  background-image:
    radial-gradient(circle at 92% -4%, rgba(255, 214, 130, 0.55), rgba(255, 214, 130, 0) 32%),
    radial-gradient(ellipse 34% 14% at 14% 12%, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 26% 10% at 58% 6%, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0) 70%),
    radial-gradient(ellipse 60% 45% at 85% 95%, rgba(150, 205, 255, 0.35), transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-size: 100% 100%;
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[data-theme="dark"] body {
  background-image:
    radial-gradient(1px 1px at 12% 18%, rgba(255,255,255,.75), transparent 60%),
    radial-gradient(1px 1px at 78% 12%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(1.5px 1.5px at 33% 72%, rgba(190,220,255,.7), transparent 60%),
    radial-gradient(1px 1px at 62% 48%, rgba(255,255,255,.5), transparent 60%),
    radial-gradient(1px 1px at 88% 82%, rgba(255,255,255,.65), transparent 60%),
    radial-gradient(1.5px 1.5px at 6% 90%, rgba(255,230,200,.6), transparent 60%),
    radial-gradient(1px 1px at 47% 8%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(ellipse 80% 60% at 30% 40%, rgba(40, 90, 200, 0.22), transparent 70%),
    radial-gradient(ellipse 60% 50% at 85% 80%, rgba(140, 50, 160, 0.16), transparent 70%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-size: 260px 260px, 310px 310px, 380px 380px, 220px 220px, 290px 290px, 340px 340px, 270px 270px, 100% 100%, 100% 100%, 100% 100%;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
svg { stroke: currentColor; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
svg .fill { fill: currentColor; stroke: none; }

.skip-link { position: absolute; left: -999px; top: 8px; background: var(--panel-solid); padding: 8px 12px; border-radius: 8px; z-index: 50; }
.skip-link:focus { left: 8px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 16px 6px;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 34px; height: 34px; filter: drop-shadow(0 2px 6px rgba(26, 111, 214, .25)); }
[data-theme="dark"] .brand-mark { filter: drop-shadow(0 0 10px rgba(92, 200, 255, .45)); }
.brand-name { margin: 0; font-size: 1.45rem; font-weight: 800; letter-spacing: -0.02em; }
.brand-name span {
  background: linear-gradient(90deg, #e06c00, #e0314d);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
[data-theme="dark"] .brand-name span { background-image: linear-gradient(90deg, #ffb35c, #ff5a6e); }
.top-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: var(--panel); border: 1px solid var(--panel-border);
  box-shadow: 0 2px 8px rgba(28, 64, 120, .08);
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn:active { transform: scale(.95); }
.icon-btn svg { width: 21px; height: 21px; }

/* ---------- controls ---------- */
.controls {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 4px 16px 10px;
}
.seg {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  box-shadow: 0 2px 8px rgba(28, 64, 120, .08);
}
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 9px;
  font-weight: 600; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); }
.seg button:not([aria-selected="true"]):hover { color: var(--text); background: var(--hover); }
.seg.small button { padding: 5px 10px; font-size: .85rem; }
.select-wrap {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  box-shadow: 0 2px 8px rgba(28, 64, 120, .08);
  padding: 0 4px 0 12px; height: 40px;
}
.select-wrap.disabled { opacity: .5; }
.select-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.select-wrap select {
  border: 0; background: transparent; padding: 6px 6px; font-weight: 600; border-radius: 8px;
  max-width: 150px;
}
.select-wrap select option { background: var(--panel-solid); color: var(--text); }

/* ---------- layout ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 400px);
  gap: 16px;
  padding: 0 16px max(16px, env(safe-area-inset-bottom));
  min-height: 0;
}

.globe-wrap {
  position: relative;
  min-height: 420px;
  border-radius: 24px;
  overflow: hidden;
}
#globe {
  position: absolute; inset: 0; width: 100%; height: 100%;
  touch-action: none; cursor: grab; display: block;
  border-radius: 24px;
}
#globe:active { cursor: grabbing; }
#globe:focus-visible { outline-offset: -3px; }
.globe-loading {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-weight: 600; letter-spacing: .02em;
  animation: pulse 1.4s ease-in-out infinite;
}
.globe-loading.error { color: var(--danger); animation: none; }
@keyframes pulse { 50% { opacity: .45; } }

.globe-tools {
  position: absolute; right: 12px; bottom: 12px;
  display: flex; flex-direction: column; gap: 6px;
}
.tool-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--panel); border: 1px solid var(--panel-border);
  font-size: 1.3rem; font-weight: 600; line-height: 1;
  display: grid; place-items: center;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.tool-btn:hover { background: var(--hover); }
.tool-btn svg { width: 19px; height: 19px; }
.legend {
  position: absolute; left: 12px; bottom: 12px;
  display: flex; align-items: center; gap: 8px;
  font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .08em;
  background: var(--panel); border: 1px solid var(--panel-border); border-radius: 999px; padding: 6px 12px;
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.legend-bar { width: 96px; height: 8px; border-radius: 99px; display: block; }
.globe-tip {
  position: absolute; transform: translate(-50%, calc(-100% - 14px));
  background: var(--panel-solid); border: 1px solid var(--panel-border);
  padding: 6px 10px; border-radius: 10px; font-size: .85rem; font-weight: 600;
  box-shadow: var(--shadow); pointer-events: none; white-space: nowrap;
}

/* ---------- side panel ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  min-height: 0;
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.round-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.round-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.score-chip {
  font-size: .8rem; font-weight: 800; padding: 4px 10px; border-radius: 99px;
  background: linear-gradient(90deg, rgba(255,179,92,.18), rgba(255,90,110,.18));
  border: 1px solid rgba(255, 140, 90, .35); color: var(--accent-2); white-space: nowrap;
}

.guess-form { display: flex; gap: 8px; }
.combo { position: relative; flex: 1; min-width: 0; }
#guess-input {
  width: 100%; height: 48px; padding: 0 14px;
  border-radius: 14px; border: 1.5px solid var(--field-border); background: var(--field);
  font-size: 1rem; transition: border-color .15s, box-shadow .15s;
}
#guess-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(92, 200, 255, .18); }
#guess-input.shake { animation: shake .35s; border-color: var(--danger); }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.ac-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20;
  list-style: none; margin: 0; padding: 6px;
  background: var(--panel-solid); border: 1px solid var(--panel-border); border-radius: 14px;
  box-shadow: var(--shadow); max-height: 300px; overflow-y: auto;
}
.ac-item {
  display: flex; align-items: baseline; gap: 8px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
}
.ac-item:hover, .ac-item.active { background: var(--hover); }
.ac-item.active { box-shadow: inset 3px 0 0 var(--accent); }
.ac-item.used { opacity: .55; }
.ac-name { font-weight: 600; }
.ac-via, .ac-used { color: var(--muted); font-size: .78rem; }
.ac-used { margin-left: auto; }
.ac-empty { padding: 9px 10px; color: var(--muted); font-size: .9rem; }

.btn {
  height: 42px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--panel-border); background: var(--hover);
  font-weight: 700; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: filter .15s, transform .1s, background .15s;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; }
.btn.primary {
  background: linear-gradient(135deg, #1a6fd6, #1559c9); color: #fff; border: 0;
  box-shadow: 0 6px 18px rgba(26, 111, 214, .28);
}
[data-theme="dark"] .btn.primary { color: #04101f; background: linear-gradient(135deg, #5cc8ff, #3a86ff); box-shadow: 0 6px 20px rgba(58, 134, 255, .35); }
.btn.ghost { background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--hover); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.guess-btn { height: 48px; border-radius: 14px; }

.action-row { display: flex; gap: 8px; }
.action-row .btn { flex: 1; height: 38px; font-size: .9rem; }

.hint-text {
  display: flex; flex-direction: column; gap: 6px;
}
.hint-line {
  margin: 0; padding: 8px 12px; border-radius: 10px; font-size: .92rem;
  background: rgba(92, 200, 255, .10); border: 1px solid rgba(92, 200, 255, .25);
}
.hint-line::before { content: "💡 "; }

.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-top: 2px; }
.list-head h2 { margin: 0; font-size: .82rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.closest { font-size: .8rem; color: var(--muted); text-align: right; }

.guess-list {
  list-style: none; margin: 0; padding: 0 2px 2px 0;
  display: flex; flex-direction: column; gap: 6px;
  overflow-y: auto; min-height: 0; flex: 1;
}
.guess-item {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr) auto 46px 64px;
  align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 12px;
  background: rgba(20, 60, 120, 0.04); border: 1px solid transparent;
  cursor: pointer; animation: rowIn .35s ease both;
}
[data-theme="dark"] .guess-item { background: rgba(255, 255, 255, 0.03); }
.guess-item:hover { background: var(--hover); }
.guess-item.newest { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(92, 200, 255, .12); }
.guess-item.target { border-color: var(--success); background: rgba(47, 230, 167, .10); }
@keyframes rowIn { from { opacity: 0; transform: translateY(-4px); } }
.g-swatch { width: 14px; height: 14px; border-radius: 5px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
/* Long names ("Saint Vincent and the Grenadines") wrap onto a second line instead of truncating. */
.g-name {
  font-weight: 650; line-height: 1.2; min-width: 0;
  overflow-wrap: anywhere; hyphens: auto; text-wrap: balance;
  display: flex; flex-direction: column;
}
.g-cap { font-weight: 600; font-size: .78rem; color: var(--muted); }
.g-dist { font-variant-numeric: tabular-nums; font-size: .9rem; color: var(--muted); white-space: nowrap; }
.guess-item.target .g-dist { color: var(--success); font-weight: 700; }
.g-dir { display: inline-flex; align-items: center; gap: 3px; color: var(--accent); }
.g-dir svg { width: 20px; height: 20px; transition: transform .4s ease; }
.g-dir small { font-size: .7rem; font-weight: 700; color: var(--muted); min-width: 1.6em; }
.guess-item.target .g-dir { color: var(--success); }
.g-prox { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.g-prox b { font-size: .82rem; font-variant-numeric: tabular-nums; }
.g-bar { display: block; width: 100%; height: 4px; border-radius: 99px; background: linear-gradient(90deg, var(--c) var(--p), rgba(128,128,128,.2) var(--p)); }
.empty { margin: 4px 0 0; color: var(--muted); font-size: .9rem; line-height: 1.5; }

/* ---------- round extras ---------- */
.sandbox-note, .capital-clue { margin: 0; padding: 8px 12px; border-radius: 10px; font-size: .88rem; }
.sandbox-note { background: rgba(255, 200, 87, .12); border: 1px solid rgba(255, 200, 87, .35); }
.capital-clue { background: rgba(92, 200, 255, .10); border: 1px solid rgba(92, 200, 255, .3); }
.capital-clue b { font-size: 1.05rem; }

/* ---------- flag card (Flags mode) ---------- */
/* Fixed 4:3 slot (all flag SVGs are 640x480 viewBoxes), so nothing jumps while the flag loads. */
.flag-card {
  --flag-h: 108px;
  margin: 0; padding: 10px 14px 10px 10px; border-radius: 14px;
  /* Flag left, caption right: keeps the card ~130px tall so the guess list keeps its room. */
  display: grid; grid-template-columns: auto 1fr; align-items: center; justify-items: start; gap: 14px;
  background: var(--hover); border: 1px solid var(--panel-border);
}
.flag-card[hidden] { display: none; }
.flag-card img, .flag-card::before {
  grid-area: 1 / 1;
  height: var(--flag-h); width: auto; max-width: 100%; aspect-ratio: 4 / 3;
  border-radius: 6px;
}
.flag-card img {
  display: block; object-fit: contain;
  /* Hairline + soft shadow so white/pale flags (Japan, Cyprus) read on the light theme. */
  box-shadow: 0 0 0 1px rgba(10, 25, 50, .28), 0 6px 16px rgba(20, 50, 100, .18);
  transition: opacity .25s ease;
}
[data-theme="dark"] .flag-card img { box-shadow: 0 0 0 1px rgba(10, 25, 50, .22), 0 6px 18px rgba(0, 0, 0, .28); }
.flag-card::before { content: ""; visibility: hidden; }
.flag-card[data-state="loading"] img, .flag-card[data-state="error"] img { opacity: 0; }
.flag-card[data-state="loading"]::before {
  visibility: visible;
  background: linear-gradient(100deg, rgba(128, 150, 190, .14) 30%, rgba(128, 150, 190, .32) 50%, rgba(128, 150, 190, .14) 70%) 0 0 / 300% 100%;
  animation: flagShimmer 1.2s linear infinite;
}
.flag-card[data-state="error"]::before {
  visibility: visible; content: "Flag unavailable";
  display: grid; place-items: center; text-align: center; padding: 6px;
  font-size: .78rem; font-weight: 700; color: var(--muted);
  background: repeating-linear-gradient(135deg, rgba(128, 150, 190, .10) 0 8px, rgba(128, 150, 190, .18) 8px 16px);
  border: 1px dashed var(--panel-border);
}
@keyframes flagShimmer { to { background-position: -300% 0; } }
.flag-caption { grid-area: 1 / 2; margin: 0; font-size: .95rem; font-weight: 650; color: var(--muted); text-align: left; line-height: 1.25; overflow-wrap: anywhere; }
.flag-card[data-revealed="true"] { border-color: var(--success); background: color-mix(in srgb, var(--success) 10%, transparent); }
.flag-card[data-revealed="true"] .flag-caption { font-size: 1.08rem; font-weight: 800; color: var(--text); }
.flag-card[data-revealed="true"] .flag-caption::before {
  content: "Answer"; display: block; margin-bottom: 1px;
  font-size: .68rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--success);
}
/* Short desktop windows: shrink the flag so the guess list keeps room. */
@media (min-width: 861px) and (max-height: 760px) { .flag-card { --flag-h: 84px; padding: 8px 12px 8px 8px; } }

.dock { display: flex; flex-direction: column; gap: 8px; }
.dock-best { display: none; }
.guess-feedback { margin: 0; font-size: .9rem; font-weight: 600; padding: 8px 12px; border-radius: 10px; background: var(--hover); }
.guess-feedback[data-kind="warmer"] { background: rgba(255, 122, 69, .14); box-shadow: inset 3px 0 0 #ff7a45; }
.guess-feedback[data-kind="colder"] { background: rgba(92, 200, 255, .10); box-shadow: inset 3px 0 0 var(--accent); }
.disambig { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.disambig-q { width: 100%; font-size: .85rem; font-weight: 700; color: var(--muted); }
.chip {
  border: 1px solid var(--accent); background: rgba(92, 200, 255, .1); color: var(--text);
  padding: 7px 12px; border-radius: 99px; font-weight: 650; font-size: .9rem;
}
.chip:hover { background: rgba(92, 200, 255, .22); }
.chip.used { opacity: .55; }
#giveup-btn[data-armed] { background: var(--danger); color: #fff; border-color: var(--danger); }
.yesterday { margin: 14px 0 0; font-size: .9rem; color: var(--muted); }
.yesterday b { color: var(--text); }
.about-credits { font-size: .82rem; color: var(--muted); line-height: 1.5; margin: 0 0 16px; }
.sandbox-msg { grid-column: 1 / -1; margin: 0; font-size: .85rem; color: var(--muted); text-align: center; }
.site-footer {
  display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: center;
  padding: 4px 16px max(8px, env(safe-area-inset-bottom)); font-size: .72rem; color: var(--muted);
}
.site-footer a { color: var(--muted); }

/* ---------- win panel ---------- */
.win-panel {
  border-radius: 18px; padding: 16px;
  background: linear-gradient(160deg, rgba(47, 230, 167, .18), rgba(255, 214, 130, .14));
  border: 1px solid rgba(11, 127, 86, .30);
  animation: rowIn .4s ease both;
}
[data-theme="dark"] .win-panel { background: linear-gradient(160deg, rgba(47, 230, 167, .14), rgba(92, 200, 255, .08)); border-color: rgba(47, 230, 167, .35); }
.win-panel[data-outcome="lost"] {
  background: linear-gradient(160deg, rgba(255, 107, 125, .12), rgba(255, 122, 69, .06));
  border-color: rgba(255, 107, 125, .35);
}
.win-kicker { margin: 0 0 2px; font-size: .85rem; font-weight: 700; color: var(--success); text-transform: uppercase; letter-spacing: .08em; }
.win-panel[data-outcome="lost"] .win-kicker { color: var(--danger); }
.win-title { margin: 0; font-size: 1.6rem; letter-spacing: -0.01em; }
.win-sub { margin: 4px 0 12px; color: var(--muted); font-size: .92rem; }
.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.mini-stats div { text-align: center; padding: 6px 0; border-radius: 10px; background: rgba(20,60,120,.05); }
[data-theme="dark"] .mini-stats div { background: rgba(255,255,255,.04); }
.mini-stats b { display: block; font-size: 1.15rem; }
.mini-stats span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.win-actions { display: flex; gap: 8px; }
.win-actions .btn { flex: 1; white-space: nowrap; padding: 0 12px; }
.countdown { margin: 10px 0 0; text-align: center; font-size: .85rem; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 18px; z-index: 100;
  transform: translate(-50%, -20px); opacity: 0;
  max-width: min(92vw, 480px);
  padding: 11px 16px; border-radius: 14px;
  background: var(--panel-solid); border: 1px solid var(--panel-border);
  box-shadow: var(--shadow); font-weight: 600; font-size: .92rem; text-align: center;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { border-color: var(--danger); }
.toast[data-kind="warn"] { border-color: #ffc857; }
.toast[data-kind="success"] { border-color: var(--success); }

/* ---------- modals ---------- */
dialog.modal {
  border: 0; padding: 0; background: transparent; color: var(--text);
  max-width: min(520px, calc(100vw - 24px)); width: 100%;
  max-height: calc(100dvh - 24px);
  overflow-y: auto; overscroll-behavior: contain;
}
dialog.modal::backdrop { background: var(--backdrop); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
dialog.modal[open] { animation: pop .22s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-card {
  position: relative;
  background: var(--panel-solid); border: 1px solid var(--panel-border); border-radius: 22px;
  padding: 22px; box-shadow: var(--shadow);
}
.modal-card h2 { margin: 0 0 12px; font-size: 1.35rem; padding-right: 36px; }
.close-btn {
  position: absolute; right: 12px; top: 12px; width: 36px; height: 36px;
  border-radius: 10px; border: 0; background: var(--hover); font-size: 1.4rem; line-height: 1;
}
.lead { margin: 0 0 12px; color: var(--muted); line-height: 1.5; }
.howto-steps { margin: 0 0 14px; padding-left: 20px; line-height: 1.55; }
.howto-steps li { margin-bottom: 4px; }
.howto-example { display: flex; flex-direction: column; gap: 6px; margin: 0 0 14px; }
.ex-row {
  display: grid; grid-template-columns: 14px 1fr auto 24px; gap: 10px; align-items: center;
  padding: 8px 10px; border-radius: 10px; background: var(--hover); font-size: .92rem;
}
.ex-row i { width: 14px; height: 14px; border-radius: 5px; }
.ex-row span { color: var(--muted); font-variant-numeric: tabular-nums; }
.ex-arrow { display: inline-block; transform: rotate(var(--r)); color: var(--accent) !important; text-align: center; }
.howto-notes { margin: 0 0 18px; padding-left: 18px; color: var(--muted); font-size: .9rem; line-height: 1.5; }
.howto-notes b { color: var(--text); }

.stats-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.stat-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile { text-align: center; padding: 12px 6px; border-radius: 12px; background: var(--hover); }
.tile b { display: block; font-size: 1.5rem; }
.tile span { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.dist-title { margin: 18px 0 8px; font-size: .82rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.dist { display: flex; flex-direction: column; gap: 5px; }
.dist-row { display: grid; grid-template-columns: 44px 1fr; gap: 8px; align-items: center; font-size: .85rem; }
.dist-k { color: var(--muted); text-align: right; font-variant-numeric: tabular-nums; }
.dist-bar {
  width: var(--w); min-width: 24px; height: 22px; border-radius: 6px;
  background: rgba(128, 150, 190, .3); display: flex; align-items: center; justify-content: flex-end; padding: 0 7px;
}
.dist-bar b { font-size: .8rem; }
.dist-row.hl .dist-bar { background: linear-gradient(90deg, #ff9445, #f03a4f); color: #fff; }

.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--panel-border); }
.setting:last-of-type { border-bottom: 0; }
.setting b { display: block; }
.setting small { color: var(--muted); font-size: .82rem; }
.switch {
  flex: none; width: 50px; height: 30px; border-radius: 99px; border: 0; padding: 3px;
  background: rgba(128, 150, 190, .35); position: relative; transition: background .2s;
}
.switch i { display: block; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 6px rgba(0,0,0,.3); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(20px); }
.fineprint { margin: 14px 0 0; font-size: .8rem; color: var(--muted); }

/* ---------- win burst ---------- */
.burst { position: absolute; left: 50%; top: 50%; pointer-events: none; }
.burst i {
  position: absolute; width: 8px; height: 8px; border-radius: 50%;
  background: var(--success); box-shadow: 0 0 12px var(--success);
  animation: fly 1.2s cubic-bezier(.2,.7,.3,1) forwards;
}
.burst i:nth-child(3n) { background: #ffd27a; box-shadow: 0 0 12px #ffd27a; }
.burst i:nth-child(3n+1) { background: #5cc8ff; box-shadow: 0 0 12px #5cc8ff; }
@keyframes fly {
  from { transform: rotate(var(--a)) translateX(0) scale(1); opacity: 1; }
  to { transform: rotate(var(--a)) translateX(var(--d)) scale(.3); opacity: 0; }
}

.noscript { text-align: center; padding: 40px; }

/* ---------- responsive ---------- */
/* Phones + small tablets (owner: Pocket, mobile pass 2026-12-05).
   One column: compact chrome, globe sized to the screen, guess bar docked to the bottom. */
@media (max-width: 860px) {
  .layout { flex: 1 0 auto; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; align-content: start; gap: 10px; padding: 0 10px max(12px, env(safe-area-inset-bottom)); }
  /* Globe takes what is left after the header (~170px), the docked guess bar and a ~70px peek of the
     guess panel, never wider than the screen (the sphere is round: extra height is dead space). */
  .globe-wrap { min-height: 0; height: clamp(220px, calc(100dvh - var(--dock-h, 120px) - 240px), min(92vw, 64dvh)); }
  /* No backdrop-filter here: it would make .panel the containing block of the position:fixed dock,
     so the dock sat on top of the panel instead of the screen bottom (and overflowed on 360px phones). */
  .panel { padding: 12px; border-radius: 20px; backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--panel-solid); }
  .guess-list { overflow: visible; }
  /* Docked guess bar: pinned to the bottom, lifted above the keyboard via visualViewport (main.js). */
  .dock {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    padding: 8px 10px max(8px, env(safe-area-inset-bottom));
    background: var(--panel-solid); border-top: 1px solid var(--panel-border);
    box-shadow: var(--dock-shadow);
    gap: 6px;
  }
  .dock-best { display: block; font-size: .8rem; font-weight: 700; color: var(--muted); padding: 0 4px; }
  /* The feedback line already names the best guess: show one or the other, not both. */
  .dock-best:has(~ .guess-feedback:not([hidden])) { display: none; }
  .guess-feedback { font-size: .84rem; padding: 6px 10px; line-height: 1.3; }
  body.playing { padding-bottom: calc(var(--dock-h, 130px) + 8px); }
  /* Suggestions open upward and never run above the visible area when the keyboard is up (--vvh: main.js). */
  .ac-list { top: auto; bottom: calc(100% + 6px); max-height: min(300px, calc(var(--vvh, 100dvh) - var(--dock-h, 130px) - 12px)); overscroll-behavior: contain; }
  .ac-item { min-height: 44px; align-items: center; }
  #guess-input, .guess-btn { height: 46px; }
  #guess-input { font-size: 16px; } /* >=16px: iOS Safari does not zoom the page on focus */
  .action-row .btn { height: 40px; }
  .controls { padding: 2px 10px 8px; gap: 8px; }
  .topbar { padding-left: 10px; padding-right: 10px; }
  .icon-btn, .tool-btn { width: 44px; height: 44px; }
  .seg button { min-height: 40px; }
  .select-wrap { height: 44px; }
  .select-wrap select { align-self: stretch; }
  /* Modal controls: 44px hit areas (the switch keeps its look; an invisible ring widens the target). */
  .close-btn { width: 44px; height: 44px; right: 8px; top: 8px; }
  .seg.small button { min-height: 44px; }
  .switch::after { content: ""; position: absolute; inset: -8px -4px; }
  /* Compact flag: small flag left, caption right. */
  .flag-card { --flag-h: 66px; gap: 12px; padding: 8px 12px 8px 8px; }
  /* SEO copy + games strip below the game: never wider than the screen (the comparison table
     forced the page to 369px on 360px phones); wide tables scroll inside their own box. */
  .layout > .seo-text, .layout > .more-games { min-width: 0; max-width: 100%; margin-left: 0; margin-right: 0; }
  .layout > .seo-text { padding-left: 8px; padding-right: 8px; }
  .seo-text table { display: block; max-width: 100%; overflow-x: auto; }
}
/* Tablets in portrait: keep the docked bar a comfortable width instead of a 700px-wide input. */
@media (min-width: 601px) and (max-width: 860px) {
  .dock { left: max(0px, calc(50% - 300px)); right: max(0px, calc(50% - 300px)); border: 1px solid var(--panel-border); border-bottom: 0; border-radius: 18px 18px 0 0; }
}
/* Phones in landscape: globe left, guesses right, guess bar docked under the guesses column. */
@media (max-width: 860px) and (orientation: landscape) and (max-height: 520px) {
  .topbar { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 2px; padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .controls { padding: 2px max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left)); flex-wrap: nowrap; }
  .controls .seg button { min-height: 40px; padding: 5px 12px; }
  .select-wrap { height: 44px; }
  .layout {
    grid-template-columns: minmax(0, 1fr) min(380px, 46vw); grid-template-rows: auto; align-items: start;
    padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right));
  }
  .globe-wrap { height: calc(100dvh - 112px); min-height: 220px; position: sticky; top: 6px; }
  .layout > :not(.globe-wrap):not(.panel) { grid-column: 1 / -1; }
  .dock { left: auto; right: max(0px, env(safe-area-inset-right)); width: calc(min(380px, 46vw) + 20px); border-radius: 18px 18px 0 0; border: 1px solid var(--panel-border); border-bottom: 0; }
  .dock-best { display: none; }
  .ac-list { max-height: min(240px, calc(var(--vvh, 100dvh) - var(--dock-h, 110px) - 8px)); }
}
/* "More games" strip (markup: index.html, card styles: css/games-strip.css). Phones: last grid row,
   below the guess list, so it never moves the globe or the dock. Desktop: the game is a fixed 100dvh view,
   so the strip sits just below the fold and pushes the build's .seo-text section down by its height. */
.layout > .more-games { grid-column: 1 / -1; min-width: 0; width: 100%; max-width: 760px; box-sizing: border-box; }
/* Below-the-fold SEO copy: skip its style/layout/paint until it nears the viewport (cuts main-thread work at load). */
.layout > .seo-text { content-visibility: auto; contain-intrinsic-size: auto 2600px; }
@media (max-width: 600px) { .layout > .seo-text { contain-intrinsic-size: auto 3800px; } }
@media (min-width: 861px) {
  body { height: 100dvh; overflow: hidden; }
  .layout { overflow: hidden; }
  .panel { overflow: hidden; }
  .layout > .more-games { position: absolute; top: 100dvh; left: 0; right: 0; height: 230px; margin: 0 auto; padding-top: 24px; }
  main.layout > .seo-text { top: calc(100dvh + 230px); }
}
@media (max-width: 600px) {
  /* Four mode tabs share one full-width row; scrolls rather than wraps if a locale gets longer. */
  .controls > .seg:first-child { display: flex; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .controls > .seg:first-child::-webkit-scrollbar { display: none; }
  .controls > .seg:first-child button { flex: 1 0 auto; padding: 7px 8px; font-size: .92rem; white-space: nowrap; }
  /* Level + Region split the second row evenly. */
  .controls > .select-wrap { flex: 1 1 0; min-width: 0; }
  .controls > .select-wrap select { flex: 1; min-width: 0; max-width: none; }
}
@media (max-width: 420px) {
  .brand-name { font-size: 1.25rem; }
  .brand-mark { width: 28px; height: 28px; }
  .top-actions { gap: 4px; }
  .select-wrap { padding-left: 8px; }
  .select-label { display: none; }
  .action-row .btn { white-space: nowrap; font-size: .86rem; padding: 0 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .guess-item { grid-template-columns: 12px minmax(0, 1fr) auto 40px 44px; gap: 7px; padding: 8px; }
  .g-dir small { display: none; }
  .win-actions .btn svg { display: none; }
  .legend-bar { width: 64px; }
  .modal-card { padding: 18px; }
  .stat-tiles { grid-template-columns: repeat(3, 1fr); }
}
/* First visit (main.js adds .first-run): a compact coach card, not a wall of rules.
   Full rules, modes and credits stay one tap away behind the "?" button. */
dialog.modal.first-run .howto-notes, dialog.modal.first-run .about-credits { display: none; }
@media (max-width: 600px) {
  dialog.modal.first-run {
    margin: auto 0 0; width: 100vw; max-width: 100vw; max-height: calc(100dvh - 48px);
  }
  dialog.modal.first-run::backdrop { background: rgba(20, 40, 80, .18); backdrop-filter: none; -webkit-backdrop-filter: none; }
  dialog.modal.first-run .modal-card {
    border-radius: 22px 22px 0 0; border-bottom: 0;
    padding: 18px 16px max(16px, env(safe-area-inset-bottom));
  }
  dialog.modal.first-run h2 { font-size: 1.2rem; margin-bottom: 8px; }
  dialog.modal.first-run .lead { display: none; }
  dialog.modal.first-run .howto-steps { font-size: .93rem; line-height: 1.45; margin-bottom: 10px; }
  dialog.modal.first-run .howto-example { margin-bottom: 12px; gap: 4px; }
  dialog.modal.first-run .ex-row { padding: 6px 10px; }
  dialog.modal.first-run #howto-ok { height: 48px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
