/* Base layer: structure and component vocabulary shared by all three themes.
   Themes (theme-young/middle/senior.css) override the custom properties under
   body[data-tier="..."] and add their own decoration. Keep selectors here flat
   (single class) so theme rules with [data-tier] prefix always win. */

:root {
  --font-display: 'Philosopher', 'Georgia', serif;
  --font-body: 'Golos Text', system-ui, sans-serif;
  --bg: #f3ecdc;
  --bg-elev: #fffaf0;
  --bg-sunken: #e7dcc4;
  --ink: #2a2118;
  --ink-soft: #6a5a48;
  --line: #c9b995;
  --accent: #b5542d;
  --accent-ink: #fff;
  --accent-2: #2a6f7a;
  --good: #3a7d44;
  --bad: #b23a3a;
  --warn: #c7901c;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
  --gap: 16px;
  --maxw: 1100px;
  --topbar-h: 60px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}
body.has-modal { overflow: hidden; }
h1, h2, h3, h4 { font-family: var(--font-display); line-height: 1.15; margin: 0 0 0.4em; }
h1 { font-size: 2.6rem; }
h2 { font-size: 1.7rem; }
h3 { font-size: 1.25rem; }
p { margin: 0 0 0.8em; }
a { color: var(--accent-2); }
button { font: inherit; color: inherit; }
img, svg { max-width: 100%; }
.muted { color: var(--ink-soft); }
.hidden, [hidden] { display: none !important; }
.skip-link { position: absolute; left: -999px; top: 0; }
.skip-link:focus { left: 8px; top: 8px; background: var(--bg-elev); padding: 8px; z-index: 100; }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--gap);
  min-height: var(--topbar-h);
  padding: 6px 16px;
  background: var(--bg-elev);
  border-bottom: 2px solid var(--line);
}
.brand { display: flex; flex-direction: column; text-decoration: none; color: inherit; line-height: 1.1; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.25rem; }
.brand-sub { font-size: 0.72rem; color: var(--ink-soft); }
.topbar-mid { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; flex: 1; }
.resources { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.resource { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; font-variant-numeric: tabular-nums; }
.resource-icon { font-size: 1.05em; }
.calendar { font-size: 0.9rem; color: var(--ink-soft); }
.nav { display: flex; gap: 4px; }
.nav a { display: inline-flex; flex-direction: column; align-items: center; gap: 0; padding: 4px 10px; text-decoration: none; color: var(--ink); border-radius: var(--radius-sm); font-size: 0.8rem; }
.nav a .nav-icon { font-size: 1.25rem; line-height: 1; }
.nav a.active { background: var(--bg-sunken); }
.nav a:hover { background: var(--bg-sunken); }

/* ---------- layout ---------- */
.screen { max-width: var(--maxw); margin: 0 auto; padding: 20px 16px 60px; }
.panel { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: var(--gap); }
.panel.error { border-color: var(--bad); }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: var(--gap); align-items: center; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: var(--gap); flex-wrap: wrap; }
.section-title { margin-top: 0; }
.section-lead { color: var(--ink-soft); max-width: 60ch; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: var(--radius-sm);
  border: 2px solid var(--line); background: var(--bg-elev); color: var(--ink);
  cursor: pointer; text-decoration: none; font-weight: 600; line-height: 1.2;
  transition: transform 0.08s, background 0.15s;
}
.btn:hover { background: var(--bg-sunken); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn-danger { border-color: var(--bad); color: var(--bad); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--bg-sunken); }
.btn-big { font-size: 1.15rem; padding: 14px 26px; }
.btn-small { font-size: 0.85rem; padding: 5px 10px; }
.link { background: none; border: 0; padding: 0; color: var(--accent-2); text-decoration: underline; cursor: pointer; }
.input, .task-input {
  font: inherit; padding: 9px 12px; border-radius: var(--radius-sm);
  border: 2px solid var(--line); background: var(--bg-elev); color: var(--ink); width: 100%;
}
label { display: block; font-weight: 600; margin-bottom: 10px; }
label .input { margin-top: 6px; font-weight: 400; }

/* ---------- stats, progress, cards ---------- */
.stat { display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.progress { height: 10px; background: var(--bg-sunken); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress-fill { height: 100%; background: var(--accent-2); border-radius: 99px; transition: width 0.3s; }
.progress.xp .progress-fill { background: var(--warn); }
.progress.hp .progress-fill { background: var(--bad); }
.progress.mana .progress-fill { background: var(--accent-2); }
.card { background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; }
.card-icon { font-size: 2rem; line-height: 1; }
.card-title { font-family: var(--font-display); font-size: 1.15rem; font-weight: 700; }
.card.locked { opacity: 0.6; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--bg-sunken); font-size: 0.78rem; font-weight: 600; }
.tag.good { background: var(--good); color: #fff; }
.tag.bad { background: var(--bad); color: #fff; }
.tag.warn { background: var(--warn); color: #fff; }

/* ---------- overlay, modal ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 30, 0.55); display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.modal {
  position: relative; background: var(--bg-elev); color: var(--ink);
  border: 2px solid var(--line); border-radius: var(--radius);
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  padding: 22px 24px; box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.modal + .modal { position: absolute; }
.modal-wide { width: min(820px, 100%); }
.modal-title { margin-right: 32px; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-close { position: absolute; top: 8px; right: 8px; border: 0; background: transparent; font-size: 1.6rem; line-height: 1; cursor: pointer; color: var(--ink-soft); padding: 4px 8px; }

/* ---------- task prompt ---------- */
.modal.task { width: min(560px, 100%); }
.task-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.task-title { font-family: var(--font-display); font-weight: 700; font-size: 1.2rem; }
.task-context { font-size: 0.85rem; color: var(--ink-soft); }
.task-timer { height: 6px; background: var(--bg-sunken); border-radius: 99px; overflow: hidden; margin-bottom: 14px; }
.task-timer-fill { height: 100%; background: var(--accent-2); transform-origin: left; transform: scaleX(1); }
.task-timer.low .task-timer-fill { background: var(--bad); }
.task-question { font-size: 1.45rem; font-weight: 600; margin: 8px 0 16px; line-height: 1.35; }
.task-question table { border-collapse: collapse; margin: 8px 0; font-size: 1rem; }
.task-question td, .task-question th { border: 1px solid var(--line); padding: 4px 10px; }
.task-input-row { display: flex; gap: 8px; }
.task-input { font-size: 1.3rem; }
.task-choices { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.btn-choice { font-size: 1.25rem; padding: 14px; }
.btn-choice.is-right { background: var(--good); border-color: var(--good); color: #fff; opacity: 1; }
.btn-choice.is-wrong { background: var(--bad); border-color: var(--bad); color: #fff; opacity: 1; }
.task-tools { display: flex; gap: 8px; margin-top: 10px; }
.task-hint { margin-top: 10px; padding: 10px 12px; background: var(--bg-sunken); border-radius: var(--radius-sm); font-size: 0.95rem; }
.task-feedback { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.task-verdict { font-weight: 700; font-size: 1.1rem; }
.modal.is-right .task-verdict { color: var(--good); }
.modal.is-wrong .task-verdict { color: var(--bad); }
.task-explain { color: var(--ink-soft); }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: var(--radius-sm); opacity: 0; transform: translateY(10px); transition: opacity 0.25s, transform 0.25s; font-weight: 600; }
.toast.show { opacity: 1; transform: none; }
.toast-success { background: var(--good); color: #fff; }
.toast-error { background: var(--bad); color: #fff; }

/* ---------- level up ---------- */
.levelup-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn-stat { flex-direction: column; padding: 16px; gap: 4px; }
.btn-stat .stat-icon { font-size: 2rem; }
.btn-stat small { font-weight: 400; color: var(--ink-soft); }

/* ---------- home / onboarding ---------- */
.hero-banner { padding: 40px 0 30px; max-width: 760px; }
.hero-kicker { color: var(--ink-soft); margin-bottom: 8px; }
.hero-title { font-size: clamp(2.8rem, 9vw, 5.5rem); margin: 0 0 16px; letter-spacing: -0.02em; }
.hero-title .semi { color: var(--accent); }
.hero-lead { font-size: 1.15rem; max-width: 60ch; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 20px; }
.tier-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); margin-bottom: 40px; }
.tier-card { border-radius: var(--radius); padding: 22px; display: flex; flex-direction: column; gap: 8px; min-height: 320px; }
.tier-card .btn { margin-top: auto; align-self: flex-start; }
.tier-ages { font-weight: 700; font-size: 0.9rem; }
.tier-title { font-size: 1.5rem; margin: 0; }
.tier-list { margin: 0; padding-left: 18px; }
.how-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-bottom: 40px; }
.how-icon { font-size: 2rem; }
.site-footer { color: var(--ink-soft); font-size: 0.9rem; }
.portrait-grid { display: flex; gap: 8px; flex-wrap: wrap; }
.portrait { font-size: 1.8rem; width: 56px; height: 56px; border-radius: var(--radius-sm); border: 2px solid var(--line); background: var(--bg-elev); cursor: pointer; }
.portrait[aria-pressed="true"] { border-color: var(--accent); background: var(--bg-sunken); }

@media (max-width: 720px) {
  body { font-size: 16px; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 6px 10px; }
  .brand-sub { display: none; }
  .topbar-mid { order: 3; width: 100%; font-size: 0.9rem; }
  .nav { margin-left: auto; }
  .nav a { padding: 4px 8px; }
  .nav .nav-label { font-size: 0.7rem; }
  .screen { padding: 14px 10px 50px; }
  .modal { padding: 18px 16px; }
  .task-choices { grid-template-columns: 1fr 1fr; }
  .levelup-choices { grid-template-columns: 1fr; }
}

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