:root {
  color-scheme: dark;
  --bg: #10151b;
  --panel-bg: #182028;
  --border: #2a343e;
  --text: #e8edf2;
  --muted: #93a2b1;
  --accent: #e08e45;
  --good: #4caf6f;
  --bad: #e0555a;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 1.25rem 1.5rem 2.5rem;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
}

.topbar h1 {
  font-size: 1.4rem;
  margin: 0;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.3rem;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
}

.menu-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.menu-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.menu-close {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
}

/* Desktop default: #app-menu's children rejoin body's flex flow (via
   display:contents below), pinned back to today's exact visual order
   with these order values regardless of where the aside sits in the
   DOM — lets the mobile drawer group .controls and .country-list-panel
   together without moving them apart at desktop width. */
#app-menu {
  display: contents;
}

.topbar {
  order: 1;
}

#app-menu > .controls {
  order: 2;
}

main.layout {
  order: 3;
}

#app-menu > .country-list-panel {
  order: 4;
}

.menu-backdrop {
  display: none;
}

@media (max-width: 900px) {
  .menu-toggle {
    display: inline-flex;
  }

  .menu-header {
    display: flex;
  }

  #app-menu {
    display: block;
    position: fixed;
    inset: 0 0 0 auto;
    width: min(85vw, 340px);
    background: var(--panel-bg);
    border-left: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.25s ease, visibility 0s linear 0.25s;
    z-index: 1000;
  }

  #app-menu.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.25s ease, visibility 0s linear 0s;
  }

  .menu-backdrop:not([hidden]) {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }

  body.menu-open {
    overflow: hidden;
  }

  .guess-buttons button {
    padding: 0.75rem 1rem;
    min-height: 44px;
  }

  .suggestions li {
    padding: 0.75rem 0.6rem;
  }
}

.stats {
  display: flex;
  gap: 1.25rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.stats strong {
  color: var(--text);
  font-size: 1.05rem;
}

.controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.controls select {
  background: var(--panel-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 0.95rem;
}

.legend {
  display: flex;
  gap: 1rem;
  list-style: none;
  margin: 0 0 0 0.5rem;
  padding: 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.legend li {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.swatch {
  width: 0.8em;
  height: 0.8em;
  border-radius: 3px;
  display: inline-block;
}

.swatch.current {
  background: #f2c94c;
}

.swatch.correct {
  background: var(--good);
}

.swatch.incorrect {
  background: var(--bad);
}

.layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
  align-items: start;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.panel h2 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  align-self: flex-start;
}

.panel-svg {
  width: 100%;
  aspect-ratio: 1 / 1;
}

.map-panel {
  min-width: 0;
}

/*
 * width:100% + aspect-ratio + max-height don't combine the way you'd
 * hope: aspect-ratio only auto-sizes the dimension left "auto", and
 * width here is a definite 100%, so max-height just clamps height
 * without shrinking width back down — the box stops being square. Using
 * min() to cap width directly (in terms of the target aspect ratio)
 * keeps both dimensions correctly proportional instead.
 */
.map-svg {
  aspect-ratio: 1.923 / 1;
  width: min(100%, 82vh * 1.923);
}

.side-col {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.side-col .panel {
  flex: 1;
}

.zoom-panel .panel-svg {
  max-width: 340px;
}

.guess-panel {
  align-items: stretch;
  justify-content: center;
}

.guess-area {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.guess-buttons {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.guess-buttons button {
  flex: 1 1 auto;
}

.input-wrap {
  position: relative;
  width: 100%;
}

#guess-input {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
}

#guess-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 10;
}

.suggestions li {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
}

.suggestions li:hover,
.suggestions li.active {
  background: #24303c;
}

button {
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #24303c;
  color: var(--text);
  cursor: pointer;
}

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

#submit-btn {
  background: var(--accent);
  color: #1a1206;
  border-color: var(--accent);
  font-weight: 600;
}

.feedback {
  min-height: 1.4em;
  font-size: 1.05rem;
  margin: 0;
}

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

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

.feedback.revealed {
  color: var(--muted);
}

.country-list-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
}

.country-list-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.country-list-header h2 {
  margin: 0;
  font-size: 1rem;
}

.country-list-summary {
  color: var(--muted);
  font-size: 0.9rem;
}

.country-list details {
  border-top: 1px solid var(--border);
  padding: 0.5rem 0;
}

.country-list details:first-child {
  border-top: none;
}

.country-list summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.25rem 0;
  list-style: none;
}

.country-list summary::-webkit-details-marker {
  display: none;
}

.country-list summary::before {
  content: "▸";
  display: inline-block;
  width: 1em;
  color: var(--muted);
}

.country-list details[open] summary::before {
  content: "▾";
}

.country-list summary .region-count {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.9rem;
}

.country-list-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  list-style: none;
  margin: 0.5rem 0 0.25rem;
  padding: 0;
}

.country-list-item {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.85rem;
  background: #202b36;
  color: var(--muted);
  border: 1px solid var(--border);
}

.country-list-item.correct {
  background: rgba(76, 175, 111, 0.15);
  border-color: var(--good);
  color: var(--good);
}

.country-list-item.incorrect {
  background: rgba(224, 85, 90, 0.15);
  border-color: var(--bad);
  color: var(--bad);
}
