:root {
  color-scheme: light;
  --ink: #13272b;
  --muted: #647174;
  --paper: #f7f4ec;
  --panel: #fffdf7;
  --line: #cfd6d3;
  --land: rgba(255, 255, 255, 0.12);
  --land-line: rgba(40, 70, 70, 0.65);
  --accent: #ef7d43;
  --accent-strong: #c94e2e;
  --sea: #cde7ec;
  --good: #1e805f;
  --bad: #b43c3c;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  height: 100vh;
  height: 100dvh;
  background:
    radial-gradient(circle at 15% 5%, rgba(239, 125, 67, 0.13), transparent 28rem),
    linear-gradient(180deg, #edf7f7 0%, var(--paper) 48%, #f3efe4 100%);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  min-width: 90px;
  min-height: 44px;
  border: 1px solid #b9c4bf;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  touch-action: manipulation;
}

.app-shell {
  width: min(1180px, 100%);
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: var(--shell-gap, 8px);
  overflow: hidden;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.9rem);
  line-height: 1.02;
}

.scoreboard {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.mode-panel {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: end;
}

.mode-copy h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.mode-options {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.mode-option {
  min-height: 76px;
  border: 1px solid #bdc8c2;
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.mode-option input {
  width: 20px;
  min-height: 20px;
  accent-color: #1d4f5c;
}

.mode-option strong,
.mode-option small {
  display: block;
}

.territory-option {
  grid-column: 1 / -1;
  min-height: 58px;
  border: 1px solid #bdc8c2;
  border-radius: 8px;
  background: #fff;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.territory-option input {
  width: 20px;
  min-height: 20px;
  accent-color: #1d4f5c;
}

.territory-option strong,
.territory-option small {
  display: block;
}

.territory-option small {
  margin-top: 2px;
  color: var(--muted);
}

.mode-option strong {
  font-size: 0.96rem;
}

.mode-option small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.25;
}

#startButton {
  grid-column: 2;
  min-width: 136px;
  padding: 0 18px;
  background: #1d4f5c;
  border-color: #173f49;
  color: #fff;
  font-weight: 850;
}

.continent-picker,
.label-size-picker,
.display-language-picker {
  grid-column: 1 / -1;
  display: grid;
  gap: 6px;
}

.continent-picker span,
.label-size-picker span,
.display-language-picker span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.continent-picker select,
.label-size-picker select,
.display-language-picker select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #a8b8b4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font: inherit;
}

[hidden] {
  display: none !important;
}

.scoreboard div {
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.88);
  display: grid;
  align-content: center;
  gap: 2px;
}

.scoreboard span {
  font-size: 1.18rem;
  font-weight: 850;
}

.scoreboard small {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0;
}

.map-panel {
  flex: 1 1 auto;
  position: relative;
  aspect-ratio: 2 / 1;
  width: min(100%, calc(var(--map-height, 42vh) * 2));
  height: var(--map-height, 42vh);
  min-height: 0;
  align-self: start;
  justify-self: center;
  border: 1px solid #adc5c7;
  border-radius: 8px;
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 6px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.22), rgba(255, 255, 255, 0.22)),
    var(--sea);
  box-shadow: 0 12px 30px rgba(31, 74, 76, 0.12);
}

.map-area {
  flex: 1 1 auto;
  min-height: 0;
}

.map-tools {
  position: static;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  padding: 6px;
  background: rgba(255, 253, 247, 0.78);
  border-bottom: 1px solid rgba(70, 100, 100, 0.18);
}

.icon-button {
  width: 44px;
  min-width: 44px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  font-size: 1.2rem;
  font-weight: 850;
}

.world-button {
  min-width: 64px;
  padding: 0 10px;
  font-size: 0.88rem;
  font-weight: 850;
}

.terrain-toggle {
  min-width: 118px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 850;
}

.terrain-relief.is-hidden {
  opacity: 0;
}

#worldMap {
  width: 100%;
  height: 100%;
  aspect-ratio: 2 / 1;
  min-height: 0;
  display: block;
  cursor: grab;
  touch-action: none;
}

#worldMap.dragging {
  cursor: grabbing;
}

.country {
  fill: var(--land);
  stroke: var(--land-line);
  stroke-width: 0.5;
  vector-effect: non-scaling-stroke;
  transition:
    fill 160ms ease,
    stroke 160ms ease,
    opacity 160ms ease;
}

.terrain-layer,
.terrain-relief {
  display: block;
  visibility: visible;
  opacity: 0.94;
  filter: contrast(1.15) saturate(1.05);
  pointer-events: none;
}

.river {
  fill: none;
  stroke: rgba(0, 120, 180, 0.75);
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 1;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.country.dimmed {
  opacity: 0.66;
}

.country.outside-region {
  display: none;
}

.country.completed {
  fill: rgba(186, 230, 190, 0.18);
  stroke: rgba(28, 94, 68, 0.72);
  stroke-width: 0.65;
  opacity: 0.94;
}

.country.active {
  fill: var(--accent);
  stroke: #6a2e1f;
  stroke-width: 1.8;
  opacity: 1;
  filter: drop-shadow(0 2px 4px rgba(76, 40, 20, 0.35));
}

.country-label {
  fill: rgba(19, 39, 43, 0.78);
  stroke: rgba(255, 253, 247, 0.82);
  stroke-width: 1.6;
  paint-order: stroke;
  font-size: 9px;
  font-weight: 400;
  opacity: 0.85;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.country-label-leader {
  stroke: rgba(19, 39, 43, 0.58);
  stroke-width: 0.55;
  stroke-linecap: round;
  vector-effect: non-scaling-stroke;
  pointer-events: none;
}

.guess-panel {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  padding: 10px;
  display: grid;
  gap: 8px;
}

.controls {
  flex: 0 0 auto;
}

.guess-panel label {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input {
  width: 100%;
  min-height: 44px;
  border: 1px solid #a8b8b4;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 0 12px;
  font-size: 1rem;
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(239, 125, 67, 0.34);
  outline-offset: 2px;
}

#submitButton {
  min-width: 90px;
  padding: 0 16px;
  background: #1d4f5c;
  border-color: #173f49;
  color: #fff;
  font-weight: 800;
}

.hints {
  min-height: 30px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.hint {
  flex: 0 0 auto;
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid #c8d2cd;
  border-radius: 8px;
  background: #fff;
  color: #24484f;
  font-size: 0.9rem;
  font-weight: 750;
}

.feedback {
  white-space: pre-line;
  min-height: 2.5em;
  line-height: 1.25;
  margin: 0;
  color: var(--muted);
  font-weight: 750;
  display: flex;
  align-items: center;
}

.status-message {
  min-height: 2.5em;
  line-height: 1.25;
}

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

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

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

.actions button {
  flex: 1 1 130px;
  min-width: 90px;
  min-height: 44px;
  padding: 0 12px;
  font-weight: 800;
}

#revealButton {
  color: var(--accent-strong);
}

.primary-action {
  background: #1d4f5c;
  border-color: #173f49;
  color: #fff;
  font-weight: 850;
}

.secondary-action {
  flex-basis: 100%;
}

.actions #nextButton {
  flex-basis: 100%;
}

.actions #nextButton[hidden] {
  display: block !important;
  visibility: hidden;
  pointer-events: none;
}

@media (max-width: 700px) {
  .app,
  .app-shell {
    height: 100dvh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .topbar {
    order: 1;
  }

  .map-panel {
    order: 2;
  }

  .scoreboard {
    order: 3;
  }

  .guess-panel {
    order: 4;
  }

  .mode-panel,
  .mode-options {
    grid-template-columns: 1fr;
  }

  #startButton {
    grid-column: 1;
    width: 100%;
  }

  .scoreboard {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }

  .scoreboard div {
    min-height: 42px;
    padding: 4px;
  }

  .scoreboard span {
    font-size: 0.82rem;
  }

  .scoreboard small {
    font-size: 0.52rem;
  }

  .country-label {
    font-size: 7px;
    stroke-width: 1.25;
  }

  .country-label-leader {
    stroke-width: 0.5;
  }

  .map-panel {
    flex: 0 0 35dvh;
    width: 100%;
    height: 35dvh;
    min-height: 30dvh;
    max-height: 38dvh;
    align-self: stretch;
    justify-self: auto;
  }

  .map-area {
    flex: 0 0 35dvh;
    height: 35dvh;
    min-height: 30dvh;
    max-height: 38dvh;
  }

  .map-area svg {
    width: 100%;
    height: 100%;
  }

  .controls {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .guess-panel {
    padding: 6px;
    gap: 5px;
  }

  .guess-panel label {
    font-size: 0.66rem;
  }

  .input-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  input,
  button {
    min-height: 40px;
  }

  #submitButton {
    width: 100%;
  }

  .hints {
    min-height: 24px;
    gap: 4px;
  }

  .hint {
    min-height: 26px;
    padding: 3px 8px;
    font-size: 0.82rem;
  }

  .feedback,
  .status-message {
    min-height: 2em;
    font-size: 0.86rem;
  }

  .actions {
    gap: 6px;
  }

  .actions button {
    flex: 1 1 calc(50% - 6px);
    min-height: 40px;
    padding: 0 8px;
    font-size: 0.9rem;
  }

  .secondary-action,
  .actions #nextButton {
    flex-basis: calc(50% - 6px);
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell {
    align-items: stretch;
  }

  .guess-panel {
    align-self: auto;
  }
}

@media (max-height: 720px) {
  .eyebrow {
    margin-bottom: 2px;
    font-size: 0.68rem;
  }

  h1 {
    font-size: clamp(1.1rem, 3vw, 1.55rem);
  }

  .scoreboard div {
    min-height: 44px;
    padding: 5px 8px;
  }

  .scoreboard span {
    font-size: 1rem;
  }

  .scoreboard small,
  .guess-panel label {
    font-size: 0.68rem;
  }

  .guess-panel {
    padding: 8px;
    gap: 6px;
  }

  .feedback {
    font-size: 0.9rem;
  }
}
