/* ==========================================================================
   岸喵 · 可读性 & 三端适配层 (assets/ui.css)
   --------------------------------------------------------------------------
   本文件必须最后加载（排在 styles.css / tools.css / qb.css 之后）。
   它只解决三件事：看得清、点得准、不溢出。历史样式一律不动。

   1. 中文字体栈 + 全局字号开关（html[data-fontscale]）
   2. 中文标题取消负字距（原来 -0.055em 会把汉字挤成一团）
   3. 触摸目标 ≥44px、键盘焦点可见
   4. 三档断点：手机 ≤680 / 平板 681–1024 / 桌面 >1024
   5. iPhone 安全区、横屏矮屏、1051–1159px 网格失效修复
   ========================================================================== */

/* ========================== 1. 字体与字号开关 ========================== */
:root {
  --font-ui: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
             "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC",
             "WenQuanYi Micro Hei", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* 触摸目标下限 */
  --tap: 44px;
}

html {
  font-size: 16px;                          /* 全站字号基准，rem 全部挂在这里 */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: calc(var(--header, 64px) + 24px);
}
html[data-fontscale="lg"] { font-size: 17.4px; }   /* 大一档 ≈ +9%  */
html[data-fontscale="xl"] { font-size: 18.8px; }   /* 特大   ≈ +18% */

body {
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.7;
  overflow-wrap: break-word;
}
kbd, code, pre, samp, .tabular { font-family: var(--font-mono); }

/* ====================== 2. 中文标题不再挤压 ====================== */
.brand,
.section-heading h2,
.hero h1,
.stage-title h2,
.prose h1,
.prose h2,
.bank-hero h1,
.member-hero h1,
.dashboard-head h1,
.price strong,
.group-buy-copy h2,
.group-buy-price strong,
.refund-head h2,
.library-hero h1,
.tool-heading h1,
.catalog-hero h1,
.resource-hero h1,
.update-hero h1,
.reference-title strong,
.reference-title h1,
.reference-section-title h2,
.qb-hero h1,
.qb-stats strong {
  letter-spacing: -0.01em;
}

/* 正文段落行高：中文 1.8 最舒服，原样式多处是 1.7/1.75 甚至没设 */
p, li, dt, dd { line-height: 1.8; }
.hero-copy > p, .library-hero p, .section-heading p { line-height: 1.8; }

/* 长中文标题在窄屏不要强制不折行 */
h1, h2, h3 { overflow-wrap: break-word; word-break: break-word; }
h1, h2, h3 { text-wrap: pretty; }

/* ====================== 3. 触摸目标 & 焦点 ====================== */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 8px;
}
@media (pointer: coarse) {
  a, button, input, select, textarea, summary, label { touch-action: manipulation; }
  .icon-button, .menu-button { width: 42px; height: 42px; }
  .button,
  .account-bar-button,
  .qb-chip,
  .tool-sidebar button,
  .icon-button,
  .menu-button,
  .desktop-nav .nav-group > button,
  .account-chip { min-height: 42px; }
  .account-dropdown button,
  .account-dropdown a { min-height: 42px; display: flex; align-items: center; }
  .mobile-nav a { min-height: var(--tap); }
  /* 表单控件在 iOS 上小于 16px 会自动放大页面，必须顶到 16px */
  input, select, textarea { font-size: max(1rem, 16px); }
  /* 原生勾选框默认只有 13px，手指点不准 */
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; flex: none; }
}

/* 文本型链接：竖向热区补到 34px，别让手指点空 */
footer a,
.footer-grid a,
.footer-bottom a,
.panel-title a,
.breadcrumb a,
.brand { display: inline-flex; align-items: center; min-height: 34px; }
.brand { min-height: 40px; }

/* ====================== 4. 头部导航（手机 / 平板） ====================== */
@media (max-width: 1024px) {
  :root { --header: 116px; }
  .site-header { height: var(--header); }
  .nav-shell { height: 64px; gap: 14px; }
  .mobile-nav {
    top: 64px;
    height: 52px;
    padding-inline: max(14px, calc((100vw - 760px) / 2));
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
    /* 右侧渐隐，提示还能左右滑 */
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 26px), transparent 100%);
  }
  .mobile-nav a {
    min-width: 0;
    flex: 0 0 auto;
    padding: 15px 14px 12px;
    font-size: 0.9375rem;      /* 15px，原来只有 13px */
    scroll-snap-align: start;
  }
  .mobile-nav a:last-child { margin-right: 26px; }
  .account-chip { padding: 9px 12px; font-size: 0.9375rem; }

  /* 工具侧栏
     Bug 现场：小屏上它是一条横向滑条（display:flex + overflow-x:auto），
     三个分组 section 作为 flex 子项被压到 155px 宽，而内部按钮加起来 378px，
     于是按钮溢出分组盒子、互相叠在一起（"生词锦囊"和"计时助手"糊成一团）。
     这里改成整行换行的胶囊区：分组各占一行，按钮在行内换行，点得准也不重叠。 */
  .tool-sidebar {
    flex-wrap: wrap;
    align-content: flex-start;
    overflow: visible;
    gap: 10px;
    padding: 16px;
  }
  .tool-sidebar section { flex: 1 1 100%; flex-wrap: wrap; gap: 8px; margin: 0 0 2px; }
  .tool-sidebar button {
    flex: 0 0 auto;
    padding: 11px 14px;
    line-height: 1.3;
    white-space: nowrap;
    border: 1px solid var(--line);
    border-radius: 10px;
  }
  .tool-sidebar button.active { border-color: var(--primary); }
}

/* ====================== 5. 手机（≤680px） ====================== */
@media (max-width: 680px) {
  .page-shell { width: calc(100% - 32px); }

  /* 首屏标题原来 50px 起，手机上像喊口号；降到 34px 更耐看 */
  .hero h1 { font-size: 2.125rem; line-height: 1.24; margin: 14px 0 16px; }
  .hero { padding-top: 34px; }
  .hero-clear { gap: 26px; }
  .eyebrow { font-size: 0.8125rem; }

  .section-heading h2,
  .stage-title h2 { font-size: 1.5rem; }
  .library-hero h1,
  .tool-heading h1,
  .catalog-hero h1,
  .resource-hero h1,
  .update-hero h1,
  .bank-hero h1, .member-hero h1, .dashboard-head h1,
  .reference-title h1, .qb-hero h1 { font-size: 1.875rem; line-height: 1.25; }
  .prose h1 { font-size: 1.75rem; }
  .prose h2 { margin-top: 36px; font-size: 1.375rem; }
  .group-buy-price strong { font-size: 2.25rem; }
  .metric-grid strong { font-size: 1.625rem; }

  /* 两列比一列更适合手机：小卡片铺满整宽反而难扫读 */
  .quick-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .metric-grid { gap: 10px; }
  .feature-grid { padding-bottom: 56px; }
  .feature-grid article,
  .stage-grid > a { padding: 20px; }

  /* 学习中心四宫格：两行两列，避免单列拉得太长 */
  .bank-stat { flex-wrap: wrap; }
  .bank-stat div { min-width: calc(50% - 5px); }
  .practice-actions .button { min-width: 46%; }

  /* 权益对比表：手机上手势横滑，不再硬撑 720px */
  .compare-table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .compare-row { min-width: 540px; padding: 12px 14px; gap: 6px; font-size: 0.875rem; }
  .scroll-hint { display: block; }

  /* 题库 / 工具箱的筛选行：flex 子项默认 min-width:auto，会把容器撑破 */
  .qb-toolbar, .hw-toolbar, .wb-toolbar, .reading-toolbar,
  .filter-head, .filter-panel form { flex-wrap: wrap; gap: 10px; }
  .qb-search { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .qb-search > *, .hw-toolbar > *, .wb-toolbar > *,
  .reading-toolbar > *, .filter-head > * { min-width: 0; }
  .qb-search .qb-select, .qb-search .qb-input { flex: 1 1 132px; }
  .qb-toolbar > strong { width: 100%; }

  /* 学习记录：四列太长，改成「标题独占一行 + 三列明细」的卡片 */
  .history-table { font-size: 0.9375rem; }
  .history-table .history-row.head { display: none; }
  .history-row {
    min-width: 0;
    padding: 14px 2px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px 10px;
    align-items: baseline;
  }
  .history-row > span:first-child { grid-column: 1 / -1; }
  .history-row > span + span { font-size: 0.875rem; color: var(--muted); }

  /* 收藏/错题等长列表：给足行高，别挤在一起 */
  .favorite-item, .wrong-item, .dict-row { padding-block: 14px; }

  .search-panel { width: calc(100vw - 24px); }
  .search-panel > p { font-size: 0.8125rem; }
  .toast { width: calc(100% - 32px); text-align: center; font-size: 0.9375rem; }

  .docs-grid, .tool-shell { display: block; }
  .docs-sidebar, .tool-sidebar { border-bottom: 1px solid var(--line); }
}

/* 小屏手机：导航栏塞得下「品牌 + 账号 + 字号 + 主题」 */
@media (max-width: 430px) {
  .nav-shell { gap: 8px; }
  .brand { font-size: 1.125rem; gap: 8px; }
  .brand-mark { width: 30px; height: 30px; font-size: 1rem; border-radius: 9px 9px 12px 9px; }
  .account-chip { padding: 0 9px; font-size: 0.875rem; }
  .mobile-nav a { padding: 15px 12px 12px; }
  .page-shell { width: calc(100% - 26px); }
}

/* ====================== 6. 平板（681–1024px，含 iPad 竖屏） ======================
   原来的断点在 820px，iPad 竖屏（820）刚好落进手机布局，
   结果页面只有 680px 宽、工具按钮挤成一排还会重叠。这里给平板单独一档。 */
@media (min-width: 681px) and (max-width: 1024px) {
  .page-shell { width: min(100% - 48px, 780px); }
  .docs-grid, .tool-shell { grid-template-columns: 210px minmax(0, 1fr); }
  .tool-content, .docs-content { padding-inline: 28px; }

  .hero { padding-top: 44px; }
  .hero h1 { font-size: 2.875rem; line-height: 1.18; }
  .hero-clear { gap: 34px; }
  .hero-visual { min-height: 340px; }

  /* 手机上单列是对的，平板上两列才不浪费横向空间 */
  .feature-grid, .price-grid, .exam-grid, .resource-grid,
  .catalog-grid, .quick-grid, .stage-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .feature-grid { padding-bottom: 64px; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .footer-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }

  /* 工具侧栏的换行规则见上方 ≤1024 区块，这里只补间距 */
  .tool-sidebar { gap: 12px; padding: 18px; }

  .timer-layout, .checkin-layout { grid-template-columns: 1fr; }
  .math-problems { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .legal-page > aside { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .target-panel { grid-template-columns: 1fr; }
  .account-bar { align-items: stretch; }

  /* 对比表在平板上能放下了，保留完整矩阵 */
  .compare-row { min-width: 0; }
  .history-row { min-width: 0; }
}

/* ========== 7. 1051–1159px：原网格列宽算出来是负值，导致整条声明失效 ========== */
@media (min-width: 1051px) and (max-width: 1159px) {
  .docs-grid { grid-template-columns: 230px minmax(0, 1fr); }
  .tool-shell { grid-template-columns: 230px minmax(0, 1fr); }
  .docs-content, .tool-content { grid-column: 2; }
}

/* ========== 7.5 顶部导航的宽度预算 ==========
   结构对齐 saduck 之后有 8 个顶级项（含 4 个 emoji 与 2 个下拉箭头），比原来的一排长很多。
   与其到处改字号，不如让「搜索框」当那个可伸缩的元素：空间不够时先缩它，
   导航本身 flex:none 永不换行、永不溢出。 */
@media (min-width: 821px) {
  .brand, .nav-actions, .desktop-nav { flex: none; }
  .search-trigger { width: auto; flex: 1 1 150px; min-width: 132px; max-width: 260px; }
}

/* 821–1050：最挤的一档，导航再瘦一圈，并把 emoji 收起来（纯装饰，不影响识别） */
@media (min-width: 821px) and (max-width: 1050px) {
  .nav-shell { gap: 12px; }
  .desktop-nav { gap: 2px; }
  .desktop-nav a,
  .desktop-nav .nav-group > button { padding-inline: 6px; font-size: 0.875rem; }
  .desktop-nav [data-emoji]::before { content: none; }
}

/* ≥1280：留出舒服的呼吸感；字号调到「大 / 特大」时靠搜索框收缩吸收增量 */
@media (min-width: 1280px) {
  .nav-shell { gap: 14px; }
  .desktop-nav { gap: 2px; }
  .desktop-nav a,
  .desktop-nav .nav-group > button { padding-inline: 8px; }
}

/* 中等宽度（iPad 横屏 1180px 等）：桌面导航 + 搜索框 + 字号开关挤不进一行，
   字号调到「特大」时导航右侧会被顶出屏幕。这里给导航瘦身，并截断过长的昵称。 */
@media (min-width: 1051px) and (max-width: 1259px) {
  .nav-shell { gap: 14px; }
  .search-trigger em { font-size: 0.875rem; text-overflow: ellipsis; }
  .search-trigger kbd { display: none; }
  .desktop-nav { gap: 2px; }
  .desktop-nav a,
  .desktop-nav .nav-group > button { padding-inline: 8px; font-size: 0.875rem; }
  /* 这一档最挤，把导航 emoji 收起来（纯装饰，不影响识别） */
  .desktop-nav [data-emoji]::before { content: none; }
  .account-name { max-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ====================== 8. 横屏矮屏 & 安全区 ====================== */
@media (max-height: 520px) and (orientation: landscape) {
  .site-header { position: static; }
  .hero { min-height: auto; padding-top: 26px; }
  .hero-visual { min-height: 260px; }
}
@supports (padding: env(safe-area-inset-left)) {
  .nav-shell { padding-left: max(0px, env(safe-area-inset-left)); }
  @media (max-width: 680px) {
    .footer-bottom { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .toast { bottom: calc(28px + env(safe-area-inset-bottom)); }
    body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
  }
}

/* ====================== 9. 字号开关按钮 ====================== */
.scroll-hint {
  display: none;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8125rem;
  text-align: center;
}

.fontscale-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-2);
  font-size: 0.9375rem;
  font-weight: 800;
  letter-spacing: 0;
}
.fontscale-button:hover { background: var(--bg-soft); color: var(--primary); }
.fontscale-button > i {
  font-style: normal;
  font-size: 0.5625rem;
  font-weight: 700;
  line-height: 1;
  opacity: 0.75;
}

/* ==========================================================================
   X. 导航「零位移」层
   --------------------------------------------------------------------------
   顶部导航必须在首屏就画成最终样子，任何「先渲染、加载后由 JS 改写」都会造成
   整页跳动或标签换位。这里把两处以前由 JS 改文本的地方交给 CSS 按 html 上的
   状态属性渲染：
     · 主题图标  ← html[data-theme]      （app.js 只维护 aria-label）
     · 字号角标  ← html[data-fontscale]  （ui.js 只维护 title/aria-label）
   ========================================================================== */

[data-theme-toggle]::before { content: '☼'; }
html[data-theme="dark"] [data-theme-toggle]::before { content: '☾'; }

.fontscale-button > i::before { content: ''; }
html[data-fontscale="lg"] .fontscale-button > i::before { content: '+'; }
html[data-fontscale="xl"] .fontscale-button > i::before { content: '++'; }

/* 手机端没有横向导航，不需要为「账号入口宽度变化」预留位置，让按钮贴合内容省出空间 */
@media (max-width: 820px) {
  .account-chip { min-width: 0; }
}
@media (pointer: coarse) { .fontscale-button { width: 42px; height: 42px; } }

/* ====================== 10. 跨设备同步面板 ====================== */
.account-dropdown-sync {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--muted);
  font-size: 0.875rem;
}
.account-dropdown-sync span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sync-panel { display: grid; gap: 12px; }
.sync-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.sync-dot {
  width: 9px;
  height: 9px;
  flex: none;
  border-radius: 50%;
  background: var(--muted);
}
.sync-dot.is-ok { background: var(--green); }
.sync-dot.is-busy { background: var(--orange); animation: sync-pulse 1s ease-in-out infinite; }
.sync-dot.is-off { background: var(--muted); }
@keyframes sync-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.sync-panel p { margin: 0; color: var(--muted); font-size: 0.875rem; line-height: 1.75; }
.sync-devices { display: flex; gap: 8px; flex-wrap: wrap; }
.sync-devices span {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-2);
  font-size: 0.8125rem;
}
.sync-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* 爱发电自助开通：付款后没自动到账时手动补单 */
.afdian-claim { margin-top: 2rem; }
.claim-card {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 1.5rem;
  align-items: center;
  padding: 1.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 16px);
  background: var(--surface, #fff);
}
.claim-card h2 { margin: 0.25rem 0 0.5rem; font-size: 1.25rem; letter-spacing: -0.01em; }
.claim-card p { margin: 0; color: var(--text-2); }
.claim-form { display: flex; flex-direction: column; gap: 0.5rem; }
.claim-form label { font-size: 0.8125rem; color: var(--text-2); }
.claim-form input {
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg, #fff);
  color: var(--text-1, inherit);
  font-size: max(1rem, 16px);
}
.claim-form small { color: var(--text-2); font-size: 0.8125rem; line-height: 1.6; }
@media (max-width: 680px) {
  .claim-card { grid-template-columns: 1fr; gap: 1rem; }
}

/* 已是会员提示 + 付款流程说明 */
.member-banner {
  margin: 0 auto 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--green-600, #3b6d11);
  border-radius: var(--radius-lg, 16px);
  background: var(--green-50, #eaf3de);
  color: var(--green-800, #27500a);
  font-size: 0.9375rem;
  line-height: 1.6;
}
.pay-flow-note {
  margin: 0 auto 1.5rem;
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--orange, #d85a30);
  border-radius: 0 10px 10px 0;
  background: var(--orange-soft, #faece7);
  color: var(--text-2);
  font-size: 0.875rem;
  line-height: 1.7;
}
.pay-flow-note strong { color: var(--text-1, inherit); }
