:root {
  --bg: #f6f3ec;
  --panel: #ffffff;
  --text: #2b2a27;
  --muted: #77736a;
  --border: #ddd7ca;
  --accent: #c2591b;
  --accent-dark: #9c4512;
  --ok: #2e8540;
  --ok-bg: #e3f2e5;
  --bad: #c0392b;
  --bad-bg: #fbe7e4;
  --land: #ebe6da;
  --land-stroke: #8d8577;
  --found: #e08a3c;
  --missed: #d9534f;
  --disabled: #d4cfc4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.5;
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 8px 16px 48px;
}

/* ---- Language switch ---- */
.lang-switch {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px 0;
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}
.lang {
  font: inherit;
  font-size: .85rem;
  padding: 3px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.lang:hover { border-color: var(--accent); color: var(--text); }
.lang.active { background: var(--accent); border-color: var(--accent); color: #fff; cursor: default; }

h1 { font-size: 2.2rem; margin: 0 0 4px; }
h2 { font-size: 1.4rem; margin: 0; }
.subtitle { color: var(--muted); margin: 0 0 32px; }

/* ---- Menu ---- */
.menu { text-align: center; padding-top: 6vh; }
.modes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
}
.mode {
  display: block;
  padding: 24px 12px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 14px;
  color: inherit;
  text-decoration: none;
  transition: border-color .15s, transform .15s, box-shadow .15s;
}
.mode:hover, .mode:focus-visible {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0,0,0,.08);
  outline: none;
}
.mode-icon { font-size: 2.6rem; display: block; margin-bottom: 8px; }
.mode-title { font-size: 1.3rem; font-weight: 700; display: block; }
.mode-desc { color: var(--muted); font-size: .95rem; }

/* ---- Game header ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.btn {
  font: inherit;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- Input ---- */
.answer {
  width: 100%;
  font-size: 1.25rem;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
}
.answer:focus { outline: none; border-color: var(--accent); }
.answer:disabled { background: #efebe3; }
.answer.shake { animation: shake .35s; border-color: var(--bad); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.feedback {
  min-height: 2.6em;
  margin: 10px 0;
  padding: 8px 12px;
  border-radius: 8px;
  visibility: hidden;
}
.feedback.ok { visibility: visible; background: var(--ok-bg); color: var(--ok); }
.feedback.bad { visibility: visible; background: var(--bad-bg); color: var(--bad); }

.counter {
  font-size: 1.6rem;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.counter small { display: block; font-size: .85rem; font-weight: 400; color: var(--muted); }

/* ---- Map ---- */
.map-wrap {
  background: #dbe9f1;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin: 12px 0;
}
.map { display: block; width: 100%; height: auto; max-height: 72vh; }
.map .country {
  fill: var(--land);
  stroke: var(--land-stroke);
  stroke-width: .8;
  stroke-linejoin: round;
  transition: fill .4s;
}
.map .marker { stroke-width: 1.2; fill-opacity: .55; }
.map .non-playable { fill: var(--disabled); stroke: var(--land-stroke); stroke-width: .8; stroke-dasharray: 3 2; }
.map .found { fill: var(--found); }
.map .missed { fill: var(--missed); }
.map .flash { animation: flash .9s; }
@keyframes flash {
  0% { fill: #ffd84d; }
  100% { fill: var(--found); }
}

.found-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
  padding: 0;
  list-style: none;
}
.found-list li {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: .9rem;
}
.found-list li.missed { border-color: var(--missed); color: var(--missed); }

/* ---- Rounds (capital / flag) ---- */
.question {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 16px;
}
.question .label { color: var(--muted); margin: 0 0 8px; }
.question .country-name { font-size: 2rem; font-weight: 700; margin: 0; }
.question .flag {
  display: block;
  margin: 8px auto 0;
  width: min(360px, 100%);
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid var(--border);
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.progress {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 16px;
}
.progress > div { height: 100%; background: var(--accent); transition: width .3s; }

/* ---- Result ---- */
.result {
  text-align: center;
  background: var(--panel);
  border: 2px solid var(--ok);
  border-radius: 14px;
  padding: 28px 20px;
  margin: 16px 0;
}
.result.partial { border-color: var(--border); }
.result h2 { margin-bottom: 8px; }
.result .actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.big { font-size: 3rem; font-weight: 800; margin: 8px 0; }

/* ---- Choices (flags-choice) ---- */
.choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}
.choices.shake { animation: shake .35s; }
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  font: inherit;
  font-size: 1.1rem;
  text-align: left;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.choice:hover, .choice:focus-visible { border-color: var(--accent); outline: none; }
.choice:active { background: #fbefe5; }
.choice .key {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.6em;
  height: 1.6em;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: .85rem;
}

/* Small copy of the flag in the error message (flag modes) */
.feedback-flag {
  height: 2em;
  width: auto;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  vertical-align: middle;
  margin-right: 10px;
  border: 1px solid rgba(0, 0, 0, .15);
}

/* ---- Autocomplete ---- */
.answer-field { position: relative; }
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 10;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.suggestions[hidden] { display: none; }
.suggestions li {
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1.05rem;
}
.suggestions li.active { background: #fbefe5; }
.feedback strong { font-weight: 700; }
