:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f1f2f8;
  --border: #e3e5ef;
  --text: #171a2c;
  --muted: #646a85;
  --accent: #6d5efc;
  --accent-2: #4a3ce0;
  --accent-soft: #ecebff;
  --ok: #12a26b;
  --ok-soft: #e3f7ee;
  --bad: #e0445a;
  --bad-soft: #fde9ec;
  --warn-soft: #fff6dd;
  --shadow: 0 1px 2px rgba(20, 24, 60, .05), 0 8px 24px rgba(20, 24, 60, .06);
  --radius: 18px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1120;
    --surface: #171a2e;
    --surface-2: #1f2340;
    --border: #2b3052;
    --text: #eceefb;
    --muted: #9aa0c3;
    --accent: #8b7fff;
    --accent-2: #a89fff;
    --accent-soft: #2a2654;
    --ok: #3ccf92;
    --ok-soft: #133528;
    --bad: #ff6b81;
    --bad-soft: #3d1a24;
    --warn-soft: #33301a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { line-height: 1.2; letter-spacing: -.02em; margin: 0 0 .5em; }
h1 { font-size: clamp(1.7rem, 4vw, 2.4rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 1em; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-size: .92em; }
.accent { color: var(--accent); }
kbd {
  font: 600 .72em var(--mono);
  padding: .1em .4em;
  border-radius: 5px;
  border: 1px solid currentColor;
  opacity: .7;
  margin-left: .4em;
}

/* ---------- Layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner, .footer-inner {
  max-width: 1080px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); font-weight: 700; min-width: 0; }
.brand-mark {
  flex: none; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-size: .95rem;
}
.brand-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: .98rem; }
.tld { color: var(--muted); font-weight: 500; }
.topnav { display: flex; gap: 4px; }
.topnav a { color: var(--muted); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: .92rem; }
.topnav a:hover { color: var(--text); background: var(--surface-2); }
.topnav a.active { color: var(--accent); background: var(--accent-soft); }
.wrap { flex: 1; width: 100%; max-width: 1080px; margin: 0 auto; padding: 32px 16px 64px; }
.footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; }
.link-btn:hover { color: var(--bad); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 700; color: var(--accent); margin-bottom: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 12px; padding: 10px 18px;
  font: 600 .95rem/1.2 inherit; cursor: pointer; transition: transform .08s, background .15s, box-shadow .15s;
  color: var(--text); background: var(--surface-2);
}
.btn:active { transform: translateY(1px); }
.btn.primary { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 6px 16px color-mix(in srgb, var(--accent) 35%, transparent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 7px 12px; font-size: .85rem; border-radius: 10px; }
.btn.lg { padding: 14px 24px; font-size: 1.05rem; border-radius: 14px; }
.btn[disabled] { opacity: .55; cursor: default; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

/* ---------- Progress ---------- */
.progress { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .35s ease; }
.progress.sm { height: 6px; }
.progress-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: 6px; font-weight: 600; }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 24px 0 36px; }
.hero h1 { font-size: clamp(2rem, 6vw, 3.2rem); margin-bottom: .3em; }
.hero h1 .grad { background: linear-gradient(135deg, var(--accent), #e85d9e); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero .lede { font-size: 1.15rem; color: var(--muted); max-width: 560px; margin: 0 auto 20px; }
.today-pill {
  display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 6px; align-items: center;
  padding: 8px 16px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-size: .92rem;
}
.mode-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-bottom: 40px; }
.mode-card { display: flex; flex-direction: column; gap: 12px; color: var(--text); transition: transform .15s, box-shadow .15s, border-color .15s; }
.mode-card:hover { transform: translateY(-3px); border-color: var(--accent); }
.mode-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; font-size: 1.5rem; background: var(--accent-soft); }
.mode-card h2 { margin: 0; }
.mode-card p { color: var(--muted); margin: 0; }
.mode-card .go { margin-top: auto; font-weight: 700; color: var(--accent); }
.reasons h2 { text-align: center; }
.reasons .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.reason-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.reason { display: flex; flex-direction: column; gap: 8px; padding: 20px; }
.reason .emoji { font-size: 1.8rem; line-height: 1; }
.reason h3 { margin: 0; font-size: 1.02rem; }
.reason p { margin: 0; color: var(--muted); font-size: .93rem; }
.reasons .btn-row { justify-content: center; margin-top: 16px; }

/* ---------- Learn ---------- */
.learn { display: grid; grid-template-columns: 250px 1fr; gap: 32px; align-items: start; }
.side { position: sticky; top: 84px; display: flex; flex-direction: column; gap: 16px; }
.sec-nav { display: flex; flex-direction: column; gap: 4px; }
.sec-link { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 12px; color: var(--muted); font-weight: 600; font-size: .92rem; }
.sec-link:hover { background: var(--surface-2); color: var(--text); }
.sec-link.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.sec-num { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; background: var(--surface-2); border: 1px solid var(--border); }
.sec-link.active .sec-num { background: var(--accent); border-color: var(--accent); color: #fff; }
.sec-link.done .sec-num { background: var(--ok); border-color: var(--ok); color: #fff; }
.lesson { min-width: 0; }
.lesson > * + * { margin-top: 24px; }
.prose { font-size: 1.02rem; }
.prose ul, .prose ol { padding-left: 1.3em; margin: 0 0 1em; }
.prose li { margin-bottom: .35em; }
.callout { padding: 14px 18px; border-radius: 14px; background: var(--accent-soft); margin: 0 0 1em; }
.callout.warn { background: var(--warn-soft); }
.flow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 1.2em; }
.flow span.step { padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 600; font-size: .9rem; }
.flow span.arrow { color: var(--muted); }
.done-banner { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; background: linear-gradient(135deg, var(--ok-soft), var(--accent-soft)); border-color: transparent; }
.done-banner h3 { margin: 0 0 4px; }
.done-banner p { margin: 0; color: var(--muted); }
.lesson-nav { display: flex; justify-content: space-between; gap: 12px; }

.month-tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 0 0 1.2em; }
.month-tile { padding: 12px; border-radius: 14px; background: var(--surface); border: 1px solid var(--border); }
.month-tile .mname { font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.month-tile .mdate { font-size: 1.4rem; font-weight: 800; color: var(--accent); }
.month-tile .mhint { font-size: .8rem; color: var(--muted); line-height: 1.35; }

.century-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 8px; margin: 0 0 1.2em; }
.century-cell { text-align: center; padding: 10px 4px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.century-cell b { display: block; font-size: 1.05rem; }
.century-cell span { font-size: .82rem; color: var(--muted); }
.century-cell.hl { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Widgets ---------- */
.widget-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.widget-title h3 { margin: 0; }
.year-stepper { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: 1.1rem; }
.icon-btn:hover { background: var(--surface-2); }
.input {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 12px; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input.year { width: 96px; text-align: center; font-weight: 700; }
.cal-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.cal-month h4 { margin: 0 0 6px; font-size: .82rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.cal-days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; font-size: .72rem; text-align: center; }
.cal-days .h { color: var(--muted); font-weight: 700; }
.cal-days .d { padding: 3px 0; border-radius: 6px; }
.cal-days .col { background: var(--accent-soft); }
.cal-days .dd { background: var(--accent); color: #fff; font-weight: 800; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: .85rem; color: var(--muted); margin-top: 16px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 4px; vertical-align: -1px; margin-right: 6px; }

/* ---------- Questions ---------- */
.quiz-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; font-weight: 600; font-size: .9rem; color: var(--muted); }
.quiz-intro { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.quiz-intro h2 { margin: 0 0 4px; }
.quiz-intro p { margin: 0; color: var(--muted); }
.q-prompt { font-size: 1.3rem; line-height: 1.45; margin: 20px 0; }
.q-prompt b { color: var(--accent); }
.q-sub { display: block; font-size: .88rem; color: var(--muted); margin-top: 4px; }
.dow-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.dow-btn {
  position: relative; padding: 14px 4px 10px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: 700 1rem inherit; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px; transition: all .12s;
}
.dow-btn small { font: 600 .7rem var(--mono); color: var(--muted); }
.dow-btn:hover:not([disabled]) { border-color: var(--accent); background: var(--accent-soft); transform: translateY(-1px); }
.dow-btn[disabled] { cursor: default; opacity: .5; }
.dow-btn.correct { opacity: 1; background: var(--ok); border-color: var(--ok); color: #fff; }
.dow-btn.wrong { opacity: 1; background: var(--bad); border-color: var(--bad); color: #fff; }
.dow-btn.correct small, .dow-btn.wrong small { color: rgba(255,255,255,.8); }
.num-row { display: flex; gap: 10px; }
.num-row .input { width: 140px; font-size: 1.2rem; font-weight: 700; text-align: center; }
.input.correct { border-color: var(--ok); background: var(--ok-soft); }
.input.wrong { border-color: var(--bad); background: var(--bad-soft); }
.q-actions { margin-top: 14px; min-height: 8px; }
.tip-box { padding: 12px 16px; border-radius: 12px; background: var(--warn-soft); font-size: .9rem; margin: -6px 0 18px; }
.tip-title { font-weight: 800; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }
.tip-grid { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; }
.tip-grid span:nth-child(odd) { font-weight: 700; }
.reveal-box { margin-top: 14px; padding: 14px 18px; border-radius: 14px; background: var(--surface-2); }
.feedback { margin-top: 18px; padding: 18px; border-radius: 14px; animation: pop .2s ease; }
.feedback.ok { background: var(--ok-soft); }
.feedback.bad { background: var(--bad-soft); }
.fb-head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.fb-icon { flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-weight: 800; }
.ok .fb-icon { background: var(--ok); }
.bad .fb-icon { background: var(--bad); }
.fb-title { font-weight: 800; }
.fb-sub { font-size: .92rem; color: var(--muted); }
.steps-wrap summary { cursor: pointer; font-weight: 700; font-size: .9rem; margin-bottom: 6px; color: var(--muted); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0 0 14px; }
.steps li { counter-increment: s; position: relative; padding: 4px 0 4px 34px; font-size: .95rem; }
.steps li::before {
  content: counter(s); position: absolute; left: 0; top: 5px; width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center; font-size: .72rem; font-weight: 800; background: var(--surface); border: 1px solid var(--border); color: var(--muted);
}
.steps .alt { color: var(--muted); font-style: italic; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.result { text-align: center; padding: 32px 24px; }
.big { font-size: clamp(2.6rem, 9vw, 4rem); font-weight: 900; letter-spacing: -.04em; line-height: 1; background: linear-gradient(135deg, var(--accent), #e85d9e); -webkit-background-clip: text; background-clip: text; color: transparent; }
.result .btn-row { justify-content: center; margin-top: 20px; }
.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; background: var(--ok-soft); color: var(--ok); font-weight: 800; font-size: .85rem; margin-top: 10px; }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 24px; }
.stat { padding: 12px; border-radius: 14px; background: var(--surface-2); }
.stat b { display: block; font-size: 1.3rem; }
.stat span { font-size: .8rem; color: var(--muted); }

/* ---------- Practice ---------- */
.page-head { margin-bottom: 24px; }
.page-head p { color: var(--muted); margin: 0; }
.setup { display: grid; grid-template-columns: 1fr 320px; gap: 24px; align-items: start; }
.setup .card > h3 { margin-top: 24px; margin-bottom: 10px; }
.setup .card > h3:first-child { margin-top: 0; }
.topic-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.topic { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--border); cursor: pointer; transition: all .12s; }
.topic input { position: absolute; opacity: 0; pointer-events: none; }
.topic:hover { border-color: var(--accent); }
.topic.sel { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.topic-title { font-weight: 700; }
.topic-desc { font-size: .82rem; color: var(--muted); }
.topic.general { grid-column: 1 / -1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: 600 .85rem inherit; cursor: pointer; }
.chip.sel, .chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.range-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface-2); gap: 4px; }
.seg button { border: 0; background: transparent; color: var(--muted); font: 700 .95rem inherit; padding: 8px 18px; border-radius: 9px; cursor: pointer; }
.seg button.sel { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background .15s; flex: none; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(18px); }
.setup-foot { margin-top: 28px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.scoring { font-size: .82rem; color: var(--muted); }
.stats-card h3 { margin-top: 0; }
.best-box { padding: 16px; border-radius: 14px; background: var(--accent-soft); margin-bottom: 18px; }
.best-box .big { font-size: 2.2rem; }
.history { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.history li { display: flex; justify-content: space-between; gap: 8px; font-size: .86rem; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.history .pts { font-weight: 800; }

.run { max-width: 720px; margin: 0 auto; }
.run-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.run-meta { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.meta-pill { padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); font-weight: 700; font-size: .85rem; font-variant-numeric: tabular-nums; }
.meta-pill.pts { color: var(--accent); }
.run .card { margin-top: 16px; }
.review-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.review-item { border: 1px solid var(--border); border-radius: 14px; padding: 12px 16px; }
.review-item summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; list-style: none; }
.review-item summary::-webkit-details-marker { display: none; }
.review-item .mark { font-weight: 900; }
.review-item .mark.ok { color: var(--ok); }
.review-item .mark.bad { color: var(--bad); }
.review-item .q { flex: 1; }
.review-item .q b { color: inherit; }
.review-item .t { font-size: .82rem; color: var(--muted); white-space: nowrap; }
.review-item .detail { font-size: .9rem; margin-top: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .learn, .setup { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; min-width: 0; }
  .sec-nav { flex-direction: row; overflow-x: auto; padding-bottom: 4px; }
  .sec-link { flex: none; }
  .sec-link span:last-child { white-space: nowrap; }
  .reason-grid { grid-template-columns: 1fr 1fr; }
  .cal-grid { grid-template-columns: repeat(3, 1fr); }
  .century-row { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 600px) {
  .wrap { padding-top: 20px; }
  .card { padding: 18px; }
  .mode-grid, .reason-grid, .topic-grid { grid-template-columns: 1fr; }
  .cal-grid { grid-template-columns: repeat(2, 1fr); }
  .month-tiles { grid-template-columns: repeat(2, 1fr); }
  .stat-row { grid-template-columns: 1fr 1fr; }
  .dow-grid { gap: 4px; }
  .dow-btn { padding: 12px 0 8px; font-size: .85rem; border-radius: 10px; }
  .q-prompt { font-size: 1.12rem; }
  .brand-name .tld { display: none; }
  .topnav a { padding: 6px 10px; }
}
