:root {
  --bg: #0b0e14; --panel: #131722; --panel2: #1a1f2e; --line: #242a38;
  --txt: #d1d4dc; --muted: #787b86; --accent: #2962ff; --accent2: #1e53e5;
  --up: #f23645; --down: #089981;        /* 台股：紅漲綠跌 */
  --up-soft: #3a1f26; --down-soft: #15302a;
  --radius: 12px; --shadow: 0 4px 20px rgba(0,0,0,.35);
}
/* ---------- 淺色主題 ---------- */
[data-theme="light"] {
  --bg: #f5f7fa; --panel: #ffffff; --panel2: #eef1f6; --line: #d8dee9;
  --txt: #1f2328; --muted: #6b7280; --accent: #2962ff; --accent2: #1e53e5;
  --up-soft: #ffe3e6; --down-soft: #dcf2ea;
  --shadow: 0 2px 12px rgba(0,0,0,.08);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--txt);
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif; font-size: 14px; }
a { color: #58a6ff; text-decoration: none; }

/* ---------- Header ---------- */
header { position: sticky; top: 0; z-index: 50; backdrop-filter: blur(8px);
  background: linear-gradient(180deg, rgba(19,23,34,.96), rgba(19,23,34,.85));
  border-bottom: 1px solid var(--line); padding: 12px 24px;
  display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
header h1 { font-size: 17px; margin: 0; font-weight: 700; letter-spacing: .5px;
  background: linear-gradient(90deg, #4d8bff, #8a5cff); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; }
nav { display: flex; gap: 6px; }
.tab { background: transparent; color: var(--muted); border: 1px solid transparent;
  padding: 8px 16px; border-radius: 999px; cursor: pointer; font-size: 14px; transition: .15s; }
.tab:hover { color: var(--txt); background: var(--panel2); }
.tab.active { background: var(--accent); color: #fff; box-shadow: 0 2px 12px rgba(41,98,255,.5); }
.tab-panel { display: none; padding: 22px 24px; max-width: 1400px; margin: 0 auto; }
.tab-panel.active { display: block; animation: fade .25s; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

/* ---------- Search ---------- */
.searchbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
#codeInput { width: 360px; max-width: 60vw; padding: 12px 16px; font-size: 15px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; color: var(--txt);
  transition: .15s; }
#codeInput:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(41,98,255,.2); }
button { background: var(--accent); color: #fff; border: none; padding: 10px 18px; border-radius: 9px;
  cursor: pointer; font-size: 14px; font-weight: 600; transition: .15s; }
button:hover { background: var(--accent2); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.ghost { background: var(--panel2); color: var(--txt); border: 1px solid var(--line); }
button.buy { background: var(--up); } button.sell { background: var(--down); }
.quick { color: var(--muted); font-size: 13px; }
.quick a { margin: 0 4px; padding: 4px 10px; background: var(--panel2); border-radius: 999px;
  display: inline-block; transition: .15s; }
.quick a:hover { background: var(--line); }

/* ---------- Stock head ---------- */
.stock-head { display: flex; align-items: baseline; gap: 18px; margin-bottom: 14px;
  padding: 14px 18px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); }
.sh-name { font-size: 20px; font-weight: 700; }
.sh-last { font-size: 30px; font-weight: 800; letter-spacing: .5px; }
.sh-chg { font-size: 17px; font-weight: 700; padding: 3px 10px; border-radius: 8px; }
.up { color: var(--up); } .down { color: var(--down); }
.sh-chg.up { background: var(--up-soft); } .sh-chg.down { background: var(--down-soft); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 1fr 340px; gap: 18px; }
@media (max-width: 980px) { .layout { grid-template-columns: 1fr; } }
.controls { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.controls label { display: inline-flex; align-items: center; gap: 5px; padding: 6px 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; font-size: 13px;
  cursor: pointer; transition: .15s; user-select: none; }
.controls label:hover { border-color: var(--accent); }
.controls input[type=checkbox] { accent-color: var(--accent); }
.range { margin-left: auto; color: var(--muted); }
.range select { background: var(--panel); color: var(--txt); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 10px; }

.chart { height: 440px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.subchart-wrap { margin-top: 12px; display: flex; flex-direction: column; gap: 12px; }
.subchart { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; position: relative; }
.subchart .sub-label { position: absolute; top: 8px; left: 12px; z-index: 3; font-size: 12px;
  font-weight: 700; color: var(--muted); background: rgba(19,23,34,.7); padding: 2px 8px; border-radius: 6px; }
.subchart .sub-val { position: absolute; top: 8px; right: 12px; z-index: 3; font-size: 12px; }
.sub-h { height: 150px; }
.chart-sm { height: 230px; background: var(--panel); border-radius: 10px; overflow: hidden; }

/* ---------- Cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 12px; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.card h3 small { color: var(--muted); font-weight: 400; font-size: 11px; margin-left: auto; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ---------- Signal gauge ---------- */
.gauge { height: 16px; border-radius: 999px; position: relative; margin: 10px 0 4px;
  background: linear-gradient(90deg, var(--down) 0%, #5a6173 50%, var(--up) 100%); }
#gaugeBar { position: absolute; top: -4px; width: 5px; height: 24px; background: #fff;
  border-radius: 3px; left: 50%; transform: translateX(-50%); transition: left .4s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 0 8px rgba(255,255,255,.6); }
.gauge-scale { display: flex; justify-content: space-between; font-size: 10px; color: var(--muted); }
.sig-label { text-align: center; font-size: 22px; font-weight: 800; margin: 10px 0; }
.reasons { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.reasons li { padding: 8px 10px; border-radius: 8px; margin-bottom: 5px; background: var(--panel2); line-height: 1.5; }
.reasons li.bull { border-left: 3px solid var(--up); }
.reasons li.bear { border-left: 3px solid var(--down); }
.reasons li.neutral { border-left: 3px solid #5a6173; }

/* ---------- Agent ---------- */
.agent-rec { font-size: 22px; font-weight: 800; text-align: center; padding: 14px;
  border-radius: 10px; background: var(--panel2); margin-bottom: 6px; }

/* ---------- Levels ---------- */
.levels { list-style: none; padding: 0; margin: 4px 0 12px; font-size: 13px; }
.levels li { padding: 8px 10px; background: var(--panel2); border-radius: 8px; margin-bottom: 5px;
  display: flex; align-items: baseline; gap: 8px; }
.levels li b { font-size: 15px; }
.lv-sub { font-size: 12px; font-weight: 700; margin: 8px 0 5px; letter-spacing: .5px; }
.up-c { color: var(--up); } .down-c { color: var(--down); }
.why-title { font-size: 13px; font-weight: 700; margin: 14px 0 8px; }
.hbtn { padding: 5px 12px; font-size: 13px; border-radius: 999px; }
.hbtn.active { background: var(--accent); }
.prob-bar { height: 12px; border-radius: 999px; background: var(--panel2); overflow: hidden; margin: 8px 0 4px; }
.prob-bar i { display: block; height: 100%; border-radius: 999px; transition: width .4s; }
.range-sel { background: var(--panel); color: var(--txt); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; }

/* ---------- News sentiment ---------- */
.senti-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.senti-score { font-size: 30px; font-weight: 800; }
.senti-bars { flex: 1; }
.senti-bar { height: 8px; border-radius: 999px; margin: 3px 0; background: var(--panel2); overflow: hidden; }
.senti-bar i { display: block; height: 100%; border-radius: 999px; }
.news-list { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.news-list li { padding: 8px 10px; background: var(--panel2); border-radius: 8px; margin-bottom: 5px;
  display: flex; gap: 8px; align-items: flex-start; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.tag.pos { background: var(--up-soft); color: var(--up); }
.tag.neg { background: var(--down-soft); color: var(--down); }
.tag.neu { background: #2a2f3d; color: var(--muted); }
.news-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.news-body a { color: var(--txt); line-height: 1.45; }
.news-body a:hover { color: #58a6ff; }
.news-meta { font-size: 11px; color: var(--muted); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: right; }
td:first-child, th:first-child { text-align: left; color: var(--muted); }
th { color: var(--muted); font-weight: 600; }

/* ---------- Forms / game ---------- */
.invest-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.invest-row input[type=number], .invest-row input[type=text], .invest-row input[type=date], #vCode, #rpCode {
  padding: 9px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; color: var(--txt); }
.invest-row input:focus { outline: none; border-color: var(--accent); }
input[type=range] { width: 240px; accent-color: var(--accent); }
.result { margin-top: 12px; padding: 14px; border-radius: 10px; background: var(--panel2); line-height: 1.8; }
.board { color: var(--muted); font-size: 13px; margin-left: 14px; }
.vsummary { display: flex; gap: 28px; font-size: 15px; margin-bottom: 10px; flex-wrap: wrap;
  padding: 14px; background: var(--panel2); border-radius: 10px; }
.vsummary b { font-size: 22px; }
.rp-day { font-size: 14px; margin-bottom: 4px; }
.rp-price { font-size: 24px; font-weight: 800; margin-bottom: 6px; }

footer { padding: 18px 24px; font-size: 12px; border-top: 1px solid var(--line); margin-top: 24px;
  color: var(--muted); text-align: center; }
.hidden { display: none !important; }

/* ========== 重構：報價列 + 子分頁 ========== */
.sh-last, .st-v, .sc-val, td, th, .pick-weight, .fair-now b, .fair-line b { font-variant-numeric: tabular-nums; }

/* 報價列 */
.quote-bar { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 20px; margin-bottom: 12px; box-shadow: var(--shadow); }
.q-top { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.q-id { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.sh-name { font-size: 21px; font-weight: 800; letter-spacing: .3px; }
.sh-last { font-size: 32px; font-weight: 800; letter-spacing: .5px; }
.sh-chg { font-size: 17px; font-weight: 700; padding: 4px 12px; border-radius: 8px; }
.sh-chg.up { background: var(--up-soft); color: var(--up); }
.sh-chg.down { background: var(--down-soft); color: var(--down); }
.quote-bar .sh-tools { margin-left: auto; }

/* 報價列內的重點數據（無框、靠分隔線） */
.quote-bar .stats-strip { margin: 14px 0 0; border: none; border-top: 1px solid var(--line);
  border-radius: 0; background: transparent; gap: 0; padding-top: 12px; }
.quote-bar .st-cell { background: transparent; padding: 6px 14px 6px 0; }

/* 子分頁 */
.subtabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 18px; flex-wrap: wrap; }
.subtab { background: transparent; color: var(--muted); border: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; padding: 10px 20px; font-size: 15px; font-weight: 600; cursor: pointer; transition: .15s; }
.subtab:hover { color: var(--txt); background: var(--panel2); border-radius: 8px 8px 0 0; }
.subtab.active { color: var(--accent); border-bottom-color: var(--accent); }
.sub-panel { display: none; }
.sub-panel.active { display: block; animation: fade .25s; }
.funda-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }

/* ---------- 主題切換鈕 ---------- */
.icon-btn { background: var(--panel2); color: var(--txt); border: 1px solid var(--line);
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px; padding: 0; margin-left: auto; }
.icon-btn:hover { background: var(--line); transform: none; }
/* 帳號鈕只放圖示 👤（不放文字，避免溢出遮住下方內容）；登入後高亮 */
#accountBtn { margin-left: 8px; }
#accountBtn.logged-in { border-color: var(--accent); color: var(--accent); }
#accountBtn.hidden { display: none; }

/* ---------- 導覽橫幅 ---------- */
.onboard { max-width: 1400px; margin: 14px auto 0; padding: 12px 18px; background: linear-gradient(90deg, rgba(41,98,255,.16), rgba(138,92,255,.16));
  border: 1px solid var(--accent); border-radius: 12px; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.onboard b { color: var(--accent); }
.onboard button { margin-left: auto; padding: 6px 14px; font-size: 13px; }

/* ---------- 搜尋自動完成 ---------- */
.search-wrap { position: relative; }
.suggest { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  overflow: hidden; max-height: 360px; overflow-y: auto; }
.sg-item { padding: 10px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); }
.sg-item:last-child { border-bottom: none; }
.sg-item:hover, .sg-item.active { background: var(--panel2); }
.sg-item b { color: var(--accent); min-width: 48px; }
.sg-item span { color: var(--txt); }
.sg-tag { margin-left: auto; font-style: normal; font-size: 11px; color: var(--down); background: var(--down-soft); padding: 1px 7px; border-radius: 999px; }
.sg-tag.mkt { margin-left: 8px; color: var(--accent); background: rgba(41,98,255,.14); }
.mkt-tag { font-size: 12px; font-weight: 700; color: var(--accent); background: rgba(41,98,255,.14);
  padding: 2px 9px; border-radius: 999px; vertical-align: middle; }
#favBtn.fav-on { background: var(--up-soft); color: var(--up); border-color: var(--up); }

/* ---------- 自選股列 ---------- */
.watchbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.wb-label { font-size: 12px; color: var(--muted); margin: 0 2px 0 6px; font-weight: 700; }
.chip-stock { padding: 5px 11px; background: var(--panel2); border: 1px solid var(--line); border-radius: 999px;
  font-size: 13px; cursor: pointer; transition: .15s; }
.chip-stock:hover { border-color: var(--accent); color: var(--accent); }

/* ---------- 個股工具列 ---------- */
.sh-tools { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.alert-wrap { display: inline-flex; gap: 4px; align-items: center; }
#alertPrice { width: 100px; padding: 7px 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; color: var(--txt); }
.mini { padding: 7px 11px; font-size: 13px; }

/* ---------- 進度條 ---------- */
.progress { height: 8px; background: var(--panel2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), #8a5cff); transition: width .4s; }

/* ---------- 選股榜 ---------- */
.boards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.board h3 small { font-size: 11px; }
.board-tbl { font-size: 13px; }
.board-tbl th { font-size: 11px; }
.board-tbl tr[data-code] { cursor: pointer; }
.board-tbl tr[data-code]:hover td { background: var(--panel2); }
.board-tbl td:first-child { color: var(--txt); font-weight: 600; }
.board-tbl .bn { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 12px; }

/* ---------- 比較 chips ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; background: var(--panel2);
  border: 1px solid var(--line); border-left-width: 3px; border-radius: 8px; font-size: 13px; }
.chip i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.chip a { cursor: pointer; color: var(--muted); margin-left: 2px; }
.chip a:hover { color: var(--up); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-right: 6px; }

/* ---------- Toast ---------- */
.toast-box { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { padding: 12px 18px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: var(--shadow); font-size: 14px; opacity: 0; transform: translateX(20px); transition: .3s; max-width: 340px; }
.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { border-left: 4px solid var(--down); }
.toast.error { border-left: 4px solid var(--up); }
.toast.info { border-left: 4px solid var(--accent); }

/* ---------- 三大法人 / 月營收 ---------- */
.inst-sum { display: flex; gap: 8px; margin-bottom: 10px; }
.inst-chip { flex: 1; background: var(--panel2); border-radius: 8px; padding: 8px; text-align: center;
  display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.inst-chip b { font-size: 15px; }
.rev-latest { font-size: 14px; margin-bottom: 8px; padding: 8px 10px; background: var(--panel2); border-radius: 8px; }

/* ---------- 重點數據條（Yahoo 風格）---------- */
.stats-strip { display: grid; grid-template-columns: repeat(8, 1fr); gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 14px; }
@media (max-width: 980px) { .stats-strip { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 560px) { .stats-strip { grid-template-columns: repeat(3, 1fr); } }
.st-cell { background: var(--panel); padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.st-l { font-size: 11px; color: var(--muted); }
.st-v { font-size: 14px; font-weight: 700; }

/* ---------- 智慧撮合價 ---------- */
.fair-card { border: 1px solid #8a5cff; }
.fair-main { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.fair-now { font-size: 14px; } .fair-now b { font-size: 20px; }
.fair-eq { font-size: 14px; font-weight: 700; }
.fair-line { font-size: 13px; margin-bottom: 10px; } .fair-line b { font-size: 18px; color: #a371f7; }
.fair-gauge { position: relative; height: 8px; border-radius: 999px; margin: 6px 0 14px;
  background: linear-gradient(90deg, var(--down), #5a6173, var(--up)); }
#fairBar { position: absolute; top: -4px; width: 4px; height: 16px; background: #fff; border-radius: 2px;
  transform: translateX(-50%); box-shadow: 0 0 6px rgba(255,255,255,.7); transition: left .4s; }

/* ---------- AI 選股配置 ---------- */
.pick { cursor: pointer; transition: .15s; }
.pick:hover { border-color: var(--accent); transform: translateY(-2px); }
.pick-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pick-rank { font-size: 13px; font-weight: 800; color: #fff; background: var(--accent); border-radius: 8px; padding: 2px 9px; }
.pick-name { font-size: 16px; font-weight: 700; }
.pick-weight { margin-left: auto; font-size: 18px; font-weight: 800; color: var(--accent); }
.weight-bar { height: 8px; border-radius: 999px; background: var(--panel2); overflow: hidden; margin-bottom: 10px; }
.weight-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #8a5cff); border-radius: 999px; }
.pick-tbl td { font-size: 13px; padding: 5px 8px; }
.pick-reason { margin-top: 8px; font-size: 13px; background: var(--panel2); padding: 8px 10px; border-radius: 8px; line-height: 1.5; }
.vg-badge { display: inline-block; font-weight: 700; font-size: 13px; padding: 5px 12px; border-radius: 999px; margin-bottom: 8px; }
.vg-slow { background: rgba(88,166,255,.15); color: #58a6ff; border: 1px solid rgba(88,166,255,.4); }
.vg-normal { background: rgba(248,81,73,.12); color: #f0883e; border: 1px solid rgba(240,136,62,.4); }

/* ---------- 策略成績單 ---------- */
.why-box { background: var(--panel2); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.why-verdict { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.why-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .why-cols { grid-template-columns: 1fr; } }
.why-basis { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.score-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
@media (max-width: 760px) { .score-grid { grid-template-columns: repeat(2, 1fr); } }
.score-cell { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; text-align: center; }
.sc-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.sc-val { font-size: 18px; font-weight: 800; }
.bt-trades-wrap { max-height: 280px; overflow-y: auto; }
.bt-trades th { font-size: 11px; position: sticky; top: 0; background: var(--panel); }
.bt-trades td { font-size: 12px; text-align: center; }
.bt-trades td:first-child, .bt-trades th:first-child { text-align: center; }

/* ---------- 進出場時機卡 ---------- */
.timing-card { border: 1px solid var(--accent); }
.tm-meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin: 8px 0; }
.tm-meta b { font-size: 14px; color: var(--txt); margin-left: 3px; }
.tm-block { margin: 8px 0; }
.tm-block .lv-sub b { font-weight: 700; }
.tm-plan { margin-top: 8px; }
.tm-plan td { font-size: 13px; }
.tm-plan td:nth-child(1), .tm-plan td:nth-child(3) { color: var(--muted); }

/* ---------- 手機優化 ---------- */
@media (max-width: 680px) {
  header { padding: 10px 14px; gap: 10px; }
  header h1 { font-size: 15px; }
  nav { gap: 4px; order: 3; width: 100%; overflow-x: auto; }
  .tab { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .icon-btn { margin-left: 0; }
  .tab-panel { padding: 16px 12px; }
  #codeInput { width: 100%; max-width: none; }
  .searchbar { gap: 8px; }
  .sh-tools { width: 100%; margin-left: 0; }
  .boards-grid { grid-template-columns: 1fr; }
}
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 登入 / 註冊 Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-overlay.hidden { display: none; }
.modal-box { position: relative; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 26px 24px; width: 340px; max-width: 92vw;
  box-shadow: 0 12px 40px rgba(0,0,0,.4); }
.modal-x { position: absolute; top: 10px; right: 12px; background: none; border: none;
  color: var(--muted); font-size: 16px; cursor: pointer; }
.modal-x:hover { color: var(--txt); }
.auth-box h2 { margin: 0 0 4px; font-size: 20px; color: var(--txt); }
.auth-sub { margin: 0 0 16px; font-size: 12px; color: var(--muted); line-height: 1.5; }
.auth-sub b { color: var(--accent); }
#authForm label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
#authForm input { width: 100%; box-sizing: border-box; margin-top: 5px; padding: 9px 11px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--txt); font-size: 14px; }
#authForm input:focus { outline: none; border-color: var(--accent); }
.primary-btn { width: 100%; padding: 10px; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 4px; }
.primary-btn:hover { background: var(--accent2); }
.primary-btn:disabled { opacity: .6; cursor: default; }
.auth-err { background: var(--up-soft); color: var(--up); font-size: 12px;
  padding: 8px 10px; border-radius: 7px; margin-bottom: 12px; }
.auth-err.hidden { display: none; }
.auth-switch { text-align: center; margin-top: 14px; font-size: 12px; color: var(--muted); }
.auth-switch a { color: var(--accent); cursor: pointer; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-switch .hidden { display: none; }

/* ---------- 登入牆（全螢幕，沒登入只看到這頁）---------- */
.auth-gate { position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center;
  justify-content: center; padding: 20px;
  background: radial-gradient(1100px 560px at 50% -8%, rgba(41,98,255,.20), transparent), var(--bg); }
.auth-gate.hidden { display: none; }
.auth-gate-box { position: relative; width: 360px; max-width: 92vw; background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 30px 26px; box-shadow: 0 24px 70px rgba(0,0,0,.55); }
.auth-gate-close { position: absolute; top: 12px; right: 14px; background: none; border: none;
  color: var(--muted); font-size: 16px; cursor: pointer; }
.auth-gate-close:hover { color: var(--txt); }
.auth-gate-close.hidden { display: none; }
.login-link { color: var(--accent); cursor: pointer; text-decoration: underline; }
.auth-brand { font-size: 22px; font-weight: 800; text-align: center; margin-bottom: 16px;
  background: linear-gradient(90deg, #4d8bff, #8a5cff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.auth-gate-box h2 { margin: 0 0 4px; font-size: 20px; color: var(--txt); }
body.gated { overflow: hidden; }

/* ---------- 新聞情緒榜 ---------- */
.news-tbl td:nth-child(3) { max-width: 320px; }
.news-head { color: var(--txt); text-decoration: none; font-size: 12px;
  display: inline-block; max-width: 240px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: middle; }
.news-head:hover { color: var(--accent); text-decoration: underline; }
.news-pill { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px;
  margin-right: 4px; vertical-align: middle; }
.news-pill.pos { background: var(--up-soft); color: var(--up); }
.news-pill.neg { background: var(--down-soft); color: var(--down); }
.news-pill.neu { background: var(--panel2); color: var(--muted); }

/* ---------- 主力選股 ---------- */
.stat-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
@media (max-width: 720px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 5px; }
.stat-box .sb-k { font-size: 12px; color: var(--muted); }
.stat-box .sb-v { font-size: 22px; font-weight: 700; color: var(--txt); }
.chip-inline { display: inline-block; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 6px; font-size: 12px; color: var(--accent); cursor: pointer; }
.chip-inline:hover { background: var(--line); }

/* ---------- 登入者：我的自選股儀表板 ---------- */
.my-watch.hidden { display: none; }
.my-watch { margin: 10px 0 4px; }
.quote-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.quote-card { display: flex; flex-direction: column; gap: 3px; padding: 10px 12px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
  text-decoration: none; transition: border-color .15s; }
.quote-card:hover { border-color: var(--accent); }
.qc-name { font-size: 13px; color: var(--txt); font-weight: 600; }
.qc-name small { color: var(--muted); font-weight: 400; margin-left: 5px; font-size: 11px; }
.qc-last { font-size: 19px; font-weight: 700; color: var(--txt); }
.qc-live { color: #e23; font-size: 11px; vertical-align: middle; animation: qcpulse 1.6s infinite; }
@keyframes qcpulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }
.qc-chg { font-size: 13px; font-weight: 600; }

/* 看股頁即時報價標記 */
.sh-rt { font-size: 11px; color: var(--muted); margin-left: 8px; vertical-align: middle;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; }
.sh-rt.live { color: var(--up); border-color: var(--up); animation: rtpulse 2s infinite; }
@keyframes rtpulse { 0%,100% { opacity: 1; } 50% { opacity: .55; } }

/* 主力選股 短線/長線 切換按鈕 */
.mode-btn{padding:6px 14px;border:1px solid var(--border,#3a3f4b);border-radius:18px;background:transparent;color:inherit;cursor:pointer;margin-right:8px;font-size:14px;transition:.15s}
.mode-btn:hover{border-color:#f23645}
.mode-btn.active{background:#f23645;color:#fff;border-color:#f23645;font-weight:600}
/* 主力選股 三步驟引導 */
.pf-step { margin: 12px 0; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.pf-step:last-of-type { border-bottom: none; padding-bottom: 0; }
.pf-step-title { font-weight: 700; font-size: 15px; margin-bottom: 9px; }
.pf-choice-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pf-choice-row label { display: inline-flex; align-items: center; gap: 4px; }
.pf-prof-btn, .pf-mode-btn { padding: 8px 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel2); color: var(--txt); cursor: pointer; font-size: 14px; font-weight: 600; transition: .15s; }
.pf-prof-btn small, .pf-mode-btn small { font-weight: 400; opacity: .65; margin-left: 5px; font-size: 11px; }
.pf-prof-btn:hover, .pf-mode-btn:hover { border-color: var(--accent); transform: translateY(-1px); }
.pf-prof-btn.active, .pf-mode-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pf-method { margin: 8px 0; }
.pf-method-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.pf-method-sub { font-weight: 400; opacity: .8; }
.pf-hint { font-size: 12.5px; color: var(--muted); margin: 9px 0 0; line-height: 1.55; }
.pf-quiz-link { font-size: 12px; color: var(--accent); cursor: pointer; margin-left: 6px; }

/* 投資人測驗 */
.qz-opts{display:flex;flex-wrap:wrap;gap:6px}
.qz-opt{display:inline-flex;align-items:center;gap:5px;padding:6px 12px;border:1px solid #2a3550;border-radius:8px;cursor:pointer;font-size:14px}
.qz-opt:hover{border-color:#4f7cff;background:#16203a}
.qz-opt input{accent-color:#4f7cff}

/* MA 圖例 */
.ma-legend{display:flex;flex-wrap:wrap;gap:14px;align-items:center;margin:4px 0 6px;font-size:13px;color:#9aa4b2}
.ma-legend span{display:inline-flex;align-items:center;gap:5px}
.ma-legend i{display:inline-block;width:16px;height:3px;border-radius:2px}

/* ===== 🔔 通知設定（獨立分頁，手機優先） ===== */
.notify-page h3{margin:0 0 6px}
.ntf-block{padding:16px 0;border-top:1px solid var(--line)}
.ntf-block:first-of-type{border-top:none;padding-top:10px}
.ntf-block-h{font-weight:700;font-size:15px;margin-bottom:12px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.ntf-block-h small{font-weight:400;font-size:12px}
.ntf-state{font-size:13px;font-weight:600}
.ntf-state.ok{color:var(--up,#22c55e)}
.ntf-state.no{color:var(--muted)}
.ntf-btn{width:100%;min-height:46px;font-size:15px;border-radius:10px}
/* 通知種類 chips：手機 2 欄、大點擊區 */
.ntf-kinds{display:flex;flex-wrap:wrap;gap:10px}
.ntf-kind{flex:1 1 calc(50% - 10px);min-width:128px;display:flex;align-items:center;gap:9px;
  padding:13px 14px;border:1px solid var(--line);border-radius:10px;background:var(--panel2);
  cursor:pointer;font-size:15px;user-select:none}
.ntf-kind input{width:19px;height:19px;flex-shrink:0;accent-color:var(--accent)}
.ntf-kind:has(input:checked){border-color:var(--accent);box-shadow:0 0 0 1px var(--accent) inset}
/* 自訂到價表單：全寬堆疊、字級 16px 防 iOS 放大 */
.ntf-form{display:flex;flex-direction:column;gap:11px}
.ntf-in{width:100%;box-sizing:border-box;padding:13px 14px;font-size:16px;border-radius:10px;
  border:1px solid var(--line);background:var(--panel);color:var(--txt)}
.ntf-op{display:flex;gap:10px}
.ntf-op-btn{flex:1;display:flex;align-items:center;justify-content:center;gap:6px;min-height:46px;
  border:1px solid var(--line);border-radius:10px;background:var(--panel2);cursor:pointer;font-size:15px}
.ntf-op-btn input{display:none}
.ntf-op-btn:has(input:checked){border-color:var(--accent);box-shadow:0 0 0 1px var(--accent) inset;font-weight:700}
/* 已設清單 */
.ntf-list{margin-top:14px;display:flex;flex-direction:column;gap:8px}
.ntf-ca{display:flex;align-items:center;gap:10px;padding:12px 14px;border:1px solid var(--line);
  border-radius:10px;background:var(--panel2)}
.ntf-ca.off{opacity:.5}
.ntf-ca .ca-info{flex:1;font-size:15px;line-height:1.45}
.ntf-ca .ca-act{display:flex;gap:8px;flex-shrink:0}
.ntf-ca .ca-act .ghost{padding:8px 13px;font-size:13px;min-height:38px}
.ntf-empty{color:var(--muted);padding:12px 0;font-size:14px}
/* 綁定流程:加好友按鈕(LINE綠)+可點複製的綁定碼 */
.ntf-bind-step{margin:10px 0}
.ntf-add-friend{display:inline-flex;align-items:center;gap:6px;margin-top:6px;padding:11px 18px;
  background:#06C755;color:#fff;font-weight:700;font-size:15px;border-radius:10px;text-decoration:none}
.ntf-add-friend:hover{filter:brightness(1.05)}
.ntf-code{display:inline-block;margin-top:6px;padding:8px 16px;font-size:24px;font-weight:800;
  letter-spacing:4px;background:var(--panel);border:1px dashed var(--accent);border-radius:10px;cursor:pointer}
.ntf-qr{margin-top:10px}
.ntf-qr img{width:140px;height:140px;background:#fff;padding:6px;border-radius:10px}
.ntf-qr .muted{font-size:12px;margin-top:4px}
/* 桌機加寬時表單橫排更省空間 */
@media(min-width:620px){
  .ntf-form{flex-direction:row;flex-wrap:wrap;align-items:center}
  #caCode{flex:1 1 160px} #caPrice{flex:1 1 130px}
  .ntf-op{flex:0 0 auto} .ntf-btn{width:auto;flex:0 0 auto;padding:0 22px}
}

/* ===== 🔔 通知中心 v2（三層式重設計） ===== */
/* [hidden] 必須勝過下面那些 display:flex 的元件,否則預設會露出來 */
[hidden]{display:none!important}
/* 區塊0 狀態列 */
.ntf-status{padding:14px 16px;border:1px solid var(--line);border-radius:14px;background:var(--panel2);margin-bottom:6px}
.ntf-status-top{display:flex;align-items:center;justify-content:space-between}
.ntf-status-title{font-size:18px;font-weight:800}
.ntf-status-line{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px;margin-top:8px}
.ntf-status-actions{display:flex;gap:8px;flex-wrap:wrap}
.ntf-mini{padding:7px 12px;font-size:13px;min-height:34px;border-radius:8px}
.ntf-snooze{margin-top:10px;padding:9px 12px;border-radius:9px;background:rgba(245,158,11,.13);
  border:1px solid rgba(245,158,11,.4);font-size:13px;display:flex;align-items:center;gap:8px;flex-wrap:wrap}
/* iOS 風 Toggle 開關 */
.ntf-switch{position:relative;display:inline-block;width:50px;height:30px;flex-shrink:0}
.ntf-switch.sm{width:46px;height:27px}
.ntf-switch input{opacity:0;width:0;height:0}
.ntf-slider{position:absolute;inset:0;cursor:pointer;background:var(--line);border-radius:30px;transition:.2s}
.ntf-slider:before{content:"";position:absolute;height:24px;width:24px;left:3px;bottom:3px;background:#fff;border-radius:50%;transition:.2s}
.ntf-switch.sm .ntf-slider:before{height:21px;width:21px}
.ntf-switch input:checked+.ntf-slider{background:var(--accent)}
.ntf-switch input:checked+.ntf-slider:before{transform:translateX(20px)}
.ntf-switch.sm input:checked+.ntf-slider:before{transform:translateX(19px)}
/* 區塊1 預設包 */
.ntf-presets{display:grid;grid-template-columns:repeat(2,1fr);gap:10px}
.ntf-preset{display:flex;flex-direction:column;align-items:center;gap:3px;padding:14px 8px;
  border:1px solid var(--line);border-radius:12px;background:var(--panel2);cursor:pointer;text-align:center}
.ntf-preset b{font-size:15px} .ntf-preset small{font-size:11px;color:var(--muted)}
.ntf-preset.on{border-color:var(--accent);box-shadow:0 0 0 2px var(--accent) inset;background:var(--panel)}
/* 區塊2 分組事件 Toggle */
.ntf-grp-h{font-size:12px;color:var(--muted);margin:14px 0 6px;letter-spacing:1px}
.ntf-grp-h:first-child{margin-top:0}
.ntf-kind2{display:flex;align-items:center;gap:12px;padding:11px 4px;border-bottom:1px solid var(--line)}
.ntf-kind2-txt{flex:1}
.ntf-kind2-t{font-size:15px;font-weight:600}
.ntf-kind2-d{font-size:12px;margin-top:2px}
/* 第3層 個股覆寫 */
.ntf-ov{margin-top:16px;border-top:1px dashed var(--line);padding-top:10px}
.ntf-collapse{cursor:pointer;display:flex;align-items:center;gap:6px;font-weight:700;font-size:14px;user-select:none}
.ntf-chev{margin-left:auto;transition:.2s} .ntf-collapse.open .ntf-chev{transform:rotate(180deg)}
.ov-body{margin-top:8px}
.ov-row{display:flex;align-items:center;gap:8px;padding:9px 2px;border-bottom:1px solid var(--line)}
.ov-name{flex:1;font-size:14px} .ov-state{font-size:12px;color:var(--muted)} .ov-state.on{color:var(--accent);font-weight:600}
.ov-gear{padding:5px 9px;min-height:32px;font-size:13px}
.ov-edit{padding:8px 2px 12px}
.ov-kinds{display:flex;flex-wrap:wrap;gap:7px}
.ov-chip{display:inline-flex;align-items:center;gap:5px;padding:6px 10px;border:1px solid var(--line);
  border-radius:20px;font-size:13px;cursor:pointer;background:var(--panel2)}
.ov-chip:has(input:checked){border-color:var(--accent);box-shadow:0 0 0 1px var(--accent) inset}
.ov-chip input{accent-color:var(--accent)}
.ov-edit-act{display:flex;gap:8px;margin-top:9px} .ov-edit-act button{flex:1;min-height:38px}
/* 區塊3 到價提醒 引導面板 */
.ca-panel{margin:8px 0 4px;padding:14px;border:1px solid var(--accent);border-radius:12px;background:var(--panel2);display:flex;flex-direction:column;gap:11px}
.ca-panel-row{display:flex;align-items:center;gap:10px;flex-wrap:wrap}
.ca-meta{font-size:13px} .ca-meta b{color:var(--txt)}
.ca-quick{display:flex;gap:6px;flex-wrap:wrap}
.ca-quick button{padding:7px 11px;font-size:13px;border:1px solid var(--line);border-radius:8px;background:var(--panel);color:var(--txt);cursor:pointer}
.ca-quick button:hover{border-color:var(--accent)}
.ca-panel-actions{display:flex;gap:10px} .ca-panel-actions button{flex:1;min-height:44px;border-radius:10px}
.ca-dist{font-size:12px;font-weight:700;margin-left:4px} .ca-dist.up{color:var(--up,#22c55e)} .ca-dist.down{color:var(--down,#ef4444)}
/* 區塊5 通知紀錄 */
.ntf-logwrap{display:flex;flex-direction:column}
.ntf-logrow{display:flex;align-items:center;gap:10px;padding:9px 2px;border-bottom:1px solid var(--line);font-size:13px}
.ntf-logrow .lg-t{color:var(--muted);flex-shrink:0;font-variant-numeric:tabular-nums}
.ntf-logrow .lg-n{font-weight:600;flex-shrink:0}
.ntf-logrow .lg-k{color:var(--muted);margin-left:auto;text-align:right}
@media(min-width:620px){ .ntf-presets{grid-template-columns:repeat(4,1fr)} }
