/* Base styles: tokens, layout, buttons, chips, cards, choices. Light + dark. */

/* Light tokens (default). Theme: data-theme="light"|"dark" on <html>, absent = auto. */
:root {
  color-scheme: light;
  --bg: #f6f4ef;
  --bg-2: #ece8de;
  --surface: #ffffff;
  --surface-2: #f8f6f1;
  --text: #1f2430;
  --muted: #646b7a;
  --border: #ddd7ca;
  --accent: #2f6fde;
  --accent-ink: #ffffff;
  --accent-soft: #e3ecfc;
  --ok: #1f9d55;
  --ok-soft: #dcf5e6;
  --bad: #d64545;
  --bad-soft: #fbe2e2;
  --warn: #b7791f;
  --warn-soft: #fdf1d8;
  --sun: #f4b63f;
  --shadow: 0 1px 2px rgb(30 30 40 / 0.06), 0 4px 14px rgb(30 30 40 / 0.07);
  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --gutter: 16px;
  --maxw: 960px;
}

/* Dark tokens: follow the OS unless the user picked light; or forced by the header toggle. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14161c;
    --bg-2: #1b1e26;
    --surface: #1f232c;
    --surface-2: #262b36;
    --text: #e9ecf2;
    --muted: #9aa3b5;
    --border: #343a48;
    --accent: #6c9cff;
    --accent-ink: #0d1424;
    --accent-soft: #23304d;
    --ok: #4ccf86;
    --ok-soft: #173826;
    --bad: #ff7a7a;
    --bad-soft: #3d1d22;
    --warn: #f0b95a;
    --warn-soft: #3a2e16;
    --sun: #f4b63f;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 18px rgb(0 0 0 / 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161c;
  --bg-2: #1b1e26;
  --surface: #1f232c;
  --surface-2: #262b36;
  --text: #e9ecf2;
  --muted: #9aa3b5;
  --border: #343a48;
  --accent: #6c9cff;
  --accent-ink: #0d1424;
  --accent-soft: #23304d;
  --ok: #4ccf86;
  --ok-soft: #173826;
  --bad: #ff7a7a;
  --bad-soft: #3d1d22;
  --warn: #f0b95a;
  --warn-soft: #3a2e16;
  --sun: #f4b63f;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 18px rgb(0 0 0 / 0.25);
}

*, *::before, *::after { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  min-height: 100vh;
}

a { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 0.5em; }
h1 { font-size: clamp(1.4rem, 4vw, 1.9rem); }
h2 { font-size: 1.2rem; }
p { margin: 0 0 0.75em; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

/* ---------- layout ---------- */
.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter) 48px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.gap { gap: 12px; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.section { margin-top: 28px; }
.section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.section-title h2 { margin: 0; }

.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  max-width: var(--maxw); margin: 0 auto; padding: 14px var(--gutter);
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 1.1rem; color: var(--text); text-decoration: none; letter-spacing: -0.01em; }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); font-size: 1.15rem; }
.site-header nav { display: flex; gap: 4px; flex-wrap: wrap; }
.header-right { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; justify-content: flex-end; }
.header-tools { display: flex; align-items: center; gap: 8px; }
.seg {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px;
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface);
}
.seg-sep { color: var(--muted); font-size: 0.8rem; opacity: 0.6; }
.seg-btn {
  font: inherit; font-size: 0.8rem; font-weight: 700; line-height: 1; letter-spacing: 0.02em;
  min-width: 30px; min-height: 28px; padding: 6px 8px; border: 0; border-radius: 999px;
  background: transparent; color: var(--muted); cursor: pointer;
}
.seg-btn:hover { color: var(--text); background: var(--bg-2); }
.seg-btn[aria-pressed="true"] { color: var(--accent); background: var(--accent-soft); }
.seg-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.site-header nav a {
  color: var(--muted); text-decoration: none; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 0.95rem;
}
.site-header nav a:hover { color: var(--text); background: var(--bg-2); }
.site-header nav a.active { color: var(--accent); background: var(--accent-soft); }

.hero { padding: 12px 0 4px; }
.hero p { color: var(--muted); max-width: 60ch; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px;
}
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); }
.grid-sm { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 200px), 1fr)); }

.game-card { display: flex; flex-direction: column; gap: 8px; text-decoration: none; color: inherit; transition: transform 0.12s ease, border-color 0.12s ease; position: relative; }
a.game-card:hover { transform: translateY(-2px); border-color: var(--accent); }
a.game-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.game-card .icon { font-size: 1.8rem; line-height: 1; }
.game-card h3 { margin: 0; font-size: 1.1rem; }
.game-card p { margin: 0; color: var(--muted); font-size: 0.93rem; }
.game-card .stats { margin-top: auto; padding-top: 6px; font-size: 0.85rem; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; }
.game-card.disabled { opacity: 0.55; box-shadow: none; background: var(--surface-2); }
.badge {
  display: inline-block; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
  padding: 2px 8px; border-radius: 999px; background: var(--bg-2); color: var(--muted);
}
.badge-medium { background: var(--warn-soft); color: var(--warn); }
.badge-low { background: var(--bad-soft); color: var(--bad); }
.badge-high { background: var(--ok-soft); color: var(--ok); }
.game-card .badge { position: absolute; top: 14px; right: 14px; }

/* ---------- chips + toggles ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; font-size: 0.95rem; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .count { font-weight: 500; opacity: 0.75; font-size: 0.85em; }

.toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; font-size: 0.95rem; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

select, input[type="text"] {
  font: inherit; color: var(--text); background: var(--surface); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; min-height: 42px;
}

/* ---------- buttons ---------- */
.btn {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 700; text-decoration: none; cursor: pointer;
  padding: 10px 18px; min-height: 44px; border-radius: 12px;
  background: var(--surface-2); color: var(--text); border: 1.5px solid var(--border);
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.07); }
.btn:focus-visible, .chip:focus-visible, .choice:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- game shell ---------- */
.hud { margin: 4px 0 14px; }
.hud-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.game-title { margin: 0; font-size: clamp(1.25rem, 4vw, 1.6rem); }
.hud-stats { display: flex; gap: 14px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.hud-score { color: var(--text); }
.hud-streak { color: var(--warn); }
.progress { height: 8px; background: var(--bg-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--ok)); border-radius: inherit; transition: width 0.3s ease; }

.round-card { display: flex; flex-direction: column; gap: 18px; }
.prompt { display: grid; place-items: center; text-align: center; min-height: 140px; padding: 8px; font-size: 1.15rem; }
.prompt:focus { outline: none; }
.prompt .big-glyph { font-size: clamp(4rem, 18vw, 7rem); font-weight: 700; line-height: 1; }

.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 420px) { .choices:not(.choices-2) { grid-template-columns: 1fr; } }

.choice {
  appearance: none; font: inherit; color: var(--text); text-align: left; cursor: pointer;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 14px; min-height: 56px; border-radius: 14px;
  background: var(--surface-2); border: 2px solid var(--border);
  transition: transform 0.08s ease, border-color 0.12s ease, background 0.12s ease;
}
.choice:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-1px); }
.choice:active:not(:disabled) { transform: translateY(1px); }
.choice:disabled { cursor: default; }
.choice-key {
  display: inline-grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 8px;
  background: var(--bg-2); color: var(--muted); font-size: 0.85rem; font-weight: 800;
}
.choice-label { font-weight: 700; font-size: 1.02rem; }
.choice-node { flex-basis: 100%; display: flex; justify-content: center; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); animation: pop 0.25s ease; }
.choice.correct .choice-key { background: var(--ok); color: var(--surface); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); animation: shake 0.3s ease; }
.choice.wrong .choice-key { background: var(--bad); color: var(--surface); }
.choice.dim { opacity: 0.5; }

.feedback:empty { display: none; }
.feedback { display: flex; flex-direction: column; gap: 10px; }
.verdict { font-weight: 800; font-size: 1.1rem; }
.verdict.ok { color: var(--ok); }
.verdict.bad { color: var(--bad); }
.explain { color: var(--text); background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.hint { font-size: 0.8rem; }
@media (hover: none) { .hint { display: none; } }

.end-card, .empty-card { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 32px 18px; }
.end-mood { font-size: 1.4rem; font-weight: 800; }
.end-score { font-size: 1.2rem; color: var(--muted); }
.end-score strong { font-size: 3.2rem; color: var(--text); }

@keyframes pop { 50% { transform: scale(1.03); } }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- notices ---------- */
.notice { background: var(--warn-soft); color: var(--text); border: 1px solid var(--warn); border-radius: var(--radius-sm); padding: 10px 14px; margin: 8px 0 14px; font-size: 0.93rem; }
.notice-error { background: var(--bad-soft); border-color: var(--bad); }

/* ---------- fact display (pages) ---------- */
.fact-text { display: inline-block; }
.fact-list { display: flex; flex-direction: column; gap: 8px; }
.fact-item { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fact-item.low { opacity: 0.6; }
.fact-note { color: var(--muted); font-size: 0.85rem; }
.unknown { color: var(--muted); font-style: italic; }

.country-card { display: flex; flex-direction: column; gap: 10px; }
.country-card h3 { margin: 0; font-size: 1.02rem; }
.country-card h3 a { color: inherit; text-decoration: none; }
.country-card h3 a:hover { color: var(--accent); }
.flag { font-size: 1.3em; margin-right: 4px; }

.profile-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.profile-head .flag { font-size: 3rem; }
.tells { margin: 0; padding-left: 1.2em; }
.type-block h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 8px; }

table.review { width: 100%; border-collapse: collapse; font-size: 0.93rem; }
table.review th, table.review td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.review th { color: var(--muted); font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; }
.table-wrap { overflow-x: auto; }

.weak-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.weak-list li { display: flex; justify-content: space-between; gap: 10px; }

.footer { margin-top: 40px; color: var(--muted); font-size: 0.85rem; text-align: center; }
