/* AI 阅读器 · 布局与组件样式
   只用 tokens.css 的 token；移动优先；正文可读性第一（X7）。
   结构：三个全屏 .page（输入/听读/设置），同时只显示一个，JS 切 .is-hidden。 */

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

html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text-primary);
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;     /* 听读时下拉不触发整页回弹 */
}

/* ── 页面容器：全屏覆盖，纵向布局 ── */
.page {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
.is-hidden { display: none !important; }

/* ══════════════ 输入页 ══════════════ */
.page--input {
  justify-content: center;
  align-items: center;
  gap: var(--sp-6);
  padding: var(--sp-5);
  padding-top: calc(var(--safe-top) + var(--sp-5));
}
.input-hero { text-align: center; }
.brand { font-size: var(--fs-display); font-weight: 700; letter-spacing: .5px; }
.brand-sub { color: var(--text-muted); font-size: var(--fs-sm); margin-top: var(--sp-2); }

.url-card {
  width: 100%;
  max-width: var(--content-max);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.url-field {
  width: 100%;
  font-family: inherit;
  font-size: var(--fs-body);
  line-height: var(--lh-body);
  color: var(--text-primary);
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-4);
  resize: none;
  transition: border-color var(--dur) var(--ease);
}
.url-field:focus { outline: none; border-color: var(--accent); }
.url-field::placeholder { color: var(--text-muted); }
.url-hint { color: var(--error); font-size: var(--fs-sm); min-height: 1.2em; padding-left: var(--sp-1); }
.url-hint:empty { min-height: 0; }
.unlock-tip { color: var(--text-muted); font-size: var(--fs-xs); text-align: center; }

.recent { width: 100%; max-width: var(--content-max); }
.recent-title { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--sp-2); }
.recent-list { list-style: none; display: flex; flex-direction: column; gap: var(--sp-2); }
.recent-list li {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-sm); color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ══════════════ 按钮 ══════════════ */
.btn {
  font-family: inherit; font-size: var(--fs-body); font-weight: 600;
  min-height: var(--tap-min);
  padding: var(--sp-3) var(--sp-5);
  border: none; border-radius: var(--radius-pill);
  cursor: pointer; transition: transform var(--dur-fast) var(--ease), opacity var(--dur-fast) var(--ease);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
}
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-1); }
.btn--block { width: 100%; }
.btn--ghost { background: var(--surface-sunken); color: var(--text-primary); }
.btn-ic { font-size: .85em; }

/* ══════════════ 顶栏（听读 / 设置共用）══════════════ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  padding-top: calc(var(--safe-top) + var(--sp-2));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-title {
  font-size: var(--fs-title); font-weight: 600;
  flex: 1; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding: 0 var(--sp-2);
}
.icon-btn {
  width: var(--tap-min); height: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--text-primary);
  background: none; border: none; cursor: pointer; border-radius: var(--radius-sm);
  flex: 0 0 auto;
}
.icon-btn:active { background: var(--surface-sunken); }
.icon-btn--ghost { visibility: hidden; }  /* 顶栏占位，保持标题居中 */

/* ══════════════ 状态条（RENDER-02 · X3 可见反馈）══════════════ */
.status-bar {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface-sunken);
  font-size: var(--fs-sm); color: var(--text-secondary);
}
.status-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--text-muted); flex: 0 0 auto;
}
.status-dot.is-fetching, .status-dot.is-translating, .status-dot.is-waiting { background: var(--accent); animation: pulse 1.2s var(--ease) infinite; }
.status-dot.is-searching { background: var(--listening); animation: pulse 1s var(--ease) infinite; }   /* C3 搜索中：监听绿，区别于朗读色 */
.status-dot.is-speaking { background: var(--speaking); animation: pulse 1s var(--ease) infinite; }
.status-dot.is-paused  { background: var(--text-muted); }
.status-dot.is-done    { background: var(--success); }
.status-dot.is-error   { background: var(--error); }
@keyframes pulse { 0%,100% { opacity: 1; transform: scale(1); } 50% { opacity: .4; transform: scale(.7); } }
.status-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.chip {
  font-family: inherit; font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-secondary); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  padding: var(--sp-1) var(--sp-3); min-height: 32px; cursor: pointer; flex: 0 0 auto;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* ══════════════ 听读正文区 ══════════════ */
.reader-body {
  flex: 1; min-height: 0; overflow-y: auto;
  padding: var(--sp-4);
  -webkit-overflow-scrolling: touch;
}
.reader-content {
  max-width: var(--content-max);
  margin: 0 auto;
  display: flex; flex-direction: column; gap: var(--sp-1);
}
/* 每个句子＝朗读/高亮/跳转的最小单元（点句可跳读，PLAY-03）*/
.sentence {
  font-size: var(--fs-read);
  line-height: var(--lh-read);
  color: var(--text-secondary);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-sm);
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
  scroll-margin: 30vh;          /* 高亮句滚到视口靠上、留出后文 */
}
.sentence.is-past { color: var(--text-muted); }      /* 已读弱化 */
.sentence.is-current {                                  /* 当前朗读句：高亮（PLAY-04）*/
  color: var(--text-primary);
  background: var(--accent-weak);
  border-left-color: var(--accent);
  font-weight: 500;
}
.sentence-en {                                          /* 英文原文（双语模式才显）*/
  display: none;
  font-size: var(--fs-sm);
  line-height: var(--lh-body);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}
.reader-content.is-bilingual .sentence-en { display: block; }
.sentence.is-skipped { color: var(--text-muted); font-style: italic; }  /* 翻译失败的段（ERR-02）*/

/* 空/加载态 */
.reader-empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-4);
  color: var(--text-muted); font-size: var(--fs-sm);
  padding: var(--sp-7) var(--sp-4); text-align: center;
}
.reader-empty.is-hidden { display: none; }
.spinner, .spinner::after { width: 28px; height: 28px; border-radius: 50%; }
.spinner {
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ══════════════ 控制条（PLAY-03）══════════════ */
.controls {
  display: flex; align-items: center; justify-content: space-around;
  gap: var(--sp-2);
  min-height: var(--control-h);
  padding: var(--sp-2) var(--sp-4);
  padding-bottom: calc(var(--safe-bottom) + var(--sp-2));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-2);
}
.ctl-btn {
  font-family: inherit;
  min-width: var(--tap-min); height: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: var(--text-primary);
  background: none; border: none; cursor: pointer; border-radius: var(--radius-pill);
  transition: transform var(--dur-fast) var(--ease);
}
.ctl-btn:active { transform: scale(.9); background: var(--surface-sunken); }
.ctl-btn--main {
  width: 60px; height: 60px; font-size: 1.75rem;
  background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-1);
}
.ctl-rate { font-size: var(--fs-body); font-weight: 600; min-width: 56px; }

/* ══════════════ 设置页 ══════════════ */
.settings-body {
  flex: 1; overflow-y: auto;
  max-width: var(--content-max); width: 100%; margin: 0 auto;
  padding: var(--sp-5) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-6);
}
.set-row { display: flex; flex-direction: column; gap: var(--sp-3); }
.set-row--switch { flex-direction: row; align-items: center; justify-content: space-between; }
.set-label { font-size: var(--fs-body); font-weight: 500; }
.set-val { color: var(--accent); font-weight: 600; }
.set-hint { font-size: var(--fs-xs); color: var(--text-muted); line-height: var(--lh-body); }

.slider { -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: var(--radius-pill); background: var(--surface-sunken); }
.slider::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); box-shadow: var(--shadow-1); cursor: pointer; }
.slider::-moz-range-thumb { width: 26px; height: 26px; border: none; border-radius: 50%; background: var(--accent); cursor: pointer; }

/* 双语开关 */
.switch {
  width: 52px; height: 30px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); border: 1px solid var(--border);
  position: relative; cursor: pointer; flex: 0 0 auto; transition: background var(--dur) var(--ease);
}
.switch-knob {
  position: absolute; top: 2px; left: 2px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-1);
  transition: transform var(--dur) var(--ease);
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(22px); }

.voice-row { display: flex; gap: var(--sp-3); align-items: center; }
.select {
  flex: 1; font-family: inherit; font-size: var(--fs-sm); color: var(--text-primary);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: var(--sp-3); min-height: var(--tap-min);
}

/* ══════════════ 指令框（CMD-01 · 听中输入「记笔记」）══════════════ */
/* 夹在正文区与控制条之间：手指够得着、不遮正文；记笔记不打断朗读（PLAY-05） */
.topbar-actions { display: flex; align-items: center; flex: 0 0 auto; }
.cmd-bar {
  display: flex; gap: var(--sp-2); align-items: center;
  padding: var(--sp-2) var(--sp-4);
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.cmd-input {
  flex: 1; min-width: 0;
  font-family: inherit; font-size: var(--fs-body);
  color: var(--text-primary); background: var(--surface-sunken);
  border: 1.5px solid var(--border); border-radius: var(--radius-pill);
  padding: var(--sp-2) var(--sp-4); min-height: var(--tap-min);
}
.cmd-input:focus { outline: none; border-color: var(--accent); }
.cmd-input::placeholder { color: var(--text-muted); }
.cmd-send { flex: 0 0 auto; padding: var(--sp-2) var(--sp-4); min-height: var(--tap-min); white-space: nowrap; }
/* VOICE-01 按住说话按钮：圆形🎤，按住进入「聆听中」脉冲（监听绿光环）。touch-action:none 防长按选中/滚动干扰按住手势 */
.cmd-mic {
  flex: 0 0 auto; width: var(--tap-min); height: var(--tap-min);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.3rem; color: var(--text-primary);
  background: var(--surface-sunken); border: 1.5px solid var(--border); border-radius: 50%;
  cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none;
  transition: transform var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}
.cmd-mic[hidden] { display: none; }   /* 覆盖 .cmd-mic 的 inline-flex（否则 hidden 属性失效）*/
.cmd-mic:active { transform: scale(.92); }
.cmd-mic.is-listening {
  background: var(--listening); color: #fff; border-color: var(--listening);
  animation: pulse-mic 1s var(--ease) infinite;
}
.cmd-mic.is-busy {   /* 云端识别中（已松手·上传识别约 1~2s）：静音灰 + 缓脉冲，区别于聆听绿 */
  background: var(--text-muted); color: #fff; border-color: var(--text-muted);
  animation: pulse 1.2s var(--ease) infinite;
}
@keyframes pulse-mic { 0%,100% { box-shadow: 0 0 0 0 rgba(47,143,107,.5); } 50% { box-shadow: 0 0 0 9px rgba(47,143,107,0); } }

/* toast：记笔记确认 / 指令未识别，控制条上方浮现、自动淡出（X3 可视反馈，与 earcon 并行） */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--control-h) + var(--safe-bottom) + var(--sp-6));
  max-width: 80vw; text-align: center;
  background: var(--text-primary); color: var(--bg);
  font-size: var(--fs-sm); font-weight: 600;
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-pill);
  box-shadow: var(--shadow-2); z-index: 50;
  opacity: 0; transition: opacity var(--dur) var(--ease); pointer-events: none;
}
.toast.is-show { opacity: 1; }
.toast[hidden] { display: none; }

/* ══════════════ 搜索浮层（C3 · 听中搜索可视反馈）══════════════ */
/* 叠加在听读页底部、控制条上方：不抢全屏(用户仍看得到已暂停的原文)，可听为主、可视为辅(X3) */
.search-overlay {
  position: fixed; left: 0; right: 0;
  bottom: calc(var(--control-h) + var(--safe-bottom));
  z-index: 40; padding: var(--sp-3) var(--sp-4);
  display: flex; justify-content: center;
  pointer-events: none;                 /* 浮层背景不挡操作，仅卡片可交互 */
}
.search-overlay.is-hidden { display: none; }
.search-card {
  pointer-events: auto;
  width: 100%; max-width: var(--content-max);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3);
}
.search-q { font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary); display: flex; align-items: center; gap: var(--sp-2); }
.search-ic { font-size: 1.1em; }
/* 浮层总结：靠后端把内容控制在 100 字内（不靠前端截断）；这里只留 max-height 滚动兜底防极端 */
.search-summary { font-size: var(--fs-body); line-height: var(--lh-body); color: var(--text-primary); max-height: 40vh; overflow-y: auto; }
.search-sources { list-style: none; display: flex; flex-direction: column; gap: var(--sp-1); }
.search-sources li { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-sources a { color: var(--text-secondary); text-decoration: none; }
.search-skip { align-self: center; font-size: var(--fs-sm); padding: var(--sp-2) var(--sp-5); }
.spinner--sm { width: 20px; height: 20px; border-width: 2.5px; }

/* ══════════════ 笔记页（NOTE-04）══════════════ */
.notes-body {
  flex: 1; overflow-y: auto;
  max-width: var(--content-max); width: 100%; margin: 0 auto;
  padding: var(--sp-4); -webkit-overflow-scrolling: touch;
}
.notes-list { list-style: none; display: flex; flex-direction: column; gap: var(--sp-3); }
.note-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: var(--sp-4);
  cursor: pointer; transition: transform var(--dur-fast) var(--ease), border-color var(--dur) var(--ease);
}
.note-card:active { transform: scale(.99); }
.note-summary { font-size: var(--fs-body); color: var(--text-primary); line-height: var(--lh-body); }
.note-src {
  font-size: var(--fs-sm); color: var(--text-secondary); margin-top: var(--sp-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.note-meta { font-size: var(--fs-xs); color: var(--text-muted); margin-top: var(--sp-2); display: flex; gap: var(--sp-3); align-items: center; }
.note-pending { color: var(--accent); }   /* 「待同步」标记（X5 本地优先，云同步失败也不挡用户） */
.notes-empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
  color: var(--text-muted); font-size: var(--fs-body);
  padding: var(--sp-7) var(--sp-4); text-align: center;
}
.notes-empty.is-hidden { display: none; }
.notes-empty-sub { font-size: var(--fs-sm); }

/* ══════════════ 桌面「手机框」预览外壳（大屏 ≥600px）══════════════ */
/* WHY：本 App 移动端优先、整页 position:fixed 全屏布局；在电脑大屏直接全屏会过宽、阅读动线被拉散。
   这里把整个 App 收进一个居中的「手机外壳」里预览，更贴近真实使用样子；手机 / 窄屏不触发、保持原生全屏。
   关键技巧：给 .device-frame 加 transform，使它成为内部 position:fixed 元素
   (.page / .toast / .search-overlay) 的 containing block —— 它们便从「相对视口」改为「相对手机框」
   铺满，于是无需改动任何页面自身的定位代码，就把全屏 App 整体收进了框里。 */
@media (min-width: 600px) {
  body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; padding: var(--sp-5);
    background: var(--frame-outer);
  }
  .device-frame {
    /* 用模拟值覆盖安全区：给顶部灵动岛 / 底部 home 条让位，避免遮住 App 内容 */
    --safe-top: 30px;
    --safe-bottom: 22px;
    position: relative; flex: 0 0 auto;
    height: min(844px, calc(100vh - 2 * var(--sp-5)));   /* 窗口不够高时整体等比缩小、不裁切 */
    aspect-ratio: 390 / 844;                             /* 锁 iPhone 比例：高受限 → 宽按比例收 */
    max-width: calc(100vw - 2 * var(--sp-5));
    background: var(--bg);
    border-radius: var(--frame-radius);
    overflow: hidden;                                    /* 圆角裁掉内部页面的直角 */
    transform: translateZ(0);                            /* ★ 创建 containing block，收编内部 fixed 元素 */
    box-shadow:
      0 0 0 12px var(--frame-body),          /* 黑色机身（spread 阴影，不占内部空间）*/
      0 0 0 13px var(--frame-body-edge),     /* 机身外缘一道高光 */
      0 40px 90px -12px rgba(0, 0, 0, .55),  /* 悬浮投影 */
      0 12px 32px rgba(0, 0, 0, .30);
  }
  /* 顶部「灵动岛」小黑条（点睛，让它一眼是部手机）*/
  .device-frame::before {
    content: ''; position: absolute; top: 11px; left: 50%;
    width: 88px; height: 26px; transform: translateX(-50%);
    background: var(--frame-body); border-radius: 14px;
    z-index: 100; pointer-events: none;
  }
  /* 底部 home indicator 小横条 */
  .device-frame::after {
    content: ''; position: absolute; bottom: 9px; left: 50%;
    width: 130px; height: 5px; transform: translateX(-50%);
    background: var(--text-muted); opacity: .55; border-radius: 3px;
    z-index: 100; pointer-events: none;
  }
}

/* 无障碍：尊重「减少动效」系统设置 */
@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}
