/* ==========================================================================
 * styles.css — API Plaza v4「调度室」系统层(暗色,对齐 OpenRouter 设计语言)
 * tokens · base · 页头(含全局搜索) · 页尾 · 按钮 · 时刻表 · 代码块 · 降级态
 * 契约见 DESIGN.md v4。变量名与 v3 兼容:旧名一律映射到暗色新值。
 * ========================================================================== */

:root {
  color-scheme: dark;

  /* ---- 画布与分层(近黑中性,极微品牌绿相) ---- */
  --bg: oklch(0.145 0.004 170);
  --surface: oklch(0.185 0.005 170);
  --surface-2: oklch(0.225 0.006 170);
  --ink: oklch(0.88 0.005 170);
  --ink-strong: oklch(0.975 0.003 170);
  --muted: oklch(0.68 0.008 170);
  --line: oklch(0.30 0.008 170);
  --line-strong: oklch(0.38 0.01 170);

  /* ---- 品牌强调(emerald,克制:主 CTA + 链接 + LIVE 点,其余单色) ---- */
  --accent: oklch(0.74 0.105 160);          /* 链接/小高亮:收敛的翡翠,非 neon */
  --accent-solid: oklch(0.55 0.10 159);     /* 主按钮底:沉稳深绿,白字 AA */
  --accent-solid-hover: oklch(0.50 0.095 159);
  --accent-wash: oklch(0.74 0.105 160 / 0.10);
  --dot: oklch(0.72 0.12 160);              /* LIVE / 语义点专用,可略亮 */
  --ok: var(--accent);
  --warn: oklch(0.75 0.11 80);
  --error: oklch(0.66 0.17 25);

  /* ---- v3 兼容别名(未改页面直接继承暗色) ---- */
  --paper: var(--bg);
  --paper-shade: var(--surface);
  --paper-inset: var(--surface-2);
  --ledger: var(--bg);
  --ledger-deep: oklch(0.12 0.004 170);
  --ledger-line: var(--line);
  --accent-deep: var(--accent);
  --mint: var(--accent);
  --mint-dim: var(--muted);
  --paper-on-ledger: var(--ink-strong);
  --faint-on-ledger: var(--muted);
  --code-bg: var(--ledger-deep);
  --code-ink: oklch(0.9 0.006 170);

  /* ---- 字体 ---- */
  --font-display: "Archivo", "Noto Sans SC", ui-sans-serif, system-ui, sans-serif;
  --font-body: "Archivo", "Noto Sans SC", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* ---- 字阶(OR 密度) ---- */
  --text-xs: 0.78rem;
  --text-sm: 0.88rem;
  --text-base: 0.98rem;
  --text-lg: 1.15rem;
  --text-xl: clamp(1.35rem, 1.15rem + 0.9vw, 1.7rem);
  --text-2xl: clamp(1.7rem, 1.35rem + 1.6vw, 2.3rem);
  --text-hero: clamp(2.4rem, 1.7rem + 3vw, 3.75rem);

  /* ---- 间距 ---- */
  --s1: 0.25rem; --s2: 0.5rem; --s3: 0.75rem; --s4: 1rem;
  --s5: 1.5rem; --s6: 2rem; --s7: 3rem; --s8: 4rem; --s9: 6rem;

  --container: 1160px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-paper: none;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);

  --z-header: 40;
  --z-sheet: 50;
  --z-modal: 55;
  --z-toast: 60;
}

/* ==========================================================================
 * base
 * ========================================================================== */

* { box-sizing: border-box; }

html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.62;
  font-kerning: normal;
  font-optical-sizing: auto;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink-strong);
  line-height: 1.12;
  text-wrap: balance;
  margin: 0 0 var(--s4);
}
h1 { font-size: var(--text-hero); font-weight: 800; letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); font-weight: 700; letter-spacing: -0.012em; }
h3 { font-size: var(--text-lg); font-weight: 600; }
:lang(zh-CN) h1, :lang(zh-CN) h2 { letter-spacing: 0; font-weight: 800; }

p { margin: 0 0 var(--s4); max-width: 68ch; text-wrap: pretty; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

code, pre, .mono { font-family: var(--font-mono); font-variant-ligatures: none; }
code { font-size: 0.9em; }
:not(pre) > code {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.08em 0.38em;
  color: var(--ink-strong);
}

img, svg { max-width: 100%; height: auto; }
button, input, select { font: inherit; color: inherit; }

::selection { background: oklch(0.78 0.14 162 / 0.28); color: var(--ink-strong); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--ink-strong); color: var(--bg);
  padding: var(--s2) var(--s4); z-index: var(--z-toast);
}
.skip-link:focus { left: var(--s4); }

.container { max-width: var(--container); margin: 0 auto; padding-inline: clamp(1.1rem, 4vw, 2rem); }
.visually-hidden { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; white-space: nowrap; }
.nobr { display: inline-block; }

/* 小标签(OR 式 uppercase meta) */
.microlabel {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 500;
}

/* ==========================================================================
 * 按钮
 * ========================================================================== */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: var(--s2);
  min-height: 42px;
  padding: 0 1.15rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: var(--text-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.18s var(--ease), border-color 0.18s var(--ease), color 0.18s var(--ease);
}
.btn:hover { text-decoration: none; }

.btn-solid { background: var(--accent-solid); color: oklch(0.99 0 0); }
.btn-solid:hover { background: var(--accent-solid-hover); }

.btn-ghost { border-color: var(--line-strong); color: var(--ink); background: transparent; }
.btn-ghost:hover { border-color: var(--muted); background: var(--surface); color: var(--ink-strong); }

.on-ledger .btn-solid, .btn-paper { background: var(--accent-solid); color: oklch(0.99 0 0); }
.on-ledger .btn-ghost { border-color: var(--line-strong); color: var(--ink); }
.on-ledger .btn-ghost:hover { border-color: var(--muted); color: var(--ink-strong); }

.btn-lg { min-height: 48px; padding: 0 1.5rem; font-size: var(--text-base); }

/* ==========================================================================
 * 页头:logo → 全局搜索(⌘K) → nav → 切换 → CTA pill
 * ========================================================================== */

.site-header {
  position: sticky; top: 0; z-index: var(--z-header);
  border-bottom: 1px solid var(--line);
}
.site-header::before {
  content: "";
  position: absolute; inset: 0; z-index: -1;
  background: oklch(0.145 0.004 170 / 0.88);
  backdrop-filter: blur(10px);
}

.header-bar { display: flex; align-items: center; gap: var(--s4); min-height: 60px; }

.brand {
  display: inline-flex; align-items: center; gap: 0.55rem;
  color: var(--ink-strong);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  flex: none;
}
.brand:hover { text-decoration: none; }
.brand svg { display: block; }

/* 全局搜索入口(header) */
.gsearch-btn {
  display: inline-flex; align-items: center; gap: var(--s2);
  min-height: 38px; min-width: 200px;
  padding: 0 0.7rem;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  color: var(--muted);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: border-color 0.18s var(--ease), background-color 0.18s var(--ease);
}
.gsearch-btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.gsearch-btn .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05rem 0.35rem;
  color: var(--muted);
}

.site-nav { display: flex; align-items: center; gap: var(--s4); margin-inline: auto; }
.site-nav a {
  color: var(--muted);
  font-size: var(--text-sm);
  font-weight: 500;
  padding: var(--s2) 0.15rem;
  transition: color 0.15s var(--ease);
}
.site-nav a:hover { color: var(--ink-strong); text-decoration: none; }
.site-nav a[aria-current="page"] { color: var(--ink-strong); }

.header-actions { display: flex; align-items: center; gap: var(--s3); margin-left: auto; }

.lang-toggle, .currency-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.currency-toggle button, .lang-toggle button {
  border: 0; background: transparent;
  padding: 0.4rem 0.65rem;
  min-height: 34px;
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.lang-toggle button[aria-pressed="true"],
.currency-toggle button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink-strong); }
.currency-toggle button { font-family: var(--font-mono); }

.nav-toggle {
  display: none;
  width: 42px; height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  align-items: center; justify-content: center;
}
.nav-toggle-bars, .nav-toggle-bars::before, .nav-toggle-bars::after {
  content: ""; display: block;
  width: 16px; height: 2px; border-radius: 2px;
  background: var(--ink-strong);
  position: relative;
  transition: transform 0.25s var(--ease);
}
.nav-toggle-bars::before { position: absolute; top: -5px; }
.nav-toggle-bars::after { position: absolute; top: 5px; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars { background: transparent; }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::before { transform: translateY(5px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bars::after { transform: translateY(-5px) rotate(-45deg); }

@media (max-width: 1023px) {
  .header-bar .gsearch-btn { min-width: 0; flex: 1 1 auto; }
  .nav-toggle { order: 3; margin-left: var(--s2); display: inline-flex; }
  .header-actions { margin-left: auto; }
  .header-actions .btn-ghost, .header-actions .lang-toggle { display: none; }
  .site-nav {
    display: none;
    position: fixed; inset: 60px 0 0 0;
    z-index: var(--z-sheet);
    background: var(--bg);
    flex-direction: column; align-items: stretch;
    gap: 0;
    padding: var(--s4) clamp(1.1rem, 4vw, 2rem) var(--s7);
    overflow-y: auto;
    border-top: 1px solid var(--line);
  }
  .site-nav.open { display: flex; }
  .site-nav a { font-size: var(--text-lg); color: var(--ink); padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
  .site-nav .nav-actions { display: flex; flex-direction: column; gap: var(--s3); margin-top: var(--s5); }
  .site-nav .lang-toggle { display: inline-flex; align-self: flex-start; margin-top: var(--s5); }
  body.nav-open { overflow: hidden; }
}
@media (min-width: 1024px) {
  .site-nav .nav-actions, .site-nav .lang-toggle { display: none; }
}
@media (max-width: 599px) {
  .header-bar .gsearch-btn .gsearch-text { display: none; }
  .header-bar .gsearch-btn { min-width: 42px; justify-content: center; }
  .gsearch-btn .kbd { display: none; }
}

/* ==========================================================================
 * 全局搜索弹层(⌘K)
 * ========================================================================== */

.gsearch-overlay {
  position: fixed; inset: 0;
  z-index: var(--z-modal);
  background: oklch(0.1 0.004 170 / 0.7);
  display: none;
  padding: 12vh clamp(1rem, 4vw, 2rem) 0;
}
.gsearch-overlay.open { display: block; }
.gsearch-panel {
  max-width: 620px; margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.gsearch-input {
  width: 100%;
  border: 0; outline: none;
  background: transparent;
  padding: 1rem 1.1rem;
  font-size: var(--text-lg);
  color: var(--ink-strong);
  border-bottom: 1px solid var(--line);
}
.gsearch-input::placeholder { color: var(--muted); }
.gsearch-results { max-height: 46vh; overflow-y: auto; }
.gsearch-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: 0.7rem 1.1rem;
  cursor: pointer;
  color: var(--ink);
}
.gsearch-item[aria-selected="true"], .gsearch-item:hover { background: var(--surface-2); }
.gsearch-item .g-name { font-weight: 600; color: var(--ink-strong); }
.gsearch-item .g-slug { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted); }
.gsearch-item .g-price { margin-left: auto; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }
.gsearch-empty { padding: 1rem 1.1rem; color: var(--muted); font-size: var(--text-sm); }

/* ==========================================================================
 * 页尾(surface + 发丝顶线)
 * ========================================================================== */

.site-footer {
  background: var(--ledger-deep);
  border-top: 1px solid var(--line);
  color: var(--ink);
  margin-top: var(--s9);
  padding: var(--s8) 0 var(--s6);
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--ink-strong); text-decoration: none; }

.footer-cols {
  display: grid;
  grid-template-columns: 1.6fr repeat(3, 1fr);
  gap: var(--s6);
  padding-bottom: var(--s6);
  border-bottom: 1px solid var(--line);
}
.footer-brand p { color: var(--muted); font-size: var(--text-sm); max-width: 34ch; }
.footer-brand .brand { color: var(--ink-strong); }
.footer-base-url { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--accent); display: inline-block; margin-bottom: var(--s3); }
.footer-col h3 { color: var(--ink-strong); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.07em; margin: 0 0 var(--s4); }
.footer-col { display: flex; flex-direction: column; gap: var(--s3); font-size: var(--text-sm); }

.status-indicator { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--text-sm); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status-dot[data-state="ok"] { background: var(--dot); animation: pulse 2.4s var(--ease) infinite; }
.status-dot[data-state="down"] { background: var(--error); animation: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 oklch(0.78 0.14 162 / 0.45); }
  50% { box-shadow: 0 0 0 6px oklch(0.78 0.14 162 / 0); }
}

.footer-base {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4);
  padding-top: var(--s5);
  font-size: var(--text-xs);
  color: var(--muted);
}
.footer-base .spacer { margin-left: auto; }

@media (max-width: 899px) {
  .footer-cols { grid-template-columns: 1fr 1fr; }
  .footer-brand { grid-column: 1 / -1; }
}
@media (max-width: 520px) { .footer-cols { grid-template-columns: 1fr; } }

/* ==========================================================================
 * 时刻表(暗色换皮,结构不变)
 * ========================================================================== */

.timetable { width: 100%; border-collapse: collapse; }
.timetable thead th {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
  color: var(--muted);
  text-align: left;
  padding: var(--s3);
  border-bottom: 1px solid var(--line-strong);
}
.timetable tbody td { padding: 0.95rem var(--s3); border-bottom: 1px solid var(--line); vertical-align: middle; }
.timetable tbody tr { transition: background-color 0.15s var(--ease); }
.timetable tbody tr:hover { background: var(--surface); }
.timetable .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.timetable thead th.num { text-align: right; }
.timetable .t-name a { color: var(--ink-strong); font-weight: 600; }
.timetable .t-name a:hover { color: var(--accent); }
.timetable .t-sub { display: block; font-size: var(--text-xs); color: var(--muted); font-family: var(--font-mono); }
.timetable .t-dim { color: var(--muted); font-size: var(--text-xs); font-family: var(--font-body); }

.chip {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.chip[data-modality="text"]::before { background: var(--accent); }
.chip[data-modality="image"]::before { background: oklch(0.72 0.12 260); }
.chip[data-modality="video"]::before { background: oklch(0.74 0.13 45); }
a.chip:hover { border-color: var(--muted); text-decoration: none; background: var(--surface-2); }

@media (max-width: 767px) {
  .timetable thead { display: none; }
  .timetable, .timetable tbody, .timetable tr, .timetable td { display: block; }
  .timetable tbody tr { padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
  .timetable tbody td { border: 0; padding: 0.3rem 0; }
  .timetable td[data-label]::before {
    content: attr(data-label);
    display: inline-block;
    min-width: 7.5em;
    font-size: var(--text-xs);
    color: var(--muted);
  }
  .timetable .num { text-align: left; }
}

/* ==========================================================================
 * 代码块
 * ========================================================================== */

.code-card {
  background: var(--ledger-deep);
  color: var(--code-ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.code-toolbar { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line); }
.code-tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.code-tabs .tab {
  border: 0; background: transparent;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  padding: 0.4rem 0.7rem;
  min-height: 32px;
  border-radius: 7px;
  cursor: pointer;
}
.code-tabs .tab[aria-selected="true"] { background: var(--surface-2); color: var(--ink-strong); }
.code-file { font-family: var(--font-mono); font-size: var(--text-xs); color: var(--muted); }

.copy-btn {
  margin-left: auto;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-size: var(--text-xs);
  border-radius: 7px;
  padding: 0.35rem 0.7rem;
  min-height: 32px;
  cursor: pointer;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn[data-copied="true"] { border-color: var(--accent); color: var(--accent); }

.code-card pre { margin: 0; padding: var(--s4) var(--s5); overflow-x: auto; font-size: 0.86rem; line-height: 1.7; }

.tok-c { color: var(--muted); }
.tok-s { color: var(--accent); }
.tok-k { color: oklch(0.78 0.09 240); }
.tok-del { color: oklch(0.62 0.1 25); text-decoration: line-through; opacity: 0.8; }
.tok-add { color: var(--accent); font-weight: 600; }

/* ==========================================================================
 * 降级态 + 骨架
 * ========================================================================== */

.data-fallback {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  padding: var(--s6);
  text-align: center;
  color: var(--muted);
  background: var(--surface);
}
.data-fallback strong { display: block; color: var(--ink-strong); margin-bottom: var(--s2); font-size: var(--text-lg); }
.data-fallback .fallback-actions { display: flex; gap: var(--s3); justify-content: center; flex-wrap: wrap; margin-top: var(--s4); }

.skeleton-rows { display: grid; gap: var(--s3); }
.sk-bar, .skeleton-row {
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 38%, var(--surface-2) 50%, var(--surface) 62%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton-row { height: 3.1rem; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .sk-bar, .skeleton-row { animation: none; } }

.sk-bar { display: block; border-radius: 6px; }
.skeleton-card { pointer-events: none; }
/* 卡片骨架(首页模型榜):复用 .board-top/.board-desc/.board-meta 盒子,高度自动贴合真实卡片 */
.skeleton-card .sk-name { width: 30%; height: 1.75rem; }
.skeleton-card .sk-usage { width: 5rem; height: 1rem; margin-left: auto; }
.skeleton-card .sk-descbar { width: 78%; height: 1.5rem; }
.skeleton-card .sk-metabar { width: 55%; height: 1.35rem; }

/* 表格骨架(模型/价格):复用 .timetable,行高随视口自动对齐 */
.sk-tsec { margin-top: var(--s6); }
.sk-tsec .sk-title { width: 7rem; height: 1.5rem; margin-bottom: var(--s4); border-radius: 8px; }
.sk-table .t-name { line-height: 1; }
.sk-table .sk-th { width: 4rem; height: 0.8rem; }
.sk-table .sk-thnum { width: 3rem; margin-left: auto; }
.sk-table .sk-name { width: 8.5rem; height: 1.35rem; }
.sk-table .sk-sub { width: 6rem; height: 0.9rem; margin-top: 0.6rem; }
.sk-table .sk-chip { width: 62%; height: 1.35rem; border-radius: 999px; }
.sk-table .sk-num { width: 3.5rem; height: 1.1rem; margin-left: auto; }
@media (max-width: 767px) { .sk-table .sk-num, .sk-table .sk-chip { margin-left: 0; } }

/* ==========================================================================
 * 通用区块
 * ========================================================================== */

.section { padding-block: var(--s8); }
.section-tight { padding-block: var(--s7); }
.section-shade { background: transparent; border-top: 1px solid var(--line); }

.section-head { margin-bottom: var(--s6); }
.section-head .lede { color: var(--muted); font-size: var(--text-lg); max-width: 58ch; }
.section-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); flex-wrap: wrap; }

/* v3 兼容:绿带类在 v4 归于画布 */
.on-ledger { background: transparent; color: var(--ink); }
.on-ledger h1, .on-ledger h2, .on-ledger h3 { color: var(--ink-strong); }
.on-ledger a { color: var(--accent); }

.rule { border: 0; border-top: 1px solid var(--line); margin: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001s !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001s !important;
  }
  html { scroll-behavior: auto; }
}
