:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #f0eee8; --text: #1d1d1b; --muted: #6b6a65;
  --line: #e2dfd6; --accent: #2f6f5e; --accent-ink: #ffffff; --accent-soft: #e3efe9;
  --learn: #f3d77a; --learn-soft: #fbf1cc; --new: #9cc3e8; --new-soft: #e2eef9;
  --again: #b54a3c; --hard: #b07a2a; --good: #2f6f5e; --easy: #3d64a8;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  --serif: "Charter", "Georgia", "Source Serif Pro", "Noto Serif SC", serif;
  --sans: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161715; --surface: #1f201e; --surface-2: #282926; --text: #e9e7e1; --muted: #9c9a93;
    --line: #34352f; --accent: #6fbfa5; --accent-ink: #10241e; --accent-soft: #23352f;
    --learn: #8a7428; --learn-soft: #3a331b; --new: #3e6489; --new-soft: #1f2d3b;
    --again: #e07a6b; --hard: #d6a456; --good: #6fbfa5; --easy: #8aa9e6;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--sans); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .6em; }
h2 { font-size: 15px; font-weight: 600; color: var(--muted); letter-spacing: .02em; }
kbd { font: 11px/1 var(--sans); border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  padding: 2px 5px; color: var(--muted); background: var(--surface); margin-left: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* header */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px;
  padding: 10px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--text); font-size: 16px; }
nav { display: flex; gap: 4px; }
nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; }
nav a:hover { text-decoration: none; background: var(--surface-2); }
nav a.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); font-weight: 600; }
.quick { margin-left: auto; }
.quick input { width: 200px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; }

main { max-width: 1080px; margin: 0 auto; padding: 28px 24px 80px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

/* cards & grid */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 20px 22px;
  box-shadow: var(--shadow); margin-bottom: 18px; }
.grid > .card { margin-bottom: 0; }
.card.error { border-color: var(--again); }
.nums { display: flex; gap: 28px; margin: 4px 0 16px; }
.nums b { display: block; font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.nums span { color: var(--muted); font-size: 13px; }
.notice { background: var(--learn-soft); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn { display: inline-flex; align-items: center; gap: 4px; padding: 8px 14px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.primary kbd { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--accent-ink) 40%, transparent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }

/* today */
.art { display: block; padding: 12px 0; border-top: 1px solid var(--line); }
.art:first-of-type { border-top: 0; padding-top: 0; }
.art h3 { font: 600 18px/1.35 var(--serif); margin: 0 0 4px; }
.art h3 a { color: var(--text); }
.meta { color: var(--muted); font-size: 13px; }
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.week div { text-align: center; padding: 8px 4px; border-radius: 8px; background: var(--surface-2); font-size: 13px; }
.week div b { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.week div.on { background: var(--accent-soft); outline: 1.5px solid var(--accent); }
.bar { display: flex; height: 10px; border-radius: 6px; overflow: hidden; background: var(--surface-2); margin: 6px 0 4px; }
.bar i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend span { background: none; }
.legend span::before { content: ""; display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; background: var(--c); }
.c-known { --c: #9aa79f; background: #9aa79f; } .c-learning { --c: var(--accent); background: var(--accent); }
.c-new { --c: var(--new); background: var(--new); } .c-unscreened { --c: var(--line); background: transparent; }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 56px; margin-top: 8px; }
.spark div { flex: 1; background: var(--accent-soft); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.spark div.today { background: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-top: 14px; }
.stats b { display: block; font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }
ol.steps { padding-left: 20px; margin: 8px 0 14px; color: var(--muted); font-size: 14px; }

/* flashcards */
.study { max-width: 640px; margin: 0 auto; }
.counter { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.flash { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  padding: 44px 36px 32px; min-height: 340px; display: flex; flex-direction: column; }
.flash .word { font: 600 44px/1.15 var(--serif); text-align: center; word-break: break-word; }
.flash .ipa { text-align: center; color: var(--muted); font-size: 17px; margin-top: 6px; }
.flash .tags { text-align: center; margin-top: 10px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); margin: 0 2px; }
.tag.hot { background: var(--learn-soft); color: var(--text); }
.speak { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 18px; vertical-align: middle; }
.speak:hover { color: var(--accent); }
.answer { border-top: 1px dashed var(--line); margin-top: 24px; padding-top: 18px; }
.meaning { font-size: 17px; }
.meaning .phr { color: var(--muted); font-size: 15px; }
.en { margin: 10px 0 0; padding: 0; list-style: none; font-size: 14px; color: var(--muted); }
.en li { margin: 4px 0; }
.en i { color: var(--text); font-style: normal; font-size: 12px; background: var(--surface-2); padding: 0 6px; border-radius: 4px; margin-right: 6px; }
.sentence { margin-top: 14px; padding: 10px 14px; border-left: 3px solid var(--learn); background: var(--learn-soft);
  border-radius: 0 8px 8px 0; font: 16px/1.55 var(--serif); }
.sentence mark { background: transparent; color: inherit; font-weight: 700; }
.sentence .src { display: block; font: 12px var(--sans); color: var(--muted); margin-top: 4px; }
.examples { margin-top: 14px; }
.examples .ex-h { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.examples ul { margin: 0; padding-left: 18px; }
.examples li { font: 15px/1.55 var(--serif); margin: 6px 0; }
.examples li mark { background: transparent; color: inherit; font-weight: 700; }
.examples .src { display: block; font: 12px var(--sans); color: var(--muted); }
.examples .zh { display: block; font: 13px var(--sans); color: var(--muted); filter: blur(4px); cursor: pointer;
  transition: filter .15s; user-select: none; }
.examples .zh.show { filter: none; user-select: text; }
.examples .credit { font-size: 11px; color: var(--muted); margin-top: 4px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: auto; padding-top: 24px; }
.rate button { padding: 10px 4px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; cursor: pointer; }
.rate button small { display: block; color: var(--muted); font-size: 12px; }
.rate button:hover { background: var(--surface-2); }
.rate .r1 { border-bottom: 3px solid var(--again); } .rate .r2 { border-bottom: 3px solid var(--hard); }
.rate .r3 { border-bottom: 3px solid var(--good); } .rate .r4 { border-bottom: 3px solid var(--easy); }
.reveal { margin-top: auto; padding-top: 24px; text-align: center; }
.under { text-align: center; margin-top: 14px; font-size: 13px; }
.under button { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; text-decoration: underline; }
.prev { text-align: center; color: var(--muted); font-size: 13px; margin-top: 14px; min-height: 20px; }
.screen-keys { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: auto; padding-top: 28px; }
.screen-keys .btn { justify-content: center; padding: 12px; font-size: 16px; }
.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.set { text-align: left; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--text); font: inherit; }
.set:hover { border-color: var(--accent); }
.set b { display: block; font-size: 16px; }
.set .bar { height: 6px; }
.set .hint { font-size: 12px; }
.set.skip { opacity: .6; }

/* reader */
.reader { max-width: 720px; margin: 0 auto; }
.reader h1 { font: 700 32px/1.25 var(--serif); margin-bottom: 8px; }
.reader .tip { font-size: 13px; color: var(--muted); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin: 16px 0 24px; }
.prose { font: 19px/1.75 var(--serif); }
.prose p { margin: 0 0 1.1em; }
.prose .prose-h { font: 700 21px/1.4 var(--serif); margin: 1.6em 0 .6em; }
.prose .w { cursor: pointer; border-radius: 3px; }
.prose .w:hover { background: var(--surface-2); }
.prose .w.learning { background: var(--learn-soft); box-shadow: inset 0 -2px 0 var(--learn); }
.prose .w.new { box-shadow: inset 0 -2px 0 var(--new); }
.no-hl .prose .w.learning, .no-hl .prose .w.new { background: none; box-shadow: none; }
.prose .w.sel { outline: 2px solid var(--accent); }
.summary textarea, .field textarea, .field input[type=text], .field input[type=number] { width: 100%; font: inherit; padding: 10px 12px; border-radius: 9px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); }
.summary textarea { min-height: 96px; font: 16px/1.5 var(--serif); }

/* panel */
.panel { position: fixed; top: 64px; right: 18px; width: 360px; max-height: calc(100vh - 84px); overflow: auto; z-index: 20;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 8px 32px rgba(0,0,0,.14); padding: 20px; }
.panel-close { position: absolute; top: 8px; right: 10px; border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
.panel h3 { font: 600 24px/1.2 var(--serif); margin: 0 0 4px; padding-right: 24px; }
.entry { border-top: 1px solid var(--line); padding: 10px 0; }
.entry .meaning { font-size: 15px; }
.field { margin: 10px 0; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field textarea { min-height: 64px; font-size: 14px; }
.status { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.status.learning { background: var(--accent-soft); color: var(--accent); }
.status.new { background: var(--new-soft); }

.list .item { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-top: 1px solid var(--line); }
.list .item:first-child { border-top: 0; }
.list .item a.t { font: 600 16px/1.4 var(--serif); color: var(--text); }
.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: var(--surface); color: var(--muted); padding: 5px 12px; border-radius: 99px; cursor: pointer; font: inherit; font-size: 13px; }
.tabs button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 30; box-shadow: 0 6px 24px rgba(0,0,0,.2); }
.done { text-align: center; padding: 60px 20px; }
.done .big { font-size: 44px; }

.touch { display: none; }
.under .touch button { color: var(--accent); }
@media (hover: none) and (pointer: coarse) {
  .touch { display: inline; }
  .desk, kbd { display: none; }
  .flash { touch-action: pan-y; user-select: none; -webkit-user-select: none; }
}
.top { padding-top: max(10px, env(safe-area-inset-top)); }
main { padding-bottom: max(80px, env(safe-area-inset-bottom)); }
.login { max-width: 360px; margin: 14vh auto 0; }
.login input { width: 100%; font: inherit; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); margin: 12px 0; font-size: 16px; }
.login .err { color: var(--again); min-height: 22px; font-size: 14px; }

@media (max-width: 1180px) {
  .panel { top: auto; bottom: 0; left: 0; right: 0; width: auto; max-height: 62vh; border-radius: 16px 16px 0 0; }
}
@media (max-width: 720px) {
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  nav { order: 3; width: 100%; overflow-x: auto; }
  .quick input { width: 140px; }
  main { padding: 18px 16px 80px; }
  .flash { padding: 32px 20px 22px; }
  .flash .word { font-size: 36px; }
  .prose { font-size: 18px; }
  .reader h1 { font-size: 26px; }
}

/* accounts (admin) */
table.users { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.users td { padding: 10px 6px; border-top: 1px solid var(--line); vertical-align: top; }
table.users tr.muted td { opacity: .6; }
table.users td.acts { text-align: right; white-space: nowrap; }
table.users td.acts .btn { margin: 2px 0 2px 4px; }
.btn.danger { color: var(--again); }
.token-box { background: var(--learn-soft); border-radius: 10px; padding: 12px 14px; margin: 10px 0; }
.token-box .token { font: 600 22px/1.4 ui-monospace, Consolas, monospace; letter-spacing: 1px; margin: 6px 0 10px; user-select: all; }
.token-box .token-link { width: 100%; margin: 4px 0 8px; font-size: 13px; }
@media (max-width: 640px) {
  table.users, table.users tbody, table.users tr, table.users td { display: block; }
  table.users td { border-top: none; padding: 4px 0; }
  table.users tr { border-top: 1px solid var(--line); padding: 8px 0; }
  table.users td.acts { text-align: left; }
  table.users td.acts .btn { margin: 2px 4px 2px 0; }
}
