:root {
  --ink: #14282f;
  --paper: #fbf8f1;
  --sea: #bcd9e3;
  --land: #efe6cf;
  --coast: #8f8367;
  --river: #5b9fc4;
  --mark: #e2462f;
  --ok: #1f7a4d;
  --bad: #b3261e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.4 "Segoe UI", system-ui, sans-serif;
}

button {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: #fff1c9; }
button:focus-visible { outline: 3px solid #f2a900; outline-offset: 2px; }
button:disabled { cursor: default; }
button.primary { background: var(--ink); color: #fff; }
button.primary:hover { background: #24505e; }

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  border-bottom: 2px solid var(--ink);
}
h1 { margin: 0; font: 700 22px Georgia, serif; }
.stats { display: flex; gap: 16px; margin-left: auto; font-variant-numeric: tabular-nums; }

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

#mapWrap { position: relative; flex: 1; min-width: 0; min-height: 0; }

#map {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--sea);
  touch-action: none;
  cursor: grab;
}
#map.dragging { cursor: grabbing; }
#map.pick { cursor: crosshair; }
#map path { vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }

.land { fill: var(--land); stroke: var(--coast); stroke-width: .8; fill-rule: evenodd; }
.lakes { fill: var(--sea); stroke: var(--river); stroke-width: .8; }
.rivers { fill: none; stroke: var(--river); stroke-width: 1; }
.borders { fill: none; stroke: #a08f66; stroke-width: 1; }

.hl-water { fill: #f59a7f; stroke: var(--mark); stroke-width: 2; }
.hl-area { fill: rgba(226, 70, 47, .6); stroke: #8e1f10; stroke-width: 1.5; fill-rule: evenodd; }
.hl-line { fill: none; stroke: var(--mark); stroke-width: 4.5; }
.hl-point { fill: var(--mark); stroke: #fff; stroke-width: 2; }
.ring { fill: none; stroke: var(--mark); stroke-width: 2.5; animation: pulse 1.4s ease-out infinite; }

.good.hl-water, .good.hl-area { fill: rgba(31, 122, 77, .65); stroke: #0d4a2c; }
.good.hl-line, .good.ring { stroke: var(--ok); }
.good.hl-point { fill: var(--ok); }
.click-mark { fill: var(--ink); stroke: #fff; stroke-width: 2; }

@keyframes pulse {
  from { stroke-opacity: 1; stroke-width: 4; }
  to { stroke-opacity: .15; stroke-width: 1; }
}

.zoom {
  position: absolute;
  right: 12px;
  bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.zoom button { width: 42px; height: 42px; padding: 0; font-size: 22px; line-height: 1; }

.toggle { display: flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap; }
.stats + .toggle { margin-left: 0; }
header .toggle { margin-left: auto; }
header .stats:not([hidden]) { margin-left: auto; }
header .stats:not([hidden]) + .toggle { margin-left: 0; }

.label {
  pointer-events: none;
  paint-order: stroke;
  stroke-linejoin: round;
  text-anchor: middle;
  dominant-baseline: central;
  user-select: none;
}
.label.country { fill: #5c5138; stroke: rgba(251, 248, 241, .85); font-weight: 600; }
.label.place { fill: #fff; stroke: #5e1208; font-weight: 700; }
.label.place.good { stroke: #0b3a22; }

.panel {
  width: 330px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  min-height: 0;
  overflow-y: auto;
  border-left: 2px solid var(--ink);
}
select, input[type=text] {
  font: inherit;
  color: inherit;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
}
#category, #learnHint { margin: 0; color: #55696f; font-size: 14px; }
#question, #learnName { margin: 0; font: 700 24px/1.25 Georgia, serif; }
#answers { display: grid; gap: 8px; }
#answers:empty { display: none; }
#answers button { text-align: left; min-height: 46px; }
#answers button.correct { background: var(--ok); border-color: var(--ok); color: #fff; }
#answers button.wrong { background: var(--bad); border-color: var(--bad); color: #fff; }
#typeForm { display: flex; gap: 8px; }
#typeInput { flex: 1; min-width: 0; }
#feedback { margin: 0; min-height: 1.4em; font-weight: 600; }
#feedback.ok { color: var(--ok); }
#feedback.bad { color: var(--bad); }
.actions { display: flex; gap: 8px; margin-top: auto; }
.actions button { flex: 1; }

#learnList {
  flex: 1;
  min-height: 80px;
  overflow-y: auto;
  display: grid;
  align-content: start;
  gap: 4px;
  margin: 0;
  padding: 3px;
  list-style: none;
}
#learnList button { width: 100%; text-align: left; border-width: 1px; padding: 6px 10px; }
#learnList button[aria-pressed=true] { background: var(--ink); color: #fff; }
#learnPanel .actions { margin-top: 0; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  background: rgba(12, 30, 38, .72);
}
.box {
  width: min(440px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  background: var(--paper);
  border-radius: 14px;
}
.box h2 { margin: 0; font: 700 30px Georgia, serif; }
.mode { display: grid; gap: 2px; text-align: left; padding: 14px; }
.mode b { font-size: 19px; }
.mode.learn { background: #e3f1e8; }

@media (max-width: 760px) {
  header { gap: 10px; padding: 8px 10px; }
  h1 { display: none; }
  .stats { font-size: 14px; gap: 10px; }
  header .stats:not([hidden]) { margin-left: 0; }
  header #menuBtn { margin-left: auto; }
  .toggle { font-size: 14px; }
  header .toggle { margin-left: 0; }
  main { flex-direction: column; }
  .panel {
    width: 100%;
    height: 48%;
    flex: none;
    padding: 10px 12px;
    gap: 6px;
    border-left: 0;
    border-top: 2px solid var(--ink);
  }
  #learnPanel > label, #learnHint { display: none; }
  .panel button, .panel select { padding-top: 5px; padding-bottom: 5px; }
  #question, #learnName { font-size: 19px; }
  #answers { grid-template-columns: 1fr 1fr; }
  #answers button { padding: 6px 8px; font-size: 14px; }
  .zoom { bottom: 8px; right: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .ring { animation: none; }
}
