/* 默认：奶白 */
:root {
  --bg: #f6f1e7;
  --panel: #fffcf5;
  --panel-2: #f1ebdd;
  --line: #e4dccb;
  --text: #2a251e;
  --text-2: #62594b;
  --text-3: #968b78;
  --accent: #0f766e;
  --on-accent: #ffffff;
  --warn: #b45309;
  --red: #d33a4c;
  --green: #16803c;
  --chart-line: #3b342a;
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  color-scheme: light;
}
/* 深色 */
:root[data-theme="dark"] {
  --bg: #0b0e13;
  --panel: #11161d;
  --panel-2: #161c25;
  --line: #222b37;
  --text: #e6ebf2;
  --text-2: #9aa6b5;
  --text-3: #647183;
  --accent: #5eead4;
  --on-accent: #062a26;
  --warn: #fbbf24;
  --red: #f0506e;
  --green: #22c55e;
  --chart-line: #c9d4e2;
  color-scheme: dark;
}
/* 红涨绿跌（默认）/ 绿涨红跌 */
body { --up: var(--red); --down: var(--green); }
body.us { --up: var(--green); --down: var(--red); }

* { box-sizing: border-box; }
/* 有些元素自己设了 display，会盖掉 hidden 属性的默认隐藏；这里保证 hidden 永远生效。 */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
button { font: inherit; color: inherit; }
.muted { color: var(--text-3); }
.up { color: var(--up); }
.down { color: var(--down); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ── 顶栏 ── */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; font-size: 16px; }
.brand .en { color: var(--text-3); font-family: var(--mono); font-size: 12px; }
.dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent); align-self: center;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); animation: pulse 2s infinite;
}
@keyframes pulse { 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.chips { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.chip {
  font-size: 12px; color: var(--text-2);
  padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel);
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }
.chip.warn { border-color: color-mix(in srgb, var(--warn) 40%, transparent); color: var(--warn); }
.top-actions { display: flex; gap: 6px; }
.chip.ok b { color: var(--accent); }
.toggle {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 12px; color: var(--text-2);
}
.toggle:hover { border-color: var(--text-3); color: var(--text); }

main { padding: 16px 20px 8px; max-width: 1480px; margin: 0 auto; }

/* ── 行情卡片 ── */
/* 左边一列放分组名，右边 7 列等宽：每组一行，所有卡片同宽同高、列对齐。 */
.tiles {
  display: grid; grid-template-columns: 72px repeat(7, minmax(0, 1fr));
  gap: 8px; margin-bottom: 16px;
}
.tile-label {
  grid-column: 1; align-self: center;
  font-size: 12px; line-height: 1.35; color: var(--text-3); letter-spacing: 0.04em;
}
.tile {
  min-width: 0; height: 74px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px 5px; cursor: pointer; text-align: left;
  transition: border-color 0.15s, background 0.15s;
}
.tile:hover { border-color: var(--text-3); }
.tile.active { border-color: var(--accent); background: var(--panel-2); }
.tile.static { cursor: default; }
.tile .name { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; font-size: 12px; color: var(--text-2); line-height: 1.2; }
.tile .name span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .name small { flex: none; color: var(--text-3); font-family: var(--mono); font-size: 10.5px; }
.tile .row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.tile .price { font-family: var(--mono); font-size: 15px; font-weight: 600; white-space: nowrap; }
.tile .chg { font-family: var(--mono); font-size: 11.5px; white-space: nowrap; }
.tile svg { display: block; width: 100%; height: 16px; }

/* ── 布局 ── */
.grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.col-main, .col-side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head h2 { font-size: 15px; margin: 0; font-weight: 600; }
.card-head h2 small { font-size: 12px; color: var(--text-3); font-weight: 400; margin-left: 6px; }

.symbol-tabs, .topic-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab {
  background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 3px 8px; cursor: pointer;
  font-size: 12px; color: var(--text-2); font-family: var(--mono);
}
.topic-tabs .tab { font-family: inherit; }
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { border-color: var(--line); background: var(--panel-2); color: var(--accent); }

.chart-meta { display: flex; gap: 16px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.chart-meta .title { font-size: 18px; font-weight: 600; }
.chart-meta .note { font-size: 12px; color: var(--text-3); }
.chart { height: 380px; width: 100%; }
.hint { font-size: 12px; color: var(--text-3); margin: 6px 0 0; }

/* ── 热点 ── */
.hot { list-style: none; margin: 0; padding: 0; counter-reset: hot; }
.hot > li { border-top: 1px solid var(--line); padding: 10px 0; counter-increment: hot; }
.hot > li:first-child { border-top: 0; }
.hot-row { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 10px; align-items: start; cursor: pointer; }
.hot-row::before { content: counter(hot); font-family: var(--mono); color: var(--text-3); font-size: 13px; padding-top: 1px; }
.hot > li:nth-child(-n+3) .hot-row::before { color: var(--accent); }
.hot-title { font-weight: 500; }
.hot-meta { font-size: 12px; color: var(--text-3); margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tag { font-size: 11px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--text-2); }
.tag.new { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.tag.rising { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.heat { text-align: right; min-width: 64px; }
.heat .v { font-family: var(--mono); font-size: 14px; font-weight: 600; }
.heat .bar { height: 3px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.heat .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--warn)); }
.hot-articles { list-style: none; margin: 8px 0 0 36px; padding: 0; display: none; }
.hot > li.open .hot-articles { display: block; }
.hot-articles li { font-size: 13px; padding: 4px 0; color: var(--text-2); }
.hot-articles li small { color: var(--text-3); margin-left: 6px; }
.hot-articles .sum { display: block; font-size: 12px; color: var(--text-3); }

/* ── 归因 ── */
.attribution .head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.attribution .head .big { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.attribution .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.explain {
  margin: 12px 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--panel-2);
  border-radius: 0 6px 6px 0; line-height: 1.6;
}
.explain .conf { font-size: 11px; margin-left: 6px; padding: 0 6px; border-radius: 4px; border: 1px solid var(--line); color: var(--text-2); white-space: nowrap; }
.primary { display: block; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; }
.primary .lbl { font-size: 11px; color: var(--accent); }
.ctx { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0; }
.ctx div { background: var(--panel-2); border-radius: 6px; padding: 5px 8px; font-size: 12px; }
.ctx b { display: block; font-family: var(--mono); font-size: 13px; }
.cands { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.cands li { padding: 5px 0; border-top: 1px dashed var(--line); display: grid; grid-template-columns: 34px 1fr; gap: 6px; }
.cands .s { font-family: var(--mono); color: var(--text-3); font-size: 12px; }
.cands small { color: var(--text-3); }
.btn {
  background: var(--accent); color: var(--on-accent); border: 0; border-radius: 6px; padding: 7px 14px; font-weight: 600; cursor: pointer; margin-top: 10px;
}
.btn[disabled] { opacity: 0.6; cursor: progress; }
.section-label { font-size: 12px; color: var(--text-3); margin: 12px 0 4px; }

/* ── 恐慌贪婪 ── */
.gauge { height: 210px; }
.fg-meta { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; font-size: 11px; color: var(--text-3); }
.fg-meta b { display: block; font-family: var(--mono); font-size: 14px; color: var(--text); }
.components { list-style: none; margin: 12px 0 0; padding: 0; font-size: 12px; }
.components li { display: grid; grid-template-columns: 1fr 90px 34px; gap: 8px; align-items: center; padding: 3px 0; color: var(--text-2); }
.components .track { height: 5px; background: var(--line); border-radius: 3px; position: relative; }
.components .track i { position: absolute; top: -2px; width: 3px; height: 9px; border-radius: 2px; background: var(--text); }
.components .v { font-family: var(--mono); text-align: right; }

/* ── 最近异动 ── */
.moves { list-style: none; margin: 0; padding: 0; max-height: 420px; overflow-y: auto; }
.moves li { display: grid; grid-template-columns: 78px 70px minmax(0, 1fr); gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.moves li:first-child { border-top: 0; }
.moves li:hover .why { color: var(--text); }
.moves .d { font-family: var(--mono); color: var(--text-3); font-size: 12px; }
.moves .s b { display: block; font-size: 12px; }
.moves .s span { font-family: var(--mono); font-size: 12px; }
.moves .why { color: var(--text-2); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.foot { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px 24px; color: var(--text-3); font-size: 12px; max-width: 1480px; margin: 0 auto; }

.skeleton { color: var(--text-3); font-size: 13px; padding: 12px 0; }

@media (max-width: 1100px) {
  .grid { grid-template-columns: 1fr; }
  /* 窄屏：分组名单独占一行，卡片自动排列 */
  .tiles { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); }
  .tile-label { grid-column: 1 / -1; margin-top: 6px; }
}
@media (max-width: 640px) {
  main { padding: 12px 16px; }
  .top { padding: 10px 16px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart { height: 300px; }
  .ctx { grid-template-columns: repeat(2, 1fr); }
  .fg-meta { grid-template-columns: repeat(2, 1fr); }
}

/* ── AI 设置 ── */
.toggle.primary { border-color: var(--accent); color: var(--accent); }
.chip.clickable { cursor: pointer; }
.chip.clickable:hover { border-color: var(--text-3); }
.settings {
  width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.settings::backdrop { background: rgba(20, 16, 10, 0.35); }
.settings form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.settings-head h2 { margin: 0; font-size: 16px; }
.settings .x { background: none; border: 0; font-size: 22px; line-height: 1; color: var(--text-3); cursor: pointer; padding: 2px 6px; }
.settings .x:hover { color: var(--text); }
.settings-body { padding: 4px 18px 12px; overflow-y: auto; }
.settings-body h3 { font-size: 13px; color: var(--text-3); font-weight: 600; margin: 16px 0 8px; letter-spacing: 0.04em; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.field-hint { font-size: 12px; color: var(--text-3); margin: -4px 0 10px; line-height: 1.5; }
.field-hint a { color: var(--accent); }
.settings input, .settings select, .settings textarea {
  font: inherit; font-size: 13px; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%;
}
.settings textarea { font-family: var(--mono); resize: vertical; }
.settings input:focus, .settings select:focus, .settings textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 0; border-color: var(--accent); }
.settings .inline { display: flex; gap: 8px; }
.settings .inline input { flex: 1; min-width: 0; }
.settings .inline .toggle { white-space: nowrap; }
.price-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.price-row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--text-3); }
.settings input.short { width: 120px; }
.settings input.mini { width: 58px; padding: 2px 6px; display: inline-block; }
.advanced { margin: 4px 0 8px; font-size: 13px; color: var(--text-2); }
.advanced summary { cursor: pointer; margin-bottom: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-2); margin-bottom: 10px; line-height: 1.6; }
.check > input { width: auto; margin-top: 4px; flex: none; }
.check b { color: var(--text); font-weight: 600; }
.settings-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.settings-foot .btn { margin-top: 0; }
.s-status { flex: 1; font-size: 12px; color: var(--text-3); min-width: 0; }
.s-status.ok { color: var(--accent); }
.s-status.err { color: var(--red); }
@media (max-width: 640px) {
  .price-row { grid-template-columns: 1fr; }
}

.settings.login { width: min(380px, calc(100vw - 32px)); }
