/* ことば · 课本单词 —— 日系清新 / 深色适配 / 单手可触 */

*,
*::before,
*::after { box-sizing: border-box; }

:root {
  --bg: #f7f4ee;
  --surface: #fffdf9;
  --surface-2: #f1ece2;
  --text: #23201a;
  --muted: #8a8478;
  --line: #e7e1d4;
  --accent: #2f6f5e;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe9;
  --danger: #c0453b;
  --danger-soft: #f8e7e4;
  --shadow: 0 6px 24px rgba(70, 58, 36, .08);
  --radius: 18px;
  --tap: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --surface-2: #24282f;
    --text: #e9e6df;
    --muted: #8d9099;
    --line: #2c3138;
    --accent: #79c9ad;
    --accent-ink: #0d1512;
    --accent-soft: #1f2f2a;
    --danger: #e2796f;
    --danger-soft: #33211f;
    --shadow: 0 6px 24px rgba(0, 0, 0, .38);
  }
}

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI",
    "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", "PingFang SC",
    "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
}

.hidden { display: none !important; }

/* ---------- 顶部警告 ---------- */
.banner {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--danger);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  padding: 10px 16px;
  text-align: center;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(12px);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: 10px 0 8px;
}

.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 16px 6px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  min-height: 38px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .18s, color .18s, border-color .18s;
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.tab-empty { color: var(--muted); font-size: 14px; padding: 10px 16px; }

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 16px 0;
}
.progress-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 60%, #9ad8c0));
  transition: width .35s ease;
}
.progress-text {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- 词库列表 ---------- */
.main { padding: 18px 16px 8px; max-width: 720px; margin: 0 auto; }

.group { margin-bottom: 26px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--muted);
  text-transform: uppercase;
}
.group-count {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 8px;
}

.word {
  position: relative;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 58px 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.word-jp { display: flex; flex-direction: column; gap: 2px; min-width: 92px; }
.word-jp .kanji {
  font-size: 26px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: .01em;
}
.word-jp .kana { font-size: 13px; color: var(--muted); letter-spacing: .02em; }

.word-cn {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
  text-align: right;
}
.word-cn .meaning { font-size: 15px; line-height: 1.45; }
.pos-tag {
  font-size: 11px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 1px 6px;
  white-space: nowrap;
}

.speak {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: transform .12s ease, background .18s;
}
.speak:active { transform: translateY(-50%) scale(.92); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 64px 24px;
  font-size: 16px;
  line-height: 2;
}
.empty span { font-size: 13px; }

/* ---------- 底部操作 ---------- */
.fab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.btn {
  border: 0;
  border-radius: 16px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  min-height: var(--tap);
  padding: 0 20px;
  cursor: pointer;
  transition: transform .1s ease, opacity .18s;
}
.btn:active { transform: scale(.975); }
.btn[disabled] { opacity: .45; pointer-events: none; }

.btn.primary { flex: 1; background: var(--accent); color: var(--accent-ink); }
.btn.ghost {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--text);
}
.btn.ghost.icon { width: 56px; padding: 0; }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 16px; border-radius: 12px; }

/* ---------- 抽背 ---------- */
.review {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
}

.review-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px;
}
.counter { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }

.review-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 0;
}

.card {
  width: min(92vw, 420px);
  height: min(62vh, 520px);
  perspective: 1400px;
  cursor: pointer;
  transition: transform .26s ease, opacity .26s ease;
  outline: none;
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 6px; border-radius: 26px; }
.card.slide-left { transform: translateX(-120%) rotate(-8deg); opacity: 0; }
.card.slide-right { transform: translateX(120%) rotate(8deg); opacity: 0; }

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform .52s cubic-bezier(.2, .8, .2, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 26px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px 24px;
  text-align: center;
}

.front-meaning {
  font-size: clamp(26px, 7vw, 38px);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: .01em;
}
.hint { color: var(--muted); font-size: 12px; letter-spacing: .1em; }

.face.back {
  transform: rotateY(180deg);
  background: var(--surface-2);
}
.back-kanji {
  font-size: clamp(46px, 13vw, 72px);
  font-weight: 700;
  line-height: 1.15;
}
.back-kana { font-size: 20px; color: var(--muted); letter-spacing: .04em; }

.pos {
  font-size: 12px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
}

.review-actions { display: flex; gap: 12px; padding-top: 6px; }
.review-actions .btn { flex: 1; min-height: 62px; font-size: 17px; border-radius: 18px; }
.btn.miss { background: var(--danger-soft); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.btn.know { background: var(--accent); color: var(--accent-ink); }

.review-done {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 24px 4px;
}
.review-done .btn { width: 100%; }
.done-title { font-size: 22px; font-weight: 700; margin: 0 0 4px; text-align: center; }
.done-sub { color: var(--muted); font-size: 14px; text-align: center; margin: 0 0 12px; }

/* ---------- 弹窗 / 提示 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(20, 18, 14, .42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}
@media (min-width: 560px) {
  .modal { align-items: center; }
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .18);
}
@media (min-width: 560px) {
  .modal-card { border-radius: 24px; }
}

.modal-card h3 { margin: 0 0 6px; font-size: 18px; }
.modal-card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  padding: 16px 4px;
  text-decoration: none;
  cursor: pointer;
  min-height: 54px;
}
.row:last-child { border-bottom: 0; }
.row.danger { color: var(--danger); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 80;
  max-width: min(88vw, 460px);
  background: rgba(30, 28, 24, .94);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  padding: 12px 18px;
  border-radius: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  .card, .card-inner, .progress-bar, .toast { transition: none; }
}

/* ---------- 书本层级 ---------- */
.books {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 16px 2px;
  scrollbar-width: none;
}
.books::-webkit-scrollbar { display: none; }

.book {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .05em;
  padding: 6px 10px;
  border-radius: 9px;
  cursor: pointer;
  white-space: nowrap;
}
.book.active { color: var(--accent); background: var(--accent-soft); }
.book-count { font-size: 10px; font-weight: 600; opacity: .75; }

/* ---------- 弹窗里的选项 ---------- */
.opt-group { margin: 16px 0; }
.opt-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  font-family: inherit;
  font-size: 13px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 40px;
}
.opt.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---------- 视频收藏 ---------- */
.video-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}
.video-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.video-tag {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 2px 8px;
}
.video-provider { font-size: 11px; color: var(--muted); }
.video-title { font-size: 16px; margin: 0 0 6px; line-height: 1.45; font-weight: 600; }
.video-note { font-size: 13px; color: var(--muted); margin: 0; line-height: 1.5; }
.video-actions { display: flex; gap: 8px; margin-top: 12px; }
.video-actions .btn { width: auto; }
.video-frame {
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-top: 12px;
  border: 0;
  border-radius: 12px;
  background: #000;
}

/* ---------- 主页 ---------- */
.home {
  min-height: 100vh;
  padding: calc(28px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 22px;
}
body:has(.home:not(.hidden)) { padding-bottom: 0; }

.home-kicker {
  margin: 0;
  font-size: 12px;
  letter-spacing: .3em;
  color: var(--accent);
  text-transform: uppercase;
}
.home-title { margin: 6px 0 6px; font-size: 30px; line-height: 1.25; font-weight: 700; }
.home-book { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

.home-progress {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
}
.home-stat { display: flex; align-items: baseline; gap: 8px; }
.home-num { font-size: 40px; font-weight: 700; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums; }
.home-label { font-size: 13px; color: var(--muted); }
.home-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin: 14px 0 8px;
}
.home-bar > i {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 999px;
  transition: width .35s ease;
}
.home-total { margin: 0; font-size: 12px; color: var(--muted); }

.home-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.home-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  box-shadow: var(--shadow);
  cursor: pointer;
  text-decoration: none;
  min-height: 84px;
}
.home-card:active { transform: scale(.985); }
.home-card.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); grid-column: 1 / -1; }
.home-card-title { font-size: 17px; font-weight: 600; }
.home-card-sub { font-size: 12px; opacity: .72; }

.home-foot { margin: auto 0 0; font-size: 11px; color: var(--muted); text-align: center; }

.home-link {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 16px;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  flex: 0 0 auto;
}
