/* 台股時光機：mobile-first，色票取自 dataviz 參考色盤（淺色／深色各自選定） */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --good: #0ca30c;
  --good-ink: #006300;
  --bad: #d03b3b;
  --warn: #fab219;
  --band: rgba(137, 135, 129, 0.16);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --good-ink: #0ca30c;
    --bad: #e66767;
    --band: rgba(195, 194, 183, 0.14);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --good-ink: #0ca30c;
  --bad: #e66767;
  --band: rgba(195, 194, 183, 0.14);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 16px/1.6 system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}
main, .top, .foot { max-width: 960px; margin: 0 auto; padding: 0 16px; }
.top { padding-top: 24px; }
.top h1 { margin: 0; font-size: 26px; }
.top p { margin: 4px 0 16px; color: var(--ink-2); }
.foot { padding-bottom: 32px; color: var(--muted); font-size: 13px; }
.foot p { margin: 4px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card h3 { margin: 16px 0 8px; font-size: 15px; }
.sub { margin: 0 0 12px; color: var(--ink-2); font-size: 14px; }

/* 表單 */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.field small { display: block; color: var(--muted); font-size: 13px; margin-top: 4px; }
input:not([type]), input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 16px; /* iOS 不自動放大 */
  padding: 10px 12px;
  border: 1px solid var(--axis);
  border-radius: 8px;
  background: var(--page);
  color: var(--ink);
}
input:focus-visible, button:focus-visible, summary:focus-visible, .seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.seg { display: flex; gap: 8px; border: 0; padding: 0; margin: 0 0 8px; flex-wrap: wrap; }
.seg legend { font-weight: 600; font-size: 14px; margin-bottom: 4px; padding: 0; width: 100%; }
.seg label { flex: 1; min-width: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span {
  display: block;
  text-align: center;
  padding: 10px 8px;
  border: 1px solid var(--axis);
  border-radius: 8px;
  cursor: pointer;
}
.seg input:checked + span { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 600; }
.hint { margin: 0 0 12px; color: var(--ink-2); font-size: 13px; }
.adv { margin: 8px 0 16px; }
.adv summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
.adv .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; padding-top: 8px; }
.check { grid-column: 1 / -1; display: flex; gap: 8px; align-items: flex-start; font-size: 14px; }
.check input { margin-top: 5px; }
[hidden] { display: none !important; }

button {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  padding: 12px 16px;
  cursor: pointer;
}
#run { width: 100%; border: 0; background: var(--accent); color: #fff; font-size: 17px; }
#run:disabled { opacity: 0.55; cursor: progress; }
.ghost { background: transparent; border: 1px solid var(--axis); color: var(--ink); }
.status { margin: 10px 0 0; color: var(--ink-2); font-size: 14px; min-height: 1.6em; }
.status.error { color: var(--bad); }

/* 結論 */
.verdict { display: flex; gap: 12px; align-items: flex-start; }
.badge {
  flex: none;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-weight: 700;
  background: var(--muted);
}
.lv-good .badge { background: var(--good); }
.lv-bad .badge { background: var(--bad); }
.lv-neutral .badge { background: var(--warn); color: #0b0b0b; }
.verdict strong { display: block; font-size: 20px; line-height: 1.35; }
.verdict p { margin: 2px 0 0; color: var(--ink-2); font-size: 14px; }
.hero { margin: 16px 0 4px; font-size: 44px; font-weight: 600; line-height: 1.1; }
.hero small { font-size: 15px; font-weight: 400; color: var(--ink-2); margin-left: 6px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.tile { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.tile span { display: block; font-size: 12px; color: var(--muted); }
.tile b { font-size: 17px; font-weight: 600; }

/* 分頁 */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; }
.tabs button { flex: none; padding: 8px 14px; background: var(--surface); border: 1px solid var(--axis); color: var(--ink); }
.tabs button[aria-selected="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* 圖表 */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--ink-2); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 4px; width: 14px; }
.tip {
  position: absolute; pointer-events: none;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  padding: 6px 10px; font-size: 13px; white-space: nowrap;
  transform: translate(-50%, calc(-100% - 10px));
}
.tip b { font-variant-numeric: tabular-nums; }
.mix { display: flex; gap: 2px; height: 14px; margin-top: 4px; }
.mix div:first-child { border-radius: 4px 0 0 4px; }
.mix div:last-child { border-radius: 0 4px 4px 0; }

/* 表格：桌機為表格，手機改卡片 */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
th button { all: unset; cursor: pointer; }
th button:focus-visible { outline: 2px solid var(--accent); }
td.wrap { white-space: normal; text-align: left; }
tr.off td { color: var(--muted); }
.pos { color: var(--good-ink); }
.neg { color: var(--bad); }
.more { margin-top: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.notes { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 13px; }

@media (max-width: 639px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr {
    display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: row dense; gap: 0 16px;
    border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; margin-bottom: 8px;
  }
  table.cards td { display: flex; justify-content: space-between; gap: 8px; border: 0; padding: 2px 0; white-space: normal; text-align: right; }
  table.cards td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  table.cards td.wrap:empty { display: none; }
  table.cards td.wrap, table.cards td.full { grid-column: 1 / -1; }
  table.cards td::before { white-space: nowrap; }
  table.plain th, table.plain td { padding: 6px 4px; font-size: 13px; }
}
@media (min-width: 640px) {
  .top h1 { font-size: 30px; }
  .tiles { grid-template-columns: repeat(3, 1fr); }
  .adv .grid { grid-template-columns: repeat(3, 1fr); }
  #run { width: auto; min-width: 200px; }
  .split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
}
@media (forced-colors: active) {
  .badge, .legend i { forced-color-adjust: none; }
}
