/* ===========================================================
   康复作息 — Stylesheet
   60 岁康复者：18px 起、按钮 48px+、对比度 4.5:1、无 CDN
   =========================================================== */

:root {
  /* 配色：低饱和、对比度高、护眼 */
  --bg: #fafafa;
  --bg-card: #ffffff;
  --text: #1a1a1a;          /* 对比度 17:1 vs --bg */
  --text-muted: #5a5a5a;     /* 对比度 7:1 */
  --primary: #2d6a9f;        /* 主蓝 */
  --primary-text: #ffffff;   /* 对比度 5.5:1 vs primary */
  --accent: #4a8c3f;         /* 健康绿 */
  --warn: #b04a3a;           /* 警示红 */
  --breath-bg: #0d1b2a;
  --breath-text: #e6edf5;
  --border: #d8d8d8;
  --focus: #ff9800;
  --tap: 48px;
  --radius: 12px;
  --gap: 16px;
  --shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a1a;
    --bg-card: #242424;
    --text: #f0f0f0;
    --text-muted: #b8b8b8;
    --primary: #6db4e8;
    --primary-text: #0d1b2a;
    --accent: #7fc77a;
    --warn: #e08870;
    --border: #3a3a3a;
    --shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html {
  font-size: clamp(18px, 4.5vw, 22px);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Source Han Sans CN", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

h1, h2, h3 { margin: 0; line-height: 1.3; }

/* ---------- Header ---------- */
.app-header {
  padding: calc(env(safe-area-inset-top, 0) + 12px) 16px 12px;
  background: var(--primary);
  color: var(--primary-text);
}
.app-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.app-title { font-size: 1.6rem; font-weight: 700; }
.status-indicator {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255, 255, 255, 0.18);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  min-height: var(--tap);
}
.status-dot {
  width: 10px; height: 10px;
  background: #aef0b0;
  border-radius: 50%;
  box-shadow: 0 0 6px #aef0b0;
}
.status-indicator.is-paused .status-dot { background: #ffd084; box-shadow: 0 0 6px #ffd084; }
.today-date { margin-top: 4px; opacity: 0.85; font-size: 0.95rem; }

/* ---------- Main ---------- */
.app-main {
  padding: var(--gap);
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card--primary {
  border-left: 4px solid var(--accent);
}
.card__title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

/* ---------- Next activity ---------- */
.next-activity__body { display: flex; flex-direction: column; gap: 8px; }
.next-activity__time { color: var(--text-muted); font-size: 0.95rem; }
.next-activity__name { font-size: 1.35rem; font-weight: 700; }
.next-activity__prompt { color: var(--text-muted); font-size: 1rem; }
.next-activity__countdown { font-size: 1.1rem; color: var(--accent); font-weight: 600; }

/* ---------- Timeline ---------- */
.timeline-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  background: var(--bg-card);
  cursor: pointer;
  min-height: var(--tap);
}
.timeline-item[aria-expanded="true"] { background: #f0f6fc; }
.timeline-item__header { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.timeline-item__time { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.timeline-item__title { font-weight: 600; font-size: 1.05rem; }
.timeline-item__voice { margin-top: 6px; color: var(--text-muted); font-size: 0.95rem; }
.timeline-item__details { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }
.timeline-item[aria-expanded="true"] .timeline-item__details { display: block; }
.timeline-item__rationale { color: var(--text-muted); font-size: 0.9rem; margin-top: 8px; }
.timeline-item__instruction { white-space: pre-wrap; }
.timeline-item__badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #2d6a9f;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
}
.timeline-item__badge.is-breath { background: #4a8c3f; }
.timeline-item__badge.is-music { background: #6e5fb8; }

/* ---------- Recurring ---------- */
.recurring-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.recurring-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px;
  background: #f4f7fa;
  border-radius: 10px;
  border: 1px solid var(--border);
  min-height: var(--tap);
}
.recurring-item__label { font-size: 1rem; }
.recurring-item__time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--accent); }

/* ---------- Music ---------- */
.music-controls { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 12px; }
.music-volume { display: inline-flex; align-items: center; gap: 8px; flex: 1 1 200px; }
.music-volume input { flex: 1; }
.hint { color: var(--text-muted); font-size: 0.9rem; margin: 0; }

/* ---------- BP form ---------- */
.bp-form { display: flex; flex-direction: column; gap: 14px; }
.bp-slot { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.bp-slot legend { padding: 0 6px; font-weight: 600; }
.bp-slot label { display: flex; flex-direction: column; gap: 4px; margin: 6px 0; }
.bp-form input[type="number"], .bp-form input[type="text"] {
  min-height: var(--tap);
  font-size: 1.1rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.bp-form input:focus, .btn:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.bp-note { display: flex; flex-direction: column; gap: 4px; }
.bp-history summary { cursor: pointer; padding: 10px 0; font-weight: 600; min-height: var(--tap); display: inline-flex; align-items: center; }
.bp-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.bp-table th, .bp-table td { padding: 8px; text-align: left; border-bottom: 1px solid var(--border); }
.bp-table th { background: #f4f7fa; }
.bp-table button { min-height: 36px; padding: 4px 10px; }

/* ---------- Reminder ---------- */
.reminder-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.permission-status { color: var(--text-muted); }

/* ---------- Buttons ---------- */
.btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 12px 20px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  font-family: inherit;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn--secondary { background: var(--bg-card); color: var(--primary); }
.btn--exit { background: var(--warn); border-color: var(--warn); color: #fff; font-size: 1.1rem; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  background: var(--text);
  color: var(--bg);
  padding: 14px 22px;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  max-width: 90vw;
  font-size: 1rem;
  transition: transform 0.3s ease;
}
.toast.is-visible { transform: translateX(-50%) translateY(0); }

/* ---------- Breath overlay ---------- */
.breath-overlay {
  position: fixed;
  inset: 0;
  background: var(--breath-bg);
  color: var(--breath-text);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0)
           env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
}
.breath-overlay[hidden] { display: none; }
.breath-overlay__inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  text-align: center;
  width: 100%;
  max-width: 600px;
}
.breath-phase {
  font-size: clamp(2.5rem, 10vw, 4rem);
  font-weight: 700;
  letter-spacing: 0.1em;
}
.breath-ring {
  --p: 0%;
  width: min(70vw, 320px);
  height: min(70vw, 320px);
  border-radius: 50%;
  background:
    conic-gradient(var(--accent) var(--p), rgba(255, 255, 255, 0.12) 0);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.breath-ring::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: var(--breath-bg);
}
.breath-countdown {
  font-size: clamp(2rem, 8vw, 3rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===========================================================
   语言训练（language.js） — 单独追加，不修改上方任何规则
   =========================================================== */
.lang-intro {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin: 0 0 10px;
}
.lang-asr-badge {
  display: inline-block;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: 999px;
  margin-bottom: 12px;
}
.lang-asr-badge.is-ok {
  background: #e6f4ea;
  color: #1e6e3a;
}
.lang-asr-badge.is-warn {
  background: #fef3e0;
  color: #8a5a00;
}
.lang-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  border-bottom: 2px solid var(--border);
}
.lang-tab {
  flex: 1;
  min-height: var(--tap);
  padding: 10px 8px;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  margin-bottom: -2px;
}
.lang-tab.is-active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.lang-tab:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: -2px;
}
.lang-panel {
  padding-top: 8px;
}
.lang-panel[hidden] { display: none; }

.lang-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0 0 12px;
}
.lang-select-label {
  display: block;
  font-weight: 600;
  margin-bottom: 10px;
  font-size: 0.95rem;
}
.lang-select {
  display: block;
  width: 100%;
  min-height: var(--tap);
  padding: 8px 12px;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  margin-top: 4px;
}
.lang-select:focus { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- 进度条 ---------- */
.lang-progress {
  margin: 12px 0;
}
.lang-progress-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.lang-progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.lang-progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}

/* ---------- 对话 lines ---------- */
.lang-lines {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lang-line {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 1.05rem;
  line-height: 1.5;
  border: 1px solid var(--border);
  background: var(--bg);
}
.lang-line--ai {
  background: #f0f4f9;
  border-left: 4px solid var(--primary);
}
.lang-line--me {
  background: #f5f9f0;
  border-left: 4px solid var(--accent);
}
.lang-line.is-current {
  border-width: 2px;
  box-shadow: 0 0 0 3px rgba(45, 106, 159, 0.18);
}
.lang-line.is-done {
  opacity: 0.75;
}
.lang-line-marker {
  flex-shrink: 0;
  font-size: 1.1rem;
}
.lang-line-text {
  flex: 1;
  word-break: break-word;
}
.lang-line-score {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.lang-line-mic,
.lang-line-skip {
  flex-shrink: 0;
  min-height: 40px;
  padding: 6px 12px;
  font-size: 0.95rem;
  border-radius: 8px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  font-family: inherit;
}
.lang-line-skip {
  background: var(--bg-card);
  color: var(--primary);
}
.lang-line-mic.is-recording {
  background: var(--warn);
  border-color: var(--warn);
  animation: lang-pulse 1.2s infinite;
}
@keyframes lang-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* ---------- 按钮 ---------- */
.lang-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}
.lang-btn {
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 12px 18px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  cursor: pointer;
  font-family: inherit;
}
.lang-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.lang-btn:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.lang-btn--primary { /* default */ }
.lang-btn--record {
  background: var(--warn);
  border-color: var(--warn);
}
.lang-btn--record.is-recording {
  animation: lang-pulse 1.2s infinite;
}
.lang-btn--ghost {
  background: var(--bg-card);
  color: var(--primary);
}
.lang-btn--ghost:disabled {
  opacity: 0.4;
}

/* ---------- 跟读文本显示 ---------- */
.lang-text-target {
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 600;
  text-align: center;
  padding: 18px 12px;
  margin: 14px 0;
  background: #f8f5e8;
  border-radius: 12px;
  line-height: 1.6;
  border: 1px solid var(--border);
}
.lang-sentence-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.lang-pos {
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- 识别结果显示 ---------- */
.lang-recognized {
  background: #f4f7fa;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-top: 10px;
  font-size: 1rem;
  color: var(--text);
  min-height: 44px;
}
.lang-recognized[hidden] { display: none; }
.lang-recognized-row { margin: 4px 0; }
.lang-recognized-row strong { color: var(--text-muted); }

/* ---------- 评分结果 ---------- */
.lang-result {
  margin-top: 14px;
  padding: 16px;
  background: #eef7ee;
  border: 1px solid #c5e0c5;
  border-radius: 12px;
  text-align: center;
}
.lang-result[hidden] { display: none; }
.lang-result h3 {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: var(--accent);
}
.lang-score-big {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  font-variant-numeric: tabular-nums;
}
.lang-score-unit {
  font-size: 1.5rem;
  margin-left: 6px;
  color: var(--text-muted);
  font-weight: 600;
}
.lang-tip {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* ---------- 歌词 ---------- */
.lang-lyrics {
  list-style: none;
  margin: 12px 0;
  padding: 12px;
  background: #f8f5e8;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.lang-lyrics-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 30px 0;
}
.lang-lyric-line {
  display: flex;
  gap: 10px;
  padding: 6px 8px;
  border-radius: 8px;
  font-size: 1.05rem;
  align-items: baseline;
}
.lang-lyric-line.is-current {
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 600;
  transform: scale(1.02);
  transition: transform 0.2s;
}
.lang-lyric-num {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 22px;
}
.lang-lyric-line.is-current .lang-lyric-num {
  color: var(--primary-text);
  opacity: 0.8;
}

/* ---------- 历史记录 ---------- */
.lang-history {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.lang-history summary {
  cursor: pointer;
  font-weight: 600;
  padding: 8px 0;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  font-size: 1rem;
}
.lang-history-empty {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 8px 0;
}
.lang-history-day { margin: 10px 0; }
.lang-history-day-label {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 4px;
}
.lang-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.lang-history-list li {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 4px 0;
  font-size: 0.95rem;
}
.lang-history-tab {
  display: inline-block;
  font-size: 0.78rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--primary);
  color: var(--primary-text);
  min-width: 32px;
  text-align: center;
}
.lang-history-title {
  flex: 1;
}
.lang-history-score {
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

/* ---------- 响应式 ---------- */
@media (max-width: 480px) {
  .lang-btn { font-size: 1rem; padding: 10px 14px; }
  .lang-tab { font-size: 0.95rem; padding: 8px 4px; }
  .lang-line { font-size: 1rem; }
  .lang-text-target { font-size: 1.3rem; padding: 14px 10px; }
  .lang-score-big { font-size: 3rem; }
}
/* ============================================================
   自动模式 toggle（追加 — header）
   ============================================================ */
.auto-mode-toggle {
  margin: 8px 16px 12px;
  padding: 8px 16px;
  font-size: 15px;
  font-weight: 600;
  border: 2px solid transparent;
  border-radius: 999px;
  background: #f1f3f5;
  color: #495057;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  -webkit-tap-highlight-color: transparent;
}
.auto-mode-toggle:hover { background: #e9ecef; }
.auto-mode-toggle:focus-visible {
  outline: 3px solid #4dabf7;
  outline-offset: 2px;
}
.auto-mode-toggle.is-on {
  background: #d3f9d8;
  color: #2b8a3e;
  border-color: #51cf66;
}
.auto-mode-toggle.is-on:hover { background: #b2f2bb; }

/* ============================================================
   语言训练 AI 模式 toggle（追加）
   ============================================================ */
.lang-mode-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 16px;
  padding: 12px 14px;
  background: #f8f9fa;
  border: 1px solid #e9ecef;
  border-radius: 12px;
}
.lang-mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: #495057;
  user-select: none;
  min-height: 44px;
}
.lang-mode-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}
.lang-mode-toggle-slider {
  display: inline-block;
  position: relative;
  width: 44px;
  height: 24px;
  background: #ced4da;
  border-radius: 999px;
  transition: background 0.2s;
  flex-shrink: 0;
}
.lang-mode-toggle-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.lang-mode-toggle input:checked + .lang-mode-toggle-slider {
  background: #4dabf7;
}
.lang-mode-toggle input:checked + .lang-mode-toggle-slider::before {
  transform: translateX(20px);
}
.lang-mode-toggle input:focus-visible + .lang-mode-toggle-slider {
  outline: 3px solid #74c0fc;
  outline-offset: 2px;
}
.lang-mode-toggle-text small {
  color: #868e96;
  font-size: 12px;
  margin-left: 4px;
}
.lang-ai-status {
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 500;
}
.lang-ai-status.is-offline {
  background: #e9ecef;
  color: #868e96;
}
.lang-ai-status.is-ai {
  background: #d0ebff;
  color: #1971c2;
}

/* AI 灵动生成的对话行高亮标记 */
.lang-line-ai-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 11px;
  background: #d0ebff;
  color: #1971c2;
  border-radius: 999px;
  vertical-align: middle;
  font-weight: 600;
}
