:root {
  --bg: #0b0e14;
  --surface: #131824;
  --surface-2: #1b2230;
  --border: #262f40;
  --text: #e6ebf5;
  --muted: #8b96a8;
  --primary: #3b82f6;
  --primary-600: #2563eb;
  --up: #ef4444;      /* 台股：漲=紅 */
  --down: #22c55e;    /* 台股：跌=綠 */
  --gold: #f5b301;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2336 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: inherit; text-decoration: none; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 24px;
  background: rgba(19, 24, 36, .8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 20px; letter-spacing: .5px; }
.brand .logo { font-size: 22px; }
.brand small { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 4px; }
.nav { display: flex; gap: 6px; margin-left: 8px; }
.nav a { padding: 8px 14px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; }
.nav a:hover { color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--text); background: var(--surface-2); }
.auth-area { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* ---------- Layout ---------- */
.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; flex: 1; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
@media (max-width: 780px) { .grid { grid-template-columns: 1fr; } }

/* ---------- Hero / search ---------- */
.hero { text-align: center; padding: 30px 10px 8px; }
.hero.compact { padding: 10px; text-align: left; }
.hero h1 { font-size: 30px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0 auto 20px; max-width: 560px; }
.search { display: flex; gap: 10px; max-width: 480px; margin: 0 auto; }
.search input {
  flex: 1; padding: 13px 16px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: 16px; outline: none;
}
.search input:focus { border-color: var(--primary); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.card-head h2 { font-size: 17px; margin: 0; margin-right: auto; }

/* ---------- Buttons / badges ---------- */
.btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--text); padding: 9px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; font-size: 14px; }
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-600); }
.btn.ghost { background: transparent; }
.badge { font-size: 12px; color: var(--muted); background: var(--surface-2); padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border); }
.badge.subtle { opacity: .8; }
.badge.badge-info { color: var(--primary); border-color: rgba(59,130,246,.45); background: rgba(59,130,246,.12); cursor: help; }
.badge.badge-live { color: var(--up); border-color: rgba(239,68,68,.45); background: rgba(239,68,68,.12); cursor: help; }
.badge.badge-live::before { content: "●"; font-size: 9px; margin-right: 4px; vertical-align: middle; animation: livePulse 1.6s ease-in-out infinite; }
@keyframes livePulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.badge.up { color: var(--up); border-color: rgba(239,68,68,.4); }
.badge.down { color: var(--down); border-color: rgba(34,197,94,.4); }

/* ---------- Tabs（今日 K 線切換） ---------- */
.tabs { display: inline-flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.tabs .tab { border: none; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 999px; cursor: pointer; }
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { background: var(--primary); color: #fff; }
.kv-date { color: var(--muted); font-size: 12px; margin: -4px 0 10px; }
.kv .v { transition: opacity .2s ease; }
.kv .v.kv-fade { opacity: 0; }
.toggle-vol { position: relative; }
.toggle-vol .k::after { content: " ⇄"; font-size: 10px; color: var(--primary); opacity: .7; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.list .row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-radius: 10px; background: var(--surface-2);
  border: 1px solid transparent; cursor: pointer;
}
.list .row:hover { border-color: var(--primary); }
.row .sym { font-weight: 700; }
.row .meta { color: var(--muted); font-size: 13px; }
.row .right { display: flex; align-items: center; gap: 10px; }
.loading, .empty { color: var(--muted); padding: 16px; text-align: center; }

/* ---------- Stock detail ---------- */
.stock-header { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 16px; }
.stock-title { display: flex; align-items: center; gap: 10px; }
.stock-title h1 { margin: 0; font-size: 30px; }
.stock-name { font-size: 18px; font-weight: 600; color: var(--muted); }
.stock-price { margin-top: 8px; display: flex; align-items: baseline; gap: 12px; }
.price { font-size: 32px; font-weight: 800; }
.change { font-size: 18px; font-weight: 700; }
.up-text { color: var(--up); }
.down-text { color: var(--down); }
.stock-status { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pill { padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; border: 1px solid var(--border); background: var(--surface-2); }
.pill.limit-up { color: var(--up); border-color: rgba(239,68,68,.5); background: rgba(239,68,68,.1); }
.pill.opened { color: var(--gold); border-color: rgba(245,179,1,.5); background: rgba(245,179,1,.08); }

.kv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kv { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.kv .k { color: var(--muted); font-size: 12px; }
.kv .v { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ---------- OHLC mini chart ---------- */
.chart { position: relative; height: 120px; padding: 8px 8px 8px 50px; background: var(--surface-2); border-radius: 10px; }
.trend-bars { height: 100%; display: flex; align-items: flex-end; gap: 4px; }
.chart .bar { flex: 1; background: linear-gradient(180deg, var(--primary), transparent); border-radius: 3px 3px 0 0; min-height: 4px; }
.chart-yaxis { position: absolute; left: 0; top: 8px; bottom: 8px; width: 46px; }
.chart-yaxis .cy-tick { position: absolute; right: 4px; transform: translateY(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.chart-grid { position: absolute; left: 50px; right: 8px; top: 8px; bottom: 8px; pointer-events: none; }
.chart-grid .cg-line { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(255,255,255,0.07); }
/* 前 1／前 2 日：單根 OHLC 燭台 */
.ohlc-candle { position: relative; width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.ohlc-candle .mc-wick { position: absolute; top: 0; width: 2px; }
.ohlc-candle .mc-body { position: absolute; width: 26px; border-radius: 3px; }
.ohlc-candle .mc-wick.up, .ohlc-candle .mc-body.up { background: var(--up); }
.ohlc-candle .mc-wick.down, .ohlc-candle .mc-body.down { background: var(--down); }

/* ---------- 3-day candlestick ---------- */
.kline3 { padding: 8px 4px; }
.kline-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.kline-col { min-width: 0; background: rgba(255,255,255,0.02); border: 1px solid rgba(255,255,255,0.06); border-radius: 10px; padding: 8px 6px 4px; }
.kline-col-wide { grid-column: 1 / -1; }
.kline-title { font-size: 13px; font-weight: 700; color: var(--text); margin: 2px 4px 8px; }
@media (max-width: 900px) { .kline-grid { grid-template-columns: 1fr; } }
.chart-wrap { position: relative; padding-left: 46px; }
.y-axis { position: absolute; left: 0; top: 0; width: 42px; height: 100%; }
.y-tick { position: absolute; right: 4px; transform: translateY(-50%); font-size: 10px; color: var(--muted); white-space: nowrap; }
.grid-lines { position: absolute; left: 46px; right: 0; top: 0; height: 160px; pointer-events: none; }
.grid-line { position: absolute; left: 0; right: 0; border-top: 1px dashed rgba(255,255,255,0.08); }
.candles { display: flex; justify-content: space-around; align-items: flex-start; gap: 12px; position: relative; }
.candles.compact { gap: 5px; }
.candles.dense { gap: 2px; }
.candle-col { display: flex; flex-direction: column; align-items: center; flex: 1; max-width: 140px; min-width: 0; }
.candles.compact .candle-col { max-width: none; }
.candle { position: relative; width: 100%; }
.candle .wick { position: absolute; left: 50%; transform: translateX(-50%); width: 2px; }
.candle .body { position: absolute; left: 50%; transform: translateX(-50%); width: 22px; border-radius: 3px; }
.candles.compact .candle .body { width: 12px; }
.candles.dense .candle .body { width: 6px; border-radius: 1px; }
.candle .wick.up, .candle .body.up { background: var(--up); }
.candle .wick.down, .candle .body.down { background: var(--down); }
.candle .limit-line { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--up); opacity: 0.5; }
.candle .lu-dot { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 6px; height: 6px; border-radius: 50%; }
.candle .lu-dot.locked { background: var(--up); box-shadow: 0 0 4px var(--up); }
.candle .lu-dot.touched { background: transparent; border: 1.5px solid var(--up); }
.candle-label { margin-top: 8px; text-align: center; font-size: 12px; line-height: 1.5; overflow: hidden; max-width: 100%; }
.candles.dense .candle-label { font-size: 10px; margin-top: 4px; }
.candle-label .d { color: var(--muted); white-space: nowrap; font-size: 11px; }
.candle-label .tag-row { margin: 2px 0; }
.candle-label .tag { display: inline-block; font-size: 10px; padding: 1px 5px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.candle-label .tag.up-tag { background: rgba(230,57,70,0.18); color: var(--up); }
.candle-label .tag.down-tag { background: rgba(46,196,110,0.18); color: var(--down); }
.candle-label .tag.flat { background: rgba(255,255,255,0.08); color: var(--muted); }
.candle-label .c { font-size: 14px; font-weight: 700; white-space: nowrap; }
.candle-label .pct { font-size: 11px; white-space: nowrap; }
.candles.compact .candle-label .c { font-size: 12px; }
.candle-label .ohlc { color: var(--muted); font-size: 11px; margin-top: 2px; }

/* ---------- Score ring ---------- */
.score-wrap { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.score-ring {
  --val: 0;
  width: 120px; height: 120px; border-radius: 50%;
  display: grid; place-items: center; flex: 0 0 auto;
  background: conic-gradient(var(--primary) calc(var(--val) * 1%), var(--surface-2) 0);
  position: relative;
}
.score-ring::before { content: ""; position: absolute; inset: 12px; border-radius: 50%; background: var(--surface); }
.score-ring span { position: relative; font-size: 30px; font-weight: 800; }
.score-details { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 200px; }
.score-details li { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.score-details li span:last-child { font-weight: 700; }

/* ---------- Next move ---------- */
.nextmove { display: flex; flex-direction: column; gap: 12px; }
.prob-bar { height: 12px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.prob-bar > div { height: 100%; background: linear-gradient(90deg, var(--down), var(--gold), var(--up)); }
.factor { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); }

/* ---------- Ticks ---------- */
.ticks { max-height: 260px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }.tick { display: grid; grid-template-columns: 70px 1fr auto; gap: 8px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.tick.flag { border-left: 3px solid var(--gold); }

/* ---------- Institutional ---------- */
.institutional { display: flex; flex-direction: column; gap: 8px; }
.inst-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.inst-row.total { border: 1px solid var(--border); background: transparent; font-weight: 700; }
.inst-row .k { color: var(--muted); }
.inst-row .v { font-weight: 700; font-variant-numeric: tabular-nums; }
.inst-streak { margin-top: 6px; text-align: right; color: var(--muted); font-size: 14px; }
.inst-series { display: flex; flex-direction: column; gap: 6px; }
.inst-bar-row { display: grid; grid-template-columns: 48px 1fr 70px; gap: 8px; align-items: center; font-size: 13px; font-variant-numeric: tabular-nums; }
.inst-bar-row .d { color: var(--muted); }
.inst-bar-row .n { text-align: right; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill.buy { background: var(--up); }
.bar-fill.sell { background: var(--down); }

/* ---------- Filter chips ---------- */
.filter-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; }
.chip:hover { color: var(--text); border-color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filter-count { margin-left: auto; color: var(--muted); font-size: 13px; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--muted); font-weight: 600; }
.table tbody tr:hover { background: var(--surface-2); }

/* ---------- Footer ---------- */
.footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--surface-2); border: 1px solid var(--border); padding: 12px 18px; border-radius: 12px; box-shadow: var(--shadow); z-index: 50; opacity: 0; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
