:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-2: #f3f0ea;
  --text: #1f1d1a;
  --muted: #6f6a62;
  --border: #e4dfd6;
  --accent: #e2a03f;
  --accent-ink: #8a5a12;
  --primary: #1f1d1a;
  --primary-ink: #ffffff;
  --link-bg: #fbe8c8;
  --hover-bg: #f1ece2;
  --nom: #2f6fd6;
  --acc: #d2552f;
  --dat: #22915a;
  --gen: #8b4fc9;
  --shadow: 0 10px 30px rgba(40, 30, 10, .12), 0 2px 6px rgba(40, 30, 10, .08);
  --new-bg: rgba(47, 111, 214, .11);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #2a2824;
    --text: #ece8e1;
    --muted: #a09a90;
    --border: #3a3631;
    --accent: #f0b45a;
    --accent-ink: #f0b45a;
    --primary: #ece8e1;
    --primary-ink: #171614;
    --link-bg: #4a3a1e;
    --hover-bg: #2e2b26;
    --nom: #6fa2ff;
    --acc: #ff8a64;
    --dat: #4fcf8c;
    --gen: #c08cff;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    --new-bg: rgba(111, 162, 255, .17);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 700; font-size: 20px; letter-spacing: -.02em; }
.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.btn { border: 1px solid var(--border); background: var(--surface); padding: 8px 14px; border-radius: 999px; font-weight: 500; }
.btn:hover { background: var(--hover-bg); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { opacity: .9; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.count { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--surface-2); font-size: 12px; text-align: center; }
.icon-btn { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; font-size: 16px; }
.icon-btn:hover { background: var(--hover-bg); }

.toggle { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; padding: 4px 8px; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 34px; height: 20px; border-radius: 10px; background: var(--border); position: relative; transition: background .2s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(14px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.toggle-label { font-weight: 500; }

/* Input view */
.input-view { max-width: 760px; width: 100%; margin: 0 auto; padding: 48px 16px 32px; flex: 1; }
.input-view h1 { font-family: Literata, Georgia, serif; font-weight: 500; font-size: clamp(28px, 5vw, 40px); line-height: 1.2; letter-spacing: -.01em; margin: 0 0 28px; }
.muted { color: var(--muted); }
textarea {
  width: 100%; min-height: 260px; resize: vertical;
  padding: 18px 20px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-family: Literata, Georgia, serif; font-size: 18px; line-height: 1.6;
}
textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; }
.hint { color: var(--muted); min-height: 1.4em; }
.hint.small { font-size: 13px; min-height: 0; margin: -8px 0 16px; }
.lang-picker { display: flex; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 24px; }
.lang-picker label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--muted); }
.lang-picker select {
  font: inherit; font-weight: 600; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 7px 32px 7px 14px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%; background-size: 5px 5px; background-repeat: no-repeat;
}
.lang-picker select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.lang-pill { font-size: 13px; font-weight: 600; color: var(--muted); padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; white-space: nowrap; }

/* Reader */
.reader-view { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 32px 16px 80px; transition: margin .25s; }
body.panel-open .reader-view { margin-right: max(16px, calc(50vw - 380px + 220px)); }
.reader { font-family: Literata, Georgia, serif; font-size: 21px; line-height: 1.85; }
.reader p { margin: 0 0 1.1em; }
.reader p.title { font-size: 1.45em; font-weight: 500; line-height: 1.3; margin-bottom: .8em; }
.w { border-radius: 4px; cursor: pointer; transition: background .12s; padding: 1px 0; }
.w:hover, .w.active { background: var(--hover-bg); }
.w.linked { background: var(--link-bg); }
.w.saved { text-decoration: underline dotted var(--accent); text-underline-offset: 6px; }

.focus-on .w[data-c] { border-bottom: 3px solid transparent; border-radius: 4px 4px 0 0; }
.focus-on .w[data-c="1"] { border-bottom-color: var(--nom); background: color-mix(in srgb, var(--nom) 9%, transparent); }
.focus-on .w[data-c="2"] { border-bottom-color: var(--acc); background: color-mix(in srgb, var(--acc) 9%, transparent); }
.focus-on .w[data-c="3"] { border-bottom-color: var(--dat); background: color-mix(in srgb, var(--dat) 9%, transparent); }
.focus-on .w[data-c="4"] { border-bottom-color: var(--gen); background: color-mix(in srgb, var(--gen) 9%, transparent); }
.focus-on .w[data-c="5"] { border-bottom-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 24px; font-size: 13px; font-weight: 500; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span::before { content: ""; width: 14px; height: 4px; border-radius: 2px; background: currentColor; }
.lg-1 { color: var(--nom); } .lg-2 { color: var(--acc); } .lg-3 { color: var(--dat); } .lg-4 { color: var(--gen); } .lg-5 { color: var(--accent-ink); }
.focus-box { margin-bottom: 18px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.focus-box .legend { margin-bottom: 6px; }
.focus-rule { margin: 0; font-size: 14px; line-height: 1.5; }
.focus-pick { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 999px; padding: 2px 4px 2px 10px; background: var(--surface); }
.focus-pick select { font: inherit; font-weight: 500; color: var(--text); background: transparent; border: 0; padding: 5px 4px; cursor: pointer; max-width: 210px; }
.focus-pick select:focus-visible { outline: 2px solid var(--accent); border-radius: 6px; }
.focus-icon { color: var(--accent-ink); }

/* Popover */
.pop {
  position: absolute; z-index: 30; width: min(360px, calc(100vw - 24px));
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px 12px; font-size: 14px; line-height: 1.45;
}
.pop-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pop-word { font-family: Literata, Georgia, serif; font-size: 20px; font-weight: 500; }
.pop-lemma { color: var(--muted); }
.pop-pos { margin-left: auto; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pop-gloss { font-weight: 600; margin-top: 4px; }
.pop-gloss .more { font-weight: 400; color: var(--muted); }
.ai-tag { display: inline-block; vertical-align: 2px; margin-left: 4px; padding: 0 6px; border-radius: 999px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .04em; color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 16%, transparent); cursor: help; }
.pop-desc { color: var(--muted); font-style: italic; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 10px; }
.chip { padding: 2px 9px; border-radius: 999px; background: var(--surface-2); font-size: 12.5px; font-weight: 500; }
.chip.k-Nom, .chip.k-Masc { background: color-mix(in srgb, var(--nom) 16%, transparent); color: var(--nom); }
.chip.k-Acc, .chip.k-Fem { background: color-mix(in srgb, var(--acc) 16%, transparent); color: var(--acc); }
.chip.k-Dat { background: color-mix(in srgb, var(--dat) 16%, transparent); color: var(--dat); }
.chip.k-Gen { background: color-mix(in srgb, var(--gen) 16%, transparent); color: var(--gen); }
.why { list-style: none; padding: 0; margin: 10px 0 0; }
.why li { position: relative; padding-left: 18px; margin-top: 4px; }
.why li::before { content: "→"; position: absolute; left: 0; color: var(--accent-ink); font-weight: 700; }
.compound { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); }
.compound .parts { font-family: Literata, Georgia, serif; font-size: 16px; }
.compound .parts b { font-weight: 500; }
.compound .plus { color: var(--muted); margin: 0 4px; }
.compound small { display: block; color: var(--muted); }
.pop-trans { margin-top: 10px; padding: 8px 10px; border-radius: 8px; background: var(--surface-2); font-size: 14px; line-height: 1.45; font-style: italic; }
.pop-trans .err { font-style: normal; }
.speak-btn { border: 0; background: transparent; cursor: pointer; font-size: 15px; padding: 2px 4px; border-radius: 6px; line-height: 1; opacity: .7; }
.speak-btn:hover, .speak-btn.playing { opacity: 1; background: var(--hover-bg); }
.btn.playing { border-color: var(--accent); }
.pop-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }

/* Side panel */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(440px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow);
  transform: translateX(105%); transition: transform .25s ease; display: flex; flex-direction: column;
}
.panel.open { transform: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.panel-head h2 { margin: 0; font-size: 17px; }
.panel-body { padding: 16px 20px 40px; overflow-y: auto; line-height: 1.5; }
.panel-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 8px; }
.panel-body h3:first-child { margin-top: 4px; }
.panel-body .sentence { font-family: Literata, Georgia, serif; font-size: 17px; padding: 10px 14px; background: var(--surface-2); border-radius: 8px; }
.panel-body .sentence mark { background: var(--link-bg); color: inherit; border-radius: 3px; padding: 0 2px; }
.panel-body .translation { color: var(--muted); margin-top: 8px; font-style: italic; }
.panel-body .tip { padding: 10px 14px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 14%, transparent); }
.panel-body .err { color: var(--acc); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 14px; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 500; }
.tables { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
table.forms { border-collapse: collapse; width: 100%; font-size: 14px; }
table.forms caption { text-align: left; font-weight: 600; padding-bottom: 4px; }
table.forms th { text-align: left; color: var(--muted); font-weight: 400; padding: 3px 10px 3px 0; white-space: nowrap; }
table.forms td { padding: 3px 0; font-weight: 500; }
table.forms tr.hit td, table.forms td.hit { color: var(--accent-ink); }
table.forms tr.hit { background: color-mix(in srgb, var(--accent) 12%, transparent); }
table.forms.wide th, table.forms.wide td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
table.forms td.form-cell { font-weight: 500; }
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--hover-bg), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin: 10px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }
.saved-item { padding: 10px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; justify-content: space-between; }
.saved-item .s-word { font-family: Literata, Georgia, serif; font-size: 17px; }
.saved-item .s-gloss { color: var(--muted); font-size: 13.5px; }
.saved-item .s-ctx { font-size: 13px; color: var(--muted); font-style: italic; margin-top: 2px; }

/* Auth modal */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(20, 16, 10, .45); }
.modal-card { position: relative; width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); padding: 28px 24px 20px; }
.modal-card h2 { margin: 0 0 6px; font-family: Literata, Georgia, serif; font-weight: 500; font-size: 24px; }
.modal-card .muted { margin: 0 0 18px; line-height: 1.45; }
.modal-close { position: absolute; top: 12px; right: 12px; }
.tabs { display: flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 10px; margin-bottom: 16px; }
.tab { flex: 1; border: 0; background: transparent; padding: 8px; border-radius: 8px; font-weight: 500; color: var(--muted); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
#authForm label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 12px; }
#authForm input { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; font-size: 15px; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
#authForm input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn.wide { width: 100%; padding: 11px; }
.err { color: var(--acc); min-height: 1.2em; margin: 4px 0 10px; font-size: 14px; }
.fine { font-size: 12.5px; color: var(--muted); text-align: center; margin: 12px 0 0; }
.avatar { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--accent); color: #1f1d1a; font-size: 12px; font-weight: 700; margin-right: 6px; vertical-align: -5px; }
.meter { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.meter > span { display: block; height: 100%; background: var(--accent); }
.account-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.danger { color: var(--acc); border-color: color-mix(in srgb, var(--acc) 40%, var(--border)); }
.inline-form { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 160px; padding: 8px 10px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }
.cta { padding: 14px; border-radius: 10px; background: var(--surface-2); margin-top: 12px; }

/* Known / new words */
.reader.show-new .w.new { background: var(--new-bg); }
.reader .w:hover, .reader .w.active { background: var(--hover-bg); }
.reader .w.linked { background: var(--link-bg); }
.known-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; font-size: 13.5px; color: var(--muted);
  padding: 10px 14px; margin-bottom: 18px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.kstats { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kstats b { color: var(--text); font-size: 15px; }
.kmeter { width: 90px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: inline-block; }
.kmeter > span { display: block; height: 100%; background: var(--dat); }
.small-toggle { margin-left: auto; padding: 0; font-size: 13px; }
.small-toggle .toggle-label { display: inline-flex !important; align-items: center; gap: 6px; font-weight: 500; }
.swatch-new { display: inline-block; width: 14px; height: 14px; border-radius: 4px; background: var(--new-bg); border: 1px solid var(--border); }
.khint { flex-basis: 100%; margin: 2px 0 0; display: flex; align-items: flex-start; gap: 6px; color: var(--text); line-height: 1.45; }
.khint .icon-btn { width: 24px; height: 24px; font-size: 12px; flex: none; }
.mark-rest { text-align: center; margin: 8px 0 0; }
.mark-rest p { color: var(--muted); }
.mark-rest a { color: var(--accent-ink); font-weight: 600; }

/* Imported articles */
.link-tip { color: var(--muted); font-size: 13.5px; margin: 4px 0 0; }
.link-tip::before { content: "🔗 "; }
.article-meta { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.article-meta .site { font-weight: 600; color: var(--text); }
.article-meta a { color: var(--accent-ink); text-decoration: none; font-weight: 500; }
.article-meta a:hover { text-decoration: underline; }
.notice { font-size: 14px; line-height: 1.45; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; background: var(--surface-2); border-left: 3px solid var(--accent); }
.notice.warn { border-left-color: var(--acc); }
.reader p.h { font-weight: 500; font-size: 1.15em; margin: 1.4em 0 .5em; }
.reader figure { margin: 1.2em 0 1.4em; }
.reader figure img { display: block; width: 100%; max-height: 460px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }
.reader figure figcaption { font-family: Inter, system-ui, sans-serif; font-size: 13px; line-height: 1.4; color: var(--muted); margin-top: 6px; }

/* Library */
.library-view { flex: 1; width: 100%; max-width: 980px; margin: 0 auto; padding: 32px 16px 60px; }
.library-view h1 { font-family: Literata, Georgia, serif; font-weight: 500; font-size: clamp(26px, 4vw, 34px); margin: 0 0 6px; }
.library-view .intro { color: var(--muted); margin: 0 0 24px; max-width: 620px; line-height: 1.5; }
.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.book-card { text-align: left; display: flex; flex-direction: column; gap: 8px; padding: 16px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; color: inherit; }
.book-card:hover { border-color: var(--accent); box-shadow: var(--shadow); }
.book-card .kind { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; align-items: center; }
.book-card h2 { font-family: Literata, Georgia, serif; font-weight: 500; font-size: 19px; line-height: 1.25; margin: 0; }
.book-card .author { color: var(--muted); font-size: 13.5px; }
.book-card .meta { display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 13px; color: var(--muted); margin-top: auto; align-items: center; }
.lvl { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.lvl-A2 { background: color-mix(in srgb, var(--dat) 18%, transparent); color: var(--dat); }
.lvl-B1 { background: color-mix(in srgb, var(--nom) 18%, transparent); color: var(--nom); }
.lvl-B2 { background: color-mix(in srgb, var(--gen) 18%, transparent); color: var(--gen); }
.lvl-C1 { background: color-mix(in srgb, var(--acc) 18%, transparent); color: var(--acc); }
.book-card .cta { font-weight: 600; color: var(--accent-ink); font-size: 14px; }
.back-link { display: inline-block; margin-bottom: 14px; color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.part-list { list-style: none; padding: 0; margin: 18px 0 0; border-top: 1px solid var(--border); }
.part-list li { border-bottom: 1px solid var(--border); }
.part-list button { width: 100%; display: flex; gap: 12px; align-items: center; text-align: left; padding: 12px 6px; border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; }
.part-list button:hover { background: var(--hover-bg); }
.part-list .num { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 2.2em; }
.part-list .ptitle { flex: 1; font-family: Literata, Georgia, serif; font-size: 16.5px; }
.part-list .pmeta { display: flex; gap: 10px; align-items: center; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.part-list .done .ptitle::after { content: " ✓"; color: var(--dat); }
.part-nav { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--border); }
.part-nav .muted { font-size: 13.5px; }
.legal-note { font-size: 12.5px; color: var(--muted); margin-top: 26px; line-height: 1.5; }

.my-books { margin: 0 0 30px; padding: 16px; border: 1px dashed var(--border); border-radius: 14px; }
.my-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.my-head h2 { margin: 0; font-family: Literata, Georgia, serif; font-weight: 500; font-size: 20px; }
.my-books .hint.small { margin: 6px 0 12px; }
.upload-btn { cursor: pointer; }
.book-card.is-busy, .book-card.is-error { cursor: default; }
.book-card.is-busy { opacity: .75; }
.spinner { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--accent); border-right-color: transparent; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.del-book { margin-left: 10px; }

/* Flashcards */
.count.due { background: var(--accent); color: #1f1d1a; font-weight: 700; }
.review-view { flex: 1; width: 100%; max-width: 640px; margin: 0 auto; padding: 28px 16px 60px; }
.review-top { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.review-top .streak { margin-left: auto; font-weight: 600; }
.flashcard { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 28px 24px 20px; }
.card-prompt { margin: 0 0 14px; color: var(--muted); font-size: 14px; }
.card-sentence { font-family: Literata, Georgia, serif; font-size: 23px; line-height: 1.6; min-height: 2em; }
.card-sentence mark { background: var(--link-bg); color: inherit; border-radius: 4px; padding: 0 3px; font-weight: 500; }
.card-back { margin-top: 22px; padding-top: 18px; border-top: 1px dashed var(--border); animation: reveal .2s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.card-headword { display: flex; align-items: center; gap: 6px; font-family: Literata, Georgia, serif; font-size: 26px; font-weight: 500; }
.card-gloss { font-size: 18px; margin-top: 6px; line-height: 1.45; }
.review-actions { margin-top: 26px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.rate-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 12px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rate-btn b { font-weight: 600; }
.rate-btn small { color: var(--muted); font-size: 12px; }
.rate-btn:hover { background: var(--hover-bg); }
.rate-btn.again b { color: var(--acc); } .rate-btn.hard b { color: var(--gen); } .rate-btn.good b { color: var(--dat); } .rate-btn.easy b { color: var(--nom); }
.review-done { text-align: center; padding: 48px 16px; }
.done-emoji { font-size: 48px; }
.review-done h2 { font-family: Literata, Georgia, serif; font-weight: 500; font-size: 28px; margin: 12px 0 8px; }
.review-done p { max-width: 420px; margin: 0 auto 22px; line-height: 1.5; }
.saved-actions { display: flex; gap: 8px; margin-bottom: 12px; }
@media (max-width: 640px) {
  .card-sentence { font-size: 20px; }
  .flashcard { padding: 22px 16px 16px; }
}

.credits { text-align: center; font-size: 12px; color: var(--muted); padding: 20px 16px; }

@media (max-width: 1100px) {
  body.panel-open .reader-view { margin-right: auto; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .toggle-label { display: none; }
  .lang-pill { display: none; }
  .reader { font-size: 19px; }
  .panel { top: auto; height: 70vh; width: 100vw; border-left: 0; border-top: 1px solid var(--border); border-radius: 16px 16px 0 0; transform: translateY(105%); }
  .panel.open { transform: none; }
}

/* ---------- phrase selection ---------- */
.reader .w.phrase-sel { background: var(--hover-bg); box-shadow: 0 2px 0 var(--accent); border-radius: 2px; }
.pop-tip { margin: 8px 0 0; font-size: 12px; color: var(--muted); }

/* ---------- read aloud ---------- */
.reader .w.speaking { background: color-mix(in srgb, var(--accent) 16%, transparent); border-radius: 2px; }
.listen-bar { position: sticky; bottom: 16px; z-index: 5; display: flex; gap: 6px; align-items: center; width: max-content;
  margin: 12px 0 0 auto; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.listen-bar .btn { border-radius: 999px; }
.listen-bar select { border: 0; background: transparent; font: inherit; font-size: 13px; color: inherit; cursor: pointer; }

/* ---------- progress ---------- */
.goal-chip { gap: 6px; font-variant-numeric: tabular-nums; }
.goal-chip.done { color: var(--accent-ink, inherit); }
.goal-chip .flame { font-weight: 600; }
.stats-today .big { font-size: 28px; font-weight: 600; margin: 2px 0 8px; font-variant-numeric: tabular-nums; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.stat-grid div { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.stat-grid b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.stat-grid small { color: var(--muted); }
.week-bars { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 120px; align-items: end; padding-bottom: 20px; }
.week-bars .bar { position: relative; height: 100%; display: flex; align-items: flex-end; justify-content: center; }
.week-bars .bar span { display: block; width: 70%; background: color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 4px 4px 0 0; }
.week-bars .bar.met span { background: var(--accent); }
.week-bars .bar small { position: absolute; bottom: -18px; font-size: 11px; color: var(--muted); }
#goalSel { font: inherit; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: inherit; }

/* ---------- export ---------- */
.saved-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.saved-actions .export { display: inline-flex; gap: 6px; }

/* ---------- sentence structure ---------- */
.st-sentence { font-family: "Literata", Georgia, serif; font-size: 17px; line-height: 1.5; margin: 0 0 14px; }
.st-clause { border-left: 3px solid var(--border); padding: 4px 0 6px 10px; margin-bottom: 14px; }
.st-head { font-weight: 600; font-size: 13px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.st-num { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--surface-2); font-size: 12px; }
.st-fields { display: flex; flex-wrap: wrap; gap: 6px; align-items: stretch; }
.fld { display: flex; flex-direction: column; gap: 3px; padding: 4px 6px 6px; border-radius: 8px; background: var(--surface-2); }
.fld > small { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.fld.f-left, .fld.f-right { background: transparent; border: 2px solid var(--accent); }
.fld-parts { display: flex; flex-wrap: wrap; gap: 4px; }
.st-part { display: inline-flex; flex-direction: column; padding: 3px 7px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); line-height: 1.25; }
.st-part b { font-weight: 500; font-family: "Literata", Georgia, serif; font-size: 15px; }
.st-part small { font-size: 11px; color: var(--muted); }
.st-part.r-verb, .st-part.r-verbpart { border-color: var(--accent); }
.st-part.r-verb b { font-weight: 700; }
.st-part.r-clause { border-style: dashed; }
.st-part.c-Nom { box-shadow: inset 3px 0 0 var(--nom); } .st-part.c-Acc { box-shadow: inset 3px 0 0 var(--acc); }
.st-part.c-Dat { box-shadow: inset 3px 0 0 var(--dat); } .st-part.c-Gen { box-shadow: inset 3px 0 0 var(--gen); }
.st-rule { font-size: 13px; margin: 6px 0 0; color: var(--text); }

/* ---------- grammar practice ---------- */
.rev-tabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.rev-tab { border: 0; background: transparent; font: inherit; font-size: 13px; padding: 5px 12px; border-radius: 999px; cursor: pointer; color: var(--muted); }
.rev-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.g-blank { display: inline-block; border-bottom: 2px solid var(--accent); min-width: 4em; }
.g-hint { color: var(--muted); font-style: italic; }
#gSentence mark.ok { background: color-mix(in srgb, var(--dat) 18%, transparent); }
#gSentence mark.fix { background: color-mix(in srgb, var(--acc) 16%, transparent); }
.g-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 18px 0 8px; }
.g-opt { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); font: inherit; cursor: pointer; color: inherit; position: relative; }
.g-opt:hover:not(:disabled) { border-color: var(--accent); }
.g-opt b { font-family: "Literata", Georgia, serif; font-weight: 500; font-size: 17px; }
.g-opt small { font-size: 12px; color: var(--muted); min-height: 1em; }
.g-opt .g-key { position: absolute; top: 6px; right: 8px; font-size: 11px; color: var(--muted); }
.g-opt.right { border-color: var(--dat); background: color-mix(in srgb, var(--dat) 10%, var(--surface)); }
.g-opt.wrong { border-color: var(--acc); background: color-mix(in srgb, var(--acc) 10%, var(--surface)); }
.g-opt:disabled { cursor: default; }
.g-feedback { margin-top: 6px; }
.g-verdict { font-weight: 600; margin: 0 0 4px; }
.g-verdict.ok { color: var(--dat); } .g-verdict.fix { color: var(--acc); }
.g-label { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.gram-cta { margin: 28px 0 8px; padding-top: 18px; border-top: 1px solid var(--border); }
.gram-cta .fine { margin-top: 6px; }

/* ---------- grammar reference cards ---------- */
.pop-topics { margin: 8px 0 2px; font-size: 13px; display: flex; flex-wrap: wrap; gap: 4px 6px; align-items: center; }
.topic-link { border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px; padding: 2px 9px; font: inherit; font-size: 12.5px; cursor: pointer; color: inherit; }
.topic-link:hover { border-color: var(--accent); }
.topic-term { margin: -4px 0 8px; color: var(--accent-ink); font-style: italic; }
.topic-summary { font-size: 15px; }
.topic-when li { margin-bottom: 4px; }
.topic-table { border-collapse: collapse; margin: 12px 0; font-size: 14px; width: 100%; }
.topic-table caption { text-align: left; font-size: 12px; color: var(--muted); padding-bottom: 4px; }
.topic-table th, .topic-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.topic-table thead th { background: var(--surface-2); font-weight: 600; }
.topic-table tbody th { font-weight: 500; color: var(--muted); }
.topic-table td { font-family: "Literata", Georgia, serif; }
.topic-tip { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.topic-ex { padding-left: 18px; }
.topic-ex li { margin-bottom: 8px; }
.topic-ex li > span { font-family: "Literata", Georgia, serif; }
.topic-ex small { display: block; color: var(--muted); }
.topic-ex.in-text li { font-family: "Literata", Georgia, serif; }

/* ===================== calm reading design ===================== */
:root { --reader-size: 21px; --ease: cubic-bezier(.2, .7, .2, 1); }
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* top bar: quiet, and out of the way while reading */
.topbar { padding: 10px 20px; border-bottom-color: transparent; background: color-mix(in srgb, var(--bg) 94%, transparent);
  transition: transform .3s var(--ease); }
body.calm .topbar { transform: translateY(-100%); }
.top-actions { gap: 2px; flex-wrap: nowrap; }
.nav-btn { display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px; white-space: nowrap; }
.nav-btn:hover { background: var(--hover-bg); color: var(--text); }
.nav-btn .count { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.nav-btn .count.due { background: var(--accent); color: #1f1d1a; }
.nav-btn.account { color: var(--text); margin-left: 4px; }
.goal-chip { border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 8px;
  display: inline-flex; gap: 6px; align-items: center; font-variant-numeric: tabular-nums; cursor: pointer; }
.goal-chip:hover { background: var(--hover-bg); color: var(--text); }
.goal-chip.done { color: var(--dat); }

/* the reading column */
.reader-view { max-width: 720px; padding: 26px 24px 140px; }
.reader { font-size: var(--reader-size); line-height: 1.8; }
.reader p { margin-bottom: 1.15em; }

/* one slim toolbar instead of boxes */
.read-tools { display: flex; align-items: center; gap: 4px 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted);
  margin: 0 0 30px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.read-tools .lang-pill { border: 0; padding: 0; font-weight: 500; font-size: 13px; }
.known-bar { display: contents; }
.kstats { font-variant-numeric: tabular-nums; cursor: default; }
.tools-right { margin-left: auto; display: flex; align-items: center; gap: 0; }
.tool { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; color: var(--muted); font: inherit;
  font-size: 13px; padding: 6px 8px; border-radius: 8px; cursor: pointer; }
.tool:hover { background: var(--hover-bg); color: var(--text); }
.tool.on { color: var(--accent-ink); }
.tool .i { width: 16px; height: 16px; }
.tool-check { user-select: none; }
.tool-check input { position: absolute; opacity: 0; pointer-events: none; }
.tool-check:has(input:checked) { color: var(--text); }
.tool-check:has(input:checked) .i { color: color-mix(in srgb, var(--nom) 70%, var(--muted)); }
.tool-check:has(input:focus-visible) { outline: 2px solid var(--accent); }
.focus-pick { border: 0; background: transparent; padding: 2px 2px 2px 8px; gap: 4px; }
.focus-pick select { color: inherit; font-size: 13px; font-weight: 500; max-width: 190px; padding: 4px 2px; }
.focus-pick.on { color: var(--accent-ink); }
.size-tools { display: inline-flex; align-items: baseline; }
.size-tools .tool { padding: 6px 5px; font-family: Literata, Georgia, serif; font-size: 13px; line-height: 1; }
.size-tools .tool.big { font-size: 18px; }
.khint { font-size: 13px; color: var(--muted); margin: -20px 0 26px; display: flex; gap: 6px; align-items: flex-start; }
.khint .icon-btn { width: 22px; height: 22px; display: inline-grid; place-items: center; color: var(--muted); }
.khint .i { width: 14px; height: 14px; }

/* focus legend: a quiet note, not a box */
.focus-box { background: transparent; padding: 0 0 0 12px; border-left: 2px solid var(--accent); border-radius: 0; margin: -12px 0 28px; }
.focus-rule { color: var(--muted); font-size: 13.5px; }

/* new words: a faint underline instead of a block of colour */
.reader.show-new .w.new { background: none; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: .3em;
  text-decoration-color: color-mix(in srgb, var(--nom) 30%, transparent); }
.reader .w.saved { text-decoration: underline dotted; text-decoration-color: var(--accent); text-decoration-thickness: 2px; text-underline-offset: .3em; }
.reader .w:hover, .reader .w.active { background: var(--hover-bg); }
.reader .w.speaking { background: color-mix(in srgb, var(--accent) 14%, transparent); }

/* word popup: meaning first, one row of actions */
.pop { padding: 16px 16px 8px; width: min(380px, calc(100vw - 24px)); border-radius: 14px; }
.speak-btn { display: inline-grid; place-items: center; color: var(--muted); opacity: 1; padding: 3px; }
.speak-btn .i { width: 17px; height: 17px; }
.speak-btn:hover, .speak-btn.playing { color: var(--accent-ink); background: var(--hover-bg); }
.why { font-size: 13.5px; }
.pop-trans { font-style: normal; }
.pop-topics .i { width: 14px; height: 14px; vertical-align: -2px; }
.pop-actions { display: flex; gap: 0; margin: 12px -8px 0; padding-top: 6px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.act { flex: 1 1 0; min-width: 46px; display: flex; flex-direction: column; align-items: center; gap: 3px; border: 0; background: transparent;
  color: var(--muted); padding: 7px 2px 5px; border-radius: 8px; font: inherit; font-size: 10.5px; line-height: 1.15; cursor: pointer; }
.act:hover { background: var(--hover-bg); color: var(--text); }
.act .i { width: 19px; height: 19px; }
.act span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.act.on, .act.playing, .act.accent { color: var(--accent-ink); }
.act[data-act="save"].on .i, .act[data-act="save-phrase"].on .i { fill: color-mix(in srgb, var(--accent) 45%, transparent); }
.act.disabled { pointer-events: none; opacity: .65; }
.act:disabled { opacity: .5; }
#phraseActions { justify-content: flex-start; }
#phraseActions .act { flex: 0 0 64px; }
.pop-tip { margin: 4px 0 2px; font-size: 11.5px; text-align: center; }

/* phones: the popup is a bottom sheet, the sentence stays visible above it */
.pop.sheet { position: fixed; left: 0 !important; right: 0; bottom: 0; top: auto !important; width: 100%; max-height: 62vh; overflow-y: auto;
  border-radius: 16px 16px 0 0; border-width: 1px 0 0; padding: 20px 18px calc(10px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .12); animation: sheet-up .18s var(--ease); }
.pop.sheet::before { content: ""; position: absolute; top: 8px; left: 50%; width: 36px; height: 4px; margin-left: -18px; border-radius: 2px; background: var(--border); }
@keyframes sheet-up { from { transform: translateY(24px); opacity: .5; } to { transform: none; opacity: 1; } }

/* read aloud: a small player that only exists while it plays */
.mini-player { position: fixed; z-index: 25; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; align-items: center; gap: 6px;
  padding: 5px 12px 5px 5px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; box-shadow: var(--shadow);
  font-size: 13px; color: var(--muted); }
.mini-player .tool { color: var(--accent-ink); padding: 7px; border-radius: 50%; }
.mini-player select { border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; }
.mp-label { font-variant-numeric: tabular-nums; min-width: 3.6em; text-align: center; }

/* after the text: quiet invitations, not big buttons */
.mark-rest { margin-top: 40px; }
.mark-rest .btn, .gram-cta .btn { background: transparent; color: var(--muted); font-size: 13.5px; font-weight: 500; }
.mark-rest .btn:hover, .gram-cta .btn:hover { color: var(--text); background: var(--hover-bg); }
.gram-cta { text-align: center; border-top: 0; margin-top: 10px; padding-top: 0; }
.part-nav { border-top-color: var(--border); }

/* credits: on the start page and in the library, not under the text */
body:has(#readerView:not([hidden])) .credits, body:has(#reviewView:not([hidden])) .credits { display: none; }

@media (max-width: 640px) {
  .topbar { padding: 6px 6px 6px 14px; }
  .nav-btn { padding: 9px 8px; gap: 4px; }
  .nav-btn > span:not(.count):not(.avatar), .acc-label { display: none; }
  .nav-btn.account { margin-left: 0; }
  .goal-chip { padding: 6px 4px; }
  .reader-view { padding: 16px 18px 140px; }
  .read-tools { gap: 2px 10px; margin-bottom: 22px; }
  .tools-right { margin-left: -8px; width: calc(100% + 16px); justify-content: space-between; }
  .tool > span:not(.nw-sample), #showNewLabel { display: none; }
  .focus-pick select { max-width: 150px; }
  .khint { margin-top: -14px; }
}

/* focus mode: the focus is the only colouring — coloured underlines, no tints, no new-word underlines */
.reader.focus-on .w.new { text-decoration: none; }
.focus-on .w[data-c] { background: none; border-bottom-width: 2.5px; border-radius: 0; }
.focus-on .w[data-c]:hover { background: var(--hover-bg); }
.nw-sample { font-family: Literata, Georgia, serif; font-size: 14px; line-height: 1; text-decoration: underline; text-decoration-thickness: 2px;
  text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--nom) 45%, transparent); }
.tool-check:not(:has(input:checked)) .nw-sample { text-decoration-color: transparent; }
.read-tools { flex-wrap: nowrap; }
.read-tools .kstats { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.focus-pick select { max-width: 160px; }
@media (max-width: 640px) {
  .read-tools { flex-wrap: wrap; }
  .size-tools .tool { padding: 6px 4px; }
}
/* read-aloud highlight: one continuous band over the sentence, not word-by-word blocks */
.reader .w.speaking { --sp: color-mix(in srgb, var(--accent) 14%, transparent); background: var(--sp); border-radius: 0;
  box-shadow: .14em 0 0 var(--sp), -.14em 0 0 var(--sp); }

/* ===================== themes: auto (system) · light · sepia · dark ===================== */
:root[data-theme="light"] {
  --bg: #faf8f4; --surface: #ffffff; --surface-2: #f3f0ea; --text: #1f1d1a; --muted: #6f6a62; --border: #e4dfd6;
  --accent: #e2a03f; --accent-ink: #8a5a12; --primary: #1f1d1a; --primary-ink: #ffffff; --link-bg: #fbe8c8; --hover-bg: #f1ece2;
  --nom: #2f6fd6; --acc: #d2552f; --dat: #22915a; --gen: #8b4fc9; --new-bg: rgba(47, 111, 214, .11);
  --shadow: 0 10px 30px rgba(40, 30, 10, .12), 0 2px 6px rgba(40, 30, 10, .08); color-scheme: light;
}
:root[data-theme="sepia"] {
  --bg: #f3ead6; --surface: #faf4e5; --surface-2: #ebdfc4; --text: #3a2e22; --muted: #7b6a54; --border: #dfd0b0;
  --accent: #c3832c; --accent-ink: #855512; --primary: #3a2e22; --primary-ink: #faf4e5; --link-bg: #efd7a6; --hover-bg: #e9dcbd;
  --nom: #2c5ca8; --acc: #b04726; --dat: #2d7449; --gen: #77489f; --new-bg: rgba(44, 92, 168, .1);
  --shadow: 0 10px 30px rgba(70, 50, 20, .14), 0 2px 6px rgba(70, 50, 20, .08); color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #171614; --surface: #211f1c; --surface-2: #2a2824; --text: #ece8e1; --muted: #a09a90; --border: #3a3631;
  --accent: #f0b45a; --accent-ink: #f0b45a; --primary: #ece8e1; --primary-ink: #171614; --link-bg: #4a3a1e; --hover-bg: #2e2b26;
  --nom: #6fa2ff; --acc: #ff8a64; --dat: #4fcf8c; --gen: #c08cff; --new-bg: rgba(111, 162, 255, .17);
  --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}
:root[data-theme="sepia"] .reader { color: #34291e; }

/* ===================== zen mode: nothing but the text ===================== */
body.zen .topbar { transform: translateY(-100%); }
body.zen .read-tools, body.zen .focus-box, body.zen .article-meta, body.zen #glossHint { opacity: 0; pointer-events: none; transition: opacity .3s; }
body.zen.zen-peek .topbar { transform: none; }
body.zen.zen-peek .read-tools { opacity: 1; pointer-events: auto; }
body.zen .mark-rest, body.zen .gram-cta, body.zen .part-nav { opacity: .55; transition: opacity .2s; }
body.zen .mark-rest:hover, body.zen .gram-cta:hover, body.zen .part-nav:hover { opacity: 1; }
.zen-exit { position: fixed; top: 12px; right: 12px; z-index: 26; opacity: 0; pointer-events: none; transition: opacity .25s; background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow); }
body.zen.zen-peek .zen-exit { opacity: 1; pointer-events: auto; }
body.zen .reader-view { padding-top: 56px; }
#themeBtn > span, #zenBtn > span { display: none; }
#showNewTool span:not(.nw-sample) { white-space: nowrap; }
.zen-exit { top: auto; bottom: 20px; right: 20px; }

/* ===================== My words ===================== */
.words-view { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 28px 20px 80px; }
.wv-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.wv-head h1 { font-family: Literata, Georgia, serif; font-weight: 500; font-size: clamp(24px, 3.5vw, 32px); margin: 0; }
.wv-head h1 .muted { font-size: .6em; font-family: Inter, system-ui, sans-serif; font-weight: 500; }
.wv-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.wv-layout { display: grid; grid-template-columns: 220px 1fr; gap: 28px; align-items: start; }
.wv-side { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 1px; font-size: 14px; }
.wv-side h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 8px 6px; font-weight: 600; }
.wv-item { display: flex; justify-content: space-between; gap: 8px; text-align: left; border: 0; background: transparent; padding: 6px 8px;
  border-radius: 8px; color: var(--text); font: inherit; cursor: pointer; }
.wv-item span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wv-item:hover { background: var(--hover-bg); }
.wv-item.active { background: var(--surface-2); font-weight: 600; }
.wv-item .n, .seg .n { color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 400; font-size: 12.5px; }
.wv-new { display: flex; gap: 4px; margin: 4px 0 0; }
.wv-new input { flex: 1; min-width: 0; font: inherit; font-size: 13.5px; padding: 5px 8px; border: 1px dashed var(--border); border-radius: 8px; background: transparent; color: var(--text); }
.wv-new input:focus { outline: 2px solid var(--accent); border-style: solid; }
.wv-group-tools { font-size: 12.5px; color: var(--muted); padding: 6px 8px 0; }
.fine.left { text-align: left; padding: 0 8px; }
.linklike { border: 0; background: none; padding: 0; font: inherit; color: var(--accent-ink); cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.linklike.danger { color: var(--acc); }
.wv-filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
#wvSearch { flex: 1 1 220px; font: inherit; padding: 8px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
#wvSearch:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.wv-status { display: inline-flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 999px; }
.seg { border: 0; background: transparent; font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 999px; color: var(--muted); cursor: pointer; }
.seg.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }
#wvSort, #wvAddTo { font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.wv-bulk { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 10px; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); font-size: 13.5px; position: sticky; top: 60px; z-index: 5; }
.wv-list { list-style: none; margin: 0; padding: 0; }
.wrow { display: grid; grid-template-columns: 20px 1fr auto; gap: 12px; padding: 14px 4px; border-bottom: 1px solid var(--border); align-items: start; }
.wrow.selected { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.wsel { margin-top: 6px; accent-color: var(--accent); }
.wtop { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.whead { font-family: Literata, Georgia, serif; font-size: 19px; font-weight: 500; }
.wstatus { margin-left: auto; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.wstatus.st-new { color: var(--nom); background: color-mix(in srgb, var(--nom) 10%, transparent); }
.wstatus.st-learning { color: var(--accent-ink); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.wstatus.st-known { color: var(--dat); background: color-mix(in srgb, var(--dat) 12%, transparent); }
.wgloss, .wnote { border-radius: 6px; padding: 1px 4px; margin: 1px -4px; cursor: text; }
.wgloss { font-weight: 500; }
.wnote { font-size: 13.5px; color: var(--text); }
.wnote.empty { color: var(--muted); opacity: 0; transition: opacity .15s; }
.wrow:hover .wnote.empty { opacity: .8; }
.wgloss:hover, .wnote:hover { background: var(--hover-bg); }
.w-edit { width: 100%; font: inherit; padding: 3px 6px; margin: 1px -6px; border-radius: 6px; border: 1px solid var(--accent); background: var(--surface); color: var(--text); }
.wctx { font-family: Literata, Georgia, serif; font-size: 15px; color: var(--muted); margin-top: 4px; line-height: 1.5; }
.wctx mark { background: none; color: var(--text); font-weight: 600; }
.wmeta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.wtag { display: inline-block; padding: 0 7px; border-radius: 999px; border: 1px solid var(--border); }
.wdel { opacity: 0; color: var(--muted); font-size: 13px; }
.wrow:hover .wdel, .wdel:focus { opacity: 1; }
.wv-empty { color: var(--muted); padding: 30px 4px; line-height: 1.5; }
body:has(#wordsView:not([hidden])) .credits { display: none; }
@media (max-width: 760px) {
  .wv-layout { grid-template-columns: 1fr; gap: 10px; }
  .wv-side { position: static; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 6px; scrollbar-width: none; }
  .wv-side h3, .wv-group-tools, .wv-side .fine { display: none; }
  .wv-item { flex: none; border: 1px solid var(--border); border-radius: 999px; padding: 5px 12px; }
  .wv-new { flex: none; margin: 0; }
  .wv-new input { width: 130px; }
  .wdel { opacity: .6; }
  .wnote.empty { display: none; }
}

.add-note { margin-left: 8px; font-size: 12px; opacity: 0; transition: opacity .15s; }
.wrow:hover .add-note, .add-note:focus { opacity: 1; }
.goal-chip { white-space: nowrap; }
.gc-short { display: none; }
@media (max-width: 640px) {
  .gc-full { display: none; } .gc-short { display: inline; }
  .add-note { opacity: .7; margin-left: 0; display: block; margin-top: 2px; }
  .top-actions { gap: 0; }
}
@media (max-width: 640px) {
  #newBtn { display: none !important; }   /* the Lupa logo does the same: back to a new text */
  .brand span { font-size: 18px; }
}

/* hoverable sentences in flashcards and grammar exercises */
.card-sentence .w, #gSentence .w { cursor: pointer; border-radius: 3px; }
.card-sentence .w:hover, .card-sentence .w.active, #gSentence .w:hover, #gSentence .w.active { background: var(--hover-bg); }
.card-sentence mark .w:hover, #gSentence mark .w:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.w-lock { cursor: default; }

/* wordmark: Lupa + Reader in a lighter grey */
.wordmark { letter-spacing: -.02em; }
.wm-light { font-weight: 400; color: var(--muted); }
@media (max-width: 380px) { .wm-light { display: none; } }  /* the smallest phones: "Lupa" alone keeps the bar on one line */

@media (max-width: 640px) {
  #newBtn:not([hidden]) { display: inline-flex !important; }
  .topbar .wm-light { display: none; }
}

/* account e-mails */
.auth-links { margin: -4px 0 6px; font-size: 13px; text-align: right; }
.auth-links a { color: var(--muted); }
.auth-msg { font-size: 14px; line-height: 1.45; padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--dat) 12%, var(--surface)); }
.verify-bar { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--text);
  padding: 6px 12px; background: color-mix(in srgb, var(--accent) 14%, var(--bg)); }
.verify-bar .icon-btn { width: 24px; height: 24px; font-size: 12px; color: var(--muted); }
.toast { position: fixed; z-index: 70; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: min(520px, calc(100vw - 32px));
  background: var(--primary); color: var(--primary-ink); padding: 10px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; line-height: 1.45; }

.pw-form { display: grid; gap: 8px; max-width: 320px; margin: 4px 0 8px; }
.pw-form input { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.pw-form input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.pw-form .btn { justify-self: start; }

/* wordmark R3: one line under "LupaReader" — ink under Lupa (follows the theme), amber under Reader */
.wm-line { display: inline-flex; padding-bottom: .3em; }
.wm-line > span { position: relative; }
.wm-line > span::after { content: ""; position: absolute; bottom: -.28em; height: .17em; }
.wm-line > .wm-a::after { left: .03em; right: 0; background: currentColor; border-radius: .09em 0 0 .09em; }
.wm-line > .wm-light::after { left: 0; right: .04em; background: var(--accent, #e2a03f); border-radius: 0 .09em .09em 0; }
@media (max-width: 640px) { .topbar .wm-light { display: inline-block; } .brand .wordmark { font-size: 17px; } }

/* "Surprise me" */
.surprise { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--border); }
.surprise-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 10px; font-size: 14.5px; }
.surprise-head .i { color: var(--accent-ink); }
.surprise-topics { display: flex; flex-wrap: wrap; gap: 6px; }
.topic-chip { border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 13.5px; padding: 6px 13px; border-radius: 999px; cursor: pointer; }
.topic-chip:hover:not(:disabled) { border-color: var(--accent); }
.topic-chip.any { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.topic-chip:disabled { opacity: .55; cursor: default; }
.surprise-next { text-align: center; margin-top: 28px; }
.surprise-next .btn { background: transparent; }

/* saved articles */
.save-article { display: inline-flex; align-items: center; gap: 4px; margin-left: 6px; border: 1px solid var(--border); background: transparent;
  color: var(--muted); font: inherit; font-size: 12.5px; padding: 2px 9px 2px 6px; border-radius: 999px; cursor: pointer; vertical-align: 1px; }
.save-article .i { width: 14px; height: 14px; }
.save-article:hover { color: var(--text); border-color: var(--accent); }
.save-article.on { color: var(--accent-ink); border-color: color-mix(in srgb, var(--accent) 50%, var(--border)); }
.save-article.on .i { fill: color-mix(in srgb, var(--accent) 45%, transparent); }
.saved-articles { margin: 0 0 30px; }
.saved-articles h2 { font-family: Literata, Georgia, serif; font-weight: 500; font-size: 20px; margin: 0 0 10px; }
.saved-articles ul { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--border); }
.saved-articles li { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px 8px; border-bottom: 1px solid var(--border); }
.sa-open { display: grid; gap: 2px; text-align: left; border: 0; background: transparent; padding: 10px 4px; font: inherit; color: inherit; cursor: pointer; min-width: 0; }
.sa-open:hover .sa-title { text-decoration: underline; text-decoration-color: var(--accent); }
.sa-title { font-family: Literata, Georgia, serif; font-size: 16.5px; overflow: hidden; text-overflow: ellipsis; }
.sa-meta { font-size: 12.5px; color: var(--muted); }
.sa-err { grid-column: 1 / -1; margin: 0 4px 10px; font-size: 13px; color: var(--muted); }
/* phones: the account button never gives way (it holds the profile: AI use, progress, password…) */
@media (max-width: 640px) {
  .nav-btn.account { flex: none; padding: 6px 4px 6px 6px; }
  .nav-btn.account .avatar { margin-right: 0; }
  .top-actions { min-width: 0; }
  .brand { flex: none; }
}
@media (max-width: 380px) {
  .goal-chip { display: none; }   /* still in the account panel → Progress */
  .topbar .nav-btn { padding: 9px 6px; }
}
