:root {
  --page: #efe7d8;
  --ocean-1: #d4e2e0;
  --ocean-2: #95bcc4;
  --land: #f3e9d6;
  --territory: #ddd0b6;
  --border: #e0d3b7;
  --solved: #7d9b4e;
  --solved-hover: #719044;
  --wrong: #d35400;
  --selected: #e0761a;
  --marker: #fffdf6;
  --marker-ring: #8a7452;
  --label-ink: #33291c;

  --panel: #fbf6ec;
  --panel-border: #e6dcc7;
  --pill-bg: #f1e7d3;
  --pill-ink: #6f5b3c;
  --input-bg: #fffdf7;
  --btn-bg: #fbf6ec;
  --btn-border: #dccdb0;
  --btn-hover: #f4ebd9;
  --accent: #a2501f;
  --accent-ring: rgba(162, 80, 31, .22);
  --shadow: 0 12px 30px rgba(88, 62, 28, .24);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--page);
  color: var(--label-ink);
  font: 15px/1.45 'Segoe UI', system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button {
  font: inherit;
  padding: 7px 13px;
  border: 1px solid var(--btn-border);
  border-radius: 9px;
  background: var(--btn-bg);
  color: var(--label-ink);
  cursor: pointer;
  transition: background .15s ease;
}
button:hover { background: var(--btn-hover); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

button.primary {
  padding: 11px 22px;
  border-color: transparent;
  background: var(--solved);
  color: #fff;
  font-weight: 650;
}
button.primary:hover { background: var(--solved-hover); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  flex: 0 0 auto;
}
.icon-btn[hidden] { display: none; }
.icon-btn .icon { width: 18px; height: 18px; display: block; }

.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 9px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--panel-border);
  z-index: 6;
  position: relative;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .2px;
  white-space: nowrap;
}
.logo { width: 18px; height: 18px; fill: var(--accent); flex: 0 0 auto; }

.field { position: relative; justify-self: center; width: min(440px, 100%); }

#answer {
  width: 100%;
  padding: 8px 13px;
  font: inherit;
  font-size: 15px;
  color: var(--label-ink);
  background: var(--input-bg);
  border: 1.5px solid var(--btn-border);
  border-radius: 10px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
#answer::placeholder { color: var(--pill-ink); opacity: .85; }
#answer:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3.5px var(--accent-ring);
}
#answer:disabled { opacity: .72; cursor: not-allowed; }

@keyframes name-shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-7px); }
  30% { transform: translateX(7px); }
  45% { transform: translateX(-5px); }
  60% { transform: translateX(5px); }
  78% { transform: translateX(-2px); }
}
#answer.shake {
  animation: name-shake .4s cubic-bezier(.36, .07, .19, .97);
  border-color: var(--wrong);
  box-shadow: 0 0 0 3.5px rgba(211, 84, 0, .18);
}
@media (prefers-reduced-motion: reduce) {
  #answer.shake { animation: none; }
}

#suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px);
  z-index: 30; margin: 0; padding: 5px; max-height: 260px; overflow: auto;
  list-style: none; background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 13px;
  box-shadow: var(--shadow);
}
#suggestions li { padding: 8px 11px; border-radius: 8px; cursor: pointer; color: var(--label-ink); }
#suggestions li:hover, #suggestions li[aria-selected='true'] { background: var(--btn-hover); }

.actions { display: flex; align-items: center; gap: 8px; justify-self: end; }

.counter {
  display: inline-flex;
  align-items: stretch;
  height: 36px;
  margin: 0;
  border: 1px solid var(--btn-border);
  border-radius: 10px;
  background: var(--btn-bg);
  color: var(--pill-ink);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}
.stat-item { display: inline-flex; align-items: center; gap: 6px; padding: 0 13px; font-size: 15px; }
.stat-item b { font-weight: 700; color: var(--label-ink); }
.stat-item + .stat-item { border-left: 1px solid var(--panel-border); }
.si { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.c-correct .si { color: var(--solved); }
.c-wrong .si { color: var(--wrong); }
.c-left .si { color: var(--pill-ink); }
#timer { display: none !important; }

.time-line { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; background: transparent; pointer-events: none; }
.time-line[hidden] { display: none; }
.time-line > div { height: 100%; background: var(--accent); transition: width .25s linear, background .3s; }
.time-line.low > div { background: var(--wrong); }

main { position: relative; flex: 1 1 auto; min-height: 0; }

.map-wrap {
  position: absolute; inset: 0; overflow: hidden; cursor: grab; user-select: none;
  background: radial-gradient(125% 105% at 50% 12%, var(--ocean-1), var(--ocean-2));
}
.map-wrap.panning { cursor: grabbing; }
.map-wrap:focus { outline: none; }
.map-wrap:focus-visible { box-shadow: inset 0 0 0 3px var(--accent-ring); }

.map-pan { position: absolute; inset: 0; }
#mapPan canvas { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; }

.map-tip {
  position: fixed; z-index: 40; left: 0; top: 0; pointer-events: none;
  padding: 5px 11px; border-radius: 8px;
  background: var(--panel); color: var(--label-ink);
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 600; white-space: nowrap;
}

.zoom-controls {
  position: absolute; top: 12px; right: 12px; z-index: 4;
  display: flex; flex-direction: column; border-radius: 11px;
  overflow: hidden; box-shadow: var(--shadow);
}
.zoom-controls button {
  width: 40px; height: 38px; padding: 0; border: 0; border-radius: 0;
  background: var(--panel); color: var(--label-ink); font-size: 17px; line-height: 1;
}
.zoom-controls button + button { border-top: 1px solid var(--panel-border); }
.zoom-controls button:hover { background: var(--btn-hover); }

dialog#victory {
  width: calc(100% - 40px); max-width: 420px; padding: 0; border: 0;
  border-radius: 18px; background: var(--panel); color: var(--label-ink); box-shadow: var(--shadow);
}
dialog#victory::backdrop { background: rgba(40, 30, 15, .45); backdrop-filter: blur(2px); }
.victory-body { padding: 26px 26px 24px; text-align: center; }
.victory-emoji { margin: 0 0 6px; font-size: 40px; line-height: 1; }
.victory-body h2 { margin: 0 0 18px; font-size: 21px; font-weight: 700; }
.victory-stats { display: flex; gap: 12px; margin: 0 0 22px; }
.stat { flex: 1; padding: 12px; border-radius: 12px; background: var(--pill-bg); }
.stat-label { display: block; font-size: 12px; color: var(--pill-ink); margin-bottom: 3px; }
.stat strong { font-size: 22px; font-variant-numeric: tabular-nums; }

.boot-status { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--label-ink); font-size: 14px; font-weight: 500; pointer-events: none; }
.boot-status[hidden] { display: none; }
.boot-status.error { background: var(--panel); color: var(--accent); padding: 24px; text-align: center; pointer-events: auto; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--panel-border); border-top-color: var(--accent); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

dialog#start, dialog#gameover {
  width: calc(100% - 40px); max-width: 400px; padding: 0; border: 0;
  border-radius: 18px; background: var(--panel); color: var(--label-ink); box-shadow: var(--shadow);
}
dialog#start::backdrop, dialog#gameover::backdrop { background: rgba(40, 30, 15, .45); backdrop-filter: blur(2px); }
.menu-body { display: flex; flex-direction: column; gap: 16px; padding: 26px; margin: 0; }
.menu-body h2 { margin: 0; font-size: 24px; font-weight: 700; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.menu-label, .menu-row > label { font-size: 15px; }
.menu-hint { margin: 0; font-size: 13px; color: var(--pill-ink); }
.menu-hint:empty { display: none; }
.stepper { display: flex; width: 170px; border: 1.5px solid var(--btn-border); border-radius: 8px; background: var(--input-bg); overflow: hidden; }
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.stepper input { flex: 1; min-width: 0; width: 0; border: 0; border-radius: 0; background: transparent; text-align: center; font: inherit; font-size: 15px; font-variant-numeric: tabular-nums; padding: 9px 0; box-shadow: none; outline: none; color: inherit; }
.stepper .step { width: 36px; padding: 0; border: 0; border-radius: 0; background: transparent; font-size: 18px; line-height: 1; cursor: pointer; }
.stepper .step:hover { background: var(--btn-hover); }
.seg { display: flex; gap: 0; width: 170px; }
.seg-btn { flex: 1; padding: 9px 0; font-size: 14px; border-radius: 0; }
.seg-btn:first-child { border-radius: 8px 0 0 8px; }
.seg-btn:last-child { border-radius: 0 8px 8px 0; margin-left: -1.5px; }
.seg-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 650; position: relative; }
.menu-start { min-height: 46px; font-size: 16px; }
.menu-actions { display: flex; gap: 10px; }
.menu-actions button { flex: 1; min-height: 44px; }
.victory-stats { margin: 0; }
