/* ==========================================================================
 * 融·金融计算器 —— 站点样式（重构版）
 * --------------------------------------------------------------------------
 * 架构（自上而下，单向依赖，不再层层覆盖）：
 *   0  Token        设计令牌：颜色 / 间距 / 圆角 / 层级 / 断点策略
 *   1  Base         元素级基础样式
 *   2  Layout       页面骨架：容器、标题区、主导航、页面栈（pane）
 *   3  Surface      面：卡片、内嵌面、表单字段、网格、chip 行
 *   4  Component    组件：按钮、输入、表格、分页、键盘、弹层、历史
 *   5  State        状态：选中 / 胜负 / 显示隐藏（由 JS 切换类名）
 *   6  Theme        深色主题、打印、动效偏好
 *
 * 断点策略：
 *   主要 3 档 —— ≤639 手机（字号 / 触控目标 / 表格列宽）、≥768 平板（标题三栏、
 *   计算页两栏）、≥1024 桌面（吸底条让位）；
 *   另有 ≤900（隐藏快捷键提示、对比卡内下拉保持自身宽度）、系统深色、打印、
 *   减弱动效各 1 个。页面级间距与卡片内边距用 clamp + 容器查询单位连续变化，
 *   不依赖断点；.auto-grid-2 / .repay-grid 用 auto-fit + minmax 自适应列数。
 *   媒体查询合计 9 个（重构前 11 个，且其中 5 个是互相覆盖的 !important 补丁）。
 *
 * 约定：!important 只出现在三类地方 —— 全屏覆盖层（要压过 Tailwind 工具类）、
 *       显示切换 [class~="hidden"]（唯一出口，防止自定义 display 压掉 .hidden）、
 *       以及打印 / 深色 / 主题过渡 / 减弱动效这些需要覆盖全局的场合。
 *       JS 依赖的类名与 id 一律保持：hidden / soft-* / term-quick-btn /
 *       pag-btn / fs-overlay / fs-bar / fs-lock /
 *       history-* /
 *       keypad-* / numkey-* / winner / tie / table-row-* / compact-card 等。
 * ========================================================================== */

/* 字体改由 index.html 的 <link> 引入（此处不再写 CSS 的 @import 规则）：
   那条规则会让浏览器先下完本文件、解析到它才去请求字体，多一个串行往返，
   在移动端 / WebView 上是能明显感觉到的首屏延迟。preconnect 也一并放到了 HTML。 */

/* ============================ 0. 设计令牌 ============================ */
:root {
    /* 颜色：浅色 */
    --bg-body-start: #e0e5ec; --bg-body-mid: #f0f4f8; --bg-body-end: #e8eef4;
    --card-bg-start: #e6ebf2; --card-bg-end: #fff;
    --card-shadow-light: #cbd5e3; --card-shadow-dark: #fbfdff;
    --inset-shadow-light: #cbd5e3; --inset-shadow-dark: #fbfdff;
    --text-primary: #1b2432; --text-secondary: #46536b; --text-tertiary: #667386;
    --border-light: #e2e8f0;
    --table-stripe-even: #fff; --table-stripe-odd: #f7f9fc;
    --table-hover: #edf1fe;
    --input-bg-start: #e4e9f1; --input-bg-end: #fdfefe;
    --button-bg-start: #e4e9f1; --button-bg-end: #fdfefe;
    --button-primary-start: #667eea; --button-primary-end: #764ba2;
    --button-clear-start: #f56565; --button-clear-end: #e53e3e;
    --button-special-start: #ed8936; --button-special-end: #dd6b20;
    --button-operator-start: #667eea; --button-operator-end: #764ba2;
    --button-equal-start: #48bb78; --button-equal-end: #38a169;
    --dreamy-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    --error-text: #e53e3e;
    --toast-bg: #1f2937; --toast-text: #f9fafb;
    --tfoot-bg: #e5e7eb; --thead-bg: #d0d7de;
    --info-icon-color: #6b7280;
    --chart-text: #374151;
    --winner-color: #48bb78;
    --winner-bg: rgba(72, 187, 120, 0.08);
    --nav-bg-start: rgba(230, 235, 242, 0.88); --nav-bg-end: rgba(255, 255, 255, 0.88);
    --focus-ring: rgba(102, 126, 234, 0.3);
    --accent-red: #ef4444;

    /* 间距刻度：4 的倍数，页面级间距用容器查询单位连续变化 */
    --sp-1: 0.25rem; --sp-2: 0.5rem; --sp-3: 0.75rem; --sp-4: 1rem; --sp-5: 1.5rem;
    --gap-page: clamp(0.75rem, 2.5cqi + 0.35rem, 1.5rem);
    --gap-stack: clamp(0.5rem, 1.6cqi + 0.25rem, 1rem);
    --pad-card: clamp(0.8rem, 2.2cqi + 0.35rem, 1.25rem);
    --pad-field-y: 0.7rem;
    --pad-field-x: clamp(0.7rem, 2cqi + 0.25rem, 1rem);

    /* 圆角 / 阴影 */
    --radius-card: 20px; --radius-field: 12px; --radius-inner: 12px;
    --radius-pill: 999px;
    --shadow-card: 8px 8px 16px var(--card-shadow-light), -8px -8px 16px var(--card-shadow-dark);
    --shadow-card-sm: 5px 5px 10px var(--card-shadow-light), -5px -5px 10px var(--card-shadow-dark);
    --shadow-inset: inset 3px 3px 6px var(--inset-shadow-light), inset -3px -3px 6px var(--inset-shadow-dark);
    --shadow-inset-strong: inset 4px 4px 8px var(--inset-shadow-light), inset -4px -4px 8px var(--inset-shadow-dark);

    /* 层级（集中登记，避免各处硬编码互相打架） */
    --z-nav: 40; --z-sticky-bar: 9000; --z-keypad: 9500;
    --z-toast: 9999; --z-fullscreen: 10000; --z-fullscreen-close: 10001;
    --z-modal: 10050; --z-banner: 10100;

    /* 触控目标与观感尺寸 */
    --tap-min: 36px;

    /* 由 JS 回填的运行时量 */
    --nav-offset: 90px;
    --sticky-bar-h: 76px;

    /* 断点（media query 里无法用变量，此处仅作单一事实来源的文档）：
       手机 < 640 | 平板 >= 768 | 桌面 >= 1024 */
}

/* ============================ 1. 基础 ============================ */
* {
    font-family: 'Inter', sans-serif;
    -webkit-tap-highlight-color: transparent;
    box-sizing: border-box;
}

/* 容器查询上下文：页面级间距随容器宽度连续变化，不依赖视口断点 */
#app-shell { container-type: inline-size; }

html { scroll-padding-top: var(--nav-offset); }

body {
    background: linear-gradient(135deg, var(--bg-body-start), var(--bg-body-mid), var(--bg-body-end));
    min-height: 100vh; min-height: 100dvh;
    color: var(--text-primary);
    /* 状态栏避让：
       打包成 APK 后，壳若把状态栏画在 WebView 之上，而页面又拿不到安全区数值
       （env(safe-area-inset-top) 在多数 Android WebView 里返回 0，除非壳主动
       声明 edge-to-edge），标题与版本号就会被系统状态栏盖住。
       这里把"基线值 + 安全区"一起写进 max()：基线值不依赖 env()，因此在拿不到
       安全区的环境里也能保证至少让出 30px（约等于常见状态栏高度）；
       支持 env() 时自动取更大的那个，不会重复留白。 */
    padding-top: max(30px, calc(10px + env(safe-area-inset-top, 0px)));
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px));
    padding-left: max(var(--gap-page), env(safe-area-inset-left, 0px));
    padding-right: max(var(--gap-page), env(safe-area-inset-right, 0px));
    transition: background-color 0.3s, background 0.3s, color 0.3s;
}

/* 已安装到桌面 / 以 standalone 方式启动时，系统状态栏本身就不占页面空间，
   上面那 30px 基线会变成多余的空白。JS 检测到后给 html 加 fs-standalone。 */
html.fs-standalone body {
    padding-top: max(12px, calc(8px + env(safe-area-inset-top, 0px)));
}
html.fs-standalone .fs-overlay { margin-top: 0 !important; }
html.fs-standalone .fs-bar { padding-top: max(8px, env(safe-area-inset-top, 0px)); }

h1, h2, h3, h4 { line-height: 1.25; }

button:focus-visible, input:focus-visible, select:focus-visible, [tabindex]:focus-visible {
    outline: 2px solid var(--button-primary-start);
    outline-offset: 2px;
}

/* 显示切换的唯一出口：模块之间靠切换 Tailwind 的 .hidden 控制显隐，
   这里保证任何自定义规则（display:flex/grid 等）都不会把它压掉。 */
[hidden], [class~="hidden"] { display: none !important; }

/* ======================== 2. 页面骨架 ======================== */
/* 2.1 内容容器：唯一负责页面左右留白（body 只负责安全区） */
.app-container {
    width: 100%;
    max-width: 72rem;
    margin-inline: auto;
}

/* 2.2 顶部标题区：窄屏纵向堆叠，≥768px 三栏让标题落在真正的中线 */
.app-header {
    display: grid;
    grid-template-columns: 1fr;
    justify-items: center;
    gap: var(--sp-2);
    margin-bottom: var(--gap-page);
    text-align: center;
}
.app-header .brand { min-width: 0; }
.app-header .brand h1 { margin-bottom: var(--sp-1); }
.app-header .brand p {
    color: var(--text-tertiary);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.app-header .top-actions {
    display: flex; flex-wrap: nowrap; align-items: center;
    justify-content: center; gap: var(--sp-1);
}

/* 2.3 主导航：内容放得下就居中，放不下就横向滚动（不再用负外边距技巧） */
.nav-shell {
    position: sticky;
    top: max(var(--sp-2), env(safe-area-inset-top));
    z-index: var(--z-nav);
    margin-bottom: var(--gap-page);
    padding: var(--sp-1);
    border-radius: var(--radius-card);
    background: linear-gradient(145deg, var(--nav-bg-start), var(--nav-bg-end));
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: box-shadow 0.25s, border-radius 0.25s;
}
.nav-shell.is-stuck {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
    border-radius: 14px;
}
.nav-scroll {
    display: flex; gap: var(--sp-2);
    overflow-x: auto;
    scroll-behavior: smooth;
    scroll-snap-type: x proximity;
    padding: 2px;
    scrollbar-width: none; -ms-overflow-style: none;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}
.nav-scroll::-webkit-scrollbar { display: none; }
/* 内容比容器窄时居中；溢出时两端的 auto 外边距自动归零，滚动范围完整 */
.nav-scroll > * { flex: 0 0 auto; scroll-snap-align: start; white-space: nowrap; }
.nav-scroll > *:first-child { margin-left: auto; }
.nav-scroll > *:last-child { margin-right: auto; }

/* 2.4 页面（pane）：切换单位，统一垂直节奏 —— 取代每个 section 各写一条 animation。
   注意：整条选择器必须包在 :where() 里（特异性 0,0,0）。否则 .pane.space-y-6 这种
   (0,2,0) 的规则会压过 Tailwind 的 `.hidden { display:none }`（0,1,0），
   被 JS 加上 .hidden 的页面仍然会显示出来。 */
.pane { animation: sectionFade 0.28s ease; }
.pane + .pane { margin-top: var(--gap-page); }
:where(.pane.space-y-6, .pane.space-y-4, .pane.space-y-3, .pane.space-y-2) {
    display: flex; flex-direction: column;
}
:where(.pane.space-y-6) { gap: var(--gap-page); }
:where(.pane.space-y-4) { gap: var(--gap-stack); }
:where(.pane.space-y-3, .pane.space-y-2) { gap: var(--sp-3); }

/* 2.5 页内标题行（标题 + 右侧操作按钮） */
.pane-head {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
    gap: var(--sp-2);
    margin-bottom: var(--sp-4);
}
.pane-head h2, .pane-head h3 { margin: 0; }

/* ============================ 3. 面 ============================ */
/* 3.1 卡片 / 内嵌面 */
.soft-card {
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: var(--shadow-card);
    border-radius: var(--radius-card);
}
.soft-card-inset {
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: var(--shadow-inset-strong);
    border-radius: var(--radius-inner);
}
/* 卡片内边距：一处定义，取代原来 5 处媒体查询 !important 覆盖 */
.card { padding: var(--pad-card); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

/* 3.2 表单字段：标签 + 控件 + 提示 + 错误，统一节奏 */
.field { display: block; }
.field + .field { margin-top: var(--gap-stack); }
.field > label, .field > .field-label {
    display: block;
    margin-bottom: var(--sp-1);
    font-size: 0.875rem;
    color: var(--text-secondary);
}
/* 字段内部的纵向间隔（label 与控件之间由 label 的 margin-bottom 负责） */
.field .soft-input + .rate-note { margin-top: var(--sp-1); }

/* 3.3 网格：列数自适应，无断点 */
.auto-grid-2 {
    display: grid;
    /* 单列 → 双列的分界由可用宽度决定：≥400px 可用宽度时并排 */
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 13rem), 1fr));
    gap: var(--gap-stack);
}
.auto-grid-2.tight { gap: var(--sp-2); }
/* 对比页的 A/B 两列：始终尽量并排（同一项左右对照才有意义），
   只有实在放不下（<320px 可用宽度）才退回单列。 */
.auto-grid-2.compare-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 8.75rem), 1fr));
}

/* 还款方式 4 按钮：窄屏 2 列、宽屏 4 列，自适应 */
.repay-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 6rem), 1fr));
    gap: var(--sp-2);
}

/* 计算页参数区 / 结果区：窄屏单列，宽屏两栏等宽 */
.calc-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--gap-page);
}

/* 3.4 快捷 chip 行 */
.chip-row, .quick-chip-row {
    display: flex; flex-wrap: wrap;
    gap: 6px;
    margin-top: var(--sp-2);
}
.chip-row:first-child { margin-top: 0; }

/* 3.5 指标块：贷款总额 / 总利息 / 还款总额 / IRR 等小结果卡 */
.metric-card {
    padding: var(--sp-3) var(--sp-3);
    text-align: center;
}

/* 3.6 字段内的辅助文本 */
.field-hint { margin-top: var(--sp-1); font-size: 0.75rem; color: var(--text-tertiary); }
/* 通用弱化文字（取代散落的 inline style="color:var(--text-tertiary)"） */
.text-muted { color: var(--text-tertiary); }
.text-muted-sm { color: var(--text-tertiary); font-size: 0.75rem; }
.accent-text { color: var(--button-primary-start); }

/* 3.7 单选项行 */
.radio-row { display: flex; flex-wrap: wrap; gap: var(--sp-3); }
.radio-row label { display: inline-flex; align-items: center; gap: var(--sp-1); cursor: pointer; }

/* 3.8 分段区块：与上一块拉开固定距离（原 .mt-6 散落各处） */
.schedule-block { margin-top: var(--gap-page); }
.result-block { margin-top: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); }

/* 3.9 对比页专用：卡片内间距与并排间距 */
.compare-grid { margin-bottom: var(--gap-page); }
.compare-submit { margin-bottom: var(--gap-page); }

/* ============================ 4. 组件 ============================ */
/* 4.0 图标系统
   sprite 定义在 index.html 的 #icon-sprite，共用一个极简宿主样式：
   fill 透明 + stroke 用 currentColor，因此图标颜色永远跟随所在控件的文字颜色，
   深色主题无需额外规则。统一用 em 尺寸，跟着控件字号走。 */
#icon-sprite symbol {
    fill: none;
    stroke: currentColor;
    /* 16px 渲染时约 1.2px、19px 时约 1.4px —— 按实际像素定的值。
       原来 1.45 在 16px 下只有 ~0.97px，细到看不出轮廓（手机变实心块、太阳射线消失）。 */
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}
/* <use> 的影子树不继承 <symbol> 上的 fill/stroke（只有 presentation attribute 才会
   继承进影子树），于是 use 会拿到默认的 fill:black。现有图标刚好都是纯描边路径，
   黑填充看不见；一旦图标里出现实心形状就会渲染成黑块，描边也会被描成黑色而不是
   跟随按钮文字色。这里把两者钉在 use 上：它们会从 use 继承进影子树，
   颜色随之永远跟随所在控件的 currentColor。 */
.icon use {
    fill: none;
    stroke: currentColor;
}
.icon {
    width: 1.1em; height: 1.1em;
    flex: 0 0 auto;
    display: inline-block;
    vertical-align: -0.15em;
    pointer-events: none;
}
/* sprite 本体只提供 symbol 定义，不参与渲染 */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
/* 分段控件（主题三档）里的图标略大，与文字视觉重量一致 */
.seg-icon { font-size: 1.15rem; line-height: 1; }
/* noscript 提示里的警示图标 */
.icon-warn { font-size: 1.35rem; color: #b45309; vertical-align: -0.2em; }

/* 4.1 按钮 */
.soft-button {
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: var(--shadow-card-sm);
    border-radius: var(--radius-field);
    color: var(--text-primary);
}
.soft-button-primary {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    box-shadow: var(--shadow-card-sm);
    border-radius: var(--radius-field);
    color: #fff;
}
.soft-button-primary:disabled { opacity: 0.6; cursor: not-allowed; }
.soft-tab-active {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    box-shadow: var(--shadow-card-sm);
    /* 圆角必须自带：原来全靠 HTML 上的 rounded-xl 工具类，重构去掉那个类之后
       选中态的按钮就变成直角了（未选中的 .soft-button 有圆角，所以只有选中项显示异常）。 */
    border-radius: var(--radius-field);
    color: #fff;
}
.soft-button:active, .soft-button-primary:active, .soft-tab-active:active {
    box-shadow: var(--shadow-inset);
}
.reset-button {
    background: linear-gradient(145deg, var(--button-clear-start), var(--button-clear-end));
    color: #fff;
    padding: 0.35rem 1rem;
    border-radius: var(--radius-pill);
    font-size: 0.8rem;
    box-shadow: var(--shadow-card-sm);
}
.theme-toggle-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.35em;
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: 3px 3px 6px var(--card-shadow-light), -3px -3px 6px var(--card-shadow-dark);
    border-radius: var(--radius-pill);
    min-height: 34px;
    padding: 0.4rem 1rem;
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: nowrap;
}
/* 期限快捷按钮 */
.term-quick-btn {
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: 3px 3px 6px var(--card-shadow-light), -3px -3px 6px var(--card-shadow-dark);
    border-radius: var(--radius-pill);
    min-height: var(--tap-min);
    padding: 6px 14px;
    font-size: 0.95rem;
    white-space: normal; line-height: 1.35;
    color: var(--text-primary);
}
/* chip */
.quick-chip {
    display: inline-flex; align-items: center; justify-content: center;
    min-height: 30px;
    padding: 5px 12px;
    border: none; border-radius: var(--radius-pill);
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: 2px 2px 5px var(--card-shadow-light), -2px -2px 5px var(--card-shadow-dark);
    color: var(--text-secondary);
    font-family: inherit; font-size: 0.75rem; font-weight: 500;
    cursor: pointer; touch-action: manipulation;
    transition: transform 0.15s, box-shadow 0.15s;
}
.quick-chip:active {
    transform: scale(0.94);
    box-shadow: inset 2px 2px 4px var(--inset-shadow-light), inset -2px -2px 4px var(--inset-shadow-dark);
}
.quick-chip.active {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    color: #fff;
    box-shadow: 2px 2px 6px rgba(102, 126, 234, 0.4);
}
/* 场景模板 chip */
.scenario-chip {
    background: linear-gradient(145deg, rgba(102, 126, 234, 0.14), rgba(118, 75, 162, 0.14));
    color: var(--button-primary-start);
    font-weight: 600;
    border: 1px solid rgba(102, 126, 234, 0.25);
}
.scenario-chip:active {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    color: #fff;
}

/* 4.2 输入控件 */
.soft-input {
    background: linear-gradient(145deg, var(--input-bg-start), var(--input-bg-end));
    box-shadow: var(--shadow-inset);
    border: none;
    border-radius: var(--radius-field);
    color: var(--text-primary);
    padding: var(--pad-field-y) var(--pad-field-x);
    /* 文本控件默认的自动最小宽度（约 20 字符）会让同行输入框在窄屏拒绝收缩，
       把单位下拉挤出卡片并撑出整页横向滚动，故置 0。 */
    min-width: 0;
}
.soft-input:focus {
    outline: none;
    box-shadow: var(--shadow-inset-strong), 0 0 0 3px var(--focus-ring);
}
/* 同行内的单位下拉保持自身宽度，只压缩输入框 */
select.soft-input { flex-shrink: 0; }
/* 一行内的“输入框 + 单位下拉”：窄屏换行时下拉也占满整行 */
.input-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.input-row > .soft-input { flex: 1 1 8rem; }
.input-row > select.soft-input { flex: 0 1 auto; }
@media (max-width: 639px) {
    .input-row > .soft-input { flex: 1 1 100%; }
    .input-row > select.soft-input { flex: 1 1 100%; }
}

/* 4.3 分段控件（主题三档） */
#theme-segmented {
    padding: 4px;
    border-radius: var(--radius-pill);
    border: none;
    box-shadow: inset 2px 2px 5px var(--inset-shadow-light), inset -2px -2px 5px var(--inset-shadow-dark);
    background: linear-gradient(145deg, var(--input-bg-start), var(--input-bg-end));
    transition: background-color 0.3s, box-shadow 0.3s;
}
.segmented { display: flex; align-items: stretch; gap: 2px; }
.segmented > button {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    min-width: 48px; min-height: 34px;
    padding: 5px 10px;
    border: none; border-radius: var(--radius-pill);
    background: transparent; color: var(--text-secondary);
    font-family: inherit; font-size: 0.78rem; font-weight: 600; line-height: 1.1;
    white-space: nowrap; cursor: pointer;
    touch-action: manipulation;
    transition: background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease, transform 0.12s;
}
/* 重要操作按钮：图标与文字居中排布（原来靠 emoji + 空格，基线不齐） */
.btn-icon { display: inline-flex; align-items: center; justify-content: center; gap: 0.4em; }
.segmented > button span { text-shadow: none; }
.segmented > button:active { transform: scale(0.95); }
.segmented > button[aria-checked="true"], .segmented > button.active {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    color: #fff;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* 4.4 计算器按键 */
.calc-button {
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: 4px 4px 8px var(--card-shadow-light), -4px -4px 8px var(--card-shadow-dark);
    border-radius: var(--radius-field);
    font-weight: 600; color: var(--text-primary);
}
.calc-button-operator { background: linear-gradient(145deg, var(--button-operator-start), var(--button-operator-end)); color: #fff; }
.calc-button-equal    { background: linear-gradient(145deg, var(--button-equal-start), var(--button-equal-end)); color: #fff; }
.calc-button-clear    { background: linear-gradient(145deg, var(--button-clear-start), var(--button-clear-end)); color: #fff; }
.calc-button-special  { background: linear-gradient(145deg, var(--button-special-start), var(--button-special-end)); color: #fff; }

/* 4.5 还款计划表 */
.sticky-table-header th { position: sticky; top: 0; z-index: 10; background: var(--thead-bg); }
.thead-bg { background: var(--thead-bg); }
.tfoot-total { background: var(--tfoot-bg); font-weight: 700; }
.table-row-even { background: var(--table-stripe-even); }
.table-row-odd  { background: var(--table-stripe-odd); }
.table-row-even:hover, .table-row-odd:hover { background: var(--table-hover); }

/* 固定列宽布局：列宽由第一行（表头）的百分比决定，表头与数据行必然逐列对齐。
   之前用浏览器默认的自动列宽算法，它会按每行内容的自然宽度去凑列宽 ——
   表头是"期数 / 剩余本金"这类短词，数据行是"¥1,501.87"这类金额，两者自然
   宽度不同，算出来的列边界就会错开，看起来就是"标题和下面数字不齐"。
   （.sticky-table-header th 里的 sticky 需要 collapsed 边框才能正常吸附，
   放在 4.6 全屏区块旁的这条全局规则里一起声明。） */
#schedule-table-main, #reverse-schedule-table-main { table-layout: fixed; border-collapse: collapse; }
#schedule-table-main th, #schedule-table-main td,
#reverse-schedule-table-main th, #reverse-schedule-table-main td {
    text-align: center;
    padding: 6px 4px;
    vertical-align: middle;
}
/* 列宽写在表头单元格上：table-layout: fixed 时列宽就取自第一行，
   表头与数据行因此必然逐列对齐。
   期数 / 还款 / 本金 / 利息 / 剩余本金 */
#schedule-table-main th:nth-child(1), #reverse-schedule-table-main th:nth-child(1) { width: 15%; }
#schedule-table-main th:nth-child(2), #reverse-schedule-table-main th:nth-child(2) { width: 20%; }
#schedule-table-main th:nth-child(3), #reverse-schedule-table-main th:nth-child(3) { width: 21%; }
#schedule-table-main th:nth-child(4), #reverse-schedule-table-main th:nth-child(4) { width: 20%; }
#schedule-table-main th:nth-child(5), #reverse-schedule-table-main th:nth-child(5) { width: 24%; }
/* 表头：加字距让短标题在宽列里更居中可读 */
#schedule-table-main th, #reverse-schedule-table-main th { font-weight: 600; letter-spacing: 0.02em; }
/* 表格容器：上下留一点内边距，避免粘性表头/首行贴边被裁 */
.table-scroll { padding: 2px 0; }
/* 表格容器：横向滚动不带动整页 */
.table-scroll {
    overflow: auto;
    max-height: 24rem;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
}
.pag-btn {
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-primary);
    background: transparent;
    cursor: pointer;
}
.pag-btn.active { background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end)); color: #fff; }
.pagination { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-3); }
.jump-input-inline {
    width: 3rem; padding: 0.1rem 0.2rem; font-size: 0.75rem; text-align: center;
    background: linear-gradient(145deg, var(--input-bg-start), var(--input-bg-end));
    box-shadow: inset 1px 1px 2px var(--inset-shadow-light), inset -1px -1px 2px var(--inset-shadow-dark);
    border: none; border-radius: 0.25rem; color: var(--text-primary);
}
.jump-btn {
    padding: 0.15rem 0.6rem; font-size: 0.75rem;
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    color: #fff; border: none; border-radius: 0.25rem; cursor: pointer;
}

/* 4.6 全屏还款计划（门户式覆盖层）
   ------------------------------------------------------------------
   历史教训：这个全屏功能在安卓 WebView 上反复出问题（荣耀机型尤甚），
   根因都是同一类 —— flex 布局不生效、CSS 变量支持不全、dvh/vh 与
   calc(env(...)) 解析异常、以及原卡片上的 .soft-card/.card 内边距规则
   在铺满时把表格挤没。

   最终方案：进入全屏时把 .table-scroll（连表格本体）搬进一个新建的
   覆盖层，退出再放回原处。覆盖层与表格区的关键尺寸由 JS 写成内联像素值，
   这里的规则只是兜底与观感；不依赖 flex、不依赖视口单位、不依赖变量解析。
   ------------------------------------------------------------------ */
.fs-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 100000;
    background: var(--card-bg-end, #fff);
    color: var(--text-primary, #1b2432);
    overflow: hidden;
}
/* 标题栏：普通块级元素，高度固定，关闭按钮在它内部绝对定位。
   顶部同样让出状态栏：基线值不依赖 env()，拿不到安全区的 WebView 也能让出
   约 30px，否则 ✕ 会被系统状态栏盖住点不到。 */
.fs-bar {
    box-sizing: border-box;
    min-height: 52px;
    padding-top: max(8px, calc(2px + env(safe-area-inset-top, 0px)));
    padding-left: 12px;
    padding-right: 60px;
    font-size: 15px;
    font-weight: 600;
    line-height: 40px;
    border-bottom: 1px solid var(--border-light, #e2e8f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* 全屏覆盖层里的表格区。
   top 由 JS 写入 --fs-top（基线 52px，等于标题栏高度），这里再叠加安全区：
   env() 只能写在 CSS 里，JS 读不到，所以分工为"JS 给基线、CSS 加安全区"。
   env() 返回 0（多数 Android WebView）时结果就是基线值，依然正确。 */
.fs-overlay .table-scroll {
    position: absolute;
    top: var(--fs-top, 52px);
    top: calc(var(--fs-top, 52px) + env(safe-area-inset-top, 0px));
    left: 0;
    right: 0;
    bottom: auto;
    margin: 0;
    padding: 0;
    max-height: none;
    overflow: auto;
    background: var(--card-bg-end, #fff);
    z-index: 1;
}
/* 全屏时锁住背后页面的滚动，避免"滑到底看到下面的按钮"。
   html 与 body 一起锁：只锁 body 时，部分 WebView 仍会滚动 <html>，
   body 的 top 偏移就白设了。 */
html.fs-lock { position: fixed; width: 100%; overflow: hidden; }
body.fs-lock {
    position: fixed;
    left: 0; right: 0;
    width: 100%;
    overflow: hidden !important;
}

/* 4.7 提示 / 说明 / 错误 */
.rate-note { font-size: 0.7rem; color: var(--text-tertiary); margin-top: var(--sp-1); }
.error-message {
    color: var(--error-text);
    font-size: 0.75rem;
    margin-left: var(--sp-2);
    margin-top: 0.2rem;
    min-height: 1.5rem;
}
.info-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px; margin-left: 4px;
    border-radius: 50%;
    background: var(--info-icon-color); color: #fff;
    font-size: 12px; font-weight: 700;
    cursor: pointer; user-select: none;
}
.tooltip-container { position: relative; display: inline-block; }
.tooltip-text {
    position: absolute;
    width: 220px; margin-left: -110px; bottom: 125%; left: 50%;
    z-index: 10;
    padding: 8px 12px;
    border-radius: 8px;
    background: var(--toast-bg); color: var(--toast-text);
    font-size: 0.8rem; font-weight: 400; text-align: left;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    visibility: hidden; opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.tooltip-container:hover .tooltip-text, .tooltip-text.show { visibility: visible; opacity: 1; }
.conclusion-box {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08), rgba(72, 187, 120, 0.08));
    border-left: 4px solid var(--button-primary-start);
    border-radius: 8px;
    padding: var(--sp-3) var(--sp-4);
    font-size: 0.9rem; line-height: 1.6;
}
/* 差异分析三行 */
.diff-list > div { padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-inner); }

/* 计算器页：窄屏占满，宽屏居中且不拉太宽 */
.calc-tool-card { width: 100%; max-width: 28rem; margin-inline: auto; }
.calc-display-box { padding: var(--sp-4); margin-bottom: var(--sp-4); }
/* 勾选项：整个 label 可点，触控目标足够大 */
.check-target {
    display: inline-flex; align-items: center; gap: var(--sp-2);
    min-height: var(--tap-min);
    padding: 4px 10px;
    border-radius: 10px;
    cursor: pointer;
}
.check-target input[type="checkbox"] {
    width: 18px; height: 18px; margin: 0;
    accent-color: var(--button-primary-start);
}

/* 4.8 图标式切换按钮（性别等） */
.icon-toggle-row { display: flex; gap: var(--sp-2); }
.icon-toggle {
    flex: 1;
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: var(--shadow-card-sm);
    border-radius: var(--radius-field);
    color: var(--text-secondary);
    padding: 0.5rem 0.75rem;
}
.icon-toggle.active {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    color: #fff;
}

/* 4.9 历史记录 */
.history-item {
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: var(--shadow-card-sm);
    border-radius: 14px;
    transition: box-shadow 0.25s, transform 0.25s;
}
.history-item:active { transform: scale(0.985); }
.history-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 0.68rem; font-weight: 600; line-height: 1.5;
    color: #fff;
}
.history-badge.standard   { background: linear-gradient(135deg, #667eea, #764ba2); }
.history-badge.reverse    { background: linear-gradient(135deg, #ed8936, #dd6b20); }
.history-badge.comparison { background: linear-gradient(135deg, #48bb78, #38a169); }
.history-metric {
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: inset 2px 2px 5px var(--inset-shadow-light), inset -2px -2px 5px var(--inset-shadow-dark);
    border-radius: 10px;
    padding: 6px 8px;
}
.history-act-btn {
    min-height: var(--tap-min);
    padding: 4px 10px;
    border: none; border-radius: var(--radius-pill);
    font-size: 0.72rem; white-space: nowrap; cursor: pointer;
    transition: opacity 0.2s, box-shadow 0.2s;
}
.history-act-btn:active { opacity: 0.75; }
.history-act-restore {
    background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end));
    color: #fff;
    box-shadow: 2px 2px 5px var(--card-shadow-light), -2px -2px 5px var(--card-shadow-dark);
}
.history-act-delete {
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    color: var(--text-secondary);
    box-shadow: 2px 2px 5px var(--card-shadow-light), -2px -2px 5px var(--card-shadow-dark);
}

/* 4.10 移动端数字键盘 */
.mobile-keypad {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: var(--z-keypad);
    max-width: 560px; margin-inline: auto;
    padding: var(--sp-3) 10px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.22);
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    transform: translateY(110%);
    visibility: hidden;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0.3s;
    user-select: none; -webkit-user-select: none;
    touch-action: manipulation;
}
.mobile-keypad.show {
    transform: translateY(0); visibility: visible;
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s linear 0s;
}
.keypad-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: var(--sp-3);
    padding: 2px var(--sp-2) var(--sp-3);
}
.keypad-label { font-size: 0.8rem; color: var(--text-tertiary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.keypad-value {
    flex: 1; min-width: 0;
    font-size: 1.35rem; font-weight: 700; color: var(--text-primary);
    text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.keypad-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-2); }
/* 计算器页的按键板：按键更矮、圆角更小，与移动键盘区分开 */
.calc-tool-card .calc-button { min-height: 44px; }
.keypad-key {
    height: 52px;
    border: none; border-radius: var(--radius-field);
    font-family: inherit; font-size: 1.2rem; font-weight: 600;
    color: var(--text-primary);
    background: linear-gradient(145deg, var(--button-bg-start), var(--button-bg-end));
    box-shadow: 3px 3px 6px var(--card-shadow-light), -3px -3px 6px var(--card-shadow-dark);
    cursor: pointer;
    transition: box-shadow 0.12s, transform 0.12s;
    touch-action: manipulation;
}
.keypad-key:active {
    box-shadow: var(--shadow-inset);
    transform: translateY(1px) scale(0.97);
}
.keypad-key.key-fn    { color: var(--button-special-start); font-size: 1.3rem; }
.keypad-key.key-clear { color: var(--button-clear-start); }
.keypad-key.key-wan   { background: linear-gradient(145deg, var(--button-special-start), var(--button-special-end)); color: #fff; }
.keypad-key.key-done  { background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end)); color: #fff; font-size: 1rem; }
.numkey-field { cursor: pointer; }
.numkey-active { box-shadow: inset 4px 4px 8px var(--inset-shadow-light), inset -4px -4px 8px var(--inset-shadow-dark), 0 0 0 3px rgba(102, 126, 234, 0.35); }

/* 4.11 数据管理弹层 */
.data-modal {
    position: fixed; inset: 0;
    z-index: var(--z-modal);
    display: none; align-items: center; justify-content: center;
    padding: var(--sp-4);
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity 0.25s;
}
.data-modal.show { display: flex; opacity: 1; }
.data-modal-panel {
    width: 100%; max-width: 400px;
    padding: var(--sp-5);
    border-radius: var(--radius-card);
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: 12px 12px 30px rgba(0, 0, 0, 0.35);
    transform: scale(0.95) translateY(10px);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.data-modal.show .data-modal-panel { transform: scale(1) translateY(0); }

/* 4.12 网络状态 / 更新提示 / toast */
.net-status {
    display: inline-block; flex-shrink: 0;
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #48bb78;
    box-shadow: 0 0 0 3px rgba(72, 187, 120, 0.2);
    transition: background 0.3s, box-shadow 0.3s;
}
.net-status.offline { background: #9ca3af; box-shadow: 0 0 0 3px rgba(156, 163, 175, 0.2); }
.toast {
    position: fixed;
    bottom: calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
    left: 50%; transform: translateX(-50%);
    z-index: var(--z-toast);
    max-width: 90%;
    padding: 12px 24px;
    border-radius: var(--radius-pill);
    background: var(--toast-bg); color: var(--toast-text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transition: opacity 0.3s;
    pointer-events: none;
}
.toast.show { opacity: 1; }
.update-banner {
    position: fixed;
    top: calc(var(--sp-3) + env(safe-area-inset-top, 0px));
    left: 50%; transform: translateX(-50%);
    z-index: var(--z-banner);
    display: flex; align-items: center; gap: var(--sp-3);
    max-width: 92vw;
    padding: 10px var(--sp-4);
    border-radius: var(--radius-pill);
    background: var(--toast-bg); color: var(--toast-text);
    font-size: 0.85rem;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
    animation: updateSlide 0.3s ease;
}
.update-banner button { border: none; border-radius: 20px; padding: 4px 12px; font-size: 0.8rem; white-space: nowrap; cursor: pointer; }
.update-banner #update-refresh-btn { background: linear-gradient(145deg, var(--button-primary-start), var(--button-primary-end)); color: #fff; }
.update-banner #update-later-btn { background: transparent; color: var(--toast-text); font-size: 1rem; padding: 0 4px; }
@keyframes updateSlide {
    from { transform: translateX(-50%) translateY(-20px); opacity: 0; }
    to   { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* 版本号徽标：显示当前跑的是哪一版。
   排查"改了没生效"时最有用 —— 不用猜是没传上去、还是 Service Worker 缓存了旧版。
   取到 version.json 才有内容，取不到就保持空白不占位。 */
.app-version {
    font-size: 0.62rem;
    line-height: 1.2;
    color: var(--text-tertiary);
    white-space: nowrap;
    padding: 2px 6px;
    border-radius: var(--radius-pill);
    background: rgba(127, 127, 127, 0.12);
    max-width: 9.5rem;
    overflow: hidden; text-overflow: ellipsis;
}
.app-version:empty { display: none; }

/* 4.13 吸底结果条（窄屏显示，桌面隐藏） */
.sticky-result-bar {
    position: fixed;
    left: var(--sp-2); right: var(--sp-2);
    bottom: calc(var(--sp-2) + env(safe-area-inset-bottom));
    z-index: var(--z-sticky-bar);
    max-width: 560px; margin-inline: auto;
    display: flex; align-items: center; gap: var(--sp-2);
    padding: 10px 14px;
    border-radius: 16px;
    background: linear-gradient(145deg, var(--card-bg-start), var(--card-bg-end));
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18), 0 4px 10px rgba(0, 0, 0, 0.10);
    transform: translateY(130%);
    transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
    pointer-events: none;
}
.sticky-result-bar.show { transform: translateY(0); pointer-events: auto; }
.sticky-result-bar .metric { flex: 1; min-width: 0; text-align: center; }
.sticky-result-bar .metric .label { font-size: 0.68rem; color: var(--text-tertiary); line-height: 1.2; }
.sticky-result-bar .metric .value { font-size: 0.98rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sticky-result-bar .metric .value.accent { color: var(--accent-red); }

/* 4.14 快捷键提示条 */
#keyboard-hint {
    margin-top: var(--sp-2);
    font-size: 0.68rem; color: var(--text-tertiary); text-align: center; line-height: 1.5;
}
#keyboard-hint kbd {
    display: inline-block; margin: 0 1px; padding: 1px 6px;
    border-radius: 4px;
    background: var(--card-bg-start); color: var(--text-secondary);
    font-family: inherit; font-size: 0.68rem;
    box-shadow: 0 1px 2px var(--card-shadow-light), inset 0 -1px 0 var(--card-shadow-light);
}

/* ============================ 5. 状态 ============================ */
.dreamy-gradient {
    background: var(--dreamy-gradient);
    -webkit-background-clip: text; background-clip: text;
    -webkit-text-fill-color: transparent;
}
.result-highlight { background: linear-gradient(135deg, rgba(102, 126, 234, 0.1), rgba(118, 75, 162, 0.1)); }
.comp-card { position: relative; transition: box-shadow 0.3s, border-color 0.3s; }
.comp-card.winner {
    border-color: var(--winner-color) !important;
    background: linear-gradient(145deg, var(--winner-bg), transparent);
}
.comp-card.winner::after,
.comp-card.tie::after {
    position: absolute; top: -10px; right: 12px;
    padding: 2px 10px;
    border-radius: var(--radius-pill);
    color: #fff; font-size: 0.7rem; font-weight: 600;
}
.comp-card.winner::after { content: '更优'; background: var(--winner-color); }
.comp-card.tie::after { content: '持平'; background: var(--text-tertiary); }

/* 按压反馈 */
.term-quick-btn, .history-item {
    transition: box-shadow 0.3s, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.3s;
}
.term-quick-btn:active { transform: scale(0.94); }
.calc-button, .soft-button, .soft-button-primary, .keypad-key { will-change: transform; }
.calc-button:active, .soft-button:active, .soft-button-primary:active,
.reset-button:active, .pag-btn:active, .history-act-btn:active { transform: scale(0.97); }

/* 主按钮点击后的一次性脉冲 */
@keyframes btnPulse {
    from { box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.5); }
    to   { box-shadow: 0 0 0 14px rgba(102, 126, 234, 0); }
}
.btn-pulse { animation: btnPulse 0.5s ease-out; }

/* 页面切换淡入。
   注意：不能加 fill-mode（both / forwards）。动画结束后 Chrome 会把 transform 保持在
   identity 矩阵（非 none），使该元素成为内部 position:fixed 元素的包含块 —— 还款计划的
   “全屏展开”会因此相对 section 定位，右侧伸出屏幕。不加 fill-mode 即恢复 transform:none。 */
@keyframes sectionFade {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: none; }
}

/* 底部占位：键盘 / 吸底结果条都是 fixed，需要按实际高度让出空间 */
body.keypad-open { padding-bottom: calc(var(--keypad-h, 320px) + var(--sp-4)); }
body.sticky-open:not(.keypad-open) {
    padding-bottom: calc(var(--sticky-bar-h, 76px) + var(--sp-3) + env(safe-area-inset-bottom, 0px));
}
body.keypad-open .sticky-result-bar { transform: translateY(130%); pointer-events: none; }

/* ============================ 6. 主题与适配 ============================ */
/* 6.1 深色主题 */
[data-theme="dark"] {
    --bg-body-start: #12161b; --bg-body-mid: #1e2630; --bg-body-end: #1a1f29;
    --card-bg-start: #252f3c; --card-bg-end: #1a222e;
    --card-shadow-light: #0a0e14; --card-shadow-dark: #333d4d;
    --inset-shadow-light: #0a0e14; --inset-shadow-dark: #333d4d;
    --text-primary: #f5f7fa; --text-secondary: #d8dee8; --text-tertiary: #a9b3c2;
    --border-light: #46536b;
    --table-stripe-even: #1e2634; --table-stripe-odd: #29323f;
    --table-hover: #35404f;
    --input-bg-start: #2b3444; --input-bg-end: #1c232e;
    --button-bg-start: #2b3444; --button-bg-end: #1c232e;
    --button-primary-start: #5a67d8; --button-primary-end: #6b46c1;
    --button-clear-start: #c53030; --button-clear-end: #9b2c2c;
    --button-special-start: #c05621; --button-special-end: #9c4221;
    --button-operator-start: #5a67d8; --button-operator-end: #6b46c1;
    --button-equal-start: #2f855a; --button-equal-end: #276749;
    --dreamy-gradient: linear-gradient(135deg, #a3bffa 0%, #b794f4 50%, #fbb6ce 100%);
    --error-text: #f87171;
    --toast-bg: #2d3748; --toast-text: #f3f4f6;
    --tfoot-bg: #374151; --thead-bg: #2d3748;
    --info-icon-color: #cbd5e0;
    --chart-text: #e5e7eb;
    --winner-color: #48bb78;
    --winner-bg: rgba(72, 187, 120, 0.12);
    --nav-bg-start: rgba(43, 52, 68, 0.92); --nav-bg-end: rgba(28, 35, 46, 0.92);
    /* 深色下拉开内嵌控件的明暗差，否则浅阴影消失在深色背景里 */
    --inset-flat: inset 2px 2px 5px rgba(0, 0, 0, 0.55), inset -2px -2px 5px rgba(255, 255, 255, 0.06);
}
[data-theme="dark"] #theme-segmented { box-shadow: var(--inset-flat); }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --bg-body-start: #12161b; --bg-body-mid: #1e2630; --bg-body-end: #1a1f29;
        --card-bg-start: #252f3c; --card-bg-end: #1a222e;
        --card-shadow-light: #0a0e14; --card-shadow-dark: #333d4d;
        --inset-shadow-light: #0a0e14; --inset-shadow-dark: #333d4d;
        --text-primary: #f5f7fa; --text-secondary: #d8dee8; --text-tertiary: #a9b3c2;
        --border-light: #46536b;
        --table-stripe-even: #1e2634; --table-stripe-odd: #29323f;
        --table-hover: #35404f;
        --input-bg-start: #2b3444; --input-bg-end: #1c232e;
        --button-bg-start: #2b3444; --button-bg-end: #1c232e;
        --button-primary-start: #5a67d8; --button-primary-end: #6b46c1;
        --button-clear-start: #c53030; --button-clear-end: #9b2c2c;
        --button-special-start: #c05621; --button-special-end: #9c4221;
        --button-operator-start: #5a67d8; --button-operator-end: #6b46c1;
        --button-equal-start: #2f855a; --button-equal-end: #276749;
        --dreamy-gradient: linear-gradient(135deg, #a3bffa 0%, #b794f4 50%, #fbb6ce 100%);
        --error-text: #f87171;
        --toast-bg: #2d3748; --toast-text: #f3f4f6;
        --tfoot-bg: #374151; --thead-bg: #2d3748;
        --info-icon-color: #cbd5e0;
        --chart-text: #e5e7eb;
        --winner-color: #48bb78;
        --winner-bg: rgba(72, 187, 120, 0.12);
        --nav-bg-start: rgba(43, 52, 68, 0.92); --nav-bg-end: rgba(28, 35, 46, 0.92);
        --inset-flat: inset 2px 2px 5px rgba(0, 0, 0, 0.55), inset -2px -2px 5px rgba(255, 255, 255, 0.06);
    }
    :root:not([data-theme]) #theme-segmented { box-shadow: var(--inset-flat); }
}

/* 6.2 主题切换时的颜色过渡（只在切换瞬间挂到 html 上，不常驻全站 transition） */
html.theme-anim, html.theme-anim body,
html.theme-anim .soft-card, html.theme-anim .soft-card-inset, html.theme-anim .soft-input,
html.theme-anim .soft-button, html.theme-anim .soft-button-primary, html.theme-anim .soft-tab-active,
html.theme-anim .calc-button, html.theme-anim .term-quick-btn, html.theme-anim .quick-chip,
html.theme-anim .nav-shell, html.theme-anim .mobile-keypad, html.theme-anim .data-modal-panel,
html.theme-anim .segmented > button, html.theme-anim .keypad-key, html.theme-anim #theme-segmented {
    transition: background-color 0.3s ease, background 0.3s ease,
                color 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease !important;
}

/* 6.3 平板及以上：标题区三栏 + 计算页两栏 + 窄屏让位结束 */
@media (min-width: 768px) {
    .app-header {
        grid-template-columns: 1fr auto 1fr;
        justify-items: stretch;
    }
    .app-header .brand { grid-column: 2; justify-self: center; }
    .app-header .top-actions { grid-column: 3; justify-self: end; }
    .calc-layout { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1024px) {
    .sticky-result-bar { display: none; }
    body.sticky-open { padding-bottom: 0; }
}
@media (max-width: 900px) {
    #keyboard-hint { display: none; }
}

/* 6.4 手机：只保留“离散跳变”的量（字号、表格列宽、触控目标），间距交给 clamp */
@media (max-width: 639px) {
    .app-header .brand h1 { font-size: 1.5rem; }
    .app-header .brand p { font-size: 0.85rem; }
    .app-header .top-actions { gap: 2px; }
    #top-actions #pwa-install-btn { padding: 4px 8px; min-height: 34px; }
    #top-actions #pwa-install-btn span:last-child { display: none; }
    #theme-segmented { padding: 3px; }
    .segmented > button { min-width: 44px; min-height: 40px; padding: 6px 8px; }

    /* 关键操作目标不小于 40px */
    .reset-button, .history-act-btn { min-height: 32px; padding: 6px 12px; }
    .soft-button, .soft-tab-active, .soft-button-primary { min-height: 40px; }
    .quick-chip, .term-quick-btn { min-height: 34px; }
    .check-target { min-height: var(--tap-min); }

    /* 输入框字号 ≥16px，避免 iOS 聚焦时自动放大 */
    .soft-input, input.soft-input, select.soft-input { font-size: 16px; }

    /* 还款计划表：窄屏压字号与列宽，让 5 列同屏。
       固定列宽下金额若超出列宽会被压扁换行，所以字号比原来再收一档，
       并禁止换行（列宽已由表头的百分比定死，靠缩字号来适配）。 */
    #schedule-table-container, #reverse-schedule-table-container { padding: var(--sp-2); }
    #schedule-table-main th, #schedule-table-main td,
    #reverse-schedule-table-main th, #reverse-schedule-table-main td {
        font-size: 0.62rem; padding: 4px 2px; white-space: nowrap;
    }
    #schedule-table-main th, #reverse-schedule-table-main th { padding: 6px 2px; font-size: 0.62rem; }
    #schedule-table-main .flex.gap-2 button, #reverse-schedule-table-main .flex.gap-2 button { font-size: 0.6rem; padding: 0.2rem 0.4rem; }
    #schedule-pagination .pag-btn, #reverse-schedule-pagination .pag-btn { font-size: 0.7rem; padding: 2px 6px; }
    .jump-input-inline { width: 2rem; font-size: 0.65rem; }
    .jump-btn { font-size: 0.65rem; padding: 0.1rem 0.4rem; }
    /* 长屏手机上把表格可视区放到 60vh，但绝不低于原来的 24rem（短屏/横屏保持原状） */
    .table-scroll { max-height: max(24rem, 60vh); }

    .keypad-key { height: 48px; font-size: 1.1rem; }
    .keypad-value { font-size: 1.15rem; }
}

/* 6.5 对比页并排卡片：可用宽度不足时自动退回单列（见 .auto-grid-2） */
.compact-card { padding: 0.7rem; }
.compact-card h3 { margin-bottom: var(--sp-2); font-size: 1rem; }
.compact-card .field + .field { margin-top: var(--sp-3); }
.compact-card .quick-chip { font-size: 0.72rem; padding: 5px 9px; }
.compact-card .rate-note { font-size: 0.65rem; line-height: 1.35; }
.compact-card .error-message { margin-left: 0; font-size: 0.68rem; min-height: 1.1rem; }
/* 并排两列时，单位下拉保持自身宽度（不跟着占满整行），否则一列里会出现两条通栏控件 */
@media (max-width: 900px) {
    .compact-card .input-row > .soft-input { flex: 1 1 100%; }
    .compact-card .input-row > select.soft-input { flex: 0 1 auto; }
}

/* ============================ 7. 打印 / 无障碍 ============================ */
@media print {
    #theme-segmented, .reset-button, .soft-button, .soft-button-primary,
    #schedule-pagination, #reverse-schedule-pagination, #payment-chart,
    #reverse-payment-chart, #irr-container, #reverse-irr-container,
    .toast, .fs-bar, #history-section, #mobile-keypad,
    .data-modal, .update-banner, #pwa-install-btn, #net-status, #scenario-row,
    #keyboard-hint, .sticky-result-bar, .nav-shell {
        display: none !important;
    }
    body { background: #fff !important; color: #000 !important; }
    .soft-card, .soft-card-inset {
        box-shadow: none !important;
        border: 1px solid #ccc !important;
        background: #fff !important;
    }
    .dreamy-gradient { -webkit-text-fill-color: #333 !important; color: #333 !important; }
    .pane { animation: none; }
    .table-scroll { max-height: none; overflow: visible; }
    table { font-size: 10px; }
}

.sr-only {
    position: absolute !important;
    width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0, 0, 0, 0);
    white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto !important; }
    *, *::before, *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .nav-scroll { scroll-behavior: auto; }
}
