:root {
  --bg: #f6faf9;
  --card: #ffffff;
  --ink: #17302d;
  --ink-2: #4a615d;
  --ink-3: #7a8c89;
  --line: #dbe7e4;
  --brand: #0f766e;
  --brand-2: #14b8a6;
  --brand-soft: #e0f4f1;
  --accent: #f59e0b;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --hl: #fff3b0;
  --shadow: 0 1px 2px rgba(16, 48, 44, .06), 0 4px 16px rgba(16, 48, 44, .06);
  --radius: 14px;
  --read: 1.05rem;
  --k-link: #5b8c2a; --k-visual: #0369a1; --k-evo: #7c3aed; --k-sci: #0f766e; --k-everyday: #c2410c; --k-career: #a16207; --k-method: #be185d;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1615; --card: #15201f; --ink: #e3efed; --ink-2: #a9bcb8; --ink-3: #7d918d; --line: #26393a;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123532; --good-soft: #10331f; --bad-soft: #3b1515; --hl: #5c4d0c;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
    --k-link: #9acd63; --k-visual: #60b6f0; --k-evo: #b69bff; --k-sci: #2dd4bf; --k-everyday: #fb923c; --k-career: #facc15; --k-method: #f472b6;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1615; --card: #15201f; --ink: #e3efed; --ink-2: #a9bcb8; --ink-3: #7d918d; --line: #26393a;
  --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123532; --good-soft: #10331f; --bad-soft: #3b1515; --hl: #5c4d0c;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  --k-link: #9acd63; --k-visual: #60b6f0; --k-evo: #b69bff; --k-sci: #2dd4bf; --k-everyday: #fb923c; --k-career: #facc15; --k-method: #f472b6;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 80px; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.6 Lexend, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--brand); }
button { font: inherit; color: inherit; }
img { max-width: 100%; height: auto; }
sup, sub { font-size: .72em; line-height: 0; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; gap: 12px; align-items: center; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink); font-weight: 600; font-size: 1.1rem; white-space: nowrap; }
.logo { font-size: 1.5rem; }
.search { flex: 1; max-width: 640px; margin-left: auto; }
.search input { width: 100%; padding: 10px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font: inherit; outline: none; }
.search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
@media (max-width: 560px) { .brand-text { display: none; } }

main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 48px; outline: none; }
.foot { max-width: 1040px; margin: 0 auto; padding: 16px 16px 40px; color: var(--ink-3); font-size: .78rem; border-top: 1px solid var(--line); }
.foot a { color: var(--ink-2); }

/* ---------- common ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); text-decoration: none; cursor: pointer; font-weight: 500; font-size: .95rem; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #062b27; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #062b27; } }
.btn.small { padding: 6px 12px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: default; }
.muted { color: var(--ink-2); }
.crumbs { font-size: .85rem; color: var(--ink-3); margin-bottom: 6px; }
.crumbs a { color: var(--ink-2); text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); line-height: 1.2; margin: 0 0 8px; font-weight: 600; }
.kicker { text-transform: uppercase; letter-spacing: .08em; font-size: .75rem; font-weight: 600; color: var(--brand); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: .78rem; font-weight: 500; }
.empty { padding: 32px; text-align: center; color: var(--ink-2); }

/* ---------- home ---------- */
.hero { padding: 28px 24px; margin-bottom: 22px; background: linear-gradient(135deg, var(--brand-soft), var(--card)); }
.hero h1 { margin-bottom: 4px; }
.hero p { margin: 0 0 14px; color: var(--ink-2); }
.hw { display: flex; gap: 8px; flex-wrap: wrap; }
.hw textarea { flex: 1 1 320px; min-height: 52px; resize: vertical; padding: 12px 14px; border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font: inherit; }
.hw textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.examples { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 6px; font-size: .85rem; color: var(--ink-3); align-items: center; }
.examples button { border: 1px dashed var(--line); background: none; border-radius: 999px; padding: 3px 10px; cursor: pointer; color: var(--ink-2); font-size: .82rem; }
.examples button:hover { border-color: var(--brand); color: var(--brand); }
.hw-results { margin-top: 16px; display: grid; gap: 10px; }
.hw-card { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; color: var(--ink); }
.hw-card:hover { border-color: var(--brand); }
.hw-card .ico { font-size: 1.4rem; width: 32px; text-align: center; flex: none; }
.hw-card .t { font-weight: 500; }
.hw-card .s { font-size: .85rem; color: var(--ink-2); }
.continue { display: flex; gap: 14px; align-items: center; padding: 14px 18px; margin-bottom: 22px; text-decoration: none; color: var(--ink); }
.continue:hover { border-color: var(--brand); }
.continue .big { font-size: 1.8rem; }
.unit { margin: 26px 0 10px; display: flex; align-items: baseline; gap: 10px; }
.unit h2 { margin: 0; font-size: 1.1rem; font-weight: 600; }
.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.ch-card { padding: 14px 16px; text-decoration: none; color: var(--ink); display: flex; gap: 12px; align-items: center; transition: transform .12s, border-color .12s; }
.ch-card:hover { border-color: var(--brand); transform: translateY(-2px); }
.ch-num { flex: none; width: 46px; height: 46px; position: relative; }
.ch-num svg { width: 46px; height: 46px; transform: rotate(-90deg); }
.ch-num span { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 600; font-size: .95rem; }
.ch-card .t { font-weight: 500; line-height: 1.3; }
.ch-card .s { font-size: .78rem; color: var(--ink-3); }

/* ---------- chapter ---------- */
.ch-head { padding: 22px 24px; margin-bottom: 18px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.sec-list { display: grid; gap: 8px; }
.sec-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; text-decoration: none; color: var(--ink); }
.sec-row:hover { border-color: var(--brand); }
.sec-row .num { flex: none; min-width: 42px; font-weight: 600; color: var(--brand); }
.sec-row .t { flex: 1; }
.sec-row .s { font-size: .8rem; color: var(--ink-3); white-space: nowrap; }
.check { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: .75rem; color: transparent; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.sub-h { margin: 22px 0 8px; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); font-weight: 600; }

/* ---------- reader ---------- */
.reader-wrap { max-width: 760px; margin: 0 auto; }
.reader-bar { position: sticky; top: 61px; z-index: 10; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; padding: 8px 0; background: var(--bg); border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.reader-bar .sp { flex: 1; }
.iconbtn { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .85rem; display: inline-flex; gap: 6px; align-items: center; }
.iconbtn:hover { border-color: var(--brand); }
.iconbtn.on { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.reader { font-size: var(--read); line-height: 1.75; }
.reader p { margin: 0 0 1em; }
.reader h3 { font-size: 1.35em; margin: 1.6em 0 .5em; line-height: 1.3; font-weight: 600; }
.reader h4 { font-size: 1.1em; margin: 1.3em 0 .4em; font-weight: 600; }
.reader .label { text-transform: uppercase; letter-spacing: .08em; font-size: .78em; font-weight: 600; color: var(--brand); margin: 0 0 .4em; }
.reader ul, .reader ol { margin: 0 0 1em; padding-left: 1.4em; }
.reader li { margin: .25em 0; }
.reader .small { font-size: .82em; color: var(--ink-2); }
.reader p.eq { text-align: center; margin: .6em 0 1.1em; overflow-x: auto; }
.reader ol.steps { list-style: none; padding-left: .4em; }
.reader ol.steps li { margin: .5em 0; }
img.math { display: inline-block; vertical-align: middle; width: auto; max-width: none; mix-blend-mode: multiply; margin: 0 .05em; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) img.math { mix-blend-mode: normal; filter: invert(1) hue-rotate(180deg); } }
:root[data-theme="dark"] img.math { mix-blend-mode: normal; filter: invert(1) hue-rotate(180deg); }
.reader b { font-weight: 600; }
.reader .flash { background: var(--hl); border-radius: 6px; transition: background 2s; }
.reader .speaking { background: var(--brand-soft); border-radius: 6px; box-shadow: 0 0 0 4px var(--brand-soft); }
.pg { float: right; margin: .2em 0 0 .8em; font-size: .7rem; color: var(--ink-3); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; line-height: 1.6; font-weight: 500; }
button.term { all: unset; cursor: pointer; font-weight: 600; border-bottom: 2px dotted var(--brand-2); }
button.term:hover, button.term:focus-visible { background: var(--brand-soft); border-radius: 3px; }
a.xref { text-decoration: none; border-bottom: 1px solid currentColor; }
figure { margin: 1.4em 0; text-align: center; }
figure img { border-radius: 10px; cursor: zoom-in; background: #fff; border: 1px solid var(--line); }
figcaption { text-align: left; font-size: .82em; color: var(--ink-2); margin-top: .5em; line-height: 1.5; }
figcaption b { color: var(--ink); }
.tablewrap { overflow-x: auto; margin: 1.2em 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.tablewrap table { border-collapse: collapse; width: 100%; font-size: .88em; line-height: 1.45; }
.tablewrap td, .tablewrap th { padding: 8px 10px; border-top: 1px solid var(--line); vertical-align: top; text-align: left; }
.tablewrap tr:first-child td, .tablewrap th { border-top: 0; background: var(--brand-soft); font-weight: 600; }
.tcap { font-size: .85em; font-weight: 600; margin: 1.2em 0 -.6em; }
details.ap { margin: 1em 0; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: .88em; }
details.ap summary { cursor: pointer; padding: 8px 14px; color: var(--ink-2); font-weight: 500; }
details.ap .tablewrap { margin: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
details.ap .tablewrap tr td { background: none; font-weight: 400; }
details.ap .tablewrap td:first-child { font-weight: 600; width: 22%; }
.box { margin: 1.6em 0; padding: 14px 18px 4px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); border-left: 5px solid var(--kc, var(--brand)); }
.box-kind { font-size: .72em; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--kc, var(--brand)); margin-bottom: 4px; }
.box > h4:first-of-type { margin-top: .2em; }
.k-link { --kc: var(--k-link); } .k-visual { --kc: var(--k-visual); } .k-evo { --kc: var(--k-evo); } .k-sci { --kc: var(--k-sci); }
.k-everyday { --kc: var(--k-everyday); } .k-career { --kc: var(--k-career); } .k-method { --kc: var(--k-method); }
.simple { margin: 0 0 24px; padding: 16px 18px; border-radius: 14px; background: linear-gradient(135deg, #fff8e6, var(--card)); border: 1px solid #f3dca2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .simple { background: #2a2310; border-color: #5a4a1a; } }
:root[data-theme="dark"] .simple { background: #2a2310; border-color: #5a4a1a; }
.simple .kicker { color: #b45309; }
.simple .big { font-size: 1.12em; font-weight: 500; margin: 4px 0 8px; }
.simple ul { margin: 0 0 6px; padding-left: 1.2em; }
.simple li { margin: .35em 0; }
.simple .words { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 4px; }
.simple .words .term { font-size: .9em; }
.pager { display: flex; gap: 10px; justify-content: space-between; margin-top: 36px; flex-wrap: wrap; }
.pager a { flex: 1 1 220px; padding: 12px 16px; text-decoration: none; color: var(--ink); }
.pager a:hover { border-color: var(--brand); }
.pager .dir { font-size: .75rem; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; }
.pager .next { text-align: right; }

/* questions */
.qcard { padding: 16px 18px; margin: 0 0 14px; }
.qnum { font-weight: 600; color: var(--brand); margin-right: 6px; }
.qstem p { margin: 0 0 .6em; }
.opts { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 8px; }
.opt { display: flex; gap: 10px; align-items: flex-start; width: 100%; text-align: left; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); cursor: pointer; line-height: 1.45; }
.opt:hover:not([disabled]) { border-color: var(--brand); }
.opt .letter { flex: none; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); font-weight: 600; font-size: .8rem; }
.opt img.choice { display: block; max-width: 100%; height: auto; border-radius: 6px; background: #fff; }
.opt.right { border-color: var(--good); background: var(--good-soft); }
.opt.right .letter { background: var(--good); color: #fff; }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .letter { background: var(--bad); color: #fff; }
.opt[disabled] { cursor: default; }
.why { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--brand-soft); font-size: .92em; }
.nokey { font-size: .8rem; color: var(--ink-3); margin-top: 8px; }

/* ---------- flashcards ---------- */
.fc-wrap { max-width: 640px; margin: 0 auto; }
.fc-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.bar { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 6px 0 18px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); transition: width .3s; }
.flip { perspective: 1200px; cursor: pointer; user-select: none; }
.flip-in { position: relative; min-height: 260px; transition: transform .45s; transform-style: preserve-3d; }
.flip.on .flip-in { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 28px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); }
.face.back { transform: rotateY(180deg); }
.face .word { font-size: clamp(1.5rem, 5vw, 2.2rem); font-weight: 600; }
.face .def { font-size: 1.15rem; line-height: 1.55; }
.face .hint { position: absolute; bottom: 12px; font-size: .75rem; color: var(--ink-3); }
.fc-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.fc-actions .btn { min-width: 150px; justify-content: center; }
.btn.good { border-color: var(--good); color: var(--good); }
.btn.again { border-color: var(--accent); color: #b45309; }
.done { text-align: center; padding: 34px 20px; }
.done .big { font-size: 3rem; }

/* ---------- quiz ---------- */
.quiz-wrap { max-width: 720px; margin: 0 auto; }
.score { font-size: 3rem; font-weight: 700; color: var(--brand); }

/* ---------- search ---------- */
.results { display: grid; gap: 12px; }
.res { padding: 14px 16px; text-decoration: none; color: var(--ink); display: block; }
.res:hover { border-color: var(--brand); }
.res .where { font-size: .78rem; color: var(--ink-3); }
.res .title { font-weight: 600; margin: 2px 0 4px; }
.res .snip { font-size: .92rem; color: var(--ink-2); }
.res .snip + .snip { margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--line); }
mark { background: var(--hl); color: inherit; border-radius: 3px; padding: 0 1px; }

/* ---------- overlays ---------- */
.pop { position: absolute; z-index: 40; max-width: min(360px, calc(100vw - 32px)); padding: 12px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); font-size: .92rem; line-height: 1.5; }
.pop .w { font-weight: 600; color: var(--brand); margin-bottom: 2px; }
.pop .from { font-size: .75rem; color: var(--ink-3); margin-top: 6px; }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(8, 20, 18, .92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 80vh; background: #fff; border-radius: 8px; touch-action: pinch-zoom; }
.lightbox p { color: #dfe9e7; max-width: 760px; font-size: .9rem; }
.lb-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 1.2rem; cursor: pointer; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; overflow: hidden; }
#confetti i { position: absolute; top: -12px; width: 9px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(105vh) rotate(720deg); opacity: .8; } }
@media (prefers-reduced-motion: reduce) { .flip-in { transition: none; } #confetti { display: none; } .ch-card:hover { transform: none; } }
@media (max-width: 560px) { .reader-bar { position: static; } .hero { padding: 20px 16px; } .ch-head { padding: 18px 16px; } }
