/* ezPDF 中文版 — 方向 A：苹果式极简阅读室（CEO 已批，见 direction-approved.md）
 * 骨架：白底、超大留白、黑白灰 + 克制蓝色点缀（#0071e3）。
 * 系统字体栈，无外部字体请求；全响应式，320px 起可用。
 */
:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --ink: #1d1d1f;
  --muted: #6e6e73;
  --line: #e5e5ea;
  --accent: #0071e3;
  --accent-soft: #e8f1fc;
  --hl-yellow: rgba(255, 214, 64, 0.55);
  --radius: 14px;
  --topbar-h: 56px;
}
* { box-sizing: border-box; }
/* hidden 属性必须压过后面的 display 声明（如 .account form 的 flex），否则
   未登录时订单/兑换表单会在视觉上一直可见。 */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button {
  font: inherit; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 8px 16px;
}
button:hover { border-color: #c7c7cc; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: #0077ed; }
button.active { background: var(--ink); border-color: var(--ink); color: #fff; }
button.danger { color: #c00; }
button.mini { padding: 4px 10px; font-size: 13px; }
button:disabled { opacity: 0.45; cursor: not-allowed; }
input[type="text"], textarea {
  font: inherit; width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
}
.muted { color: var(--muted); font-size: 13px; }

/* ---------- 首页 ---------- */
.hero { max-width: 720px; margin: 0 auto; padding: 72px 20px 40px; text-align: center; }
.hero h1 { font-size: 40px; line-height: 1.2; margin: 12px 0; letter-spacing: -0.02em; }
.hero .sub { color: var(--muted); font-size: 17px; max-width: 520px; margin: 0 auto 28px; }
.hero-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.steps { max-width: 720px; margin: 0 auto; padding: 0 20px 16px; color: var(--muted); text-align: center; }
.features { max-width: 960px; margin: 24px auto; padding: 0 20px 32px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.feature { background: var(--surface); border-radius: var(--radius); padding: 20px; }
.feature h3 { margin: 0 0 6px; font-size: 16px; }
.feature p { margin: 0; color: var(--muted); font-size: 14px; }
.pricing { max-width: 960px; margin: 0 auto; padding: 0 20px 48px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.price-card { background: var(--surface); border-radius: var(--radius); padding: 24px; }
.price-card h3 { margin: 0 0 4px; }
.price-card .price { font-size: 28px; font-weight: 700; margin: 8px 0; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 14px 20px;
}
.topbar .brand { font-weight: 700; font-size: 18px; margin-right: auto; }
.topbar nav { display: flex; gap: 4px; align-items: center; }
.topbar nav a { color: var(--ink); padding: 6px 10px; border-radius: 999px; }
.topbar nav a:hover { background: #ececf1; }
.dropzone {
  max-width: 720px; margin: 0 auto 32px; padding: 0 20px;
}
.dropzone-inner {
  border: 2px dashed var(--line); border-radius: var(--radius);
  padding: 36px 20px; text-align: center; color: var(--muted); background: var(--surface);
}
.dropzone-inner.dragging, body.dragging .dropzone-inner { border-color: var(--accent); background: var(--accent-soft); }
footer { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 20px 48px; }

/* ---------- 阅读器 ---------- */
#reader-shell { display: flex; flex-direction: column; height: 100dvh; background: var(--bg); }
#reader-shell.dragging #scroller { outline: 2px dashed var(--accent); outline-offset: -8px; }
.reader-topbar {
  height: var(--topbar-h); flex: none;
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  background: rgba(255, 255, 255, 0.86); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line); z-index: 20;
  /* N3：顶栏永不纵向折行——按钮文字不换行、按钮不收缩，内容超宽时整条顶栏
     横向滚动（宽屏上内容放得下，不会出现滚动条）。 */
  overflow-x: auto; scrollbar-width: none;
}
.reader-topbar::-webkit-scrollbar { display: none; }
.reader-topbar > a, .reader-topbar > button { white-space: nowrap; flex: none; }
.reader-topbar .doc-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 30vw; min-width: 56px; flex-shrink: 1; }
.reader-topbar .spacer { flex: 1; }
.tool-group { display: flex; gap: 6px; flex: none; }
.tool-group button { padding: 7px 12px; white-space: nowrap; flex: none; }
#page-label { color: var(--muted); font-size: 13px; white-space: nowrap; flex: none; }
#scroller { flex: 1; overflow: auto; padding: 20px 12px 48px; -webkit-overflow-scrolling: touch; }
#pages { display: flex; flex-direction: column; align-items: center; }
.page-holder { margin: 0 auto 16px; background: #fff; box-shadow: 0 2px 16px rgba(0, 0, 0, 0.10); border-radius: 2px; width: 100%; max-width: 820px; }
.page { position: relative; width: 100%; height: 100%; overflow: hidden; background: #fff; touch-action: pan-y; }
.page canvas { display: block; width: 100%; height: 100%; }
.text-layer { position: absolute; inset: 0; overflow: hidden; line-height: 1; }
.text-layer span { color: transparent; position: absolute; white-space: pre; transform-origin: 0 0; }
.text-layer ::selection { background: rgba(0, 113, 227, 0.25); }
.anno-layer { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.anno-layer .hl { pointer-events: auto; }
.anno-layer .hl-yellow { fill: var(--hl-yellow); }
.anno-layer .hl-blue { fill: rgba(64, 156, 255, 0.4); }
.anno-layer .hl-green { fill: rgba(48, 209, 88, 0.4); }
.anno-layer .hl-red { fill: rgba(255, 69, 58, 0.35); }
.anno-layer .note-pin { pointer-events: auto; cursor: pointer; }
.anno-layer .note-pin circle { fill: var(--accent); }
.anno-layer .note-pin text { fill: #fff; font-size: 1.8px; text-anchor: middle; }
.anno-layer .pen-stroke { fill: none; stroke-width: 0.45; stroke-linecap: round; stroke-linejoin: round; }
.anno-layer .pen-blue { stroke: #0071e3; }
.anno-layer .pen-red { stroke: #ff3b30; }
.anno-layer .pen-green { stroke: #30d158; }
#side-panel {
  position: fixed; right: 12px; top: calc(var(--topbar-h) + 12px); width: 300px; max-width: calc(100vw - 24px);
  max-height: calc(100dvh - var(--topbar-h) - 24px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; z-index: 30; box-shadow: 0 8px 32px rgba(0, 0, 0, 0.14);
}
#side-panel h3 { margin: 4px 0 10px; font-size: 15px; }
.anno-row { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; flex-wrap: wrap; }
/* N4：批注行首栏（类型 · 第 n / m 页）不断行，超长时省略而不在页码中间断开；
   首栏与删除按钮都不收缩（删除按钮不许折成「删/除」两行），挤占的宽度由批注正文省略承担 */
.anno-row > span:first-child { white-space: nowrap; flex: none; order: 1; }
.anno-row button { flex: none; white-space: nowrap; order: 2; }
.anno-row span { overflow: hidden; text-overflow: ellipsis; }
/* D2（QA 二轮）：首栏 nowrap 后正文列只剩约 90px、逐字换行。改为正文独占第二行、
   全宽正常换行；删除按钮用 order 留在首行右侧（不掉到正文下方）；无正文
   （高亮/画笔）时空行不占位。 */
.anno-row .anno-text { flex: 1 1 100%; overflow: visible; text-overflow: clip; white-space: normal; word-break: break-word; order: 3; }
.anno-row .anno-text:empty { display: none; }
#note-panel {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  width: min(560px, calc(100vw - 24px)); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; z-index: 40;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.16);
}
#note-panel textarea { min-height: 72px; resize: vertical; margin-bottom: 10px; }
.note-actions { display: flex; gap: 8px; justify-content: flex-end; }
#empty-state { max-width: 560px; margin: 12vh auto 0; text-align: center; padding: 0 20px; }
#empty-state h2 { font-size: 24px; margin-bottom: 8px; }
#wechat-banner {
  margin: 12px; padding: 14px 16px; background: #fff8e1; border: 1px solid #f0d48a;
  border-radius: var(--radius);
}
#wechat-banner h3 { margin: 0 0 4px; font-size: 15px; }
#wechat-banner p { margin: 0 0 8px; font-size: 14px; }
#toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 14px; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
#status-line { text-align: center; color: var(--muted); font-size: 13px; padding: 8px; }
#sync-line, #quota-line { font-size: 13px; color: var(--muted); }

/* 伪全屏：iOS / 不支持真全屏时的全屏阅读模式 */
#reader-shell.pseudo-fullscreen {
  position: fixed; inset: 0; z-index: 50; height: 100dvh;
}
body.pseudo-fullscreen-on { overflow: hidden; }

/* ---------- 账号与购买 ---------- */
.account { max-width: 960px; margin: 0 auto; padding: 0 20px 48px; }
.account h2 { font-size: 24px; margin: 8px 0 12px; }
.account h3 { font-size: 16px; margin: 24px 0 8px; }
.account form { display: flex; flex-direction: column; gap: 10px; }
.account form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.account form label span { color: var(--muted); }
.account form button { align-self: flex-start; }
.account select {
  font: inherit; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink);
}
.auth-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.auth-grid form { background: var(--surface); border-radius: var(--radius); padding: 20px; }
.auth-grid form h3 { margin: 0 0 4px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table td, .mini-table th { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: left; word-break: break-all; }
#auth-msg, #order-msg, #redeem-msg { min-height: 1.4em; font-size: 14px; }
#auth-msg:empty, #order-msg:empty, #redeem-msg:empty { display: none; }
@media (max-width: 640px) {
  .auth-grid { grid-template-columns: 1fr; }
}

/* ---------- 响应式 ---------- */
@media (max-width: 834px) {
  .features { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 32px; }
  .hero { padding-top: 48px; }
  .reader-topbar .doc-title { max-width: 22vw; min-width: 56px; }
  .tool-group button { padding: 7px 9px; font-size: 13px; }
  /* N3：≤834px 顶栏不再纵向折行——整条顶栏单行横向滚动，按钮文字不换行，
     标题弹性省略但保留最小宽度（不被挤到 0 而消失），不再出现「缩/小」式断字。 */
  .reader-topbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .reader-topbar::-webkit-scrollbar { display: none; }
  .reader-topbar > a, .reader-topbar > button, #page-label { white-space: nowrap; flex: none; }
  .tool-group { flex: none; }
  .tool-group button { white-space: nowrap; }
}
@media (max-width: 390px) {
  .hero h1 { font-size: 28px; }
  .features { grid-template-columns: 1fr; }
  .pricing { grid-template-columns: 1fr; }
  .reader-topbar { flex-wrap: nowrap; height: var(--topbar-h); padding: 0 8px; row-gap: 6px; overflow-x: auto; }
  #scroller { padding: 12px 8px 40px; }
  #side-panel { top: auto; bottom: 12px; right: 12px; left: 12px; width: auto; max-height: 46dvh; }
}

/* 常驻播放条：触屏上原生 <audio> controls 只在 hover/focus 才出现，
   列表播放必须有常驻条，否则播着但无控制器（音频 POC §2.1）。 */
#audio-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96); border-top: 1px solid var(--line);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.08);
}
#audio-bar[hidden] { display: none; }
#audio-bar audio { flex: 1; min-width: 0; height: 36px; }
.audio-bar-title {
  max-width: 32vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 13px; color: var(--ink);
}
/* 播放条出现时给滚动区留底，避免遮住最后一页 */
body.has-audio-bar #scroller { padding-bottom: 64px; }
/* 降级提示：有音频注解但无可播资产（Flash 边车 / muLaw 等），永不静默空白 */
.audio-notice {
  color: #8e6d00; background: #fff8e1; border: 1px solid #ffe082;
  border-radius: 8px; padding: 8px 10px; font-size: 13px; line-height: 1.5;
}
#audio-downloads { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
#audio-downloads:empty { display: none; }
