/* 每日選股 — built for reading on a phone, at arm's length, by people over 60.
   Warm paper background, deep navy brand, Taiwan price colors (red up, green down).
   Good/caution signals use blue/amber so they never read as price moves. */

:root {
  --bg: #f4f1ea;
  --surface: #ffffff;
  --surface-sunk: #f8f6f1;
  --ink: #1b1d21;
  --ink-2: #4a4f57;
  --ink-3: #6b7079;
  --line: #e6e0d5;
  --brand: #183a63;
  --brand-ink: #ffffff;
  --brand-soft: #e7eef8;
  --gold: #a87a22;
  --up: #cf2e27;
  --up-soft: #fdebe9;
  --down: #1b7f45;
  --down-soft: #e5f4ea;
  --flat: #6b7079;
  --good: #1d5fa8;
  --good-soft: #e8f0fa;
  --warn: #935700;
  --warn-soft: #fff3d9;
  --shadow: 0 1px 2px rgba(24, 58, 99, 0.05), 0 8px 24px rgba(24, 58, 99, 0.07);
  --radius: 18px;
  --bar: rgba(255, 255, 255, 0.82);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121418; --surface: #1c1f25; --surface-sunk: #171a1f; --ink: #f1f2f4; --ink-2: #c3c8d0;
    --ink-3: #9aa1ab; --line: #2c3139; --brand: #8fb6ec; --brand-ink: #0d1b2e; --brand-soft: #1f2b3d;
    --gold: #e0b35a; --up: #ff6b61; --up-soft: #3a1f1d; --down: #4cc47e; --down-soft: #16301f;
    --good: #8fb6ec; --good-soft: #1c2940; --warn: #f0b44c; --warn-soft: #33270f;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); --bar: rgba(28, 31, 37, 0.85); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121418; --surface: #1c1f25; --surface-sunk: #171a1f; --ink: #f1f2f4; --ink-2: #c3c8d0;
  --ink-3: #9aa1ab; --line: #2c3139; --brand: #8fb6ec; --brand-ink: #0d1b2e; --brand-soft: #1f2b3d;
  --gold: #e0b35a; --up: #ff6b61; --up-soft: #3a1f1d; --down: #4cc47e; --down-soft: #16301f;
  --good: #8fb6ec; --good-soft: #1c2940; --warn: #f0b44c; --warn-soft: #33270f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3); --bar: rgba(28, 31, 37, 0.85); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 19px; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  line-height: 1.6;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}
.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bar);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink);
  font-weight: 800; font-size: 1rem;
}
.brand-name { font-size: 1.1rem; font-weight: 800; letter-spacing: 0.02em; }
.date-chip {
  font-size: 0.8rem; color: var(--ink-2);
  background: var(--surface-sunk); border: 1px solid var(--line);
  padding: 3px 10px; border-radius: 999px; white-space: nowrap;
}

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bar);
  -webkit-backdrop-filter: blur(18px) saturate(170%);
  backdrop-filter: blur(18px) saturate(170%);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 4px; border-radius: 14px;
  color: var(--ink-3); text-decoration: none; font-size: 0.82rem; font-weight: 700;
  transition: transform 100ms ease-out;
}
.tabbar svg { width: 26px; height: 26px; }
.tabbar a[aria-current="page"] { color: var(--brand); background: var(--brand-soft); }
.tabbar a:active { transform: scale(0.96); }

main { max-width: 680px; margin: 0 auto; padding: 12px 16px 24px; }

/* ---------- headings & text ---------- */
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 26px 2px 10px; }
.section-head h2 { margin: 0; font-size: 1.2rem; letter-spacing: -0.01em; }
.section-head .count { color: var(--ink-3); font-size: 0.9rem; }
h3 { font-size: 1.02rem; margin: 0 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--ink-2); }
.small { font-size: 0.85rem; }

/* ---------- hero ---------- */
.hero {
  background: linear-gradient(145deg, #183a63 0%, #26548a 100%);
  color: #fff;
  border-radius: 22px;
  padding: 18px 18px 16px;
  box-shadow: var(--shadow);
}
.hero .eyebrow { font-size: 0.85rem; opacity: 0.85; }
.hero .headline { font-size: 1.4rem; font-weight: 800; line-height: 1.35; margin: 4px 0 12px; letter-spacing: -0.01em; }
.hero .headline b { font-size: 2.1rem; color: #ffd98a; margin: 0 3px; font-variant-numeric: tabular-nums; }
.market {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: rgba(255, 255, 255, 0.12); border-radius: 14px; padding: 10px 14px;
}
.market .label { font-size: 0.82rem; opacity: 0.85; }
.market .value { font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.market .move { font-weight: 800; padding: 3px 10px; border-radius: 999px; background: #fff; font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.stat { background: rgba(255, 255, 255, 0.12); border-radius: 12px; padding: 8px 10px; }
.stat .n { font-size: 1.25rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .t { font-size: 0.76rem; opacity: 0.88; line-height: 1.3; }

/* ---------- cards ---------- */
.card {
  display: block; position: relative;
  background: var(--surface); color: inherit; text-decoration: none;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin: 12px 0;
  box-shadow: var(--shadow);
  transition: transform 120ms ease-out;
}
a.card:active { transform: scale(0.985); }
.stock-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.stock-name { font-size: 1.3rem; font-weight: 800; line-height: 1.25; letter-spacing: -0.01em; }
.stock-meta { font-size: 0.82rem; color: var(--ink-3); margin-top: 2px; }
.price-box { text-align: right; white-space: nowrap; }
.price { font-size: 1.35rem; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.move-pill {
  display: inline-block; margin-top: 4px;
  font-size: 0.82rem; font-weight: 800; padding: 1px 9px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.move-pill.up { background: var(--up-soft); }
.move-pill.down { background: var(--down-soft); }
.move-pill.flat { background: var(--surface-sunk); }
.spark { display: block; width: 100%; height: 40px; margin: 10px 0 0; }

.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.85rem; font-weight: 700; line-height: 1.3;
  padding: 5px 10px; border-radius: 10px;
  background: var(--surface-sunk); color: var(--ink-3);
  border: 1px solid var(--line);
}
.badge svg { width: 16px; height: 16px; flex: none; }
.badge.ok { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.miss { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.empty-state { text-align: center; color: var(--ink-2); padding: 28px 12px; }
.empty-state svg { width: 48px; height: 48px; color: var(--ink-3); }

/* ---------- disclosure ---------- */
details.fold { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; box-shadow: var(--shadow); }
details.fold > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px 16px; font-weight: 700; min-height: 52px;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::after { content: "展開"; font-size: 0.85rem; color: var(--brand); font-weight: 800; }
details.fold[open] > summary::after { content: "收起"; }
details.fold .fold-body { padding: 0 16px 14px; }
details.fold .card { box-shadow: none; }
.rules { margin: 0; padding-left: 1.3em; }
.rules li { margin: 4px 0; }

/* ---------- Claude commentary ---------- */
.ai-card { border-left: 5px solid var(--gold); }
.ai-label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; font-weight: 800; color: var(--gold); letter-spacing: 0.02em; }
.ai-label svg { width: 16px; height: 16px; }
.ai-card h3 { margin: 6px 0 0; font-size: 1.1rem; }
.ai-card p { margin: 8px 0 0; }
.ai-summary { font-size: 1.12rem; font-weight: 800; line-height: 1.5; }
.ai-section { margin-top: 12px; }
.ai-section h4 { margin: 0; font-size: 0.95rem; color: var(--gold); }
.ai-section p { margin: 2px 0 0; }
.link-btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 48px;
  padding: 10px 18px; border-radius: 14px; border: 2px solid var(--line);
  background: var(--surface); color: var(--brand); font-weight: 700; text-decoration: none;
}

/* ---------- notice ---------- */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--warn-soft); color: var(--ink);
  border-radius: 14px; padding: 12px 14px; margin: 24px 0 8px;
  font-size: 0.86rem;
}
.notice svg { width: 20px; height: 20px; flex: none; color: var(--warn); margin-top: 2px; }

/* ---------- search ---------- */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 2px solid var(--line); border-radius: 16px;
  padding: 6px 6px 6px 14px; box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--brand); }
.search svg { width: 22px; height: 22px; color: var(--ink-3); flex: none; }
.search input {
  flex: 1; min-width: 0; border: none; outline: none; background: transparent; color: var(--ink);
  font: inherit; font-size: 1.1rem; padding: 8px 0;
}
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ---------- buttons ---------- */
button {
  font: inherit; font-size: 1rem; font-weight: 700;
  min-height: 48px; padding: 10px 18px; border-radius: 14px;
  border: 2px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  cursor: pointer; transition: transform 100ms ease-out;
}
button:active { transform: scale(0.97); }
button.ghost { background: var(--surface); color: var(--brand); }
button.chip {
  min-height: 44px; padding: 6px 14px; border-radius: 999px;
  background: var(--surface); color: var(--brand); border: 2px solid var(--line); font-size: 0.95rem;
}
button.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.star-btn { display: inline-flex; align-items: center; gap: 6px; }
.star-btn svg { width: 20px; height: 20px; }

/* ---------- stock detail ---------- */
.detail-head .price { font-size: 2.2rem; letter-spacing: -0.02em; }
.detail-actions { display: flex; gap: 10px; margin-top: 12px; }
.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px;
  background: var(--surface-sunk); border: 1px solid var(--line); border-radius: 14px; padding: 4px;
}
.segmented button { min-height: 44px; border: none; background: transparent; color: var(--ink-2); border-radius: 10px; }
.segmented button.on { background: var(--surface); color: var(--brand); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.kline { width: 100%; height: 560px; background: #fff; border-radius: 14px; overflow: hidden; margin-top: 10px; border: 1px solid var(--line); }
.kline-legend { margin-top: 10px; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.kline-legend .row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 14px; }
.kline-legend .row + .row { margin-top: 2px; }
.kline-legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; }
.chip-group { margin-top: 12px; }
.chip-group .label { font-size: 0.82rem; color: var(--ink-3); font-weight: 700; margin-bottom: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.signal-list { list-style: none; margin: 0; padding: 0; }
.signal-list li { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.signal-list li:first-child { border-top: none; }
.signal-list svg { width: 20px; height: 20px; flex: none; margin-top: 3px; }
.good-card h3 { color: var(--good); }
.good-card svg { color: var(--good); }
.warn-card h3 { color: var(--warn); }
.warn-card svg { color: var(--warn); }
.num-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.num-tile { background: var(--surface-sunk); border-radius: 12px; padding: 8px 10px; }
.num-tile .k { font-size: 0.78rem; color: var(--ink-3); line-height: 1.35; }
.num-tile .v { font-weight: 800; font-size: 0.98rem; line-height: 1.35; font-variant-numeric: tabular-nums; }

/* ---------- backtest ---------- */
.compare { display: grid; gap: 14px; }
.bar-row .bar-label { display: flex; justify-content: space-between; font-weight: 700; font-size: 0.95rem; }
.bar-track { height: 14px; background: var(--surface-sunk); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-fill.mine { background: var(--brand); }
.bar-fill.market { background: #9aa6b6; }
.year-row { display: grid; grid-template-columns: 3.2em 1fr 1fr; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.year-row:first-child { border-top: none; }
.year-row .h { font-size: 0.8rem; color: var(--ink-3); font-weight: 700; }
.variant-row { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.variant-row:first-child { border-top: none; }
.variant-row .name { flex: 1; }
.variant-row .vals { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 700; }
.variant-row .vals small { display: block; font-weight: 400; color: var(--ink-3); }

/* ---------- one-click analysis & toast ---------- */
button.ask {
  width: 100%; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  margin-top: 12px; background: var(--gold); border-color: var(--gold); color: #fff;
}
button.ask svg { width: 20px; height: 20px; }
button:disabled { opacity: 0.55; cursor: default; transform: none; }
button.ask.small { width: auto; min-height: 44px; margin-top: 10px; padding: 8px 14px; font-size: 0.95rem; }
.watch-card .card-link { display: block; color: inherit; text-decoration: none; }
.watch-card .card-link:active { opacity: 0.85; }
.ai-snippet { margin-top: 12px; padding: 10px 12px; border-radius: 12px; background: var(--surface-sunk); border-left: 4px solid var(--gold); }
.ai-snippet p { margin: 4px 0; font-size: 0.95rem; }
.ai-snippet a { font-weight: 800; color: var(--brand); font-size: 0.9rem; }
.watch-status { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.watch-status svg { width: 16px; height: 16px; color: var(--gold); }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 14px;
  background: #1b1d21; color: #fff; font-weight: 700; font-size: 0.95rem; text-align: center;
  transition: opacity 160ms ease-out, transform 160ms ease-out;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  a.card:active, button:active, .tabbar a:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .topbar, .tabbar { background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --line: #9a9489; --ink-3: #3f444b; }
}

/* ---------- desktop: top navigation and grids ---------- */
.topnav { display: none; }
@media (min-width: 900px) {
  html { font-size: 18px; }
  body { padding-bottom: 0; }
  .tabbar { display: none; }
  .topbar { padding: 12px 32px; gap: 24px; }
  .topnav { display: flex; gap: 6px; margin-right: auto; margin-left: 24px; }
  .topnav a {
    display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-radius: 12px;
    color: var(--ink-2); text-decoration: none; font-weight: 700;
  }
  .topnav a svg { width: 22px; height: 22px; }
  .topnav a:hover { background: var(--surface-sunk); }
  .topnav a[aria-current="page"] { background: var(--brand-soft); color: var(--brand); }
  main { max-width: 1240px; padding: 24px 32px 56px; }

  .top-grid { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 20px; align-items: stretch; }
  .top-grid > * { margin: 0; }
  .top-grid > :only-child { grid-column: 1 / -1; }
  .hero { padding: 24px; }
  .hero .headline { font-size: 1.6rem; }
  .hero .headline b { font-size: 2.6rem; }

  .card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; align-items: start; }
  .card-grid > .card { margin: 0; }
  details.fold .card-grid { padding-top: 4px; }
  a.card:hover, .watch-card:hover { box-shadow: 0 2px 4px rgba(24, 58, 99, 0.06), 0 14px 32px rgba(24, 58, 99, 0.12); }

  .search { max-width: 760px; }
  .detail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 24px; align-items: start; margin-top: 16px; }
  .detail-main { grid-column: 1; grid-row: 1; }
  .detail-side { grid-column: 2; grid-row: 1; }
  .detail-side > .card:first-child { margin-top: 0; }
  .detail-main > .section-head:first-child { margin-top: 0; }
  .kline { height: 680px; }
  .signal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .signal-grid > .card { margin: 0; }
  .num-grid { grid-template-columns: repeat(3, 1fr); }

  .bt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
  .bt-grid > div > .section-head:first-child { margin-top: 8px; }
}
@media (min-width: 1200px) {
  .num-grid { grid-template-columns: repeat(4, 1fr); }
}
