:root {
  --bg: #0f1420;
  --panel: #171e2e;
  --panel-2: #1e2639;
  --line: #2a3450;
  --text: #e8ecf5;
  --muted: #8a94ab;
  --gold: #f2c14e;
  --gold-dim: #8a6d23;
  --ok: #4fd18b;
  --err: #ff6b6b;
  --main: #f2c14e;
  --daily: #4cc9f0;
  --train: #ff7a59;
  --side: #b388ff;
  --rest: #7c9cff;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans", "Microsoft YaHei", sans-serif;
  font-size: 16px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(48px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--err); min-height: 1.2em; font-size: 14px; }

/* 按钮和输入 */
.btn { border: 0; border-radius: 10px; padding: 12px 16px; font-size: 16px; font-weight: 600; cursor: pointer; color: var(--text); background: var(--panel-2); }
.btn.primary { background: var(--gold); color: #1a1406; }
.btn.ghost { background: transparent; color: var(--muted); padding-left: 0; }
.btn.danger { background: transparent; color: var(--err); border: 1px solid #5a2b33; }
.btn.wide { width: 100%; margin-top: 12px; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 20px; cursor: pointer; padding: 6px; line-height: 1; }
input[type=password], input[type=text], textarea {
  width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font: inherit; outline: none;
}
input:focus, textarea:focus { border-color: var(--gold-dim); }
label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
label.check { display: flex; gap: 8px; align-items: center; margin: 12px 0 4px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0 8px; }

/* 解锁 */
#lock { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.lock-card { width: 100%; max-width: 360px; text-align: center; }
.lock-card form { text-align: left; }
.lock-card input { margin-bottom: 10px; }
.lock-card .btn { width: 100%; margin-top: 8px; }
.lock-emblem { font-size: 40px; color: var(--gold); }
.lock-card h1 { margin: 8px 0 4px; font-size: 24px; }

/* 顶部 */
.top { background: var(--bg); padding-top: calc(14px + env(safe-area-inset-top)); }
.top-row { display: flex; justify-content: space-between; align-items: flex-start; }
.day-label { color: var(--gold); font-size: 13px; letter-spacing: .08em; }
.top h1 { margin: 2px 0 10px; font-size: 22px; }
.xp-text { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
#xp-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); transition: width .4s ease; }
.banner { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: #2a2414; color: var(--gold); font-size: 14px; }
.tabs { display: flex; gap: 6px; margin-top: 12px; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; color: var(--muted); padding: 10px 4px; margin-right: 14px; font: inherit; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--gold); }

.motto { margin: 14px 0 0; color: var(--muted); font-size: 14px; border-left: 3px solid var(--gold-dim); padding-left: 10px; }

/* 任务列表 */
.quest-list { list-style: none; margin: 12px 0 0; padding: 0; }
.quest {
  display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--c, var(--line)); border-radius: var(--radius); padding: 12px 12px 12px 10px; margin-bottom: 10px; cursor: pointer;
}
.quest.done { opacity: .55; }
.quest.done .q-title { text-decoration: line-through; }
.check-btn {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--c, var(--muted));
  background: transparent; color: #0f1420; font-size: 16px; font-weight: 800; cursor: pointer; display: grid; place-items: center;
}
.quest.done .check-btn { background: var(--c); }
.q-main { flex: 1; min-width: 0; }
.q-meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.q-type { color: var(--c); font-weight: 700; }
.q-title { font-weight: 600; }
.q-sum { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.q-xp { flex: none; font-size: 12px; color: var(--gold); font-weight: 700; }
.q-note { font-size: 12px; color: var(--muted); margin-left: 6px; }
.t-main { --c: var(--main); } .t-daily { --c: var(--daily); } .t-train { --c: var(--train); }
.t-side { --c: var(--side); } .t-rest { --c: var(--rest); }

.journal { margin-top: 8px; }

/* 封存 */
.archive-list { list-style: none; padding: 0; margin: 12px 0; }
.archive-list li { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; cursor: pointer; display: flex; justify-content: space-between; }
.archive-view img { width: 100%; border-radius: var(--radius); border: 1px solid var(--line); margin-top: 8px; }

/* 详情面板 */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.sheet-panel {
  position: relative; width: 100%; max-width: 640px; max-height: 88vh; overflow-y: auto; background: var(--panel);
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line);
}
.sheet-head { display: flex; align-items: center; gap: 10px; }
.sheet-head .icon-btn { margin-left: auto; }
.tag { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; color: #0f1420; background: var(--c, var(--muted)); }
.sheet-panel h2 { margin: 10px 0 6px; font-size: 20px; }
.note-label { margin-top: 18px; }

/* 详情正文 */
.md { font-size: 15px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md h3 { font-size: 16px; margin: 16px 0 6px; color: var(--gold); }
.md blockquote { margin: 8px 0; padding: 6px 10px; border-left: 3px solid var(--line); color: #c9d1e3; background: var(--panel-2); border-radius: 0 8px 8px 0; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; margin: 8px 0; }
.md td, .md th { border: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
.md code { background: var(--panel-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }
.md a { color: var(--daily); word-break: break-all; }

/* 同步状态 */
.sync { position: fixed; left: 0; right: 0; bottom: 0; text-align: center; font-size: 12px; color: var(--muted); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 40%); }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); margin-right: 6px; vertical-align: middle; }
.dot.ok { background: var(--ok); } .dot.busy { background: var(--gold); } .dot.bad { background: var(--err); }

/* 金币 */
.top-actions { display: flex; align-items: center; gap: 4px; }
.coin-chip { background: #2a2414; color: var(--gold); border: 1px solid var(--gold-dim); border-radius: 99px; padding: 6px 12px; font: inherit; font-weight: 700; font-size: 15px; cursor: pointer; }
.w-balance { text-align: center; font-size: 40px; font-weight: 800; color: var(--gold); margin-top: 8px; display: flex; justify-content: center; gap: 8px; }
.center { text-align: center; }
input[type=number] { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: inherit; outline: none; }
.spend-list { list-style: none; padding: 0; margin: 0; }
.spend-list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.spend-list li > div:first-child { flex: 1; min-width: 0; }
.spend-amt { color: var(--err); font-weight: 700; }

/* 今日日语 */
.ja { margin-top: 12px; font-size: 16px; }
.md h2 { font-size: 19px; margin: 14px 0 8px; }
.md details { background: var(--panel-2); border-radius: 10px; padding: 8px 12px; margin: 10px 0; }
.md summary { cursor: pointer; color: var(--gold); font-weight: 600; }

/* 今日日语（结构化讲义） */
.ja-bar { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.ja-bar label { margin: 0; white-space: nowrap; }
.ja-bar select { flex: 1; background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 10px; font: inherit; }
.ja-head h2 { margin: 4px 0 4px; font-size: 21px; }
.ja-sec { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 12px 0; }
.ja-sec h3 { margin: 0 0 8px; font-size: 16px; color: var(--gold); }
.ja-sec ol, .ja-sec ul { padding-left: 22px; margin: 4px 0; }
.ja-sec li { margin: 6px 0; }
.ja-sec details { margin-top: 4px; }
.ja-sec summary { color: var(--daily); cursor: pointer; font-size: 14px; }
.ja-expr, .ja-vocab { padding: 8px 0; border-bottom: 1px solid var(--line); }
.ja-expr:last-child, .ja-vocab:last-child { border-bottom: 0; }
.ja-big { font-size: 18px; font-weight: 600; }
.ja-star { color: var(--gold); font-size: 14px; }
.ja-extra { color: var(--muted); font-size: 14px; }
.ja-line { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.ja-who { flex: none; min-width: 3.5em; color: var(--daily); font-weight: 600; }
.ja-zh { color: var(--muted); font-size: 14px; margin-top: 2px; }
.small-btn { padding: 4px 0; font-size: 14px; }
.card-tools { display: flex; justify-content: space-between; align-items: center; }
.flashcard { min-height: 170px; margin: 8px 0; border-radius: 14px; border: 1px solid var(--gold-dim); background: var(--panel-2); display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 6px; padding: 18px; cursor: pointer; user-select: none; }
.flashcard.flipped { border-color: var(--daily); }
.ja-card-front { font-size: 24px; font-weight: 700; }
.card-nav { display: flex; gap: 10px; }
.card-nav .btn { flex: 1; }

/* 注音、发音、文法 */
.hide-rt rt { visibility: hidden; }
rt { font-size: 0.55em; color: var(--muted); }
.kana-btn { padding: 9px 12px; font-size: 14px; white-space: nowrap; }
.tap { cursor: pointer; border-radius: 6px; }
.tap:active { background: var(--panel-2); }
.playing { background: #1d3340; outline: 1px solid var(--daily); }
.spk { font-size: 13px; opacity: .7; }
.ja-line-main { flex: 1; min-width: 0; }
.zh-btn { flex: none; align-self: flex-start; background: var(--panel-2); color: var(--muted); border: 0; border-radius: 6px; padding: 2px 8px; font-size: 13px; cursor: pointer; }
.ja-line { cursor: default; }
.ja-gram { padding: 8px 0; border-bottom: 1px solid var(--line); }
.ja-gram:last-child { border-bottom: 0; }
.ja-ex { margin-top: 6px; padding: 6px 8px; background: var(--panel-2); border-radius: 8px; }
.flashcard .tag { margin-bottom: 4px; }
#d-link { margin-top: 14px; background: #14303a; color: var(--daily); }

/* 强制休息 */
.quest.locked { opacity: .6; border-left-style: dashed; }
.quest.locked .check-btn { border-style: dashed; color: var(--muted); font-size: 13px; cursor: not-allowed; }
.lock-msg { color: var(--train); }
#d-toggle:disabled { opacity: .7; cursor: not-allowed; }
.ja-credits { color: var(--muted); font-size: 12px; margin: 18px 0 8px; line-height: 1.6; }

/* 每日资讯 */
.tabs .tab { margin-right: 10px; }
.dg-h { font-size: 16px; color: var(--gold); margin: 18px 0 8px; display: flex; align-items: center; justify-content: space-between; }
.dg-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.dg-card p { margin: 6px 0; }
.dg-today { border-color: var(--gold-dim); background: #221d10; }
.dg-title { font-weight: 700; }
.dg-title a { color: var(--text); text-decoration: underline; text-decoration-color: var(--gold-dim); }
.dg-meta { margin-top: 4px; }
.dg-stars { color: var(--gold); letter-spacing: 1px; }
.dg-tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); color: var(--daily); }
.dg-links a { font-size: 13px; color: var(--daily); }
.dg-actions { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.dg-want { padding: 6px 12px; font-size: 14px; }
.dg-want.on { background: var(--side); color: #0f1420; }
.dg-empty { margin-top: 16px; }

/* 标签多了：可以横向滑动 */
.tabs { overflow-x: auto; white-space: nowrap; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs .tab { margin-right: 6px; flex: none; }

/* 听全文 */
.dlg-tools { display: flex; gap: 12px; align-items: center; margin: 4px 0 6px; }
.full-btn { padding: 6px 12px; font-size: 14px; background: #14303a; color: var(--daily); }
.ja-line.now { background: #1d3340; border-radius: 8px; }

/* 日语复习 */
.rv-top { margin: 12px 0; }
.rv-tally { display: flex; gap: 14px; font-size: 14px; margin-bottom: 6px; }
.t-ok { color: var(--ok); } .t-mid { color: var(--gold); } .t-bad { color: var(--err); }
.rv-top .bar div { height: 100%; background: linear-gradient(90deg, var(--gold-dim), var(--gold)); }
.rv-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 16px; min-height: 240px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; }
.rv-card.open { border-color: var(--daily); cursor: default; }
.rv-kind { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.rv-practice { color: var(--train); }
.rv-ask { font-size: 13px; color: var(--muted); }
.rv-front { font-size: 28px; font-weight: 700; text-align: center; margin: 14px 0; }
.rv-front.zh { font-size: 22px; }
.rv-back { border-top: 1px dashed var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.rv-tap { text-align: center; margin-top: auto; }
.play-btn { background: none; border: 0; font-size: 16px; cursor: pointer; }
.rv-grade { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.rv-grade button { border: 0; border-radius: 12px; padding: 12px 4px; font: inherit; font-weight: 700; color: #0f1420; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.rv-grade small { font-weight: 400; font-size: 11px; opacity: .8; }
.g-bad { background: var(--err); } .g-mid { background: var(--gold); } .g-ok { background: var(--ok); }
.rv-done { text-align: center; padding: 20px 0; }
.rv-stages { display: flex; justify-content: center; align-items: flex-end; gap: 8px; margin: 16px 0 8px; }
.rv-col { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.rv-col div { width: 22px; background: var(--daily); border-radius: 4px 4px 0 0; }
.rv-fc { margin-bottom: 12px; }

/* 饮食页（从 饮食/preview_template.html 复制） */
.dt-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.dt-card h3 { margin: 0 0 10px; font-size: 15px; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.dt-bar { position: relative; height: 10px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.dt-bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--ok); }
.dt-bar.thin { height: 6px; }
.dt-bar .dt-band { position: absolute; top: 0; bottom: 0; background: rgba(255,255,255,.10); border-left: 1px dashed var(--muted); border-right: 1px dashed var(--muted); }
.dt-bar .dt-mark { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--text); }
.dt-main-num { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.dt-main-num b { font-size: 34px; line-height: 1.1; }
.dt-main-num .arrow { color: var(--muted); }
.dt-main-num .tgt { font-size: 20px; color: var(--gold); font-weight: 700; }
.dt-row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin: 6px 0 4px; }
.dt-goal { padding: 10px 0; border-top: 1px solid var(--line); }
.dt-goal:first-of-type { border-top: 0; }
.dt-goal .lab { font-weight: 600; }
.dt-goal .val { font-variant-numeric: tabular-nums; }
.dt-warn > i { background: var(--err) !important; }
.dt-pace { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); }
.dt-pace.ahead, .dt-pace.on { color: var(--ok); } .dt-pace.behind { color: var(--err); } .dt-pace.start { color: var(--daily); }
.dt-stones { display: flex; gap: 4px; margin-top: 12px; }
.dt-stone { flex: 1; text-align: center; font-size: 11px; color: var(--muted); padding: 6px 2px; border-radius: 8px; background: var(--panel-2); }
.dt-stone b { display: block; font-size: 13px; color: var(--text); }
.dt-stone.next { outline: 1px solid var(--gold); } .dt-stone.next b { color: var(--gold); }
.dt-stone.hit b { color: var(--ok); } .dt-stone.miss b { color: var(--err); }
.dt-kcal { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; margin-bottom: 12px; }
.dt-kcal div { background: var(--panel-2); border-radius: 10px; padding: 8px 4px; }
.dt-kcal b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.dt-kcal span { font-size: 12px; color: var(--muted); }
.dt-balance { text-align: center; font-size: 14px; margin-top: 10px; }
.dt-balance b { font-size: 18px; color: var(--ok); }
.dt-meal { border-top: 1px solid var(--line); padding: 10px 0; }
.dt-meal:first-of-type { border-top: 0; padding-top: 0; }
.dt-meal-head { display: flex; justify-content: space-between; font-weight: 600; }
.dt-meal-head span { color: var(--gold); font-variant-numeric: tabular-nums; }
.dt-items { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.dt-items td { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.dt-items td.n { text-align: right; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; padding-left: 8px; }
.dt-items tr:last-child td { border-bottom: 0; }
.dt-items tr.sum td { color: var(--text); font-weight: 600; border-top: 1px solid var(--line); }
.dt-note { font-size: 13px; color: var(--muted); margin-top: 4px; }
.dt-advice { background: rgba(242,193,78,.08); border-color: #4a3d1c; }
.dt-advice p { margin: 0; }
.dt-chart svg { width: 100%; height: auto; display: block; }
.dt-legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.dt-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
details.dt-card summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: 15px; }
details.dt-card[open] summary { margin-bottom: 8px; }

/* 手机：打勾的圆圈保持正圆（去掉浏览器给按钮加的默认内边距和外观） */
.check-btn { -webkit-appearance: none; appearance: none; padding: 0; margin: 0; min-width: 30px; min-height: 30px;
  aspect-ratio: 1 / 1; box-sizing: border-box; line-height: 1; flex: 0 0 30px; }

/* 金币：用 CSS 画的金色硬币，不用表情符号（有的手机会画成银币） */
.coin { display: inline-block; width: 1em; height: 1em; border-radius: 50%; vertical-align: -0.15em; margin-right: .25em;
  background: radial-gradient(circle at 35% 30%, #fff3c4 0 12%, #ffd75e 13% 45%, #e9a91e 46% 70%, #b77a0b 71% 100%);
  box-shadow: inset 0 0 0 .08em #9a6508, 0 0 0 .04em rgba(0,0,0,.25); }
.coin.big { width: .9em; height: .9em; margin-right: .15em; }
.coin-chip { display: inline-flex; align-items: center; }
.q-xp { display: inline-flex; align-items: center; gap: 2px; }
.q-xp .coin { margin-right: 0; margin-left: .2em; }
.w-balance { align-items: center; }

/* 滑动切换：竖向滚动交给浏览器，横向由脚本处理；动画时不出现横向滚动条 */
html, body { overflow-x: hidden; }
#main { touch-action: pan-y; }
.tab-body { will-change: transform, opacity; }

/* 页面本身不允许横向滚动（clip 连脚本滚动也禁止；旧浏览器退回 hidden） */
html, body { overflow-x: hidden; overflow-x: clip; }
