:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f0e9dd;
  --ink: #2b2118;
  --ink-soft: #6b5b4b;
  --line: #e2d7c6;
  --accent: #8a4b23;
  --accent-ink: #fff;
  --accent-soft: #f3e2d3;
  --good: #2f7a4b;
  --good-soft: #dcefe2;
  --bad: #b23b2e;
  --bad-soft: #f6dcd8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1612; --surface: #241d18; --surface-2: #2f2620; --ink: #f1e8dc; --ink-soft: #b9a894;
    --line: #3d3229; --accent: #e0a172; --accent-ink: #1b1612; --accent-soft: #3a2a1f;
    --good: #7fcf9b; --good-soft: #1f3528; --bad: #f08b7e; --bad-soft: #3d221e;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}
:root[data-theme="dark"] {
  --bg: #1b1612; --surface: #241d18; --surface-2: #2f2620; --ink: #f1e8dc; --ink-soft: #b9a894;
  --line: #3d3229; --accent: #e0a172; --accent-ink: #1b1612; --accent-soft: #3a2a1f;
  --good: #7fcf9b; --good-soft: #1f3528; --bad: #f08b7e; --bad-soft: #3d221e;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-family: Georgia, "Times New Roman", serif; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }

.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--ink); font-family: Georgia, serif; font-size: 1.1rem; white-space: nowrap; }
.brand-mark { font-size: 1.3rem; }
.topnav { display: flex; gap: 4px; }
.topnav a { text-decoration: none; color: var(--ink-soft); padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: .95rem; }
.topnav a.active { background: var(--accent-soft); color: var(--accent); }

main { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 24px 16px 48px; outline: none; }
.foot { text-align: center; color: var(--ink-soft); font-size: .8rem; padding: 16px; border-top: 1px solid var(--line); }

.hero { display: grid; gap: 16px; grid-template-columns: 1fr auto; align-items: center; margin-bottom: 28px; }
.hero p { color: var(--ink-soft); margin: 0; }
.ring { --p: 0; width: 92px; height: 92px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0); }
.ring span { width: 72px; height: 72px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-weight: 700; font-size: 1.1rem; }

.group-title { display: flex; align-items: baseline; gap: 8px; margin: 28px 0 12px; }
.group-title small { color: var(--ink-soft); font-weight: 400; font-family: system-ui, sans-serif; font-size: .85rem; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow);
}
a.card { text-decoration: none; color: inherit; display: flex; flex-direction: column; gap: 6px; transition: transform .12s ease, border-color .12s; }
a.card:hover { transform: translateY(-2px); border-color: var(--accent); }
.card .emoji { font-size: 1.8rem; }
.card h3 { margin: 0; }
.card p { margin: 0; color: var(--ink-soft); font-size: .92rem; }
.meter { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: auto; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.meta { font-size: .8rem; color: var(--ink-soft); display: flex; justify-content: space-between; margin-top: 8px; }

.crumbs { font-size: .9rem; margin-bottom: 12px; }
.crumbs a { text-decoration: none; }
.tabs { display: flex; gap: 6px; margin: 16px 0 20px; flex-wrap: wrap; }
.tabs a { text-decoration: none; padding: 8px 16px; border-radius: 999px; border: 1px solid var(--line); color: var(--ink); background: var(--surface); font-weight: 600; font-size: .95rem; }
.tabs a.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.lesson section { margin-bottom: 14px; }
.lesson .card { padding: 20px 22px; }
.lesson p { margin: 0 0 .8em; }
.lesson ul { margin: .2em 0 .4em; padding-left: 1.2em; }
.lesson li { margin: .25em 0; }
.lesson .done-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px; }
.toc a { font-size: .85rem; text-decoration: none; background: var(--surface-2); color: var(--ink); padding: 4px 10px; border-radius: 99px; }

.btn {
  appearance: none; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-block;
}
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

.flash-wrap { max-width: 560px; margin: 0 auto; }
.flash { perspective: 1200px; cursor: pointer; height: 280px; }
.flash-inner { position: relative; width: 100%; height: 100%; transition: transform .45s ease; transform-style: preserve-3d; }
.flash.flipped .flash-inner { transform: rotateY(180deg); }
.face {
  position: absolute; inset: 0; backface-visibility: hidden; display: grid; place-items: center; text-align: center;
  padding: 24px; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface); box-shadow: var(--shadow); overflow: auto;
}
.face.front { font-family: Georgia, serif; font-size: 1.35rem; }
.face.back { transform: rotateY(180deg); background: var(--accent-soft); font-size: 1.05rem; }
.face .hint { position: absolute; bottom: 10px; left: 0; right: 0; font-size: .75rem; color: var(--ink-soft); font-family: system-ui, sans-serif; }
.counter { text-align: center; color: var(--ink-soft); font-size: .9rem; margin-bottom: 10px; }

.quiz-q { font-family: Georgia, serif; font-size: 1.2rem; margin-bottom: 16px; }
.opts { display: grid; gap: 10px; }
.opt {
  text-align: left; font: inherit; padding: 14px 16px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; display: flex; gap: 12px; align-items: flex-start;
}
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .key { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); font-weight: 700; font-size: .85rem; }
.opt.correct { border-color: var(--good); background: var(--good-soft); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt:disabled { cursor: default; }
.explain { margin-top: 14px; padding: 12px 16px; border-radius: 12px; background: var(--surface-2); font-size: .95rem; }
.score-big { font-size: 3rem; font-weight: 800; font-family: Georgia, serif; text-align: center; margin: 8px 0; }
.center { text-align: center; }
.muted { color: var(--ink-soft); }
.progressbar { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-bottom: 18px; }
.progressbar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

.search-box { width: 100%; font: inherit; font-size: 1.05rem; padding: 12px 16px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink); }
.search-box:focus { outline: none; border-color: var(--accent); }
.result { margin-top: 12px; }
.result .src { font-size: .8rem; color: var(--ink-soft); }
mark { background: var(--accent-soft); color: inherit; padding: 0 2px; border-radius: 3px; }
.pill { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-soft); }

@media (max-width: 560px) {
  .hero { grid-template-columns: 1fr; }
  .ring { display: none; }
  .brand { font-size: 1rem; }
  .topnav a { padding: 6px 8px; font-size: .88rem; }
  .flash { height: 320px; }
}

/* narrow-screen fixes */
.opt > span:last-child, .face, .card, .quiz-q { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 480px) {
  .topbar { padding: 8px 12px; }
  .brand-text { display: none; }
  .brand-mark { font-size: 1.6rem; }
}

/* lesson figures */
.figs { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); margin-top: 16px; align-items: start; }
.figs.one { grid-template-columns: minmax(0, 560px); justify-content: center; }
figure { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.zoom { all: unset; cursor: zoom-in; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.zoom:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.zoom img { max-width: 100%; max-height: 340px; height: auto; display: block; }
figcaption { font-size: .85rem; color: var(--ink-soft); text-align: center; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(20, 14, 10, .88); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; cursor: zoom-out; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 82vh; background: #fff; border-radius: 8px; padding: 8px; }
.lightbox p { color: #f1e8dc; margin: 0; text-align: center; max-width: 700px; }
.lb-close { position: absolute; top: 12px; right: 12px; font-size: 1.4rem; background: none; border: 0; color: #fff; cursor: pointer; }
.card-img { max-width: 100%; max-height: 150px; background: #fff; border-radius: 8px; padding: 4px; margin: 0 auto 10px; display: block; }
.flash:has(.card-img) { height: 340px; }
