:root {
  --bg: #f6f5f1; --surface: #ffffff; --surface-2: #efede7; --line: #e3e0d8;
  --text: #1c1b18; --muted: #77746b; --accent: #1f4e79; --accent-ink: #ffffff;
  --up: #d23a3a; --down: #168a52; --flat: #77746b; --warn: #b7791f;
  --up-bg: rgba(210,58,58,.10); --down-bg: rgba(22,138,82,.10);
  --radius: 14px; --shadow: 0 1px 2px rgba(30,25,10,.06);
  --font: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "SF Mono", "Roboto Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121315; --surface: #1b1c1f; --surface-2: #25272b; --line: #2e3035;
    --text: #ecebe6; --muted: #9a998f; --accent: #7fb2e5; --accent-ink: #0f1a26;
    --up: #ff6b6b; --down: #3fcf8e; --flat: #9a998f; --warn: #e0a63a;
    --up-bg: rgba(255,107,107,.12); --down-bg: rgba(63,207,142,.12);
    --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); overflow-x: hidden; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.up { color: var(--up); } .down { color: var(--down); } .flat { color: var(--flat); }
.muted { color: var(--muted); } .small { font-size: 12.5px; }

/* 頂部 */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); padding: calc(10px + env(safe-area-inset-top)) 0 8px; }
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.title { font-size: 20px; font-weight: 700; letter-spacing: .02em; margin: 0; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; margin-top: 8px; background: var(--surface-2); padding: 3px; border-radius: 12px; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: 1 0 auto; white-space: nowrap; text-align: center; text-decoration: none; color: var(--muted); padding: 7px 10px; border-radius: 9px; font-size: 14px; }
.nav a.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.status { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); margin: 6px 0 0; flex-wrap: wrap; gap: 2px 14px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--flat); flex: none; }
.dot.on { background: var(--down); box-shadow: 0 0 0 3px var(--down-bg); }

/* 元件 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { margin: 12px 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); text-decoration: none; color: inherit; min-height: 58px; }
.row:first-child { border-top: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12.5px; color: var(--muted); }
.row .px { text-align: right; flex: none; }
.row .px b { display: block; font-size: 17px; font-weight: 600; }
.chip { display: inline-block; min-width: 74px; text-align: right; padding: 2px 8px; border-radius: 8px; font-size: 13px; font-family: var(--mono); }
.chip.up { background: var(--up-bg); } .chip.down { background: var(--down-bg); } .chip.flat { background: var(--surface-2); }
.btn { text-decoration: none; color: var(--text); border: 1px solid var(--line); background: var(--surface); border-radius: 11px; padding: 9px 14px; min-height: 40px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; justify-content: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn.danger { color: var(--up); }
.btn.sm { padding: 5px 10px; min-height: 34px; font-size: 13.5px; }
.btn.icon { padding: 0; width: 40px; }
.btn:disabled { opacity: .5; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=datetime-local], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); min-height: 44px; font-size: 16px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form { padding: 4px 14px 14px; margin: 12px 0; }
.sect { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 6px; }
.sect h2 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 0; letter-spacing: .04em; }
.empty { text-align: center; color: var(--muted); padding: 28px 16px; }
.warn { color: var(--warn); font-size: 13px; margin: 6px 0 0; }
.suggest { margin-top: 6px; overflow: hidden; }
.suggest button { width: 100%; text-align: left; border: 0; border-top: 1px solid var(--line); background: transparent; padding: 11px 14px; cursor: pointer; display: flex; gap: 10px; }
.suggest button:first-child { border-top: 0; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--surface-2); color: var(--muted); }
.tag.buy { background: var(--up-bg); color: var(--up); } .tag.sell { background: var(--down-bg); color: var(--down); }

/* 圖表頁 */
.hero { padding: 6px 0 4px; display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; }
.hero .big { font-size: 34px; font-weight: 700; line-height: 1.1; }
.chart-box { margin-top: 8px; padding: 6px; }
#chart { width: 100%; height: 56vh; min-height: 320px; max-height: 520px; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; padding: 6px 8px 2px; font-family: var(--mono); }
.legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--line); border-radius: 12px; overflow: hidden; margin-top: 10px; }
.kv div { background: var(--surface); padding: 8px 10px; }
.kv small { display: block; color: var(--muted); font-size: 11.5px; }
.actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

/* 登入 */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 360px; padding: 26px 22px; }
.login h1 { margin: 0 0 4px; font-size: 24px; }
.err { color: var(--up); font-size: 14px; min-height: 20px; margin: 8px 0 0; }

.foot { margin-top: 28px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.8; }
.foot a { color: inherit; }
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; font-size: 14px; max-width: 86vw; z-index: 20; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 1.1.0：選股、設定、體檢、圖表開關 */
.pad { padding: 14px; margin: 12px 0; }
.toggles { display: flex; flex-wrap: wrap; gap: 4px 18px; margin: 10px 2px 0; font-size: 13.5px; }
.toggles label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.toggles label[hidden] { display: none; }
.toggles input, .sw input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.note { margin: 10px 2px 0; line-height: 1.6; }
.scr-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.scr-head select { min-width: 150px; }
.regime { text-align: right; } .regime b { display: block; font-size: 20px; }
.srow { align-items: flex-start; }
.srow-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.srow .hits { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.tag.hit { background: var(--surface-2); color: var(--text); }
.score { text-align: center; flex: none; min-width: 34px; line-height: 1.1; } .score b { font-size: 20px; } .score small { display: block; color: var(--muted); font-size: 11px; }
.sw { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.sw:first-of-type { border-top: 0; }
.sw span { display: block; } .sw small { display: block; font-size: 12px; }
.lvl { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; } .lvl b { font-size: 20px; }
.advice { margin: 10px 0 0; padding-left: 18px; font-size: 13.5px; }
