/* Hàn Ngữ Toàn Thư
   Layout: thư viện tra cứu hai cột (mục lục cố định + trang học), khối âm tiết Hangul làm mô-típ,
   lưới ô chữ 원고지 cho phần viết; xanh lục lam 단청 làm màu nhấn, đỏ son dùng tiết chế. */
:root {
  --bg: #F0F3F1;
  --surface: #FFFFFF;
  --surface-2: #F6F8F7;
  --ink: #15201C;
  --ink-2: #3A4843;
  --muted: #64736D;
  --line: #D7DFDB;
  --line-2: #E6ECE9;
  --accent: #0D6A64;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEEEB;
  --red: #B23A2C;
  --red-soft: #F7E3DF;
  --gold: #9C6F12;
  --gold-soft: #F6EBD3;
  --good: #2C7A4C;
  --good-soft: #DDF0E3;
  --warn: #9A5F0C;
  --bad: #B3261E;
  --l-A1: #6AAE9D; --l-A2: #3B9481; --l-B1: #1F7A74; --l-B2: #2A6288; --l-C1: #3C4D8C; --l-C2: #503A7C;
  --shadow: 0 1px 2px rgba(18, 40, 33, .06), 0 4px 16px rgba(18, 40, 33, .05);
  --f-display: "Fraunces", "Nanum Myeongjo", Georgia, serif;
  --f-body: "Be Vietnam Pro", "Noto Sans KR", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-ko: "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --f-ko-serif: "Nanum Myeongjo", "Noto Serif KR", serif;
  --r: 10px;
  --side: 264px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1412; --surface: #151D1A; --surface-2: #1B2521; --ink: #E2EAE6; --ink-2: #BAC7C1; --muted: #8E9C96;
    --line: #2B3733; --line-2: #222D29; --accent: #4CB5AB; --accent-ink: #04201D; --accent-soft: #15332F;
    --red: #E8806E; --red-soft: #3A201B; --gold: #D9AE57; --gold-soft: #33290F; --good: #63C288; --good-soft: #15301F; --warn: #E3A64A; --bad: #F07167;
    --l-A1: #8ED0BE; --l-A2: #62BEA9; --l-B1: #48B0A7; --l-B2: #5C9ACB; --l-C1: #7E8FDA; --l-C2: #A08AD4;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1412; --surface: #151D1A; --surface-2: #1B2521; --ink: #E2EAE6; --ink-2: #BAC7C1; --muted: #8E9C96;
  --line: #2B3733; --line-2: #222D29; --accent: #4CB5AB; --accent-ink: #04201D; --accent-soft: #15332F;
  --red: #E8806E; --red-soft: #3A201B; --gold: #D9AE57; --gold-soft: #33290F; --good: #63C288; --good-soft: #15301F; --warn: #E3A64A; --bad: #F07167;
  --l-A1: #8ED0BE; --l-A2: #62BEA9; --l-B1: #48B0A7; --l-B2: #5C9ACB; --l-C1: #7E8FDA; --l-C2: #A08AD4;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.6; margin: 0; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 30; background: var(--surface); }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3, h4 { line-height: 1.25; text-wrap: balance; margin: 0; }
h1 { font-family: var(--f-display); font-weight: 700; font-size: clamp(1.6rem, 3vw, 2.2rem); letter-spacing: -.01em; }
h2 { font-family: var(--f-display); font-weight: 700; font-size: 1.35rem; }
h3 { font-size: 1.05rem; font-weight: 600; }
h4 { font-size: .95rem; font-weight: 600; margin-top: 1.2rem; margin-bottom: .4rem; color: var(--ink); }
p { margin: .5rem 0; }
ul { margin: .4rem 0; padding-left: 1.2rem; }
li { margin: .2rem 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.muted { color: var(--muted); font-size: .88rem; }
.ko, k { font-family: var(--f-ko); }
k { cursor: pointer; border-bottom: 1px dotted color-mix(in srgb, var(--accent) 45%, transparent); transition: color .15s; }
k:hover { color: var(--accent); }
k.speaking { color: var(--accent); background: var(--accent-soft); border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Shell ---------- */
.shell { min-height: 100vh; }
.side {
  position: fixed; top: 0; bottom: 0; left: 0; width: var(--side); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 14px calc(env(safe-area-inset-bottom, 0px) + 18px) calc(env(safe-area-inset-left, 0px) + 14px);
  overflow-y: auto; display: flex; flex-direction: column; gap: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 2px 4px 8px; }
.brand svg { flex: none; }
.brand b { font-family: var(--f-display); font-size: 1.15rem; line-height: 1.1; display: block; }
.brand span { font-size: .72rem; color: var(--muted); letter-spacing: .04em; }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-group > small { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); padding: 6px 10px 4px; font-weight: 600; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 8px; text-decoration: none; color: var(--ink-2); font-size: .92rem; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link .ko { font-size: .78rem; color: var(--muted); margin-left: auto; }
.nav-link.active .ko { color: var(--accent); }
.side-foot { margin-top: auto; font-size: .78rem; color: var(--muted); padding: 8px 10px; border-top: 1px solid var(--line-2); }

.main { margin-left: var(--side); min-width: 0; }
.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
  padding-block: 10px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: flex; align-items: center; gap: 10px;
}
.menu-btn { display: none; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; width: 38px; height: 38px; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.search { position: relative; flex: 1; max-width: 560px; min-width: 0; }
.search input { width: 100%; border: 1px solid var(--line); background: var(--surface-2); border-radius: 999px; padding: 8px 14px 8px 36px; outline: none; }
.search input:focus { border-color: var(--accent); background: var(--surface); }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.results { position: absolute; left: 0; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 60vh; overflow-y: auto; padding: 6px; }
.results a { display: flex; gap: 10px; align-items: baseline; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.results a:hover, .results a.hl { background: var(--surface-2); }
.results a small { color: var(--muted); font-size: .75rem; flex: none; min-width: 72px; }
.results .empty { padding: 10px; color: var(--muted); font-size: .9rem; }
.top-tools { display: flex; gap: 8px; align-items: center; margin-left: auto; }
.sync { font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.sync.cloud { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.sync.error { color: var(--bad); }

.page { max-width: 1100px; margin: 0 auto; padding-block: 24px 64px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 20px; }
.page-head { display: flex; flex-direction: column; gap: 6px; }
.page-head .eyebrow { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); font-weight: 600; }
.page-head .lead { color: var(--ink-2); max-width: 70ch; }
.page-head .ko-title { font-family: var(--f-ko-serif); color: var(--muted); font-size: 1rem; }

.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 35; }

@media (max-width: 1023px) {
  .side { transform: translateX(-102%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .sync { display: none; }
}
@media (max-width: 600px) { .rate-lbl { display: none; } }

/* ---------- Building blocks ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; min-width: 0; }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: .9rem; text-decoration: none; line-height: 1.3; }
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); color: var(--accent-ink); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 4px 10px; font-size: .8rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.done { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 45%, var(--line)); color: var(--good); }

.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); padding: 4px 12px; border-radius: 999px; font-size: .82rem; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--accent); }
.chip.on { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.lv { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 20px; padding: 0 6px; border-radius: 5px; font-size: .7rem; font-weight: 700; letter-spacing: .03em; color: #fff; flex: none; }
.lv-A1 { background: var(--l-A1); } .lv-A2 { background: var(--l-A2); } .lv-B1 { background: var(--l-B1); }
.lv-B2 { background: var(--l-B2); } .lv-C1 { background: var(--l-C1); } .lv-C2 { background: var(--l-C2); }
:root[data-theme="dark"] .lv { color: #0B1210; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lv { color: #0B1210; } }
.tag { font-size: .72rem; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 1px 7px; white-space: nowrap; }

.bar { height: 8px; background: var(--line-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; transition: width .4s ease; }
.select, .input, .textarea { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--muted); }

/* Tables, callouts, examples */
.tbl-wrap { overflow-x: auto; margin: .6rem 0; border: 1px solid var(--line); border-radius: 8px; }
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: var(--surface-2); padding: 8px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.tbl td { padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.callout { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; margin: .8rem 0; background: var(--surface-2); }
.callout > b { display: block; font-size: .78rem; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 4px; }
.callout.key { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.callout.key > b { color: var(--accent); }
.callout.tip > b { color: var(--good); }
.callout.warn { border-color: color-mix(in srgb, var(--red) 35%, var(--line)); background: var(--red-soft); }
.callout.warn > b { color: var(--red); }
.callout.info > b { color: var(--gold); }
.callout .tbl-wrap { background: var(--surface); }
.exs { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 8px; margin: .5rem 0; background: var(--surface); }
.ex { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 4px 16px; padding: 8px 12px; border-bottom: 1px solid var(--line-2); align-items: baseline; }
.ex:last-child { border-bottom: 0; }
.ex k { font-size: 1.02rem; border-bottom-color: transparent; }
.ex .vi { color: var(--ink-2); font-size: .9rem; }
.ex .note { grid-column: 1 / -1; color: var(--muted); font-size: .8rem; }
@media (max-width: 640px) { .ex { grid-template-columns: 1fr; } }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: var(--ink); }
.tile b { font-family: var(--f-display); font-size: 1.9rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile small { color: var(--muted); font-size: .8rem; }
.tile .bar { margin-top: 6px; }
a.tile:hover { border-color: var(--accent); }
.today { display: flex; flex-direction: column; }
.today a { display: flex; gap: 12px; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line-2); text-decoration: none; color: var(--ink); }
.today a:last-child { border-bottom: 0; }
.today a:hover b { color: var(--accent); }
.today .dot { width: 30px; height: 30px; flex: none; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-family: var(--f-ko); font-weight: 700; font-size: .85rem; }
.today span { display: flex; flex-direction: column; min-width: 0; }
.today small { color: var(--muted); }
.lvrow { display: grid; grid-template-columns: 40px minmax(0, 1fr) 54px 74px; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line-2); }
.lvrow:last-child { border-bottom: 0; }
.lvrow .t { font-size: .85rem; color: var(--ink-2); }
.lvrow .pct { text-align: right; font-variant-numeric: tabular-nums; font-size: .85rem; }
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 12px); gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 12px; height: 12px; border-radius: 3px; background: var(--line-2); }
.heat i.h1 { background: color-mix(in srgb, var(--accent) 30%, var(--line-2)); }
.heat i.h2 { background: color-mix(in srgb, var(--accent) 55%, var(--line-2)); }
.heat i.h3 { background: color-mix(in srgb, var(--accent) 80%, var(--line-2)); }
.heat i.h4 { background: var(--accent); }
.legend { display: flex; gap: 4px; align-items: center; font-size: .75rem; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* ---------- Mindmap ---------- */
.mm-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 14px; align-items: start; }
@media (max-width: 980px) { .mm-wrap { grid-template-columns: 1fr; } }
.mm { position: relative; height: 560px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden;
  background-image: radial-gradient(var(--line-2) 1px, transparent 1px); background-size: 22px 22px; }
.mm svg { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.mm svg:active { cursor: grabbing; }
.mm-tools { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; }
.mm-hint { position: absolute; left: 12px; bottom: 10px; font-size: .75rem; color: var(--muted); background: var(--surface); padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line-2); }
.mm-links path { fill: none; stroke-width: 1.5px; stroke-opacity: .55; }
.mm-node circle { stroke-width: 2px; }
.mm-node text { font-family: var(--f-body); font-size: 12.5px; fill: var(--ink); paint-order: stroke; stroke: var(--surface); stroke-width: 4px; stroke-linejoin: round; }
.mm-node.k-root text { font-family: var(--f-display); font-size: 16px; font-weight: 700; }
.mm-node.k-level text { font-weight: 700; font-size: 14px; }
.mm-node.k-cat text { font-weight: 600; fill: var(--ink-2); }
.mm-node.sel text { fill: var(--accent); }
.mm-node.is-done text { fill: var(--good); }
.mm-node { cursor: pointer; }
.mm-detail { position: sticky; top: 76px; }
.outline details { border-left: 2px solid var(--line); padding-left: 12px; margin: 4px 0; }
.outline summary { cursor: pointer; padding: 3px 0; }
.outline a { display: block; padding: 2px 0; font-size: .9rem; }

/* ---------- Lessons ---------- */
.toc { display: flex; flex-wrap: wrap; gap: 6px; }
.toc a { font-size: .82rem; text-decoration: none; border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; color: var(--ink-2); background: var(--surface); }
.toc a.done { color: var(--good); border-color: color-mix(in srgb, var(--good) 40%, var(--line)); }
.lesson { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); scroll-margin-top: 80px; }
.lesson-head { display: flex; gap: 12px; align-items: center; padding: 14px 18px; cursor: pointer; width: 100%; text-align: left; background: none; border: 0; }
.lesson-head h3 { flex: 1; min-width: 0; }
.lesson-head h3 small { display: block; font-family: var(--f-ko-serif); font-weight: 700; color: var(--muted); font-size: .85rem; margin-top: 2px; }
.lesson-head .chev { transition: transform .2s; color: var(--muted); flex: none; }
.lesson.open .lesson-head .chev { transform: rotate(90deg); }
.lesson-body { padding: 0 18px 18px; border-top: 1px solid var(--line-2); }
.lesson-body > :first-child { margin-top: 14px; }
.check { width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--line); display: grid; place-items: center; flex: none; color: transparent; }
.check.on { background: var(--good); border-color: var(--good); color: #fff; }
.lesson-foot { display: flex; justify-content: flex-end; margin-top: 14px; }

/* ---------- Grammar ---------- */
.gcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 10px; }
.gcard { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; text-decoration: none; color: var(--ink); min-width: 0; }
.gcard:hover { border-color: var(--accent); }
.gcard .f { font-family: var(--f-ko); font-size: .9rem; color: var(--ink-2); overflow-wrap: anywhere; }
.gcard .t { font-weight: 600; }
.gcard.known { border-color: color-mix(in srgb, var(--good) 45%, var(--line)); }
.formula { font-family: var(--f-ko); font-size: 1.05rem; background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--line)); border-radius: 8px; padding: 10px 14px; color: var(--ink); overflow-wrap: anywhere; }
.err-list li { margin: .35rem 0; }
.cmp { border-left: 3px solid var(--gold); padding: 6px 12px; background: var(--gold-soft); border-radius: 0 8px 8px 0; margin: .5rem 0; }

/* ---------- Widgets ---------- */
.jamo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin: .6rem 0; }
.jamo { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px; cursor: pointer; text-align: center; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.jamo:hover { border-color: var(--accent); }
.jamo .g { font-family: var(--f-ko-serif); font-size: 1.9rem; font-weight: 800; line-height: 1.1; }
.jamo small { font-size: .72rem; color: var(--muted); line-height: 1.25; }
.jamo-info { font-size: .88rem; padding: 8px 12px; background: var(--surface-2); border-radius: 8px; min-height: 2.4em; }
.syl { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; align-items: center; margin: .6rem 0; }
@media (max-width: 560px) { .syl { grid-template-columns: 1fr; } }
.syl-block { width: 150px; height: 150px; border: 2px solid var(--ink); border-radius: 6px; position: relative; display: grid; place-items: center; background: var(--surface);
  background-image: linear-gradient(var(--line-2) 1px, transparent 1px), linear-gradient(90deg, var(--line-2) 1px, transparent 1px); background-size: 50% 50%; cursor: pointer; }
.syl-block span { font-family: var(--f-ko-serif); font-size: 92px; font-weight: 800; line-height: 1; }
.engine-out { margin-top: 10px; }
.engine-out .pron { font-family: var(--f-ko); font-size: 1.6rem; font-weight: 700; color: var(--accent); }
.steps { margin: .4rem 0; padding-left: 1.1rem; font-size: .9rem; }
.roots { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; margin-top: 10px; }
.root { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.root .h { font-family: var(--f-ko-serif); font-size: 1.8rem; font-weight: 800; line-height: 1; }
.root .meta { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.root ul { list-style: none; padding: 0; margin: 6px 0 0; font-size: .86rem; }
.root li { display: flex; gap: 6px; flex-wrap: wrap; }
.root li .hj { color: var(--muted); }
.picker-out { margin-top: 12px; }

/* ---------- Flashcards ---------- */
.fc-stage { display: grid; place-items: center; padding: 10px 0; }
.fc { width: min(560px, 100%); min-height: 280px; border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); padding: 28px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; position: relative; }
.fc .front { font-family: var(--f-ko); font-size: clamp(2rem, 6vw, 3rem); font-weight: 700; line-height: 1.2; overflow-wrap: anywhere; }
.fc .front.vi { font-family: var(--f-body); font-size: clamp(1.4rem, 4vw, 2rem); }
.fc .back { display: flex; flex-direction: column; gap: 6px; align-items: center; border-top: 1px dashed var(--line); padding-top: 12px; width: 100%; }
.fc .back .m { font-size: 1.15rem; font-weight: 600; }
.fc .back .hj { font-family: var(--f-ko-serif); font-size: 1.3rem; }
.fc .corner { position: absolute; top: 12px; left: 14px; display: flex; gap: 6px; }
.fc .corner-r { position: absolute; top: 10px; right: 10px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; width: min(560px, 100%); margin-top: 12px; }
.rate .btn { justify-content: center; flex-direction: column; gap: 0; padding: 8px 4px; }
.rate .btn small { font-size: .7rem; color: var(--muted); }
.rate .again { border-color: color-mix(in srgb, var(--red) 50%, var(--line)); }
.rate .easy { border-color: color-mix(in srgb, var(--good) 50%, var(--line)); }

/* ---------- Quiz ---------- */
.qopts { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; }
.qopt { display: flex; gap: 10px; align-items: flex-start; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 10px 12px; cursor: pointer; }
.qopt:hover:not([disabled]) { border-color: var(--accent); }
.qopt .n { flex: none; width: 22px; height: 22px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; font-size: .75rem; font-weight: 700; color: var(--muted); }
.qopt span:last-child { font-family: var(--f-ko); }
.qopt.right { border-color: var(--good); background: var(--good-soft); }
.qopt.wrong { border-color: var(--bad); background: var(--red-soft); }
.qopt[disabled] { cursor: default; }
.qq { font-family: var(--f-ko); font-size: 1.1rem; font-weight: 500; }
.qexp { padding: 10px 12px; border-radius: 8px; background: var(--surface-2); font-size: .9rem; }
.score-ring { font-family: var(--f-display); font-size: 3rem; font-weight: 700; color: var(--accent); }

/* ---------- Writing ---------- */
.paper { font-family: var(--f-ko); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; line-height: 1.9; margin: .5rem 0; }
.wgo { --cell: 30px; width: 100%; min-height: 300px; resize: vertical; border: 1px solid var(--line); border-radius: 8px; padding: 0 8px; font-family: var(--f-ko); font-size: 17px;
  line-height: var(--cell); background-color: var(--surface); color: var(--ink);
  background-image: linear-gradient(color-mix(in srgb, var(--red) 22%, transparent) 1px, transparent 1px), linear-gradient(90deg, color-mix(in srgb, var(--red) 12%, transparent) 1px, transparent 1px);
  background-size: var(--cell) var(--cell); background-attachment: local; letter-spacing: 12.5px; }
.wgo.plain { letter-spacing: normal; background-image: linear-gradient(color-mix(in srgb, var(--red) 18%, transparent) 1px, transparent 1px); background-size: 100% var(--cell); }
.wgo:focus { outline: none; border-color: var(--accent); }
.counter { display: flex; gap: 12px; align-items: center; font-size: .85rem; flex-wrap: wrap; }
.counter b { font-variant-numeric: tabular-nums; font-size: 1.05rem; }
.counter .state { padding: 2px 8px; border-radius: 999px; font-size: .75rem; }
.state.ok { background: var(--good-soft); color: var(--good); }
.state.low, .state.high { background: var(--red-soft); color: var(--red); }
.model { white-space: pre-wrap; font-family: var(--f-ko); line-height: 1.85; }
.score-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.score-grid .card { padding: 12px; }
.chart53 { width: 100%; max-width: 520px; height: auto; display: block; }
.chart53 text { fill: var(--ink-2); font-family: var(--f-ko); font-size: 12px; }
.chart53 .bar-r { fill: var(--accent); }
.chart53 .axis { stroke: var(--line); }

/* ---------- Talk ---------- */
.chat { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); }
.msg.ai { align-self: flex-start; border-top-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); border-top-right-radius: 4px; }
.msg .ko-line { font-family: var(--f-ko); white-space: pre-wrap; }
.msg .fb { margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: .86rem; color: var(--ink-2); white-space: pre-wrap; }
.msg .fb b { color: var(--gold); font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; display: block; }
.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 44px; max-height: 160px; resize: vertical; }
.scen { display: flex; flex-direction: column; gap: 4px; text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.scen:hover { border-color: var(--accent); }
.scen.on { border-color: var(--accent); background: var(--accent-soft); }
.scen small { color: var(--muted); }

/* ---------- Library ---------- */
.lib { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.lib .card { display: flex; flex-direction: column; gap: 6px; padding: 14px; }
.lib .card h3 a { text-decoration: none; }
.lib .card h3 a:hover { text-decoration: underline; }
.lib .meta { display: flex; gap: 6px; flex-wrap: wrap; }

/* Plan */
.phase { display: flex; flex-direction: column; gap: 12px; }
.phase-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.split { display: flex; height: 26px; border-radius: 6px; overflow: hidden; font-size: .72rem; }
.split span { display: grid; place-items: center; color: #fff; white-space: nowrap; overflow: hidden; padding: 0 4px; }
.split span:nth-child(1) { background: var(--l-B1); } .split span:nth-child(2) { background: var(--l-B2); } .split span:nth-child(3) { background: var(--l-C1); }
.split span:nth-child(4) { background: var(--red); } .split span:nth-child(5) { background: var(--gold); }
.cl { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.cl li label { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; font-size: .9rem; }
.cl input { margin-top: 4px; accent-color: var(--accent); }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 8px 16px; border-radius: 999px; font-size: .88rem; z-index: 60; box-shadow: var(--shadow); max-width: calc(100% - 32px); }
.empty-state { text-align: center; padding: 28px; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 500; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
.lvgrid { display: grid; gap: 12px; grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1180px) { .lvgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .lvgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
