/* 背古诗 · 样式
   设计基准：375 CSS px 竖屏
   配色：宣纸暖白 #F6F1E6 / 墨 #262220 / 朱红 #A63A2A / 金 #BA9860
   可访问性：正文对比度 ≥ 4.5:1（tests/palette.test.js 会校验）
*/

:root {
  --paper: #F6F1E6;
  --paper-2: #FFFDF8;
  --ink: #262220;
  --ink-2: #6C645A;
  --ink-3: #9A9186;
  --cinnabar: #A63A2A;
  --cinnabar-2: #C4563F;
  --gold: #BA9860;
  --gold-2: #D9C49A;
  --green: #3B6D11;
  --green-bg: #EAF3DE;
  --amber: #854F0B;
  --amber-bg: #FAEEDA;
  --red: #A32D2D;
  --red-bg: #FCEBEB;
  --line: rgba(38, 34, 32, 0.15);
  --line-2: rgba(38, 34, 32, 0.30);

  --r-md: 8px;
  --r-lg: 12px;
  --r-xl: 16px;

  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --font-kai: "Kaiti SC", KaiTi, STKaiti, "楷体", serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  overscroll-behavior-y: none;
}

body { min-height: 100vh; }

.app {
  max-width: 720px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

button { font-family: inherit; font-size: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }

.empty {
  padding: 48px 24px; text-align: center; color: var(--ink-2);
}

/* ================= 通用按钮 ================= */
.btn {
  flex: 1;
  min-height: 44px;           /* 可访问性：≥44px */
  padding: 11px 16px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-2);
  background: var(--paper-2);
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn--primary {
  background: var(--cinnabar);
  border-color: var(--cinnabar);
  color: #fff;
}
.btn--ghost { background: transparent; color: var(--ink-2); }
.btn--big { min-height: 52px; font-size: 17px; }
.btn--stop {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.icon-btn {
  width: 44px; height: 44px;
  border: none; background: transparent;
  color: var(--ink-2); font-size: 20px; line-height: 1;
  border-radius: var(--r-md);
}
.icon-btn:active { background: rgba(38,34,32,.06); }

.mini-btn {
  min-height: 32px; padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--paper-2);
  color: var(--ink-2); font-size: 13px;
}

.tappable { cursor: pointer; }

/* ================= 首页 ================= */
.home-header { padding: 22px 20px 10px; }
.home-title {
  margin: 0; font-family: var(--font-kai);
  font-size: 26px; font-weight: 500; letter-spacing: 3px;
}
.home-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-2); }

.due-card {
  margin: 8px 16px 16px;
  padding: 14px 16px;
  border-radius: var(--r-xl);
  background: var(--paper-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
}
.due-card--on {
  background: var(--amber-bg);
  border-color: var(--gold);
}
.due-num {
  width: 44px; height: 44px; flex: none;
  border-radius: 50%;
  background: var(--cinnabar); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 500;
}
.due-card:not(.due-card--on) .due-num { background: var(--line); color: var(--ink-2); }
.due-text { display: flex; flex-direction: column; gap: 2px; }
.due-text strong { font-size: 16px; font-weight: 500; }
.due-hint { font-size: 13px; color: var(--ink-2); }

.poem-list { padding: 0 16px 24px; display: flex; flex-direction: column; gap: 12px; }

.poem-card {
  display: flex; align-items: center; gap: 14px;
  padding: 12px;
  border-radius: var(--r-lg);
  background: var(--paper-2);
  border: 1px solid var(--line);
}
.poem-card:active { background: #F3EDDF; }
.poem-thumb {
  width: 72px; height: 72px; flex: none;
  object-fit: cover; border-radius: var(--r-md);
  background: var(--line);
}
.poem-info { flex: 1; min-width: 0; }
.poem-name {
  font-family: var(--font-kai); font-size: 19px; font-weight: 500;
  margin-bottom: 2px;
}
.poem-author { font-size: 13px; color: var(--ink-2); }
.poem-meta { margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; }
.tag {
  font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--paper); color: var(--ink-2);
  border: 1px solid var(--line);
}
.tag--passed { background: var(--green-bg); color: var(--green); border-color: transparent; }
.tag--reviewing { background: var(--amber-bg); color: var(--amber); border-color: transparent; }
.tag--mastered { background: var(--green-bg); color: var(--green); border-color: transparent; }
.poem-arrow { font-size: 22px; color: var(--ink-3); flex: none; }

/* ================= 关卡页 ================= */
.level-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--paper); z-index: 5;
}
.level-title {
  flex: 1; text-align: center;
  font-family: var(--font-kai); font-size: 18px; font-weight: 500;
}

.stage-bar {
  display: flex; gap: 6px;
  padding: 12px 16px;
}
.stage-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px;
  border-radius: var(--r-md);
  color: var(--ink-3);
  font-size: 12px;
}
.stage-item.is-current { color: var(--cinnabar); }
.stage-item.is-done { color: var(--green); }
.stage-item.is-locked { opacity: .45; cursor: not-allowed; }
.stage-dot {
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid currentColor; font-size: 12px;
}
.stage-item.is-current .stage-dot { background: var(--cinnabar); color: #fff; border-color: var(--cinnabar); }
.stage-item.is-done .stage-dot { background: var(--green); color: #fff; border-color: var(--green); }

.level-body {
  flex: 1; overflow-y: auto;
  padding: 8px 16px 16px;
  -webkit-overflow-scrolling: touch;
}
.level-foot {
  display: flex; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.hint { font-size: 14px; color: var(--ink-2); margin-bottom: 14px; }
.hint--sm { font-size: 13px; margin-bottom: 0; }

.line-row {
  padding: 12px 14px; margin-bottom: 10px;
  border-radius: var(--r-lg);
  background: var(--paper-2);
  border: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.line-row:active { background: #F3EDDF; }
.line-row.is-playing { border-color: var(--cinnabar); background: #FBF0EC; }
.line-text {
  flex: 1;
  font-family: var(--font-kai); font-size: 20px; letter-spacing: 1px;
}
.line-pinyin { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

.level-picker { display: flex; gap: 8px; margin-bottom: 14px; }
.lv-btn {
  min-height: 40px; padding: 8px 20px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: var(--paper-2);
  color: var(--ink-2); font-size: 14px;
}
.lv-btn.is-on { background: var(--cinnabar); border-color: var(--cinnabar); color: #fff; }
.lv-btn.is-locked { opacity: .4; }

.recite-preview {
  padding: 16px; border-radius: var(--r-lg);
  background: var(--paper-2); border: 1px solid var(--line);
}
.challenge-placeholder {
  padding: 20px; border-radius: var(--r-lg);
  background: var(--paper-2); border: 1px dashed var(--line-2);
  color: var(--ink-2); font-size: 14px; text-align: center;
}

/* 节奏模式独立入口（避免藏在被锁阶段里形成死锁） */
.rhythm-entry {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 16px 0;
  padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--amber-bg);
  border: 1px solid var(--gold);
}
.rhythm-entry:active { background: #F5E4CB; }
.rhythm-entry-icon {
  width: 40px; height: 40px; flex: none;
  border-radius: 50%;
  background: var(--cinnabar); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
}
.rhythm-entry-text { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.rhythm-entry-text strong { font-size: 15px; font-weight: 500; color: var(--amber); }
.rhythm-entry-desc { font-size: 12px; color: var(--ink-2); }
.rhythm-entry .poem-arrow { color: var(--amber); }

/* ================= 节奏模式 ================= */
.rhythm-screen {
  flex: 1; display: flex; flex-direction: column;
  min-height: 100vh;
}
.rhythm-screen--center {
  align-items: center; justify-content: center; gap: 12px;
}

.rhythm-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
.rhythm-title {
  flex: 1; font-family: var(--font-kai); font-size: 17px; font-weight: 500;
}
.rhythm-level { font-size: 12px; color: var(--ink-2); }

.explain {
  margin: 14px 16px;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--amber-bg);
  color: var(--amber);
  font-size: 13px;
}

.section-title {
  margin: 6px 16px 8px;
  font-size: 13px; color: var(--ink-2);
}

.mode-picker { display: flex; gap: 10px; padding: 0 16px 14px; }
.mode-btn {
  flex: 1; padding: 12px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line-2);
  background: var(--paper-2);
  display: flex; flex-direction: column; gap: 2px; text-align: left;
}
.mode-btn strong { font-size: 15px; font-weight: 500; }
.mode-btn.is-on { border-color: var(--cinnabar); background: #FBF0EC; }
.mode-desc { font-size: 12px; color: var(--ink-2); }

.beats-info {
  margin: 0 16px 14px; padding: 12px 14px;
  border-radius: var(--r-lg);
  background: var(--paper-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 6px;
}
.beats-line { font-family: var(--font-kai); font-size: 15px; color: var(--ink-2); }

.rhythm-foot {
  margin-top: auto;
  display: flex; gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.rhythm-foot--singing { align-items: center; }
.rhythm-meta { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.combo-num { font-size: 15px; color: var(--cinnabar); font-weight: 500; min-height: 22px; }
.timer { font-size: 13px; color: var(--ink-2); }

/* 拍点进度条 */
.beat-progress {
  display: flex; gap: 8px;
  padding: 12px 16px 4px;
}
.beat-seg { flex: 1; display: flex; gap: 3px; }
.beat-cell {
  flex: 1; height: 4px; border-radius: 2px;
  background: var(--line);
  transition: background .12s ease;
}
.beat-cell.is-done { background: var(--green); }
.beat-cell.is-now { background: var(--amber); }

/* 诗句区 */
.rhythm-stage {
  flex: 1;
  padding: 12px 16px;
  display: flex; flex-direction: column; gap: 18px;
  justify-content: center;
}
.rhythm-line {
  opacity: .5;
  transition: opacity .2s ease;
}
.rhythm-line.is-current { opacity: 1; }
.rhythm-chars { display: flex; flex-wrap: wrap; gap: 4px; }
.rchar {
  font-family: var(--font-kai);
  font-size: 30px; line-height: 1.35;
  min-width: 30px; text-align: center;
  border-radius: 4px;
  border-bottom: 3px solid transparent;
  transition: border-color .1s ease, color .1s ease;
}
.rchar.is-hidden { color: var(--ink-3); }
.rchar.is-now { border-bottom-color: var(--amber); }
.rchar.is-hit { color: var(--green); }
.rhythm-pinyin {
  font-size: 12px; color: var(--ink-3); margin-top: 3px;
  letter-spacing: .5px;
}

.voice-dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--line);
  margin: 0 auto 14px;
  transition: transform .06s linear, background .1s ease;
}
.voice-dot.is-on { background: var(--green); }
.voice-dot.is-off { opacity: .3; }

/* 倒计时 */
.countdown {
  font-family: var(--font-kai);
  font-size: 88px; font-weight: 500;
  color: var(--cinnabar);
}
.countdown.pop { animation: pop .5s ease; }
@keyframes pop {
  0% { transform: scale(.6); opacity: .4; }
  60% { transform: scale(1.08); opacity: 1; }
  100% { transform: scale(1); }
}
.countdown-hint { font-size: 14px; color: var(--ink-2); }

/* 结算 */
.stars {
  display: flex; justify-content: center; gap: 10px;
  padding: 26px 0 12px;
}
.star { font-size: 40px; color: var(--line); line-height: 1; }
.star.is-on { color: var(--amber); }

.result-main { text-align: center; padding-bottom: 14px; }
.result-line { font-size: 16px; }
.result-line--dim { font-size: 13px; color: var(--ink-2); margin-top: 4px; }

.record-badge {
  margin: 0 16px 16px;
  padding: 10px 14px; border-radius: var(--r-md);
  background: var(--amber-bg); color: var(--amber);
  text-align: center; font-size: 15px; font-weight: 500;
}
.record-badge--soft { background: var(--paper-2); color: var(--ink-2); font-weight: 400; }

.line-detail {
  margin: 0 16px 16px;
  border-radius: var(--r-lg);
  background: var(--paper-2); border: 1px solid var(--line);
  overflow: hidden;
}
.detail-row {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
}
.detail-row:last-child { border-bottom: none; }
.detail-text { flex: 1; font-family: var(--font-kai); font-size: 16px; }
.detail-score { font-size: 13px; color: var(--green); }
.detail-row.has-miss .detail-score { color: var(--amber); }

/* ================= 大屏适配 ================= */
@media (min-width: 560px) {
  .rchar { font-size: 34px; }
  .home-title { font-size: 30px; }
}
