* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 var(--font);
  padding: calc(16px + var(--safe-top)) 14px calc(32px + var(--safe-bottom));
  min-height: 100vh;
}
#app { max-width: 560px; margin: 0 auto; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 15px; font-weight: 600; margin: 20px 0 10px; color: var(--muted); }
h3 { font-size: 14px; font-weight: 600; }
button { font-family: inherit; }
a { color: var(--accent); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}
.card.tight { padding: 10px 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.btn {
  min-height: 46px;
  padding: 0 16px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:active { background: #304054; }
.btn:disabled { opacity: .42; cursor: default; }
.btn.primary { background: var(--accent-dim); border-color: #3a6fa5; color: #dcecff; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 12px; }
.btn.danger { border-color: #7a3538; color: var(--bad); }
.btn.active { border-color: var(--accent); color: var(--accent); }
.btn-grid { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.btn-grid.one { grid-template-columns: 1fr; }

.pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; line-height: 20px; height: 22px; padding: 0 9px;
  border-radius: 11px; background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--line); white-space: nowrap;
}
.pill.ok { background: #12382c; color: var(--ok); border-color: #1d5e48; }
.pill.warn { background: #3b2c10; color: var(--warn); border-color: #6b4c14; }
.pill.bad { background: #3d1f22; color: var(--bad); border-color: #6d3035; }
.pill.info { background: #1c2b3c; color: var(--accent); border-color: #2f5375; }

.banner {
  background: #3a2a12; border: 1px solid #7a5518; color: var(--warn);
  border-radius: var(--radius); padding: 11px 13px; margin-top: 12px; font-size: 12px; line-height: 1.7;
}
.banner.info { background: #16293c; border-color: #2f5375; color: var(--accent); }

.hud { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand b { font-size: 17px; letter-spacing: .3px; }

.hero {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px 16px; text-align: center; margin-top: 8px;
}
.hero .sigil { width: 76px; height: 76px; margin: 0 auto 12px; }
.hero p { color: var(--muted); font-size: 13px; margin-top: 8px; }

.chapter {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-top: 10px;
}
.chapter .num {
  width: 38px; height: 38px; flex: none; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 600; color: #0e1219;
}
.chapter .meta { flex: 1; min-width: 0; }
.chapter .meta .t { font-size: 14px; font-weight: 600; }
.chapter .meta .s { font-size: 11px; color: var(--muted); }
.level-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 10px 0 4px; }

.bar { height: 9px; border-radius: 5px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--danger); transition: width .35s ease; }
.bar.xp > i { background: var(--accent); }

/* ---------------- 扇形例句牌组 ---------------- */
.deck-stage {
  position: relative;
  height: 344px;
  margin: 14px -6px 0;
  perspective: 1100px;
  overflow: hidden;
  touch-action: pan-y;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  cursor: grab;
}
.deck-stage.dragging { cursor: grabbing; }
.deck-stage.dragging .fan-card { transition: none; }
/* 切卡收尾帧：扇形归位与卡片内容替换一次绘制完成，避免回弹或空白闪烁 */
.deck-stage.no-transition .fan-card { transition: none !important; }

.fan-card {
  position: absolute; left: 14px; right: 14px; top: 6px; bottom: 6px;
  display: flex; flex-direction: column;
  padding: 14px 15px 12px;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(160deg, #1d2836 0%, var(--surface) 52%, #171e29 100%);
  box-shadow: 0 14px 32px rgba(0, 0, 0, .38);
  transform-origin: 50% 165%;
  will-change: transform, opacity;
  pointer-events: none;
  overflow: hidden;
  --bx: 0%; --rot: 0deg; --sc: 1; --dy: 0px;
  transform: translateX(calc(var(--bx) + var(--dx, 0px)))
             rotate(calc(var(--rot) + var(--drot, 0deg)))
             scale(var(--sc)) translateY(var(--dy));
  transition: transform .34s cubic-bezier(.22, .7, .24, 1), opacity .34s ease, filter .34s ease;
}
.fan-card[data-pos="center"] { z-index: 3; opacity: 1; }
.fan-card[data-pos="left"]  { --bx: -64%; --rot: -17deg; --sc: .86; --dy: 16px; z-index: 2; opacity: .5; filter: saturate(.65); }
.fan-card[data-pos="right"] { --bx: 64%;  --rot: 17deg;  --sc: .86; --dy: 16px; z-index: 2; opacity: .5; filter: saturate(.65); }
.fan-card-empty { opacity: 0 !important; }

/* 扇形滑动：当前卡沿弧线飞出，相邻卡转正，第三张继续退出画面 */
.deck-stage.turn-next .fan-card[data-pos="center"] { transform: translateX(118%) rotate(30deg) scale(.84) translateY(18px); opacity: 0; z-index: 2; }
.deck-stage.turn-next .fan-card[data-pos="right"]  { transform: translateX(0) rotate(0deg) scale(1) translateY(0); opacity: 1; z-index: 4; filter: none; }
.deck-stage.turn-next .fan-card[data-pos="left"]   { transform: translateX(-122%) rotate(-30deg) scale(.8) translateY(20px); opacity: 0; }
.deck-stage.turn-prev .fan-card[data-pos="center"] { transform: translateX(-118%) rotate(-30deg) scale(.84) translateY(18px); opacity: 0; z-index: 2; }
.deck-stage.turn-prev .fan-card[data-pos="left"]   { transform: translateX(0) rotate(0deg) scale(1) translateY(0); opacity: 1; z-index: 4; filter: none; }
.deck-stage.turn-prev .fan-card[data-pos="right"]  { transform: translateX(122%) rotate(30deg) scale(.8) translateY(20px); opacity: 0; }

.fc-top { display: flex; align-items: center; gap: 6px; }
.fc-target { font-size: 21px; font-weight: 600; line-height: 1.5; margin: 18px 0 8px; min-height: 62px; }
.fc-target .w { border-radius: 3px; padding: 0 1px; transition: color .12s, background .12s; }
.fc-target .w.on { color: #0e1219; background: var(--accent); }
/* 日语汉字后的平假名注音：括号 + 小字号 + 弱化颜色（卡片与收藏页通用） */
.ruby { font-size: .66em; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.fc-target .w.on .ruby { color: #0e1219; }
.fc-zh { font-size: 13px; color: var(--muted); }
.fc-ipa { font-size: 11px; color: var(--faint); margin-top: 4px; font-family: ui-monospace, Menlo, monospace; }
.fc-art { margin-top: auto; padding-top: 10px; }
.fc-art .scene { display: block; width: 100%; height: 58px; border-radius: 10px; background: var(--surface-2); }
.wave { display: flex; align-items: center; justify-content: center; gap: 2px; height: 30px; margin-top: 8px; }
.wave i { width: 4px; min-height: 4px; border-radius: 2px; background: var(--line-strong); transition: height .09s linear; }
.fc-bottom { display: flex; justify-content: space-between; font-size: 10px; color: var(--faint); margin-top: 2px; }

.deck-controls { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.nav-round {
  width: 44px; height: 44px; flex: none; border-radius: 50%;
  background: var(--accent-dim); border: 1px solid #3a6fa5; color: #dcecff;
  font-size: 26px; line-height: 1; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.nav-round:active { transform: scale(.94); }
.deck-hint { text-align: center; margin-top: 8px; line-height: 1.7; }
.audio-gate {
  margin-top: 12px; padding: 12px; border-radius: var(--radius);
  border: 1px solid #7a5518; background: #3a2a12; color: var(--warn); font-size: 12px;
}
.audio-gate[hidden] { display: none; }
/* --------------------------------------------- */

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 600; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
.setting { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .k { flex: 1; font-size: 13px; }
select, input[type="range"] { font-size: 16px; }
select {
  min-height: 38px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 0 8px;
}
input[type="range"] { accent-color: var(--accent); width: 120px; }
.toggle { min-width: 56px; }

#toast { position: fixed; left: 0; right: 0; top: calc(10px + var(--safe-top)); pointer-events: none; z-index: 30; }
.toast {
  max-width: 520px; margin: 0 auto 6px; width: fit-content;
  background: var(--surface-2); border: 1px solid var(--line-strong);
  color: var(--text); border-radius: 20px; padding: 8px 16px; font-size: 12px;
}
.toast.ok { border-color: #1d5e48; color: var(--ok); }
.toast.bad { border-color: #6d3035; color: var(--bad); }
.toast.warn { border-color: #6b4c14; color: var(--warn); }

.footer { margin-top: 22px; text-align: center; font-size: 11px; color: var(--faint); line-height: 1.8; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.boot { padding: 60px 0; text-align: center; color: var(--muted); }

/* --------------------------------------------- v3.0 语种选择 / 场景域分组 */
.lang-grid { display: grid; gap: 12px; margin-top: 16px; }
.lang-card {
  position: relative; display: block; width: 100%; text-align: left;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line-strong); border-left: 4px solid var(--lang-color, var(--accent));
  border-radius: var(--radius); padding: 16px 16px 14px; cursor: pointer;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform .16s ease, border-color .16s ease, background .16s ease;
}
.lang-card:active { transform: scale(.985); background: var(--surface-2); }
.lang-card:hover { border-color: var(--lang-color, var(--accent)); }
.lang-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 24px; padding: 0 8px; border-radius: 6px;
  background: var(--lang-color, var(--accent)); color: #12141a;
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
}
.lang-name { display: block; margin-top: 10px; font-size: 20px; font-weight: 600; }
.lang-native { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.lang-meta { display: block; font-size: 12px; color: var(--muted); margin-top: 10px; }
.lang-progress {
  display: block; height: 6px; margin-top: 12px; border-radius: 3px;
  background: var(--surface-2); border: 1px solid var(--line); overflow: hidden;
}
.lang-progress > i {
  display: block; height: 100%; border-radius: 3px;
  background: var(--lang-color, var(--accent));
}
.lang-foot { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.lang-enter { margin-left: auto; color: var(--lang-color, var(--accent)); font-size: 13px; font-weight: 600; }
.lang-pill { border-color: var(--accent-dim); color: var(--accent); }
.domain-heading {
  margin: 22px 0 8px; padding: 0 0 6px;
  border-bottom: 1px solid var(--line);
  color: var(--accent); font-size: 13px; font-weight: 600; letter-spacing: .5px;
}
@media (max-width: 360px) {
  .lang-card { padding: 14px 12px; }
  .lang-name { font-size: 18px; }
}
