:root {
  --primary: #b0613f;
  --on-primary: #fff;
  --primary-container: #ffdbce;
  --on-primary-container: #3a1709;
  --secondary: #76574a;
  --bg: #faf6f0;
  --fg: #3a3530;
  --surface: #fff;
  --surface-variant: #f4ece3;
  --muted: #6b625b;
  --outline: #d8ccc1;
  --correct: #2e7d32;
  --wrong: #ba1a1a;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary: #ffb59a;
    --on-primary: #552b1a;
    --primary-container: #6f3e2a;
    --on-primary-container: #ffdbce;
    --secondary: #e6bca9;
    --bg: #1c1b1a;
    --fg: #e8e4de;
    --surface: #24201e;
    --surface-variant: #34302d;
    --muted: #cfc8c0;
    --outline: #4d4743;
    --correct: #2e7d32;
    --wrong: #b3261e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 18px/1.6 var(--sans);
}
h1, h2, h3 { font-family: var(--serif); font-weight: 400; margin: 0; line-height: 1.25; }
h1 { font-size: 2.1rem; }
h2 { font-size: 1.6rem; }
p { margin: 0; }
a { color: var(--primary); }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg);
  border-bottom: 1px solid var(--outline);
}
.top-inner {
  max-width: 760px; margin: 0 auto; padding: 0 16px;
  display: flex; align-items: center; gap: 12px; height: 60px;
}
.brand { font-family: var(--serif); font-size: 1.4rem; color: var(--primary); text-decoration: none; margin-right: auto; }
nav { display: flex; gap: 2px; }
nav a {
  color: var(--fg); text-decoration: none; font-size: .95rem;
  padding: 8px 12px; border-radius: 999px;
}
nav a:hover { background: var(--surface-variant); }
nav a.active { background: var(--primary-container); color: var(--on-primary-container); font-weight: 600; }
.icon-btn {
  background: none; border: 0; color: var(--fg); cursor: pointer;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-variant); }
@media (max-width: 560px) {
  .brand { display: none; }
  nav { margin-right: auto; }
  nav a { padding: 8px 8px; font-size: .9rem; }
}

main { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; outline: none; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 6px; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.label { font-size: .85rem; font-weight: 600; letter-spacing: .02em; }

.card { background: var(--surface-variant); border-radius: 16px; padding: 20px; }
.card.primary { background: var(--primary-container); color: var(--on-primary-container); }
.card h2 { font-size: 1.45rem; }

.btn {
  display: block; width: 100%; text-align: center; text-decoration: none;
  font: 600 1rem var(--sans); cursor: pointer;
  padding: 12px 20px; border-radius: 999px; border: 1px solid transparent;
  background: var(--primary); color: var(--on-primary);
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .4; cursor: default; filter: none; }
.btn.outline { background: transparent; color: var(--primary); border-color: var(--outline); }
.btn.text { background: transparent; color: var(--primary); }
.btn.danger { color: var(--wrong); }

.bar { height: 8px; background: var(--surface-variant); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }

.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); text-decoration: none; font-size: .95rem; }
.back:hover { color: var(--fg); }
.body { white-space: pre-line; font-size: 1.06rem; line-height: 1.7; }

figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; }
figure img { max-width: 100%; max-height: 240px; object-fit: contain; }
figcaption { font-size: .85rem; color: var(--muted); text-align: center; }
.gallery { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
.gallery figure { flex: 0 1 150px; }
.gallery img { max-height: 170px; }
.q-img img { max-height: 220px; }

.question { font-weight: 600; font-size: 1.1rem; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex; gap: 12px; align-items: baseline; text-align: left;
  font: 1rem/1.45 var(--sans); cursor: pointer;
  padding: 12px 18px; border-radius: 14px;
  background: var(--surface); color: var(--fg); border: 1px solid var(--outline);
}
.choice:hover:not(:disabled) { border-color: var(--primary); }
.choice:disabled { cursor: default; }
.choice kbd { font: 600 .8rem var(--sans); color: var(--muted); min-width: 1ch; }
.choice.correct { background: var(--correct); border-color: var(--correct); color: #fff; }
.choice.wrong { background: var(--wrong); border-color: var(--wrong); color: #fff; }
.choice.correct kbd, .choice.wrong kbd { color: #fff; }
.explain { background: var(--surface-variant); border-radius: 14px; padding: 16px; font-size: .98rem; }

.module h3 { font-family: var(--sans); font-size: 1.05rem; font-weight: 600; color: var(--secondary); padding: 20px 0 6px; border-bottom: 1px solid var(--outline); }
.module ul { list-style: none; margin: 0; padding: 0; }
.module a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 6px; color: var(--fg); text-decoration: none; border-radius: 8px;
}
.module a:hover { background: var(--surface-variant); }
.done-mark { color: var(--primary); flex: none; }

.big { font-family: var(--serif); font-size: 3.5rem; color: var(--primary); line-height: 1; }
.result-pass { color: var(--correct); }
.result-fail { color: var(--wrong); }

dialog {
  border: 0; border-radius: 20px; padding: 28px; width: min(420px, calc(100vw - 32px));
  background: var(--bg); color: var(--fg);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
.field { display: flex; flex-direction: column; gap: 6px; font-size: .95rem; }
input[type=text] {
  font: 1rem var(--sans); padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--outline); background: var(--surface); color: var(--fg);
}
.check { display: flex; gap: 10px; align-items: center; }
.check input { width: 20px; height: 20px; accent-color: var(--primary); }

.celebration { position: fixed; inset: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 97%, transparent); }
.celebration canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.celebration-body {
  position: relative; height: 100%; max-width: 440px; margin: 0 auto; padding: 0 24px;
  display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 16px;
}
.celebration h2 { font-size: 2.4rem; font-weight: 700; color: var(--primary); }
.cel-sub { font-family: var(--serif); font-size: 1.5rem; }
.cel-enc { font-size: 1.25rem; margin-bottom: 32px; }

.hint { font-size: .8rem; color: var(--muted); text-align: center; }
@media (hover: none) { .hint, .choice kbd { display: none; } }
