:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f1;
  --text: #14201e;
  --muted: #5d6b68;
  --border: #d8e0de;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d5efec;
  --good: #15803d;
  --good-soft: #dcfce7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --warn: #d97706;
  --sea: #dbeafe;
  --land: #f8faf9;
  --land-edge: #9fb3ae;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 4px 16px rgba(0, 0, 0, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1413;
    --surface: #16201f;
    --surface-2: #1d2a28;
    --text: #e8efed;
    --muted: #9aaba7;
    --border: #2a3a37;
    --accent: #2dd4bf;
    --accent-text: #062723;
    --accent-soft: #123b37;
    --good: #4ade80;
    --good-soft: #10331f;
    --bad: #f87171;
    --bad-soft: #3b1515;
    --warn: #fbbf24;
    --sea: #0f2433;
    --land: #3b504c;
    --land-edge: #5d7570;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 16px) calc(env(safe-area-inset-right) + 16px)
           calc(env(safe-area-inset-bottom) + 24px) calc(env(safe-area-inset-left) + 16px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
h2 { font-size: 22px; font-weight: 700; }
h3 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
p { margin: 0; }
.muted { color: var(--muted); }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.lang-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 6px 12px;
  border-radius: 999px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* Segmentert valg / chips */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg button { border: 0; background: transparent; color: var(--text); font: inherit; font-size: 15px; font-weight: 600; padding: 10px 6px; border-radius: 9px; min-height: 44px; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgba(0,0,0,.12); color: var(--accent); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 15px; padding: 9px 14px; border-radius: 999px; min-height: 44px;
}
.chips button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }

.field + .field { margin-top: 18px; }
.hint { font-size: 14px; color: var(--muted); margin-top: 8px; }

.btn {
  display: block; width: 100%;
  border: 0; border-radius: 14px;
  font: inherit; font-size: 18px; font-weight: 700;
  padding: 16px; min-height: 56px;
  background: var(--accent); color: var(--accent-text);
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); font-weight: 600; }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); font-weight: 600; font-size: 16px; }
.btn:disabled { opacity: .5; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.link-btn { border: 0; background: none; color: var(--accent); font: inherit; font-weight: 600; padding: 8px 0; min-height: 44px; }

/* Quiz */
.quiz-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .3s ease; }
.score-pill { font-weight: 700; font-variant-numeric: tabular-nums; }
.streak { font-size: 15px; font-weight: 600; color: var(--muted); min-height: 21px; text-align: center; }

.question { text-align: center; padding: 12px 0 4px; }
.flag { font-size: 72px; line-height: 1; margin-bottom: 12px; }
.question .q-label { color: var(--muted); font-size: 17px; }
.question .q-subject { font-size: 30px; font-weight: 800; letter-spacing: -.01em; margin-top: 4px; overflow-wrap: anywhere; }

.options { display: grid; gap: 10px; }
.option {
  border: 2px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 18px; font-weight: 600; text-align: left;
  padding: 14px 16px; min-height: 60px; border-radius: 14px;
  box-shadow: var(--shadow);
  transition: background .15s, border-color .15s;
}
.option:active:not(:disabled) { transform: scale(.985); }
.option:disabled { opacity: 1; }
.option.correct { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.option.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.option.dim { opacity: .55; }

.feedback { min-height: 24px; text-align: center; font-weight: 600; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.note { font-size: 15px; color: var(--muted); text-align: center; margin-top: 4px; }

/* Resultat */
.result-hero { text-align: center; padding: 16px 0; }
.big-score { font-size: 64px; font-weight: 800; color: var(--accent); line-height: 1; font-variant-numeric: tabular-nums; }
.record { font-weight: 700; color: var(--good); margin-top: 8px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .f { font-size: 26px; }
.list .grow { flex: 1; min-width: 0; }
.list .right { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.list small { display: block; color: var(--muted); font-size: 14px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 26px; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 14px; }

.badge {
  display: inline-block; min-width: 24px; padding: 1px 8px; margin-left: 6px;
  border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 14px; font-weight: 700; vertical-align: 2px; font-variant-numeric: tabular-nums;
}

/* Lyntempo */
.blitz-btn small { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-top: 2px; }
.blitz-secs { font-weight: 800; font-size: 18px; font-variant-numeric: tabular-nums; }
.progress.blitz { height: 8px; }
.progress.blitz > div { transition: width .1s linear; }
.progress.urgent > div { background: var(--bad); }

/* Dagens utfordring */
.daily { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), var(--surface) 70%); }
.daily-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.daily-head h3 { color: var(--accent); }
.daily-streak { font-size: 14px; font-weight: 700; }
.daily-score { font-size: 18px; font-weight: 700; }
.squares { font-size: 22px; letter-spacing: 2px; margin: 6px 0 12px; line-height: 1.2; }
.btn.small { font-size: 16px; min-height: 48px; padding: 10px 12px; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); z-index: 20;
  transform: translate(-50%, 12px); opacity: 0; transition: opacity .2s, transform .2s;
  background: var(--text); color: var(--bg); font-weight: 600; font-size: 15px;
  padding: 10px 18px; border-radius: 999px; pointer-events: none;
}
.toast.open { opacity: 1; transform: translate(-50%, 0); }

.dialog-input {
  width: 100%; margin: -6px 0 16px; padding: 10px 12px;
  font: 16px ui-monospace, Menlo, monospace; color: var(--text); /* 16px hindrer iOS-zoom */
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; resize: none;
}

/* Kart-hint */
.map-slot { display: flex; justify-content: center; }
.hint-btn {
  border: 1px dashed var(--border); background: transparent; color: var(--muted);
  font: inherit; font-size: 15px; font-weight: 600; padding: 8px 16px; border-radius: 999px; min-height: 40px;
}
.map { display: block; width: 100%; aspect-ratio: 2 / 1; border-radius: 14px; border: 1px solid var(--border); }
.map .sea { fill: var(--sea); }
.map .land { fill: var(--land); stroke: var(--land-edge); stroke-width: .6px; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.map .dot { fill: var(--bad); stroke: #fff; stroke-width: 2px; vector-effect: non-scaling-stroke; }
.map .ring { fill: none; stroke: var(--bad); stroke-width: 2px; vector-effect: non-scaling-stroke; opacity: .5; }
.with-map .flag { font-size: 44px; margin-bottom: 6px; }
.with-map .question { padding-top: 0; }

/* Fremgang per verdensdel */
.world-progress { font-size: 17px; margin-bottom: 8px; }
.world-progress b { font-size: 28px; color: var(--accent); font-variant-numeric: tabular-nums; }
.bar { display: flex; height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar.big { height: 10px; }
.bar-known { background: var(--good); }
.bar-learning { background: var(--warn); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.known { background: var(--good); }
.sw.learning { background: var(--warn); }
.sw.new { background: var(--surface-2); border: 1px solid var(--border); }

.region-row { border-bottom: 1px solid var(--border); }
.region-row summary {
  list-style: none; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto 16px; align-items: center; column-gap: 10px; row-gap: 8px;
  padding: 12px 0; min-height: 44px;
}
.region-row summary::-webkit-details-marker { display: none; }
.region-row summary::after { content: "›"; color: var(--muted); font-size: 20px; grid-column: 3; grid-row: 1; transition: transform .15s; }
.region-row[open] summary::after { transform: rotate(90deg); }
.region-row .region-name { font-weight: 600; }
.region-row .region-count { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }
.region-row .bar { grid-column: 1 / -1; }
.country-list { list-style: none; margin: 0 0 12px; padding: 0; font-size: 15px; }
.country-list li { display: flex; align-items: baseline; gap: 10px; padding: 6px 0; }
.country-list .grow { flex: 1; min-width: 0; }
.country-list .muted { text-align: right; }
.st-icon { width: 18px; text-align: center; font-weight: 700; flex: none; }
.st-known .st-icon { color: var(--good); }
.st-learning .st-icon { color: var(--warn); }
.st-new .st-icon { color: var(--muted); }

/* Dialog */
.dialog-overlay {
  position: fixed; inset: 0; z-index: 10;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 16px);
  opacity: 0; transition: opacity .15s ease;
}
.dialog-overlay.open { opacity: 1; }
.dialog {
  width: 100%; max-width: 488px;
  background: var(--surface); color: var(--text);
  border-radius: 20px; padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .3);
  transform: translateY(16px); transition: transform .15s ease;
}
.dialog-overlay.open .dialog { transform: none; }
.dialog p { font-size: 17px; margin-bottom: 18px; }
.dialog-actions { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; }
.dialog-actions .btn { font-size: 17px; min-height: 52px; padding: 12px; }
.btn.danger-solid { background: var(--bad); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
