:root {
  color-scheme: light;
  --page: #f5f7f2;
  --surface: #fff;
  --surface-muted: #edf1e9;
  --ink: #17241d;
  --muted: #64736a;
  --line: #dce4dc;
  --green: #266d4d;
  --green-light: #d9efdf;
  --yellow: #f0c84b;
  --shadow: 0 16px 48px #16352212;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--page); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.topbar { height: 68px; padding: 0 max(20px, calc((100% - 1040px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { color: var(--ink); text-decoration: none; font-size: 1.65rem; font-weight: 850; letter-spacing: -.08em; }
.brand span { color: #e08b44; }
.topbar nav { display: flex; align-items: center; gap: 8px; }
.nav-button, .icon-button, .text-button { border: 0; background: transparent; color: var(--ink); }
.nav-button { padding: 9px 13px; border-radius: 9px; font-size: .9rem; }
.nav-button:hover, .icon-button:hover { background: var(--surface-muted); }
.icon-button { min-width: 40px; min-height: 40px; border-radius: 10px; font-size: 1.25rem; }
main { padding: 34px 18px 56px; }
.game-shell { max-width: 760px; margin: auto; }
.round-heading { display: flex; align-items: end; justify-content: space-between; gap: 18px; margin-bottom: 14px; }
.eyebrow { margin: 0 0 6px; color: var(--green); font-size: .72rem; font-weight: 800; letter-spacing: .12em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.6rem, 5vw, 2.25rem); letter-spacing: -.045em; line-height: 1.1; }
h2 { margin-bottom: 0; font-size: 1.05rem; }
.round-meta { margin: 0; color: var(--muted); text-align: right; font-size: .85rem; line-height: 1.55; }
.round-meta strong { color: var(--ink); letter-spacing: .1em; }
.data-notice { margin-bottom: 12px; padding: 8px 11px; border: 1px solid #eddbad; border-radius: 8px; background: #fff9e8; color: #6a5421; font-size: .78rem; }
.map-card { overflow: hidden; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); }
.map-header, .guess-heading { display: flex; align-items: center; justify-content: space-between; }
.map-header { margin-bottom: 12px; }
.map-hint { color: var(--muted); font-size: .78rem; }
.text-button { padding: 5px 8px; color: var(--green); font-size: .84rem; font-weight: 650; }
.text-button:hover { text-decoration: underline; }
.treemap { display: grid; width: 100%; aspect-ratio: 1.85 / 1; min-height: 190px; overflow: hidden; border-radius: 10px; background: var(--surface-muted); }
.treemap svg { display: block; width: 100%; height: 100%; }
.treemap-cell { position: relative; display: flex; min-width: 0; min-height: 0; align-items: center; justify-content: center; overflow: hidden; padding: 5px; border: 2px solid var(--surface); color: #14251b; text-align: center; }
.treemap-cell span { overflow: hidden; max-height: 100%; font-size: clamp(.55rem, 1.4vw, .78rem); font-weight: 750; line-height: 1.2; text-overflow: ellipsis; }
.treemap-cell small { display: block; margin-top: 3px; font-size: .82em; font-weight: 600; opacity: .8; }
.treemap-cell[hidden] { display: none; }
.export-list { margin-top: 10px; color: var(--muted); font-size: .83rem; }
.export-list summary { cursor: pointer; }
.export-list ol { columns: 2; padding-left: 22px; color: var(--ink); }
.total-label { margin: 12px 0 0; color: var(--muted); font-size: .88rem; }
.total-label strong { margin-left: 5px; color: var(--ink); }
.play-area { margin-top: 22px; }
.guess-heading { margin-bottom: 8px; }
.guess-counter { color: var(--muted); font-size: .86rem; font-variant-numeric: tabular-nums; }
.guess-list { display: grid; gap: 6px; margin: 0 0 12px; padding: 0; list-style: none; }
.guess-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(65px, .7fr) 42px 46px; gap: 7px; align-items: center; min-height: 42px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); font-size: .88rem; }
.guess-row .country-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.guess-row .distance, .guess-row .proximity { text-align: right; font-variant-numeric: tabular-nums; }
.guess-row .arrow { text-align: center; font-size: 1.1rem; }
.guess-row.hit { border-color: #9acba8; background: var(--green-light); }
.guess-row.reveal { border-color: #e9c682; background: #fff5dc; }
.guess-form { display: flex; gap: 9px; }
.autocomplete { position: relative; flex: 1; min-width: 0; }
.autocomplete input, select { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #cbd6cc; border-radius: 9px; outline: none; background: var(--surface); color: var(--ink); }
.autocomplete input:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px #266d4d22; }
.primary-button, .secondary-button { min-height: 44px; padding: 10px 16px; border: 0; border-radius: 9px; font-weight: 750; }
.primary-button { background: var(--green); color: #fff; }
.primary-button:hover { background: #1d593d; }
.secondary-button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.secondary-button:hover { background: var(--surface-muted); }
.autocomplete-options { position: absolute; z-index: 3; top: calc(100% + 4px); right: 0; left: 0; max-height: 240px; overflow: auto; margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); box-shadow: var(--shadow); list-style: none; }
.autocomplete-options li { padding: 9px 10px; border-radius: 7px; cursor: pointer; }
.autocomplete-options li[aria-selected="true"], .autocomplete-options li:hover { background: var(--surface-muted); }
.autocomplete-options li[aria-disabled="true"] { color: var(--muted); cursor: not-allowed; text-decoration: line-through; }
.message { min-height: 1.4em; margin: 7px 0 0; color: #9b422f; font-size: .84rem; }
.round-result { margin: 10px 0; padding: 12px; border-radius: 10px; background: var(--green-light); font-weight: 700; }
.round-result.lost { background: #fff0d6; }
.end-actions { flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.end-actions:not([hidden]) { display: flex; }
.end-actions .primary-button { flex: 1 1 170px; }
.game-footer { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; margin-top: 18px; }
.game-footer .text-button { color: var(--muted); }
.source-link { align-self: center; color: var(--muted); font-size: .75rem; text-decoration: none; }
.source-link:hover { text-decoration: underline; }
.app-dialog { width: min(460px, calc(100% - 24px)); max-height: min(88vh, 760px); padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 80px #10201555; }
.app-dialog::backdrop { background: #12201988; backdrop-filter: blur(2px); }
.dialog-content { display: grid; gap: 16px; padding: 22px; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { font-size: 1.35rem; }
.close-button { font-size: 1.6rem; }
.dialog-content label:not(.toggle-label) { display: grid; gap: 6px; font-size: .9rem; font-weight: 700; }
.dialog-content fieldset { margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 9px; }
.dialog-content legend { padding: 0 4px; font-size: .9rem; font-weight: 700; }
.continent-options { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.toggle-label, .continent-options label { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.toggle-label input, .continent-options input { accent-color: var(--green); }
.import-label { cursor: pointer; color: var(--green); font-size: .9rem; font-weight: 700; }
.import-label input { display: block; width: 100%; margin-top: 5px; font-weight: 400; }
.stats-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-card { padding: 12px 8px; border-radius: 9px; background: var(--surface-muted); text-align: center; }
.stat-card strong { display: block; font-size: 1.25rem; }
.stat-card span { color: var(--muted); font-size: .7rem; }
.stats-distribution { display: grid; gap: 6px; }
.distribution-row { display: grid; grid-template-columns: 25px 1fr 28px; gap: 7px; align-items: center; font-size: .8rem; }
.distribution-bar { height: 12px; border-radius: 4px; background: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; clip-path: inset(50%); }
body.dark { color-scheme: dark; --page: #121b17; --surface: #1b2821; --surface-muted: #26372d; --ink: #edf4ee; --muted: #a4b4a9; --line: #36493d; --green: #60a982; --green-light: #294d37; --yellow: #d9bb48; --shadow: 0 16px 48px #0004; }
body.dark .topbar { border-color: var(--line); }
body.dark .data-notice { border-color: #5e5030; background: #302a1b; color: #e9d79c; }
body.dark .treemap-cell { color: #14251b; }
body.dark .guess-row.reveal { background: #332b1b; }
body.dark .primary-button { color: #102015; }
@media (max-width: 540px) {
  .topbar { height: 60px; padding: 0 12px; }
  .topbar nav { gap: 0; }
  .nav-button { padding: 8px; font-size: .8rem; }
  .icon-button { min-width: 36px; }
  main { padding: 22px 12px 36px; }
  .map-card { padding: 13px; }
  .treemap { min-height: 175px; aspect-ratio: 1.35 / 1; }
  .guess-row { grid-template-columns: minmax(0, 1fr) 64px 32px 38px; gap: 4px; padding: 5px 7px; font-size: .81rem; }
  .guess-form { gap: 6px; }
  .guess-form .primary-button { padding: 9px 12px; }
  .end-actions { gap: 6px; }
  .end-actions .secondary-button { flex: 1 1 112px; padding: 8px; font-size: .82rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .guess-row, .primary-button { transition: background-color .18s ease, transform .18s ease; }
  .guess-row.hit { animation: reveal .4s ease-out; }
  @keyframes reveal { from { transform: translateY(3px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }
}
