:root {
  --bg: #0c1015;
  --panel: #151a21;
  --panel-2: #1c222a;
  --border: #2b333c;
  --text: #edf1f5;
  --text-dim: #8a96a3;

  --accent: #d99a4e;
  /* sand / ochre — brand accent, used sparingly */
  --accent-ink: #2a1a08;
  /* text color on top of accent-filled controls */
  --accent-dim: #6b5330;

  --good: #3fa587;
  /* correct / found */
  --good-dim: #1c3d34;
  --bad: #e2564f;
  /* wrong */
  --bad-dim: #4a2422;

  --sea: #0a1a1f;
  /* map background */
  --land: #2c3a48;
  /* province fill */
  --land-hover: #3a4b5c;
  --land-found: var(--good);
  --land-target: var(--accent);

  --font-display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Georgia, "Times New Roman", serif;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius: 14px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

button,
input {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 20px calc(60px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(20px + env(safe-area-inset-left, 0px));
  padding-right: calc(20px + env(safe-area-inset-right, 0px));
  display: flex;
  flex-direction: column;
  gap: 18px;
}

header.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 14px;
}

header.top h1 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  text-wrap: balance;
}

header.top h1 .flag {
  font-size: 1.3rem;
}

nav.tabs {
  display: flex;
  gap: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}

nav.tabs button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 9px 18px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  white-space: nowrap;
}

nav.tabs button:hover {
  color: var(--text);
}

nav.tabs button.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.game-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.prompt {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.prompt .label {
  color: var(--text-dim);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.prompt .target {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 600;
  color: var(--accent);
  text-wrap: balance;
}

.stats {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.stat .n {
  font-size: 1.15rem;
  font-weight: 700;
}

.stat .l {
  font-size: 0.7rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

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

button.btn {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.05s ease;
}

button.btn:hover {
  border-color: var(--accent-dim);
}

button.btn:active {
  transform: scale(0.97);
}

button.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

button.btn.primary:hover {
  filter: brightness(1.08);
}

.map-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--sea);
  border: 1px solid var(--border);
  box-shadow: inset 0 0 0 6px var(--panel), inset 0 0 40px rgba(0, 0, 0, 0.4);
  touch-action: none;
}

svg#map {
  display: block;
  width: 100%;
  height: auto;
  cursor: pointer;
  user-select: none;
}

path.province {
  fill: var(--land);
  stroke: var(--sea);
  stroke-width: 0.6;
  transition: fill 0.12s ease;
}

path.province:hover {
  fill: var(--land-hover);
}

path.province.found {
  fill: var(--land-found);
}

path.province.wrong-reveal {
  fill: var(--bad);
}

path.province.skip-reveal {
  fill: var(--accent);
}

.find-label {
  font-family: var(--font-body);
  font-size: 4px;
  fill: #f7fafc;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--sea);
  stroke-width: 0.8px;
  font-weight: 700;
}

path.province.awaiting {
  fill: var(--land-target);
  stroke: #ffffff;
  stroke-width: 1.4;
}

path.province.dim {
  opacity: 0.5;
}

.ref-label {
  font-family: var(--font-body);
  font-size: 3.6px;
  fill: #eef3f8;
  text-anchor: middle;
  pointer-events: none;
  paint-order: stroke;
  stroke: var(--sea);
  stroke-width: 0.6px;
  font-weight: 600;
}

.ref-label.small {
  font-size: 2.6px;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: #06121a;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  transform: translate(-50%, -130%);
  white-space: nowrap;
  box-shadow: var(--shadow);
  z-index: 5;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.tooltip.show {
  opacity: 1;
}

.zoom-controls {
  position: absolute;
  right: 10px;
  bottom: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 4;
}

.zoom-controls button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(21, 26, 33, 0.92);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}

.zoom-controls button:hover {
  border-color: var(--accent-dim);
}

.hint {
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 10px;
  line-height: 1.5;
}

.search-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.search-row input {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 12px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 0.9rem;
}

.search-row input:focus {
  outline: none;
  border-color: var(--accent);
}

.type-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
  align-items: center;
}

.type-form input {
  flex: 1;
  min-width: 200px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  font-family: var(--font-body);
  font-size: 1rem;
}

.type-form input:focus {
  outline: none;
  border-color: var(--accent);
}

.type-form input.correct {
  border-color: var(--good);
}

.type-form input.incorrect {
  border-color: var(--bad);
}

.feedback {
  min-height: 22px;
  font-weight: 700;
  font-size: 0.95rem;
}

.feedback.good {
  color: var(--good);
}

.feedback.bad {
  color: var(--bad);
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(6, 12, 18, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  text-align: center;
  padding: 20px;
  border-radius: 10px;
}

.overlay h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.7rem;
  font-weight: 600;
}

.overlay p {
  margin: 0;
  color: var(--text-dim);
  max-width: 46ch;
}

.hidden {
  display: none !important;
}

footer.foot {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.75rem;
  margin-top: 8px;
}

footer.foot a {
  color: var(--text-dim);
}

/* ---------- tablet ---------- */
@media (max-width: 900px) {
  .app {
    padding-top: 20px;
    gap: 14px;
  }

  .panel {
    padding: 14px;
  }
}

/* ---------- phone & small tablet ---------- */
@media (max-width: 640px) {
  header.top {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  header.top h1 {
    font-size: 1.3rem;
    justify-content: center;
  }

  nav.tabs {
    justify-content: stretch;
  }

  nav.tabs button {
    flex: 1;
    min-width: 0;
    padding: 10px 6px;
    font-size: 0.76rem;
    text-align: center;
    white-space: normal;
    line-height: 1.25;
  }

  .prompt {
    justify-content: center;
    width: 100%;
  }

  .prompt .target {
    font-size: 1.3rem;
  }

  .game-top {
    justify-content: center;
    text-align: center;
  }

  .stats {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .stat {
    align-items: center;
  }

  .actions {
    justify-content: center;
  }

  .actions .btn,
  .type-form .btn {
    flex: 1;
    min-width: 0;
    text-align: center;
  }

  .search-row input {
    font-size: 16px;
    /* prevents iOS auto-zoom on focus */
  }

  .type-form {
    flex-direction: column;
    align-items: stretch;
  }

  .type-form input {
    min-width: 0;
    font-size: 16px;
    /* prevents iOS auto-zoom on focus */
  }

  .type-form .btn {
    flex: none;
  }

  .zoom-controls button {
    width: 40px;
    height: 40px;
    font-size: 1.25rem;
  }

  button.btn {
    padding: 10px 14px;
    /* comfortable touch target */
  }
}

@media (max-width: 400px) {
  .app {
    padding-left: calc(12px + env(safe-area-inset-left, 0px));
    padding-right: calc(12px + env(safe-area-inset-right, 0px));
  }

  header.top h1 {
    font-size: 1.1rem;
  }

  .prompt .target {
    font-size: 1.1rem;
  }

  .stat .n {
    font-size: 1rem;
  }
}