@font-face {
  font-family: "Fraunces";
  src: url("../fonts/Fraunces.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "Literata";
  src: url("../fonts/Literata.ttf") format("truetype");
  font-display: swap;
}

:root {
  --ink: #1f1a14;
  --paper: #f3ebe0;
  --sand: #e6d7c3;
  --clay: #8b4513;
  --sea: #3d6b8c;
  --land: #c4a574;
  --olive: #5a6b3a;
  --focus: #2c5282;
  --radius: 0.5rem;
  --border: 2px solid var(--ink);
  --shadow: 0 2px 0 color-mix(in srgb, var(--ink) 18%, transparent);
  --font-display: "Fraunces", "Palatino Linotype", Palatino, serif;
  --font-body: "Literata", "Georgia", serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background-color: var(--sand);
  background-image:
    linear-gradient(
      165deg,
      color-mix(in srgb, var(--paper) 28%, transparent),
      color-mix(in srgb, var(--sand) 35%, transparent)
    ),
    url("../img/page-texture.png");
  background-size: auto, 220px 220px;
  background-repeat: no-repeat, repeat;
  line-height: 1.45;
}

main {
  max-width: 96rem;
  margin: 0 auto;
  padding: 0.65rem 0.75rem 1.5rem;
}

.section {
  display: none;
}

.section.is-active {
  display: block;
  animation: fade-in 0.35s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(0.35rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 650;
  letter-spacing: 0.01em;
}

h1 {
  font-size: clamp(2.4rem, 6vw, 3.6rem);
  margin: 0.4rem 0 0.6rem;
  line-height: 1.05;
}

h2 {
  font-size: 1.55rem;
  margin: 0 0 0.75rem;
}

h3 {
  font-size: 1.05rem;
  margin: 0 0 0.45rem;
}

.purpose {
  max-width: 42rem;
  margin: 0 0 1.25rem;
  font-size: 1.05rem;
}

.top-actions,
.home-footer,
.player-actions,
.dialog-actions,
.choice-row,
.zoom-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.top-actions {
  justify-content: flex-end;
}

.home-footer {
  margin-top: 1.75rem;
}

button,
.map-card {
  font: inherit;
  color: var(--ink);
  background: color-mix(in srgb, var(--paper) 88%, white);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0.55rem 0.95rem;
  transition:
    background 0.15s ease,
    transform 0.12s ease,
    box-shadow 0.15s ease;
}

button:hover,
.map-card:hover {
  background: color-mix(in srgb, var(--sand) 70%, white);
  transform: translateY(-1px);
}

button:active,
.map-card:active {
  transform: translateY(1px);
  box-shadow: none;
}

button:focus-visible,
.map-card:focus-visible,
input:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

button.is-selected {
  background: color-mix(in srgb, var(--olive) 22%, var(--paper));
  border-color: var(--olive);
}

.player-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: center;
  margin: 0 0 1.35rem;
  padding: 0.85rem 1rem;
  border: var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 75%, white);
}

.player-badge {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.55rem 1rem;
  min-width: 8rem;
  flex: 1 1 12rem;
}

.player-name {
  font-family: var(--font-display);
  font-size: clamp(2rem, 5.5vw, 3rem);
  font-weight: 650;
  line-height: 1.05;
  letter-spacing: 0.01em;
}

.player-recent-score {
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 3vw, 1.55rem);
  font-weight: 600;
  opacity: 0.88;
}

.player-recent-score[hidden] {
  display: none !important;
}

.asked-count {
  margin: 0;
  font-size: 0.95rem;
  opacity: 0.85;
}

.map-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.1rem 1.25rem;
}

.map-card {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 0.45rem;
  padding: 1.35rem 1.4rem;
  min-height: 6.5rem;
}

.map-card .map-title {
  font-family: var(--font-display);
  font-size: clamp(1.3rem, 2.2vw, 1.55rem);
  font-weight: 650;
}

.map-card .map-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1rem;
  align-items: center;
}

.map-card .marks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem 0.85rem;
}

.map-card .mark {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.9rem;
  opacity: 0.75;
}

.map-card .mark.is-filled {
  opacity: 1;
}

.map-card .mark-dot {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 50%;
  border: 2px solid var(--ink);
  background: transparent;
}

.map-card .mark.is-filled .mark-dot {
  background: var(--olive);
  border-color: var(--olive);
}

.map-card .stars {
  font-size: 1.1rem;
  letter-spacing: 0.05em;
}

.map-card .map-note {
  font-size: 0.95rem;
  opacity: 0.8;
}

.map-stage .place-marker {
  fill: color-mix(in srgb, var(--clay) 70%, white);
  stroke: var(--ink);
  stroke-width: 1.5;
}

.map-stage .place-marker.disputed {
  fill: color-mix(in srgb, var(--sea) 35%, white);
}

.map-stage .disputed-label {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 650;
  fill: var(--clay);
  paint-order: stroke;
  stroke: color-mix(in srgb, var(--paper) 90%, white);
  stroke-width: 3px;
  text-anchor: middle;
  pointer-events: none;
}

.map-stage .feedback-arc {
  fill: none;
  stroke: var(--clay);
  stroke-width: 2.5;
  stroke-dasharray: 6 4;
  opacity: 0.9;
  pointer-events: none;
}

.map-stage .feedback-tap {
  fill: color-mix(in srgb, var(--clay) 55%, white);
  stroke: var(--ink);
  stroke-width: 2;
  pointer-events: none;
}

.map-stage .feedback-correct {
  fill: color-mix(in srgb, var(--olive) 45%, white);
  stroke: var(--olive);
  stroke-width: 2.5;
  pointer-events: none;
}

.map-stage .feature-path {
  fill: none;
  stroke: transparent;
  stroke-width: 1.5;
  pointer-events: none;
}

.map-stage .feature-path.feature-area {
  fill: transparent;
}

.map-stage .feature-path.is-highlighted {
  stroke: #c45c26;
  stroke-width: 5.5;
  stroke-linejoin: round;
  stroke-linecap: round;
  fill: none;
  opacity: 0.95;
}

.map-stage .feature-path.feature-area.is-highlighted {
  fill: color-mix(in srgb, #c45c26 12%, transparent);
}

.name-choices button.choice-correct {
  background: color-mix(in srgb, #3d7a4a 28%, var(--paper));
  border-color: #3d7a4a;
}

.name-choices button.choice-wrong {
  background: color-mix(in srgb, #a33c2c 24%, var(--paper));
  border-color: #a33c2c;
}

#round.is-active {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0;
}

.round-layout {
  position: relative;
  width: min(100%, 96vw);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 0.4rem;
  justify-items: stretch;
  padding: 0.45rem 0.5rem 0.65rem;
  border: var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 78%, white);
  box-shadow: 0 8px 28px color-mix(in srgb, var(--ink) 14%, transparent);
}

.round-header {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  align-items: baseline;
  text-align: center;
}

.prompt {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2.8vw, 1.55rem);
  flex: 0 1 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: baseline;
  gap: 0.35rem 0.55rem;
  text-align: center;
}

.prompt-mode {
  font-weight: 500;
  opacity: 0.72;
  font-size: 0.92em;
}

.prompt-target {
  font-weight: 700;
  font-size: 1.18em;
  letter-spacing: 0.01em;
}

.map-stage {
  position: relative;
  width: min(100%, calc(min(88vh, 92vw) * 4 / 5));
  aspect-ratio: 4 / 5;
  max-height: min(88vh, 58rem);
  height: auto;
  margin-inline: auto;
  overflow: hidden;
  border: var(--border);
  border-radius: var(--radius);
  background: transparent;
  touch-action: manipulation;
}

.map-stage svg {
  width: 100%;
  height: 100%;
  display: block;
  user-select: none;
  pointer-events: auto;
}

.map-stage .place-label {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 650;
  fill: var(--ink);
  paint-order: stroke;
  stroke: color-mix(in srgb, var(--paper) 90%, white);
  stroke-width: 3px;
  pointer-events: none;
}

.map-stage .water-label {
  font-family: var(--font-display);
  font-size: 22px;
  font-style: italic;
  font-weight: 600;
  fill: var(--sea);
  paint-order: stroke;
  stroke: color-mix(in srgb, #e8f2f8 85%, white);
  stroke-width: 4px;
  pointer-events: none;
}

.map-stage .guess-marker,
.map-stage .answer-marker {
  pointer-events: none;
}

.name-choices {
  width: min(100%, 42rem);
  margin-inline: auto;
  display: grid;
  gap: 0.55rem;
  justify-self: center;
}

.name-choices button {
  width: 100%;
  text-align: left;
}

.feedback-slot {
  width: min(100%, 42rem);
  min-height: 9.5rem;
  margin: 0.4rem auto 0.2rem;
  padding: 0.2rem 0;
  box-sizing: border-box;
  display: flex;
  align-items: stretch;
  justify-content: center;
  justify-self: center;
}

.feedback-panel {
  width: 100%;
  padding: 0.85rem 1rem;
  border: var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 82%, white);
  text-align: center;
}

.feedback-panel[hidden],
.name-choices[hidden],
.asked-count[hidden],
button[hidden],
.results-overlay[hidden] {
  display: none !important;
}

.results-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: color-mix(in srgb, var(--ink) 28%, transparent);
  border-radius: inherit;
}

.results-box,
.sources-box {
  max-width: 40rem;
  margin: 0 auto;
  padding: 1.25rem 1.35rem;
  border: var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 80%, white);
}

.results-overlay .results-box {
  width: min(100%, 26rem);
  box-shadow: 0 12px 40px color-mix(in srgb, var(--ink) 28%, transparent);
}

.sources-box ul {
  padding-left: 1.2rem;
}

.dialog-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: color-mix(in srgb, var(--ink) 45%, transparent);
  z-index: 40;
}

.dialog-backdrop.is-open {
  display: flex;
  animation: fade-in 0.2s ease-out;
}

.dialog {
  width: min(100%, 26rem);
  padding: 1.2rem 1.25rem;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 0 12px 40px color-mix(in srgb, var(--ink) 28%, transparent);
}

.dialog-setup,
.dialog-history {
  width: min(100%, 30rem);
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
  max-height: min(50vh, 22rem);
  overflow: auto;
}

.history-list li {
  padding: 0.55rem 0.7rem;
  border: var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--paper) 88%, white);
}

.history-list .history-points {
  font-family: var(--font-display);
  font-weight: 650;
}

.history-list .history-level {
  font-size: 0.95rem;
  opacity: 0.85;
}

.dialog label {
  display: block;
  margin: 0.65rem 0 0.35rem;
}

.dialog input[type="text"] {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: var(--border);
  border-radius: var(--radius);
  background: white;
}

.dialog input[type="range"] {
  width: 100%;
}

.dialog-actions {
  margin-top: 1rem;
}

.dialog-actions-setup {
  margin-top: 2rem;
  padding-top: 0.35rem;
}

.setup-choices {
  display: grid;
  gap: 1rem;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}

.player-list button {
  width: 100%;
  text-align: left;
}

@media (max-width: 640px) {
  main {
    padding: 0.75rem 0.85rem 2rem;
  }

  .map-list {
    gap: 0.85rem 0.75rem;
  }

  .map-card {
    padding: 1.15rem 1rem;
    min-height: 5.75rem;
  }

  .map-stage {
    max-height: min(78vh, 40rem);
    width: min(100%, calc(min(78vh, 96vw) * 4 / 5));
  }

  .feedback-slot {
    min-height: 8.5rem;
    margin: 0.35rem auto 0.15rem;
    padding: 0.15rem 0;
  }

  .map-stage .place-label {
    font-size: 15px;
  }

  .map-stage .water-label {
    font-size: 18px;
  }

  .player-name {
    font-size: clamp(1.75rem, 8vw, 2.4rem);
  }
}
