:root {
  --bg: #f7f4ee;
  --panel: #fffdf9;
  --ink: #26221d;
  --muted: #7a7166;
  --line: #e4ddd1;
  --accent: #9b3b2a;
  --accent-soft: #f3e2dc;
  --ok: #3d6b4a;
  --heat-0: #ece6db;
  --heat-1: #e9c3b8;
  --heat-2: #d58f7c;
  --heat-3: #b85c47;
  --heat-4: #8c2f1f;
  --serif: "Iowan Old Style", "Palatino Linotype", "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1916;
    --panel: #24211d;
    --ink: #ebe5dc;
    --muted: #a0968a;
    --line: #3a352f;
    --accent: #e0826c;
    --accent-soft: #3d2721;
    --ok: #86b894;
    --heat-0: #2e2a25;
    --heat-1: #5a3329;
    --heat-2: #8a4636;
    --heat-3: #c1614b;
    --heat-4: #ef947d;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.6 var(--sans);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  max-width: 960px; margin: 0 auto; padding: 16px;
  border-bottom: 1px solid var(--line);
}
.brand { font: 600 20px var(--serif); color: var(--ink); letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 16px; flex: 1; flex-wrap: wrap; }
.nav a { color: var(--muted); }
.nav a.on { color: var(--ink); font-weight: 600; }
.linkbtn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.linkbtn:hover { color: var(--accent); }

main { max-width: 960px; margin: 0 auto; padding: 24px 16px 64px; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; }
h2 { font-size: 18px; margin: 32px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.flash { background: var(--accent-soft); padding: 8px 12px; border-radius: 6px; margin-bottom: 16px; }

input, textarea, select, button { font: inherit; color: inherit; }
input[type=text], input[type=password], input[type=date], input[type=search], textarea, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 7px 10px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.btn {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap;
}
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.quiet { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn:disabled { opacity: .5; cursor: default; }

/* 搜索 */
.search { position: relative; }
.search form { display: flex; gap: 8px; }
.search input[type=search] { flex: 1; font-size: 18px; padding: 10px 14px; }
.suggest {
  position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 10;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  list-style: none; padding: 4px 0; margin-left: 0; display: none;
  box-shadow: 0 6px 20px rgba(0,0,0,.08);
}
.suggest li { padding: 6px 14px; cursor: pointer; display: flex; gap: 12px; overflow: hidden; }
.suggest li.on, .suggest li:hover { background: var(--accent-soft); }
.suggest .hint { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; padding-top: 2px; }

.recent { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 6px 12px; font-size: 14px; }

/* 词条 */
.entry-wrap { display: grid; grid-template-columns: 1fr 260px; gap: 24px; margin-top: 24px; }
@media (max-width: 760px) { .entry-wrap { grid-template-columns: 1fr; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; }
.headword { font: 600 34px/1.2 var(--serif); margin: 0; word-break: break-word; }
.phon { color: var(--muted); font-size: 16px; margin-top: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); }
.defs { list-style: none; padding: 0; margin: 16px 0 0; }
.defs li { padding: 5px 0; font-family: var(--serif); font-size: 17px; border-top: 1px dashed var(--line); }
.defs li:first-child { border-top: 0; }
.section-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 18px; }
.forms { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; }
.en-def li { font-size: 15px; font-family: var(--sans); color: var(--muted); }
.zh-entry + .zh-entry { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.zh-entry .pinyin { font-size: 18px; color: var(--accent); }
.eng-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; margin-top: 8px; }
.eng-list div { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notfound { margin-top: 24px; }

/* 侧栏：个人记录 */
.side h3 { margin: 0 0 10px; font-size: 16px; }
.side .row { margin-bottom: 12px; }
.side label.lbl { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.side input[type=text], .side input[type=date], .side textarea { width: 100%; }
.side textarea { min-height: 60px; resize: vertical; }
.folder-checks { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; }
.folder-checks label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.newfolder { display: flex; gap: 6px; margin-top: 8px; }
.newfolder input { flex: 1; min-width: 0; }
.savedflag { color: var(--ok); font-weight: 600; }
.status { font-size: 12px; color: var(--ok); height: 18px; }

/* 列表 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .grow { flex: 1; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { font-weight: 500; color: var(--muted); font-size: 13px; }
table.list tr:last-child td { border-bottom: 0; }
table.list .w { font: 600 16px var(--serif); white-space: nowrap; }
table.list .brief { color: var(--muted); font-size: 14px; }
.table-scroll { overflow-x: auto; }
@media (max-width: 640px) { .hide-sm { display: none; } }

.folder-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.folder-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; color: var(--ink); display: block; }
.folder-card:hover { border-color: var(--accent); text-decoration: none; }
.folder-card .name { font: 600 17px var(--serif); }
.folder-card .n { font-size: 26px; font-family: var(--serif); color: var(--accent); }
.create-folder { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
details.edit { margin-bottom: 16px; }
details.edit form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }

/* 统计 */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.kpi .v { font: 600 28px var(--serif); }
.kpi .k { color: var(--muted); font-size: 13px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 12px 8px; }
.bars .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.bars .track { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.bars .bar { width: 100%; max-width: 36px; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .num { font-size: 12px; color: var(--muted); }
.bars .lab { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; }
.heat-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; }
.heat { display: flex; gap: 3px; min-width: 360px; }
.heat .wk { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.heat .d { width: 100%; aspect-ratio: 1; border-radius: 2px; background: var(--heat-0); }
.heat .d.l1 { background: var(--heat-1); } .heat .d.l2 { background: var(--heat-2); }
.heat .d.l3 { background: var(--heat-3); } .heat .d.l4 { background: var(--heat-4); }
.heat .d.fut { visibility: hidden; }
.hbar { display: grid; grid-template-columns: 140px 1fr 40px; gap: 10px; align-items: center; padding: 4px 0; }
.hbar .track { background: var(--heat-0); border-radius: 3px; height: 10px; }
.hbar .fill { background: var(--accent); height: 100%; border-radius: 3px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 700px) { .two-col { grid-template-columns: 1fr; } }
.pill-list { display: flex; flex-wrap: wrap; gap: 6px 14px; }

/* 登录 */
.login-box { max-width: 340px; margin: 12vh auto 0; padding: 0 16px; }
.login-box h1 { font-size: 30px; margin-bottom: 4px; }
.login-box form { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.err { color: var(--accent); }

/* 旭日图 */
.sun-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px 18px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.seg button { background: none; border: 0; padding: 5px 14px; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sun-body { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 20px; align-items: center; margin-top: 8px; }
@media (max-width: 720px) { .sun-body { grid-template-columns: 1fr; } }
#sun-chart svg { width: 100%; max-width: 520px; height: auto; display: block; margin: 0 auto; }
#sun-side .crumbs { margin-bottom: 8px; }
.sun-list { list-style: none; padding: 0; margin: 0; max-height: 380px; overflow: auto; }
.sun-list li { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-radius: 5px; font-size: 14px; }
.sun-list li[data-path] { cursor: pointer; }
.sun-list li:hover, .sun-list li.hi { background: var(--accent-soft); }
.sun-list .sw { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.sun-list .sw.leaf { border-radius: 50%; }
.sun-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sun-list .ct { color: var(--muted); font-size: 12px; }

/* 背单词 */
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 4px; border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; line-height: 18px; text-align: center; vertical-align: 1px; }
.rv-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 12px 24px; margin-bottom: 12px; }
.rv-chips { display: flex; gap: 18px; color: var(--muted); font-size: 14px; }
.rv-chips b { color: var(--ink); font: 600 20px var(--serif); margin-right: 2px; }
.rv-controls label { display: flex; align-items: center; gap: 6px; }
.rv-progress { height: 3px; background: var(--line); border-radius: 2px; overflow: hidden; margin-bottom: 16px; }
.rv-bar { height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.rv-card { max-width: 640px; margin: 0 auto; min-height: 340px; display: flex; flex-direction: column; }
.rv-top { display: flex; justify-content: space-between; align-items: center; }
.tag.new { background: var(--accent); color: #fff; }
.rv-word { font: 600 44px/1.2 var(--serif); text-align: center; margin: 44px 0 24px; word-break: break-word; }
.rv-speak { background: none; border: 0; cursor: pointer; font-size: 20px; vertical-align: middle; opacity: .6; }
.rv-speak:hover { opacity: 1; }
.rv-back { border-top: 1px solid var(--line); padding-top: 12px; margin-bottom: 8px; }
.rv-back .phon { text-align: center; margin: -8px 0 8px; }
.rv-meta { margin-top: 12px; }
.rv-note { margin-top: 8px; font-size: 14px; background: var(--accent-soft); border-radius: 6px; padding: 6px 10px; }
.rv-actions { margin-top: auto; padding-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; }
.rv-reveal { padding: 10px 28px; font-size: 16px; }
.kbd { font-size: 11px; opacity: .7; border: 1px solid currentColor; border-radius: 3px; padding: 0 4px; margin-left: 6px; }
.rv-rate { flex: 1 1 110px; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 6px; border-radius: 8px; cursor: pointer; border: 1px solid var(--line); background: var(--panel); }
.rv-rate span { font-size: 12px; color: var(--muted); }
.rv-rate .kbd { margin: 2px 0 0; }
.rv-rate:hover { border-color: currentColor; }
.rv-rate.r1 { color: #b0413e; } .rv-rate.r2 { color: #b07a2a; } .rv-rate.r3 { color: #3d6b4a; } .rv-rate.r4 { color: #3e6b8a; }
@media (prefers-color-scheme: dark) {
  .rv-rate.r1 { color: #e58a7f; } .rv-rate.r2 { color: #dcae62; } .rv-rate.r3 { color: #86b894; } .rv-rate.r4 { color: #86b3d4; }
}
.rv-suspend { flex-basis: 100%; margin-top: 4px; }
.rv-empty { max-width: 640px; margin: 0 auto; text-align: center; padding: 48px 20px; }
.rv-done-big { font: 600 24px var(--serif); margin-bottom: 8px; }
.rv-explain { max-width: 640px; margin: 24px auto 0; }
.rv-explain ul { padding-left: 20px; }
.review-line { font-size: 13px; margin-bottom: 12px; }

/* 拼写 */
.tag.sp { background: #3e6b8a; color: #fff; }
.sp-body { text-align: center; }
.sp-prompt-word { font: 600 40px/1.2 var(--serif); margin: 28px 0 4px; }
.sp-lines { text-align: left; max-width: 460px; margin: 24px auto 0; }
.sp-ask { margin: 18px 0 8px; }
.sp-input { width: 100%; max-width: 360px; font: 500 24px/1.3 ui-monospace, "SF Mono", Menlo, monospace !important; text-align: center; padding: 10px 12px !important; letter-spacing: .04em; }
.sp-input:read-only { border-color: var(--ok); }
.sp-hint { margin-top: 8px; font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .05em; min-height: 20px; }
.sp-feedback { margin-top: 10px; }
.sp-ok { color: var(--ok); font: 600 22px var(--serif); }
.sp-diff { display: flex; justify-content: center; align-items: baseline; gap: 10px; font: 500 20px ui-monospace, "SF Mono", Menlo, monospace; margin: 2px 0; }
.sp-diff .small { font-family: var(--sans); width: 3em; text-align: right; }
.sp-mine del { color: #c0392b; text-decoration: line-through; background: rgba(192,57,43,.12); }
.sp-right ins { color: var(--ok); text-decoration: none; background: rgba(61,107,74,.16); border-bottom: 2px solid var(--ok); }
@keyframes shake { 0%,100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.shake { animation: shake .25s; border-color: #c0392b !important; }

/* ---------- 手机 / PWA ---------- */
.tabbar { display: none; }
.ios-tip { display: flex; align-items: center; gap: 10px; max-width: 960px; margin: 10px auto 0; padding: 10px 14px; background: var(--accent-soft); border-radius: 8px; font-size: 13px; }
.ios-tip[hidden] { display: none; }
.ios-tip span { flex: 1; }
.ios-tip svg { width: 15px; height: 15px; vertical-align: -2px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.install-btn { white-space: nowrap; }

/* 独立窗口运行时：顶栏避开刘海 / 状态栏 */
.standalone .topbar { padding-top: max(16px, env(safe-area-inset-top)); }

@media (max-width: 640px) {
  /* 输入框 16px 以上，iOS 聚焦时才不会自动放大页面 */
  input[type=text], input[type=password], input[type=date], input[type=search], textarea, select { font-size: 16px; }
  .topbar { padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); gap: 12px; }
  .topbar .nav { display: none; }
  .topbar .brand { flex: 1; }
  .ios-tip { margin: 10px 16px 0; }
  main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom)); }
  h1 { font-size: 26px; }

  /* 底部标签栏 */
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--panel); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tabbar a { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11px; padding: 4px 0; text-decoration: none; -webkit-tap-highlight-color: transparent; }
  .tabbar a.on { color: var(--accent); }
  .tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
  .tabbar .badge { position: absolute; top: 0; left: 50%; margin-left: 6px; }

  /* 查词 */
  .search input[type=search] { font-size: 17px; }
  .headword { font-size: 30px; }
  .card { padding: 16px; }

  /* 背单词 */
  .rv-head { gap: 6px 16px; }
  .rv-chips { gap: 14px; }
  .rv-controls { gap: 8px 14px; }
  .rv-controls .shortcut-hint { display: none; }
  .rv-card { min-height: 0; }
  .rv-word { font-size: 36px; margin: 28px 0 20px; }
  .rv-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .rv-actions .rv-reveal, .rv-actions .rv-suspend, .rv-actions .sp-next, .rv-actions .sp-skip { grid-column: 1 / -1; }
  .rv-actions .sp-submit { grid-column: 1 / -1; padding: 12px; font-size: 16px; }
  .rv-rate { max-width: none; padding: 12px 6px; }
  .rv-reveal { padding: 14px; }
  .rv-actions .kbd { display: none; }
  .sp-prompt-word { font-size: 32px; margin-top: 16px; }
  .sp-input { font-size: 22px !important; }
  .sp-diff { font-size: 17px; }
}

/* 账号 */
.acct-link { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.acct-link:hover, .acct-link.on { color: var(--accent); text-decoration: none; }
.acct-link svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.login-logo { border-radius: 13px; display: block; margin-bottom: 14px; }
.login-box code, .card code { font-size: 12px; background: var(--accent-soft); padding: 1px 4px; border-radius: 3px; }
.account { max-width: 520px; }
.acc-form { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.acc-form h3 { margin: 0; font-size: 16px; }
.acc-form label { display: flex; flex-direction: column; gap: 4px; }
.acc-form label span { font-size: 12px; color: var(--muted); }
.flash.err { color: var(--accent); }
.acc-logout { margin-top: 8px; }
@media (max-width: 640px) { .acct-link span { display: none; } .acct-link svg { width: 22px; height: 22px; } }
