/* GeoTrainer — map/travel theme */

/* Windows doesn't render emoji country flags natively — this font fills the gap.
   unicode-range limits it strictly to flag characters. */
@font-face {
  font-family: "Twemoji Country Flags";
  unicode-range: U+1F1E6-1F1FF, U+1F3F4, U+E0062-E007F;
  src: url("https://cdn.jsdelivr.net/npm/country-flag-emoji-polyfill@0.1.8/dist/TwemojiCountryFlags.woff2") format("woff2");
  font-display: swap;
}

:root {
  --parchment: #F5EFE0;
  --parchment-deep: #EDE4CE;
  --ink: #1F2A44;
  --ink-soft: #4A5470;
  --terracotta: #C4643B;
  --terracotta-deep: #A54E2C;
  --sage: #7C8A5A;
  --ocean: #3E6C8D;
  --stamp-green: #2E7D4F;
  --stamp-red: #B33A3A;
  --card: #FBF7EC;
  --line: #D8CCAF;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(31, 42, 68, 0.10);
  --serif: "Fraunces", Georgia, serif;
  --sans: "Inter", -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  /* keep the column truly centered even when a scrollbar appears */
  scrollbar-gutter: stable both-edges;
}

body {
  font-family: "Twemoji Country Flags", var(--sans);
  color: var(--ink);
  background-color: var(--parchment);
  /* subtle topographic contours */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='420' height='420' viewBox='0 0 420 420'%3E%3Cg fill='none' stroke='%231F2A44' stroke-opacity='0.05' stroke-width='1.4'%3E%3Cpath d='M60 340c40-70 10-120 60-160s130-10 150-70 90-60 130-40'/%3E%3Cpath d='M40 360c50-80 20-140 70-180s140-20 160-80 90-70 140-50'/%3E%3Cpath d='M20 380c60-90 30-160 80-200s150-30 170-90 90-80 150-60'/%3E%3Ccircle cx='330' cy='320' r='30'/%3E%3Ccircle cx='330' cy='320' r='55'/%3E%3Ccircle cx='330' cy='320' r='82'/%3E%3C/g%3E%3C/svg%3E");
  /* anchor the contour pattern to the center so it frames the column symmetrically */
  background-position: center top;
  min-height: 100vh;
}

#app {
  max-width: 540px;
  margin: 0 auto;
  padding: 18px 16px calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh;
}

.screen { display: none; animation: screenIn 0.25s ease; }
.screen.active { display: block; }
@keyframes screenIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }

/* ---------- home ---------- */
.home-header { text-align: center; padding-top: 14px; }
.compass { width: 64px; height: 64px; color: var(--ink); animation: compassIn 0.8s ease; }
@keyframes compassIn { from { transform: rotate(-40deg) scale(0.8); opacity: 0; } to { transform: none; opacity: 1; } }

h1 {
  font-family: var(--serif);
  font-weight: 900;
  font-size: clamp(1.9rem, 7vw, 2.6rem);
  letter-spacing: -0.01em;
  margin-top: 6px;
}
.tagline { color: var(--ink-soft); font-size: 0.95rem; margin-top: 4px; }

.route-divider {
  height: 0;
  border-top: 2px dashed var(--line);
  margin: 22px 8px;
  position: relative;
}
.route-divider::before, .route-divider::after {
  content: "";
  position: absolute; top: -5px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--terracotta);
}
.route-divider::before { left: -2px; }
.route-divider::after { right: -2px; }

/* minmax(0, 1fr) lets cards shrink below their content's intrinsic width —
   otherwise the non-wrapping chip row blows the cards out past the column */
.mode-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.mode-card {
  min-width: 0;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.mode-card-head { display: flex; gap: 12px; align-items: flex-start; }
.mode-emoji { font-size: 1.7rem; line-height: 1.2; }
.mode-card h2 { font-family: var(--serif); font-size: 1.25rem; font-weight: 700; }
.mode-card p { color: var(--ink-soft); font-size: 0.88rem; margin-top: 2px; }

.mode-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }

/* filter chips — wrap, no horizontal scroll; collapsed view shows a "+N more" toggle */
.chip-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 12px;
}
.chip {
  flex: 0 0 auto;
  font-size: 0.8rem; font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--parchment);
  color: var(--ink-soft);
  cursor: pointer;
  transition: all 0.15s;
}
.chip.selected {
  background: var(--ocean);
  border-color: var(--ocean);
  color: #fff;
}
.chip.chip-more {
  border-style: dashed;
  background: transparent;
  color: var(--ocean);
  border-color: var(--ocean);
}

/* buttons */
.btn {
  font-family: var(--sans);
  font-weight: 600;
  font-size: 0.95rem;
  padding: 12px 16px;
  border-radius: 10px;
  border: 1.5px solid transparent;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--terracotta); color: #fff; }
.btn-primary:hover { background: var(--terracotta-deep); }
.btn-outline { background: transparent; border-color: var(--terracotta); color: var(--terracotta-deep); }
.btn-navy { background: var(--ink); color: var(--parchment); }
.btn-wide { width: 100%; margin-top: 14px; }

.settings-row { display: grid; gap: 10px; padding: 0 6px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 0.92rem; font-weight: 500; cursor: pointer; }
.toggle small { color: var(--ink-soft); font-weight: 400; }
.toggle input { width: 20px; height: 20px; accent-color: var(--terracotta); cursor: pointer; }

.home-footer { text-align: center; margin-top: 20px; color: var(--ink-soft); font-size: 0.78rem; }

/* ---------- quiz ---------- */
.quiz-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 4px 0 10px;
}
.btn-icon {
  background: var(--card); border: 1.5px solid var(--line);
  width: 40px; height: 40px; border-radius: 10px;
  font-size: 1.15rem; color: var(--ink); cursor: pointer;
}
.quiz-header-mid { flex: 1; text-align: center; }
.quiz-mode-label { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; display: block; }
.quiz-sub-label { font-size: 0.75rem; color: var(--ink-soft); }
.quiz-header-right { display: flex; gap: 8px; align-items: center; min-width: 40px; justify-content: flex-end; }
.quiz-timer {
  background: var(--stamp-red); color: #fff;
  font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 6px 10px; border-radius: 8px; font-size: 0.95rem;
}
.quiz-timer.calm { background: var(--ocean); }
.quiz-score {
  background: var(--ink); color: var(--parchment);
  font-weight: 700; font-variant-numeric: tabular-nums;
  padding: 6px 10px; border-radius: 8px; font-size: 0.95rem;
}

.streak-bar { min-height: 20px; text-align: center; font-size: 0.8rem; color: var(--terracotta-deep); font-weight: 600; }

.question-card {
  position: relative;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 20px;
  margin-top: 8px;
  min-height: 150px;
  display: flex; flex-direction: column; justify-content: center;
  text-align: center;
  overflow: hidden;
}
.question-type {
  position: absolute; top: 10px; left: 14px;
  font-size: 0.65rem; letter-spacing: 0.12em; font-weight: 700;
  color: var(--ink-soft);
}
.question-text {
  font-size: clamp(1.35rem, 5.5vw, 1.9rem);
  font-weight: 500;
  line-height: 1.45;
  word-break: break-word;
}
.question-text.mono { font-family: "Courier New", monospace; font-weight: 700; letter-spacing: 0.02em; }

/* road marking diagram */
.question-text.road { line-height: 0; }
.road-svg { width: 100%; height: auto; border-radius: 10px; display: block; }
.feedback-question.road { padding: 12px; }
.feedback-question.road .road-svg { margin-top: 4px; }

.road-img { width: 100%; height: auto; max-height: 220px; object-fit: cover; border-radius: 10px; display: block; }
.road-img.small { max-height: 130px; }
.img-credit {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  color: var(--ink-soft);
  text-decoration: none;
  text-align: right;
  letter-spacing: 0.02em;
}
a.img-credit:active { opacity: 0.7; }

.photo-link {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ocean);
  text-decoration: none;
  border-bottom: 1.5px dashed var(--ocean);
}
.photo-link:active { opacity: 0.7; }

/* passport stamp */
.stamp {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) rotate(-14deg) scale(2.2);
  padding: 8px 22px;
  border: 3.5px double currentColor;
  border-radius: 8px;
  font-family: var(--serif);
  font-weight: 900;
  font-size: 1.5rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
}
.stamp.show-correct, .stamp.show-wrong {
  animation: stampIn 0.45s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}
.stamp.show-correct { color: var(--stamp-green); }
.stamp.show-wrong { color: var(--stamp-red); }
@keyframes stampIn {
  0% { opacity: 0; transform: translate(-50%, -50%) rotate(-14deg) scale(2.2); }
  60% { opacity: 0.95; transform: translate(-50%, -50%) rotate(-14deg) scale(0.95); }
  100% { opacity: 0.9; transform: translate(-50%, -50%) rotate(-14deg) scale(1); }
}

/* answers — thumb-friendly 2x2 */
.answer-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}
.answer-btn {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  background: var(--card);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 16px 10px;
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  cursor: pointer;
  min-height: 58px;
  transition: transform 0.08s, border-color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.answer-btn:active { transform: scale(0.97); }
.answer-btn .flag { font-size: 1.25rem; font-family: "Twemoji Country Flags", var(--sans); }
.answer-btn.correct { background: #E4F0E7; border-color: var(--stamp-green); color: var(--stamp-green); }
.answer-btn.wrong { background: #F6E4E4; border-color: var(--stamp-red); color: var(--stamp-red); }
.answer-btn:disabled { cursor: default; opacity: 0.9; }
.answer-grid.pair { grid-template-columns: 1fr; }
.answer-grid.pair .answer-btn { min-height: 64px; font-size: 1.05rem; }

/* feedback card */
.feedback-wrap {
  position: fixed; inset: 0;
  background: rgba(31, 42, 68, 0.35);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.feedback-card {
  background: var(--card);
  border-top: 4px solid var(--terracotta);
  border-radius: 18px 18px 0 0;
  width: 100%; max-width: 540px;
  max-height: 78vh; overflow-y: auto;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
  animation: slideUp 0.25s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.feedback-card h3 { font-family: var(--serif); font-size: 1.2rem; }
.feedback-card h3.good { color: var(--stamp-green); }
.feedback-card h3.bad { color: var(--stamp-red); }
.feedback-answer { font-size: 1.05rem; font-weight: 600; margin-top: 6px; }
.tip-block {
  background: var(--parchment);
  border-left: 3px solid var(--ocean);
  border-radius: 0 8px 8px 0;
  padding: 10px 12px;
  margin-top: 10px;
  font-size: 0.9rem;
  line-height: 1.5;
}
.tip-block.pair { border-left-color: var(--terracotta); }
/* missed sentence repeated on the feedback card, giveaways highlighted */
.feedback-question {
  background: var(--parchment);
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 12px 14px 14px;
  margin-top: 12px;
  text-align: center;
}
.feedback-question p {
  font-size: 1.2rem;
  font-weight: 500;
  line-height: 1.5;
  word-break: break-word;
}
.feedback-question.mono p { font-family: "Courier New", monospace; font-weight: 700; letter-spacing: 0.02em; }
.tip-block.insent { border-left-color: var(--stamp-green); }
.tip-block.other {
  font-size: 0.8rem;
  color: var(--ink-soft);
  border-left-color: var(--line);
}
.tip-line { margin-top: 5px; }
.tip-line:first-of-type { margin-top: 0; }
.feedback-card mark {
  background: rgba(196, 100, 59, 0.22);
  color: var(--terracotta-deep);
  font-weight: 700;
  border-radius: 3px;
  padding: 0 2px;
}
.tip-block.mnemonic { border-left-color: var(--sage); font-style: italic; }
.tip-label {
  display: block;
  font-size: 0.65rem; letter-spacing: 0.1em; font-weight: 700;
  text-transform: uppercase; color: var(--ink-soft);
  font-style: normal;
  margin-bottom: 3px;
}

/* ---------- results ---------- */
.results-card { text-align: center; padding-top: 40px; }
.results-heading { font-family: var(--serif); font-size: 1.9rem; font-weight: 900; }
.results-stamp {
  margin: 26px auto 10px;
  width: 180px; height: 180px;
  border: 4px double var(--stamp-green);
  border-radius: 50%;
  color: var(--stamp-green);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transform: rotate(-8deg);
  animation: stampIn2 0.5s cubic-bezier(0.2, 1.4, 0.4, 1);
}
@keyframes stampIn2 { from { transform: rotate(-8deg) scale(1.6); opacity: 0; } to { transform: rotate(-8deg) scale(1); opacity: 1; } }
.results-score { font-family: var(--serif); font-size: 4rem; font-weight: 900; line-height: 1; }
.results-score-label { letter-spacing: 0.2em; text-transform: uppercase; font-size: 0.7rem; font-weight: 700; }
.results-best { color: var(--terracotta-deep); font-weight: 600; min-height: 22px; }
.results-stats { list-style: none; margin-top: 14px; color: var(--ink-soft); font-size: 0.92rem; }
.results-stats li { padding: 3px 0; }
.results-actions { margin-top: 8px; }

/* ---------- stats ---------- */
.stats-main { padding-bottom: 30px; }
.stats-section { margin-top: 18px; }
.stats-section h3 {
  font-family: var(--serif); font-size: 1.1rem;
  border-bottom: 2px dashed var(--line);
  padding-bottom: 6px; margin-bottom: 10px;
}
.stat-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  text-align: center; padding: 12px 6px;
}
.stat-card .num { font-family: var(--serif); font-weight: 900; font-size: 1.5rem; display: block; }
.stat-card .lbl { font-size: 0.68rem; color: var(--ink-soft); letter-spacing: 0.05em; text-transform: uppercase; }

.acc-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 4px;
  border-bottom: 1px solid var(--parchment-deep);
  font-size: 0.9rem;
}
.acc-row .flag { width: 26px; }
.acc-row .name { flex: 1; font-weight: 500; }
.acc-row .bar {
  flex: 1.2; height: 8px; background: var(--parchment-deep);
  border-radius: 999px; overflow: hidden;
}
.acc-row .bar i { display: block; height: 100%; background: var(--sage); border-radius: 999px; }
.acc-row.weak .bar i { background: var(--stamp-red); }
.acc-row .pct { width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.pair-card {
  background: var(--card); border: 1.5px solid var(--line);
  border-radius: 12px; padding: 12px; margin-bottom: 10px;
}
.pair-card .pair-title { font-weight: 700; font-size: 0.95rem; }
.pair-card .pair-count { color: var(--stamp-red); font-size: 0.8rem; font-weight: 600; }
.pair-card .pair-tip { font-size: 0.85rem; color: var(--ink-soft); margin-top: 6px; line-height: 1.5; }
.pair-card .btn { margin-top: 10px; padding: 9px 14px; font-size: 0.85rem; }

.empty-note { color: var(--ink-soft); font-size: 0.9rem; padding: 8px 2px; }

.btn-danger-ghost {
  background: transparent; border: 1.5px solid var(--stamp-red);
  color: var(--stamp-red);
}

@media (min-width: 560px) {
  .question-card { min-height: 180px; }
}
