:root {
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
  color-scheme: dark;
  --bg: #0e1116;
  --card: #161b22;
  --text: #eef2f7;
  --muted: #9da7b3;
  --accent: #24c8a5;
  --guessed: #2f81f7;
  --missed: #30363d;
  --border: #2a3340;
  --button-bg: #1f2937;
  --button-text: #ffffff;
  --map-bg: #0b1220;
  --map-boundary: rgba(255, 255, 255, 0.28);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f6f8fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #4b5563;
  --accent: #047857;
  --guessed: #2563eb;
  --missed: #e5e7eb;
  --border: #d7dee8;
  --button-bg: #ffffff;
  --button-text: #111827;
  --map-bg: #eef2f7;
  --map-boundary: rgba(17, 24, 39, 0.2);
  --gradient-end: #dbe4f3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(135deg, var(--bg), var(--gradient-end));
  color: var(--text);
  min-height: 100vh;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 0.85rem 1rem 1rem;
}

h1,
h2 {
  margin: 0 0 0.35rem;
}

h1 {
  font-size: 1.75rem;
  line-height: 1.15;
}

h2 {
  font-size: 1.15rem;
  line-height: 1.2;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.page-header > div {
  flex: 1;
}

header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.hud {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.65rem 0;
}

.guessed-hud {
  margin: 0 0 0.55rem;
  grid-template-columns: 1fr;
  gap: 0.5rem;
}

.stat {
  background: var(--card);
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.progress-wrap {
  width: 100%;
  height: 10px;
  background: var(--missed);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 0.7rem;
}

.guessed-progress {
  margin-bottom: 0.7rem;
}

#progressBar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #06b6d4, var(--accent));
  transition: width 180ms ease;
}

#guessForm {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
}

.utility-panel {
  display: flex;
  justify-content: flex-end;
  gap: 0.45rem;
  margin: 0;
  margin-left: auto;
  padding: 0.5rem 0.6rem;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: fit-content;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  margin: 0.45rem 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.mode-toggle input {
  width: 1rem;
  height: 1rem;
  margin: 0;
}

input,
button,
.button-link {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 0.58rem 0.72rem;
  font-size: 0.95rem;
}

button,
.button-link {
  background: var(--button-bg);
  color: var(--button-text);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle {
  white-space: nowrap;
}

.utility-button {
  border-radius: 999px;
  border: 1px solid transparent;
  padding: 0.38rem 0.7rem;
  font-size: 0.82rem;
  line-height: 1.2;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  cursor: pointer;
}

.utility-button-theme {
  background: color-mix(in srgb, var(--button-bg) 72%, var(--accent) 28%);
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border) 55%);
  color: var(--button-text);
}

.utility-button-solutions {
  background: color-mix(in srgb, #d97706 20%, var(--button-bg) 80%);
  border-color: color-mix(in srgb, #d97706 50%, var(--border) 50%);
  color: var(--button-text);
}

.utility-button-reset {
  background: color-mix(in srgb, #b91c1c 18%, var(--button-bg) 82%);
  border-color: color-mix(in srgb, #b91c1c 45%, var(--border) 55%);
  color: var(--button-text);
}

button:hover,
.button-link:hover {
  filter: brightness(1.1);
}

.utility-button:hover {
  filter: brightness(1.08);
}

.page-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.page-card {
  margin-top: 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.solution-layout {
  display: grid;
  gap: 1rem;
}

.solution-layout .map-container {
  aspect-ratio: 4 / 3;
}

.solutions-list {
  max-height: 26rem;
  overflow: auto;
}

#status {
  min-height: 1.1rem;
  margin: 0.35rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.map-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.9fr) minmax(280px, 1fr);
  gap: 1.25rem;
  align-items: start;
}

.map-panel {
  min-width: 0;
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
}

.map-tooltip {
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(10px, calc(-100% - 10px));
  padding: 0.38rem 0.55rem;
  border-radius: 8px;
  background: rgba(14, 17, 22, 0.92);
  color: #ffffff;
  font-size: 0.86rem;
  font-weight: 600;
  white-space: nowrap;
  pointer-events: none;
  z-index: 1;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

:root[data-theme="light"] .map-tooltip {
  background: rgba(17, 24, 39, 0.92);
}

.map-legend {
  color: var(--muted);
  margin: 0.35rem 0 0;
  font-size: 0.92rem;
}

.guessed-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.guessed-empty {
  color: var(--muted);
  margin: 0.25rem 0 0.75rem;
}

.guessed-list {
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 0.5rem;
  display: grid;
  overflow: auto;
  min-height: 0;
}

.guessed-list li {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.75rem;
}

.guessed-list-name {
  display: block;
  font-weight: 600;
}

.guessed-list-population {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.15rem;
}

.privacy-notice {
  margin-top: 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.privacy-notice p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.sources {
  margin-top: 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.sources-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
  line-height: 1.55;
}

.sources-list a {
  color: var(--accent);
}

.sources-list a:hover {
  text-decoration: none;
}

.contact {
  margin-top: 1.25rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}

.contact p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.contact a {
  color: var(--accent);
}

@media (max-width: 680px) {
  .page-header {
    flex-direction: column;
    align-items: stretch;
  }

  .utility-panel {
    justify-content: stretch;
    flex-wrap: wrap;
  }

  .utility-button {
    flex: 1 1 140px;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .guessed-section {
    height: auto !important;
  }

  #guessForm {
    grid-template-columns: 1fr;
  }
}
