/* 浪一下 · 设计令牌 + 组件（样式只消费令牌 —— 编码后 grep 无裸色值/裸字号） */

/* ============ 令牌（同一套令牌，两主题两套值；语义见设计文档 §5.1） ============ */
:root, [data-theme="dark"] {
  --bg: #0d0e13;
  --surface: #15171f;
  --surface-2: #1d2029;
  --border: #272b3a;
  --ink: #f1efe9;
  --ink-dim: #a3a1ab;
  --primary: #ff7a45;
  --primary-ink: #221008;
  --wave: #5ab6ff;
  --ok: #4ade80;
  --bad: #f87171;
  --on-hue: #141312;   /* 彩色徽标上的文字（跨 hue 恒定深墨） */
  --on-bad: #ffffff;   /* 危险色条上的文字 */
  --hue-1: hsl(15 62% 62%);  --hue-2: hsl(45 62% 62%);
  --hue-3: hsl(90 45% 58%);  --hue-4: hsl(150 48% 56%);
  --hue-5: hsl(200 62% 62%); --hue-6: hsl(260 55% 68%);
  --hue-7: hsl(310 55% 66%); --hue-8: hsl(340 62% 66%);
  --shadow-lift: 0 10px 28px rgb(0 0 0 / .38);
  --glass: rgb(13 14 19 / .82);
}
[data-theme="light"] {
  --bg: #f4f1e8;
  --surface: #fffdf6;
  --surface-2: #efeadd;
  --border: #e2dcc9;
  --ink: #26221a;
  --ink-dim: #6e6960;
  --primary: #e05f2b;
  --primary-ink: #fff6ef;
  --wave: #1a6fd4;
  --ok: #157f3c;
  --bad: #b42318;
  --on-hue: #1c1a14;
  --on-bad: #ffffff;
  --hue-1: hsl(15 55% 45%);  --hue-2: hsl(45 62% 40%);
  --hue-3: hsl(90 40% 36%);  --hue-4: hsl(150 45% 34%);
  --hue-5: hsl(200 55% 42%); --hue-6: hsl(260 45% 50%);
  --hue-7: hsl(310 45% 46%); --hue-8: hsl(340 55% 46%);
  --shadow-lift: 0 10px 24px rgb(84 70 40 / .18);
  --glass: rgb(244 241 232 / .86);
}
:root {
  /* 字阶（headline 24 / h2 20 / brand 18 / title 16 / body 13.5 / meta 12；display 44 与 icon 26 为图形字号） */
  --fs-headline: 24px; --fs-h2: 20px; --fs-brand: 18px; --fs-title: 16px; --fs-body: 13.5px; --fs-meta: 12px;
  --fs-display: 44px; --fs-icon: 26px;
  --lh-body: 1.6;
  /* 间距 8pt 系（4 微调） */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  /* 圆角三档 */
  --r-s: 6px; --r-m: 10px; --r-l: 16px;
  /* 动效（150 反馈 / 220 换批） */
  --t-fast: 150ms; --t-med: 220ms;
  --font: system-ui, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", sans-serif;
}

/* ============ 基础 ============ */
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* 防 display:flex 覆盖 hidden 语义 */
html { color-scheme: dark; }
[data-theme="light"] { color-scheme: light; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 var(--fs-body)/var(--lh-body) var(--font);
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
img { display: block; }
:focus-visible { outline: 2px solid var(--wave); outline-offset: 2px; border-radius: var(--r-s); }
.container { max-width: 1360px; margin-inline: auto; padding-inline: var(--s5); }
.main { padding-block: var(--s5) var(--s7); }

/* ============ 头栏（报摊规则：chrome 压到最小高度） ============ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--glass);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: var(--s4); height: 56px; }
.brand { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.brand-tile {
  display: grid; place-items: center; width: 36px; height: 36px;
  background: color-mix(in srgb, var(--primary) 16%, var(--surface-2));
  border: 1px solid color-mix(in srgb, var(--primary) 45%, var(--border));
  border-radius: var(--r-m); font-size: var(--fs-brand);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-size: var(--fs-brand); font-weight: 700; letter-spacing: .5px; }
.brand-tag { font-size: var(--fs-meta); color: var(--ink-dim); white-space: nowrap; }

.actions { display: flex; align-items: center; gap: var(--s2); }

/* 按钮：主操作唯一（每屏一个 --primary 实心钮） */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 36px; padding-inline: var(--s4);
  border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; user-select: none;
  font-size: var(--fs-body); font-weight: 500;
  transition: transform var(--t-fast) ease-out, border-color var(--t-fast), background var(--t-fast), filter var(--t-fast);
}
.btn:hover { border-color: color-mix(in srgb, var(--wave) 55%, var(--border)); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(.97); }
.btn.primary {
  background: var(--primary); border-color: transparent; color: var(--primary-ink); font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.big { height: 48px; width: 100%; font-size: var(--fs-title); border-radius: var(--r-m); }
.btn.icon-only { width: 36px; padding-inline: 0; }
.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--wave); font-size: var(--fs-body); text-decoration: underline; text-underline-offset: 3px;
}
.dice { display: inline-block; }
.spinning .dice { animation: spin var(--t-med) ease-out; }
@keyframes spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-dim); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.dot.warn { background: var(--primary); }
.dot.off { background: var(--ink-dim); }

/* 分类 chips（希克定律：同屏 8 个决策项封顶） */
.chips { display: flex; gap: var(--s2); padding-block: var(--s2) var(--s3); overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 44px; padding-inline: var(--s4); border-radius: 999px;
  display: inline-flex; align-items: center;
  background: transparent; border: 1px solid var(--border); color: var(--ink-dim);
  cursor: pointer; font-size: var(--fs-body);
  transition: color var(--t-fast), border-color var(--t-fast), background var(--t-fast);
}
.chip:hover { color: var(--ink); }
.chip.active {
  color: var(--ink); border-color: var(--wave);
  background: color-mix(in srgb, var(--wave) 14%, transparent);
}

.randbar {
  display: flex; align-items: center; gap: var(--s3);
  padding-block: 0 var(--s3); color: var(--ink-dim);
}
.randbar-text { font-size: var(--fs-meta); }

/* 源状态面板（浮层：阴影解释层级） */
.sources-panel {
  position: absolute; inset-inline-end: var(--s5); top: calc(100% + var(--s2));
  width: min(360px, calc(100vw - var(--s6)));
  max-height: 60vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l);
  box-shadow: var(--shadow-lift); padding: var(--s3);
  display: flex; flex-direction: column; gap: var(--s1);
}
.src-row {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); border-radius: var(--r-s);
}
.src-row:hover { background: var(--surface-2); }
.src-name { font-weight: 500; }
.src-meta { margin-inline-start: auto; color: var(--ink-dim); font-size: var(--fs-meta); text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }

/* ============ 卡片流（瀑布报摊） ============ */
.grid { column-gap: var(--s4); }
.card {
  break-inside: avoid; display: flex; flex-direction: column; width: 100%;
  margin-bottom: var(--s4);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l);
  overflow: hidden;
  transition: transform var(--t-fast) ease-out, border-color var(--t-fast), box-shadow var(--t-fast);
  animation: cardIn var(--t-med) ease-out both;
  animation-delay: calc(var(--i, 0) * 24ms);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}
.card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--primary) 55%, var(--border));
  box-shadow: var(--shadow-lift);
}
.cover { position: relative; aspect-ratio: 16 / 10; background: var(--surface-2); }
.cover img { width: 100%; height: 100%; object-fit: cover; }
.badge {
  position: absolute; top: var(--s2); inset-inline-start: var(--s2);
  padding: 2px var(--s2); border-radius: 999px;
  background: var(--hue, var(--surface-2)); color: var(--on-hue);
  font-size: var(--fs-meta); font-weight: 600; line-height: 1.6;
  max-width: calc(100% - var(--s5)); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.heat-chip {
  position: absolute; top: var(--s2); inset-inline-end: var(--s2);
  padding: 2px var(--s2); border-radius: 999px;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  color: var(--wave); font-size: var(--fs-meta); font-weight: 600; line-height: 1.6;
  border: 1px solid color-mix(in srgb, var(--wave) 40%, transparent);
}
.card-body { padding: var(--s3) var(--s4) var(--s1); }
.card-title {
  margin: 0; font-size: var(--fs-title); font-weight: 600; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-desc {
  margin: var(--s1) 0 0; color: var(--ink-dim);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s2) var(--s4) var(--s3);
  font-size: var(--fs-meta); color: var(--ink-dim);
}
.card-go { color: var(--primary); font-weight: 600; opacity: 0; transition: opacity var(--t-fast); }
.card:hover .card-go, .card:focus-visible .card-go { opacity: 1; }

/* 列数断点：560/900/1280（附录 A） */
@media (min-width: 560px)  { .grid { column-count: 2; } }
@media (min-width: 900px)  { .grid { column-count: 3; } }
@media (min-width: 1280px) { .grid { column-count: 4; } }

/* 骨架 */
.card.sk { height: 260px; position: relative; overflow: hidden; border-radius: var(--r-l); background: var(--surface); }
.card.sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--surface-2) 80%, var(--border)) 50%, transparent 70%);
  animation: shimmer 1.2s infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

/* 状态面板（空 / 错） */
.state-panel {
  max-width: 460px; margin: var(--s7) auto; text-align: center;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-l);
  padding: var(--s6) var(--s5);
}
.state-emoji { font-size: var(--fs-display); margin-bottom: var(--s3); }
.state-panel h2 { margin: 0 0 var(--s2); font-size: var(--fs-h2); }
.state-panel p { margin: 0 0 var(--s5); color: var(--ink-dim); }
.state-actions { display: flex; gap: var(--s3); justify-content: center; flex-wrap: wrap; }

.loadmore-row { text-align: center; padding-top: var(--s4); }
.loadmore-row .btn { min-width: 160px; }

/* ============ 详情页 ============ */
.back { color: var(--ink-dim); font-weight: 500; }
.back:hover { color: var(--ink); }
.hero {
  position: relative; border-radius: var(--r-l); overflow: hidden;
  aspect-ratio: 16 / 9; max-height: 420px; width: 100%;
  background: var(--surface-2); margin-bottom: var(--s5);
}
.hero img { width: 100%; height: 100%; object-fit: cover; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: var(--s5); align-items: start; }
@media (max-width: 899.98px) { .detail-grid { grid-template-columns: 1fr; } }
.detail-title { margin: 0 0 var(--s3); font-size: var(--fs-headline); line-height: 1.4; font-weight: 700; }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.meta-chip {
  padding: 3px var(--s3); border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: var(--fs-meta); color: var(--ink-dim);
}
.meta-chip.src-chip { color: var(--ink); font-weight: 600; }
.meta-chip.wave-chip { color: var(--wave); border-color: color-mix(in srgb, var(--wave) 40%, var(--border)); }
.detail-desc { margin: var(--s4) 0 0; max-width: 68ch; color: color-mix(in srgb, var(--ink) 88%, var(--ink-dim)); }
.detail-sk { height: 380px; border-radius: var(--r-l); position: relative; overflow: hidden; background: var(--surface); }
.detail-sk::after { content: ""; position: absolute; inset: 0; animation: shimmer 1.2s infinite;
  background: linear-gradient(100deg, transparent 30%, color-mix(in srgb, var(--surface-2) 80%, var(--border)) 50%, transparent 70%); }

.detail-side { display: flex; flex-direction: column; gap: var(--s3); }
.info-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-m); padding: var(--s3) var(--s4); }
.info-row {
  display: flex; justify-content: space-between; gap: var(--s3);
  padding: var(--s2) 0; font-size: var(--fs-body);
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: 0; }
.info-row > span { color: var(--ink-dim); }
.info-row > strong { font-weight: 600; text-align: end; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.side-note { margin: 0; font-size: var(--fs-meta); color: var(--ink-dim); text-align: center; }

.related { margin-top: var(--s6); }
.related-title { font-size: var(--fs-brand); margin: 0 0 var(--s4); }
.related-grid { column-count: 4; }
@media (max-width: 1279.98px) { .related-grid { column-count: 3; } }
@media (max-width: 899.98px)  { .related-grid { column-count: 2; } }
@media (max-width: 559.98px)  { .related-grid { column-count: 1; } }

/* ============ 页脚 / 浮动件 ============ */
.foot { padding-block: var(--s5) var(--s7); color: var(--ink-dim); font-size: var(--fs-meta); border-top: 1px solid var(--border); }
.foot p { margin: var(--s1) 0; }
.foot-stats { font-weight: 500; }

.fab {
  display: none; position: fixed; inset-inline-end: var(--s5); bottom: var(--s5); z-index: 30;
  width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: var(--primary-ink); font-size: var(--fs-icon);
  box-shadow: var(--shadow-lift);
  transition: transform var(--t-fast) ease-out;
}
.fab:active { transform: scale(.94); }
@media (max-width: 899.98px) { .fab { display: block; } }

.toast {
  position: fixed; bottom: var(--s6); left: 50%; transform: translateX(-50%); z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  box-shadow: var(--shadow-lift); padding: var(--s2) var(--s5);
  font-size: var(--fs-body); max-width: min(80vw, 480px);
}
.offline-bar {
  position: fixed; top: 0; inset-inline: 0; z-index: 50;
  background: var(--bad); color: var(--on-bad); text-align: center;
  padding: var(--s2); font-size: var(--fs-body); font-weight: 600;
}

/* 无障碍：尊重减少动态偏好（三·1·1） */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* 移动端微调 */
@media (max-width: 559.98px) {
  .container { padding-inline: var(--s4); }
  .brand-tag { display: none; }
  .topbar-in { height: 52px; }
  .btn.primary { padding-inline: var(--s3); }
  #randomBtn { display: none; } /* 移动端用 FAB 🎲（拇指区，≥44px） */
  .sources-panel { inset-inline: var(--s4); width: auto; }
}
@media (pointer: coarse) {
  .btn, .chip { height: 44px; } /* 触控目标 ≥44px（附录 A） */
}
