/* 古诗背诵小达人 — 全局样式（iPad 优先，大字号、大按钮） */
:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --bg: #eef3fb;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 18px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, .25);
  padding-top: calc(14px + env(safe-area-inset-top));
}
.brand { color: #fff; text-decoration: none; font-size: 24px; font-weight: 700; }
.topnav { display: flex; gap: 10px; flex-wrap: wrap; }
.nav-link {
  color: rgba(255, 255, 255, .92); text-decoration: none;
  font-size: 18px; padding: 6px 12px; border-radius: 10px;
  background: rgba(255, 255, 255, .15);
}
.nav-link:active { background: rgba(255, 255, 255, .3); }

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--card);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 2px 12px rgba(30, 41, 59, .06);
}
.card-center { max-width: 420px; margin: 10vh auto 0; }
.center { text-align: center; }

.page-title { font-size: 28px; margin-bottom: 18px; }
.hint { color: var(--muted); font-size: 17px; margin-top: 10px; }
.empty-tip { color: var(--muted); text-align: center; padding: 30px 0; font-size: 19px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: 14px;
  padding: 14px 26px;
  font-size: 20px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: transform .08s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-plain { background: #f1f5f9; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-big { font-size: 26px; padding: 20px 44px; border-radius: 18px; }
.btn-sm { font-size: 15px; padding: 6px 12px; border-radius: 8px; }
.btn-row { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }

/* ---------- 表单 ---------- */
.input, .textarea, .search-input {
  width: 100%;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  font-size: 19px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.input:focus, .textarea:focus, .search-input:focus { outline: none; border-color: var(--primary); }
.textarea { resize: vertical; }
.search-row { margin-bottom: 16px; }
.form-inline { display: flex; gap: 10px; flex-wrap: wrap; }
.form-inline .input { flex: 1; min-width: 140px; }
.form-col { display: flex; flex-direction: column; gap: 12px; max-width: 560px; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 18px; }
.check-row input[type="checkbox"] { width: 22px; height: 22px; }

/* ---------- 学生选人 ---------- */
.class-tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.chip {
  border: 2px solid var(--border); background: #fff; color: var(--muted);
  border-radius: 999px; padding: 6px 20px; font-size: 18px; cursor: pointer;
}
.chip.on { border-color: var(--primary); color: var(--primary); background: #eff6ff; }

.name-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.name-btn {
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 26px 8px;
  font-size: 27px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all .12s ease;
}
.name-btn:active {
  border-color: var(--primary);
  background: #eff6ff;
  transform: scale(.97);
}

/* ---------- 背诵任务卡片 ---------- */
.poem-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.poem-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: linear-gradient(160deg, #fff, #f4f8ff);
  border: 2px solid var(--border);
  border-radius: 18px;
  padding: 24px 12px;
  cursor: pointer;
  transition: all .12s ease;
}
.poem-card:active { border-color: var(--primary); transform: scale(.98); }
.poem-card-title { font-size: 26px; font-weight: 700; }
.poem-card-author { color: var(--muted); font-size: 17px; }
.poem-card-badge { margin-top: 8px; font-size: 15px; padding: 3px 14px; border-radius: 999px; }
.poem-card-badge.todo { background: #fef3c7; color: #b45309; }
.poem-card-badge.done { background: #dcfce7; color: #15803d; }

.task-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}
.back-link {
  background: none; border: none; color: var(--primary);
  font-size: 19px; cursor: pointer; text-decoration: none; padding: 6px 10px;
}
.sr-badge { color: #b45309; font-size: 15px; background: #fef3c7; padding: 4px 10px; border-radius: 8px; }

/* ---------- 背诵界面 ---------- */
.poem-stage { text-align: center; padding: 30px 10px 34px; }
.poem-label { color: var(--muted); font-size: 19px; letter-spacing: 6px; }
.poem-title { font-size: 52px; font-weight: 800; margin: 8px 0; }
.poem-author { color: var(--muted); font-size: 22px; }

.mic-pulse {
  font-size: 72px;
  display: inline-block;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}
.listening { font-size: 22px; color: var(--primary-dark); margin: 8px 0 18px; }

.volume-wrap {
  width: 80%;
  max-width: 480px;
  height: 24px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin: 0 auto;
}
.volume-bar {
  height: 100%;
  width: 0%;
  background: #94a3b8;
  border-radius: 999px;
  transition: width .1s linear;
}
.timer {
  font-size: 40px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  margin: 16px 0 20px;
}
#recordPanel .btn { display: block; margin: 10px auto; }

.subtitle-box {
  width: 100%;
  max-width: 640px;
  min-height: 88px;
  max-height: 160px;
  overflow-y: auto;
  margin: 0 auto 14px;
  padding: 12px 16px;
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 22px;
  line-height: 1.6;
  color: var(--text);
  text-align: left;
  white-space: pre-wrap;
  word-break: break-all;
}

.countdown-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 41, 59, .82);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
/* display:flex 会覆盖 hidden 默认的 display:none，需显式声明让其可隐藏 */
.countdown-overlay[hidden] { display: none; }
.countdown-overlay span {
  color: #fff;
  font-size: 160px;
  font-weight: 800;
  animation: pulse 1s ease-in-out infinite;
}

/* ---------- 评分结果 ---------- */
.res-poem { color: var(--muted); font-size: 20px; margin-bottom: 6px; }

.pass-badge {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin: 8px 0 14px;
}
.pass-icon { font-size: 92px; line-height: 1; }
.pass-text { font-size: 34px; font-weight: 800; }
.pass-badge.pass .pass-text { color: var(--success); }
.pass-badge.fail .pass-text { color: var(--danger); }

.comment { font-size: 21px; color: var(--primary-dark); margin: 16px 0 4px; }
.degraded-tip { color: #b45309; font-size: 15px; margin-top: 6px; }

/* ---------- 排行榜 ---------- */
.rank-list { display: flex; flex-direction: column; gap: 10px; }
.rank-row {
  display: flex; align-items: center; gap: 14px;
  background: #fff; border: 2px solid var(--border);
  border-radius: 16px; padding: 14px 18px;
}
.rank-row:nth-child(1) { border-color: #fbbf24; background: #fffbeb; }
.rank-row:nth-child(2) { border-color: #cbd5e1; background: #f8fafc; }
.rank-row:nth-child(3) { border-color: #fb923c; background: #fff7ed; }
.rank-medal { font-size: 34px; width: 56px; text-align: center; flex-shrink: 0; }
.rank-num {
  display: inline-block;
  background: #e2e8f0; color: var(--muted);
  border-radius: 50%; width: 40px; height: 40px;
  line-height: 40px; font-size: 19px; font-weight: 700;
}
.rank-name { font-size: 26px; font-weight: 700; flex: 1; }
.rank-class { color: var(--muted); font-size: 17px; }
.rank-meta { color: var(--muted); font-size: 16px; }
.rank-points { font-size: 30px; font-weight: 800; color: var(--primary); }

/* ---------- 后台 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(30, 41, 59, .06);
}
.stat-card b { display: block; font-size: 40px; color: var(--primary); }
.stat-card span { color: var(--muted); font-size: 17px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 17px; }
th, td { padding: 10px 10px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td small { color: var(--muted); }
.rec-text { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.poem-content { max-width: 320px; white-space: pre-line; font-size: 15px; color: var(--muted); }
.tag-on { background: #dcfce7; color: #15803d; padding: 2px 12px; border-radius: 999px; font-size: 15px; }
.tag-off { background: #f1f5f9; color: var(--muted); padding: 2px 12px; border-radius: 999px; font-size: 15px; }

/* ---------- 弹层 ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 150;
  padding: 16px;
}
/* display:flex 会覆盖 hidden 默认的 display:none，需显式声明让其可隐藏 */
.modal[hidden] { display: none; }
.modal-box {
  width: 100%;
  max-width: 720px;
  max-height: 84vh;
  overflow-y: auto;
  margin: 0;
}

/* ---------- 通用组件 ---------- */
.spinner {
  width: 56px; height: 56px;
  border: 6px solid #e2e8f0;
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 30px auto 16px;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%; bottom: 40px;
  transform: translateX(-50%);
  background: rgba(15, 23, 42, .88);
  color: #fff;
  padding: 12px 26px;
  border-radius: 12px;
  font-size: 18px;
  z-index: 200;
  max-width: 86vw;
  text-align: center;
}

/* ---------- 小屏适配 ---------- */
@media (max-width: 600px) {
  .poem-title { font-size: 40px; }
  .name-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .name-btn { font-size: 23px; padding: 20px 6px; }
  .page-title { font-size: 24px; }
  .topbar { flex-direction: column; gap: 8px; }
}
