/* PitchX next — 全局样式: 设计 token / 骨架 / tab 栏 / 公共组件。
   各功能模块的样式写在各自的 css (static/css/<module>.css), 由 main.js 统一引入, 只用这里的 token 和组件类。
   骨架原则 (DESIGN.md §2): 文档自然滚动; tab 栏 fixed 贴底, 安全区在 tab 栏内 padding; 不用 100vh/100dvh 外壳、
   不用整页 fixed 容器; 页面顶栏用 position:sticky。 */

/* ── 设计 token ─────────────────────────────────────────── */
:root {
  --tab-h: 56px;                 /* tab 栏可点区高度 (不含安全区) */
  --bar-h: 52px;                 /* 页面顶栏高度 */
  --col: 600px;                  /* 内容列宽: 桌面也按手机比例居中一列 */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", "Segoe UI", sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
}
:root, :root[data-theme="dark"] {
  color-scheme: dark;
  --canvas: #000;                /* 列外画布 (桌面两侧) */
  --bg: #000;                    /* 页面底 */
  --surface: #141416;            /* 卡片 / 行 */
  --surface-2: #1c1c1f;          /* 抬升面: 顶栏 / tab 栏 / 输入框 / 胶囊 */
  --surface-3: #2a2a2e;          /* 按下 / 选中底 */
  --line: rgba(255, 255, 255, .08);
  --line-2: rgba(255, 255, 255, .14);
  --text: #eef2f5;
  --text-2: #b7c0c9;
  --muted: #7d8a97;
  --accent: #4ade80;             /* PitchX 荧光绿 */
  --accent-ink: #052611;         /* 绿底上的字 */
  --accent-soft: rgba(74, 222, 128, .14);
  --danger: #ef4444;
  --warn: #f59e0b;
  --info: #60a5fa;
  --shadow: 0 8px 28px rgba(0, 0, 0, .45);
}
:root[data-theme="light"] {
  color-scheme: light;
  --canvas: #eef1f4;
  --bg: #ffffff;
  --surface: #f5f7f9;
  --surface-2: #ffffff;
  --surface-3: #e9edf1;
  --line: rgba(0, 0, 0, .08);
  --line-2: rgba(0, 0, 0, .14);
  --text: #11181f;
  --text-2: #3d4853;
  --muted: #6b7783;
  --accent: #16a34a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(22, 163, 74, .12);
  --danger: #dc2626;
  --warn: #d97706;
  --info: #2563eb;
  --shadow: 0 8px 28px rgba(15, 25, 35, .14);
}

/* ── 骨架 ───────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--canvas); }
body {
  margin: 0;
  min-height: 100%;
  background: var(--canvas);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* 内容让出底部 tab 栏 (含安全区) */
  padding-bottom: calc(var(--tab-h) + var(--safe-bottom));
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
a { color: inherit; }

/* 每个 tab 一个根容器: 居中一列, 至少一屏高 (短页面下方也是页面底色, 不露画布) */
.tab-root {
  width: min(100%, var(--col));
  margin: 0 auto;
  min-height: 100vh;
  background: var(--bg);
}
/* 页面栈里的一页 (core/nav.js); 只有栈顶可见 */
.page { min-height: 100vh; padding-top: var(--safe-top); }

/* ── 底部 tab 栏 (days4fun 同款: fixed 贴底, 安全区在自己的 padding 里, 背景铺到 home 横条下) ── */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 300;
  display: flex;
  width: min(100%, var(--col));
  padding: 0 0 var(--safe-bottom);
  transform: translateX(-50%);
  background: color-mix(in srgb, var(--surface-2) 94%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar-btn {
  flex: 1 1 0;
  height: var(--tab-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
}
.tabbar-btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar-btn.active { color: var(--accent); }
.tabbar-btn:active { transform: scale(.95); }
/* 键盘弹起时 (cipher 输入) tab 栏让位: 被键盘盖住也无意义, 收起避免和输入框抢位置 */
html.kb-open .tabbar { display: none; }

/* ── 页面顶栏 (sticky, 随文档滚动吸顶) ─────────────────────── */
.appbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--bar-h);
  padding: 0 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.appbar-title { flex: 1 1 auto; min-width: 0; font-size: 17px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar-title.center { text-align: center; }
.appbar .spacer { flex: 1 1 auto; }

.icon-btn {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text);
}
.icon-btn:active { transform: scale(.94); background: var(--surface-3); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn.ghost { background: none; }

/* ── 分段胶囊 (二级 tab) ──────────────────────────────────── */
.seg { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 10px 16px; }
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none;
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}
.seg button.active { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.seg.small button { height: 28px; padding: 0 11px; font-size: 13px; background: none; }
.seg.small button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ── 列表 / 卡片 / 区块 ───────────────────────────────────── */
.section { padding: 0 16px; }
.section-title { margin: 18px 16px 8px; color: var(--accent); font-size: 14px; font-weight: 700; letter-spacing: .02em; }
.section-title.center { text-align: center; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.list { margin: 0; padding: 0; list-style: none; }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.row:active { background: var(--surface); }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 13px; }
.chev { flex: none; width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 12px; font-weight: 600; }
.pill.accent { background: var(--accent-soft); color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn:active { transform: scale(.97); }

/* ── 状态: 加载 / 空 / 出错 ─────────────────────────────── */
.state { padding: 48px 24px; text-align: center; color: var(--muted); font-size: 14px; }
.state.error { color: var(--danger); }
.spinner { display: inline-block; width: 22px; height: 22px; border: 2.5px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.2s ease-in-out infinite; border-radius: var(--radius-sm); }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

/* ── 底部弹层 (sheet): 全屏遮罩 + 底部面板; 面板自己让出安全区 ── */
.sheet { position: fixed; inset: 0; z-index: 900; display: flex; flex-direction: column; justify-content: flex-end; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); animation: fadeIn .2s ease; }
.sheet-panel {
  position: relative;
  width: min(100%, var(--col));
  max-height: 86vh;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 0 calc(16px + var(--safe-bottom));
  background: var(--surface-2);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--shadow);
  animation: sheetIn .26s var(--ease);
}
.sheet-handle { width: 38px; height: 5px; margin: 0 auto 8px; border-radius: 3px; background: var(--line-2); }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes sheetIn { from { transform: translateY(100%); } }

/* ── 杂项 ──────────────────────────────────────────────── */
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.num { font-variant-numeric: tabular-nums; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { object-fit: contain; flex: none; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-bottom) + 16px); z-index: 950;
  transform: translateX(-50%); max-width: min(90vw, 420px); padding: 10px 16px; border-radius: 999px;
  background: var(--surface-3); color: var(--text); font-size: 14px; box-shadow: var(--shadow); animation: fadeIn .2s ease;
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }
