/* 日语词汇 · 红宝书 —— 样式（移动优先，iOS Safari 适配） */
:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #8a91a3;
  --line: #e8eaf1;
  --primary: #f43f5e;
  --primary-d: #e11d48;
  --n5: #22c55e;
  --n4: #06b6d4;
  --n3: #eab308;
  --n2: #f97316;
  --n1: #ef4444;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}
#app { max-width: 520px; margin: 0 auto; min-height: 100dvh; }
a { color: inherit; text-decoration: none; }

/* 启动屏 */
.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100dvh; gap: 12px; }
.boot-logo { font-size: 56px; font-weight: 700; color: var(--primary); animation: pulse 1.2s infinite; }
.boot-text { color: var(--muted); font-size: 14px; }
@keyframes pulse { 50% { opacity: .35; } }

/* 页面骨架 */
.page { display: flex; flex-direction: column; min-height: 100dvh; }
.topbar { padding: calc(env(safe-area-inset-top, 0px) + 14px) 16px 10px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700; }
.content { flex: 1; padding: 4px 16px 90px; }

/* 底部导航 */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 520px; display: flex;
  background: rgba(255,255,255,.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabbar a { flex: 1; text-align: center; padding: 8px 0 6px; font-size: 11px; color: var(--muted); }
.tabbar a span { display: block; font-size: 20px; margin-bottom: 2px; }
.tabbar a.on { color: var(--primary); font-weight: 600; }

/* 卡片与通用 */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 4px rgba(30,35,60,.06); }
.sec-title { font-size: 15px; margin: 18px 2px 10px; display: flex; align-items: center; justify-content: space-between; }
.mini-link { font-size: 13px; color: var(--primary); }
.muted { color: var(--muted); font-size: 13px; line-height: 1.7; }
.err { color: var(--n1); font-size: 13px; min-height: 18px; }
.warn { color: var(--n2); }
.empty-tip { text-align: center; color: var(--muted); font-size: 13px; padding: 22px 10px; background: var(--card); border-radius: var(--radius); }
.empty-tip a { color: var(--primary); }
.back-link { margin: 16px 0; text-align: center; font-size: 14px; color: var(--muted); }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 12px; padding: 12px 18px; font-size: 15px; font-weight: 600;
  cursor: pointer; transition: transform .06s, opacity .15s; user-select: none;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.success { background: var(--n5); border-color: var(--n5); color: #fff; }
.btn.danger { background: #fff; border-color: var(--n1); color: var(--n1); }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.grow { flex: 1; }
.icon-btn { border: none; background: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 6px; }

/* 主页概览 */
.hero { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; }
.hero-row { display: flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--muted); }
.hero-row b { font-size: 24px; color: var(--text); font-weight: 700; }

/* 词书卡片 */
.deck-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.deck-card { background: var(--card); border-radius: var(--radius); padding: 12px; box-shadow: 0 1px 4px rgba(30,35,60,.06); display: block; }
.deck-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.deck-name { font-size: 14px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.deck-count { font-size: 11px; color: var(--muted); white-space: nowrap; }
.deck-meta { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.due-badge { color: var(--primary); font-weight: 600; }
.lv-bd-N5 { border-left: 3px solid var(--n5); }
.lv-bd-N4 { border-left: 3px solid var(--n4); }
.lv-bd-N3 { border-left: 3px solid var(--n3); }
.lv-bd-N2 { border-left: 3px solid var(--n2); }
.lv-bd-N1 { border-left: 3px solid var(--n1); }

/* 等级色标签 */
.chip { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 700; color: #fff; white-space: nowrap; }
.chip-N5 { background: var(--n5); } .chip-N4 { background: var(--n4); }
.chip-N3 { background: var(--n3); color: #5b4700; } .chip-N2 { background: var(--n2); }
.chip-N1 { background: var(--n1); }

/* 进度条 */
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--n5), var(--n4)); border-radius: 3px; transition: width .3s; }
.bar.big { height: 10px; }

/* 学习/复习卡片 */
.session-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.session-bar .bar { flex: 1; }
.session-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sc-meta { font-size: 12px; color: var(--muted); text-align: center; margin-bottom: 8px; }

.study-card { min-height: 60dvh; display: flex; flex-direction: column; cursor: pointer; }
.sc-top { display: flex; align-items: center; gap: 8px; }
.sc-word { font-size: 14px; font-weight: 600; flex: 1; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sc-reps { font-size: 11px; color: var(--n2); }
.sc-main { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 12px 0; }
.sc-kanji { font-size: 44px; font-weight: 700; text-align: center; line-height: 1.25; word-break: break-all; }
.sc-kana { font-size: 20px; color: var(--muted); text-align: center; }
.sc-hint { text-align: center; color: var(--muted); font-size: 12px; padding-bottom: 6px; }
.sc-img-wrap { flex: 1; display: flex; align-items: flex-start; justify-content: center; overflow: auto; -webkit-overflow-scrolling: touch; max-height: 56dvh; }
.sc-img { max-width: 100%; border-radius: 8px; }
.img-fallback { width: 100%; flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
.fb-kana { font-size: 26px; font-weight: 700; }
.fb-kanji { font-size: 20px; color: var(--muted); margin-top: 6px; }
.fb-note { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* 居中卡片（完成/提示页） */
.center-card { text-align: center; padding: 34px 20px; }
.center-card p { margin: 8px 0; }
.big-emoji { font-size: 52px; margin-bottom: 8px; }

/* 测试 */
.test-q { text-align: center; font-size: 14px; font-weight: 600; color: var(--muted); margin: 6px 0 14px; }
.test-kanji { text-align: center; font-size: 40px; font-weight: 700; margin: 6px 0 10px; }
.listen-btn { margin: 8px 0 14px; }
.kb-input {
  min-height: 52px; display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  background: #fff; border: 2px solid var(--primary); border-radius: 12px;
  padding: 10px 14px; font-size: 22px; margin-bottom: 10px; word-break: break-all;
}
.caret { display: inline-block; width: 2px; height: 26px; background: var(--primary); margin-left: 2px; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }
.test-img { min-height: 140px; max-height: 34dvh; margin-bottom: 12px; }
.choices { display: grid; gap: 10px; }
.choice {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 14px; font-size: 17px; font-weight: 600; cursor: pointer; text-align: center;
}
.choice:active { background: #f0f2f8; }
.choice.right { border-color: var(--n5); background: #f0fdf4; }
.choice.wrong { border-color: var(--n1); background: #fef2f2; }
.feedback { text-align: center; font-size: 15px; font-weight: 600; padding: 12px; border-radius: 12px; margin-top: 12px; }
.feedback.ok { background: #f0fdf4; color: #15803d; }
.feedback.bad { background: #fef2f2; color: #b91c1c; }

/* 假名键盘 */
.kb { background: #eef0f6; border-radius: 12px; padding: 8px; margin-bottom: 10px; }
.kb-fn { display: flex; gap: 6px; margin-bottom: 8px; }
.kb-fn button { flex: 1; border: none; border-radius: 8px; padding: 9px; font-size: 14px; font-weight: 600; background: #dde1ec; color: var(--text); cursor: pointer; }
.kb-fn .kb-bs { flex: 0.6; font-size: 17px; }
.kb-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 4px; }
.kb-key {
  border: none; background: #fff; border-radius: 7px; aspect-ratio: 1/1.15;
  font-size: 15px; font-weight: 600; color: var(--text); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.kb-key:active { background: var(--primary); color: #fff; }

/* 罗马音键盘（QWERTY → 假名） */
.rk-display {
  display: flex; align-items: center; flex-wrap: wrap; gap: 2px;
  background: #fff; border-radius: 10px; padding: 9px 14px;
  min-height: 46px; margin-bottom: 8px; font-size: 24px; word-break: break-all;
}
.rk-kana { line-height: 1.3; }
.rk-pending { color: var(--muted); font-size: 16px; align-self: center; }
.rk .caret { height: 28px; }
.rk-rows { display: flex; flex-direction: column; gap: 6px; }
.rk-row { display: flex; gap: 6px; }
.rk-row-mid { padding: 0 18px; }
.rk-key {
  flex: 1; aspect-ratio: auto; height: 42px; font-size: 15px;
  text-transform: uppercase; font-family: -apple-system, sans-serif;
}
.rk-key.rk-bs { flex: 1.6; font-size: 17px; background: #dde1ec; }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; z-index: 80; background: rgba(20, 24, 36, .45);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: 16px; padding: 18px;
  width: 100%; max-width: 400px; max-height: 80dvh; overflow: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}
.modal-box h3 { margin: 0 0 6px; font-size: 17px; }
.modal-box .muted { margin: 4px 0 8px; }
.modal-box .btn-row .btn { margin-top: 14px; }

/* 词书点选列表（弹窗内） */
.deck-pick { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.deck-pick-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1.5px solid var(--line); background: #fff; border-radius: 12px;
  padding: 13px 14px; font-size: 15px; cursor: pointer; text-align: left; color: var(--text);
}
.deck-pick-item:active { background: #f0f2f8; border-color: var(--primary); }
.dpi-name { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dpi-count { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* 搜索 */
.search-bar-wrap { margin-bottom: 10px; }
.search-input {
  width: 100%; padding: 12px 64px 12px 16px; font-size: 16px; border: 1.5px solid var(--line);
  border-radius: 12px; background: #fff; outline: none; height: 46px;
}
.search-input:focus { border-color: var(--primary); }
.kb-toggle {
  position: absolute; right: 22px; top: 4px; border: none; border-radius: 10px;
  padding: 8px 10px; font-size: 14px; font-weight: 700; background: #eef0f6; color: var(--text); cursor: pointer;
}
.kb-toggle.on { background: var(--primary); color: #fff; }
.search-bar-wrap { position: relative; }
.filter-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.fchip { border: 1.5px solid var(--line); background: #fff; color: var(--muted); border-radius: 20px; padding: 5px 12px; font-size: 12px; font-weight: 600; cursor: pointer; }
.fchip.on { border-color: var(--primary); color: var(--primary); background: #fff1f3; }
.f-sep { flex: 0 0 100%; height: 0; }
.result-count { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
/* 结果区底部留白：避免固定定位的「已选」条挡住最后一行 */
#search-results { padding-bottom: 76px; }

/* 词汇行 */
.word-list { background: var(--card); border-radius: var(--radius); overflow: hidden; margin-bottom: 14px; }
.word-row { display: flex; align-items: center; gap: 8px; padding: 11px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.word-row:last-child { border-bottom: none; }
.word-row.selectable { cursor: pointer; }
.w-j { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 38%; }
.w-k { color: var(--muted); font-size: 12px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.w-st { font-size: 11px; color: var(--muted); }
.w-st.ok { color: var(--n5); font-weight: 600; }
.w-st.ing { color: var(--n2); font-weight: 600; }

/* 选择栏 */
.sel-bar {
  position: fixed; bottom: calc(var(--safe-b) + 64px); left: 50%; transform: translateX(-50%);
  width: calc(100% - 32px); max-width: 488px;
  background: #20242f; color: #fff; border-radius: 14px; padding: 10px 14px;
  display: flex; align-items: center; gap: 8px; font-size: 13px; z-index: 30;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
.sel-bar .btn { margin-top: 0; }
.sel-bar .btn.small { background: #3a3f4f; border-color: #3a3f4f; color: #fff; }
.sel-bar span { margin-right: auto; }

/* 统计 */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { text-align: center; padding: 14px 4px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 11px; color: var(--muted); }
.chart { display: flex; align-items: flex-end; justify-content: space-between; height: 130px; padding: 10px 4px 0; }
.chart-col { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; }
.chart-stack { flex: 1; width: 46%; display: flex; flex-direction: column-reverse; border-radius: 4px 4px 0 0; overflow: hidden; }
.chart-stack i { display: block; width: 100%; }
.cs-new { background: var(--primary); }
.cs-rev { background: #93a3c4; }
.chart-label { font-size: 10px; color: var(--muted); margin-top: 6px; }
.legend { display: flex; gap: 14px; justify-content: center; font-size: 12px; color: var(--muted); padding: 8px 0 2px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.dot.new { background: var(--primary); } .dot.rev { background: #93a3c4; }
.lv-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.lv-pct { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* 表单 */
.form-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; font-size: 14px; }
.form-row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.form-row input {
  border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font-size: 16px; width: 90px; text-align: center; outline: none;
}
.form-row.col input { width: 100%; text-align: left; }

/* 桌面微调 */
@media (min-width: 521px) {
  body { background: #eceef4; }
  #app { background: var(--bg); box-shadow: 0 0 30px rgba(0,0,0,.06); }
}
