/* 词海灯塔 — new frontend. Tokens first, then shared components; each screen keeps its own section. */
:root {
  --font: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
  --radius: 16px; --radius-sm: 12px; --gutter: 16px;
  --tabbar-h: 62px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
html[data-theme="sunny"] {
  color-scheme: light;
  --bg: #f7f0e3; --bg-2: #fbf4e7; --surface: #fffaf2; --surface-2: #fff; --line: #eadfca; --line-2: #e2d3b8;
  --ink: #2c3b57; --ink-2: #46597a; --muted: #7f8ba3; --accent: #e3953a; --accent-ink: #fff; --accent-soft: #fdebd3;
  --sky: #2f86cc; --good: #3f9f62; --hard: #d98b1e; --again: #d65b5b; --mark: #b0651c;
  --shadow: 0 10px 24px rgba(146,112,70,.12), 0 2px 4px rgba(146,112,70,.08);
  --study-bg: radial-gradient(120% 70% at 50% -10%, #fff6e4 0%, #f7ecd8 50%, #efe0c6 100%);
  --veil: rgba(44,59,87,.1); --glass: rgba(255,255,255,.72);
}
html[data-theme="harbor"], html:not([data-theme]) {
  color-scheme: dark;
  --bg: #071827; --bg-2: #0b2236; --surface: #0f2a40; --surface-2: #12324c; --line: rgba(255,255,255,.1); --line-2: rgba(255,255,255,.16);
  --ink: #eef4f8; --ink-2: #c8d6e1; --muted: #93a9bb; --accent: #f0b660; --accent-ink: #1a1206; --accent-soft: rgba(240,182,96,.16);
  --sky: #8fd0ff; --good: #5cc98a; --hard: #f0b660; --again: #ef7d7d; --mark: #ffd27a;
  --shadow: 0 12px 30px rgba(0,0,0,.28);
  --study-bg: radial-gradient(120% 70% at 50% -10%, #1d4b6e 0%, #0d2a42 45%, #071827 100%);
  --veil: rgba(255,255,255,.12); --glass: rgba(255,255,255,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; overflow-x: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
mark { background: none; color: var(--mark); font-weight: 800; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.i { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* Headwords keep their spelling intact; the fitter adapts type to the actual space.
   Extremely long terms remain readable by horizontal scrolling at the minimum size. */
.study-term:has([data-fit-term]), .ln-term:has([data-fit-term]) { min-width:0; max-width:100%; overflow-x:auto; overflow-y:hidden; scrollbar-width:none; }
.study-term [data-fit-term], .ln-term [data-fit-term] { display:block; flex:none; min-width:0; white-space:nowrap; word-break:normal; overflow-wrap:normal; }
.study-term>[data-fit-term]~*, .ln-term>[data-fit-term]~* { flex-shrink:0; }
.study-term [data-fit-term][data-phrase="true"], .ln-term [data-fit-term][data-phrase="true"] { flex:0 1 auto; max-width:100%; white-space:normal; }

/* ---- shell ---------------------------------------------------------------------------------- */
#view { min-height: 100dvh; }
body.with-tabbar #view { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 4px 8px max(6px, env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 90%, transparent);
  border-top: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); }
.tabbar.on-scene { background: linear-gradient(180deg, transparent, rgba(0,0,0,.35)); border-top-color: transparent; color: #fff; }
.tabbar a { display: grid; justify-items: center; align-content: center; gap: 2px; height: 52px; color: inherit; text-decoration: none; font-size: 11px; opacity: .6; }
.tabbar a[aria-current="page"] { opacity: 1; color: var(--accent); }
.tabbar a:focus:not(:focus-visible) { outline: none; }
.tabbar a:focus-visible { outline: 2px solid var(--accent); outline-offset: -4px; border-radius: 12px; }
.tabbar.on-scene a[aria-current="page"] { color: #fff; }
.tabbar svg.i { width: 23px; height: 23px; }
@media (min-width: 900px) { .tabbar { left: 50%; right: auto; width: 520px; transform: translateX(-50%); bottom: 14px; border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding-bottom: 4px; } }

/* ---- page chrome (tab pages) ---------------------------------------------------------------- */
.page { width: 100%; max-width: 760px; margin: 0 auto; padding: max(14px, env(safe-area-inset-top)) var(--gutter) 24px; }
.page-head { display: flex; align-items: center; gap: 10px; margin: 6px 0 16px; }
.page-head h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: .3px; margin-right: auto; }
.page-sub { margin: -10px 0 16px; color: var(--muted); font-size: 13px; }

/* full-screen pages (pushed over the tabs) */
.screen { min-height: 100dvh; display: flex; flex-direction: column; background: var(--bg); }
.screen-top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px; padding: max(8px, env(safe-area-inset-top)) 10px 6px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.screen-top h2 { margin: 0 auto 0 4px; font-size: 17px; }

/* ---- components ------------------------------------------------------------------------------ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 44px; padding: 0 18px; border-radius: 999px; white-space: nowrap;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font-weight: 650; transition: transform .12s var(--ease), background .15s; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { height: 34px; padding: 0 12px; font-size: 13px; }
.icon-btn { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 0; border-radius: 12px; background: none; color: inherit; }
.icon-btn:hover { background: var(--glass); }
.icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 10px 16px; background: none; border: 0; width: 100%; text-align: left; color: inherit; text-decoration: none; }
.row .row-main { flex: 1; min-width: 0; }
.row .row-sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.row .row-end { color: var(--muted); font-size: 13px; }
.section-title { margin: 22px 4px 8px; font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .5px; }
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .field textarea { height: 48px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-2); background: var(--surface-2); outline: none; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.notice { min-height: 20px; margin: 4px 0 10px; font-size: 13px; color: var(--again); }
.notice.ok { color: var(--good); }
.empty { display: grid; justify-items: center; gap: 8px; padding: 48px 16px; color: var(--muted); text-align: center; }
.empty img { width: 84px; height: 84px; object-fit: contain; opacity: .9; }
.segmented { display: inline-flex; padding: 3px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line); }
.segmented button { height: 32px; padding: 0 14px; border: 0; border-radius: 999px; background: none; font-size: 13px; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* dialogs (also used by assets/avatar.js: .detail, .detail-top, .ghost-btn, .primary-btn) */
dialog { border: 0; padding: 0; border-radius: 20px; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 40px); box-shadow: 0 24px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(5,12,20,.5); backdrop-filter: blur(2px); }
dialog .detail { padding: 18px; }
dialog .detail-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
dialog .detail-top h3 { margin: 0; font-size: 18px; }
.ghost-btn, .primary-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); font-weight: 600; }
.primary-btn { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.icon-btn.ui-close, dialog .icon-btn { color: var(--ink); }

/* bottom sheet */
.sheet { position: fixed; inset: 0; z-index: 80; display: grid; align-items: end; background: rgba(5,12,20,.45); animation: fade .2s ease; }
.sheet-panel { width: 100%; max-width: 560px; margin: 0 auto; max-height: 86dvh; overflow: auto; padding: 10px 18px max(18px, env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0; background: var(--surface); animation: rise .28s var(--ease); }
.sheet-panel::before { content: ""; display: block; width: 38px; height: 4px; margin: 0 auto 12px; border-radius: 4px; background: var(--line-2); }
.sheet-panel h3 { margin: 4px 0 14px; font-size: 18px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom)); z-index: 200; transform: translate(-50%, 8px); opacity: 0;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 999px; background: rgba(20,28,40,.88); color: #fff; font-size: 14px; pointer-events: none;
  transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
body:not(.with-tabbar) .toast { bottom: calc(90px + env(safe-area-inset-bottom)); }

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: .4; } }
@keyframes pop { from { transform: scale(.4); } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }

/* Choice chips (学习计划 sheet) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-btn { height: 36px; padding: 0 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-size: 14px; }
.chip-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); font-weight: 650; }
