/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --page: #f8f8f6;
  --surface: #ffffff;
  --surface-2: #f2f1ed;
  --ink: #0e0e0d;
  --ink-2: #4c4b47;
  --muted: #74726b;
  --hairline: #e7e6df;
  --rule: #cfcec5;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.16);

  /* categorical, fixed order: 2330 / 0050 / 2886 / 2883 / 1303, TWII neutral */
  --c-2330: #e34948;
  --c-0050: #2a78d6;
  --c-2886: #1baf7a;
  --c-2883: #4a3aa7;
  --c-1303: #eda100;
  --c-TWII: #898781;

  /* sequential ramp for the drawdown heat grid */
  --rose: 200, 44, 44;

  --shadow: 0 1px 2px rgba(20, 20, 18, .04), 0 14px 34px -20px rgba(20, 20, 18, .22);
  --radius: 16px;
  --radius-sm: 10px;
  --maxw: 780px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #171716;
    --surface-2: #212120;
    --ink: #ffffff;
    --ink-2: #c6c5ba;
    --muted: #9a988f;
    --hairline: #2b2b29;
    --rule: #3a3a36;
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.24);

    --c-2330: #e66767;
    --c-0050: #3987e5;
    --c-2886: #199e70;
    --c-2883: #9085e9;
    --c-1303: #c98500;
    --c-TWII: #898781;

    --rose: 224, 96, 96;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px 80px; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; }

h1 { font-size: clamp(26px, 5.2vw, 31px); line-height: 1.3; margin: 0 0 14px; }
h2 { font-size: 20px; line-height: 1.4; margin: 0 0 8px; }
h3 { font-size: 16px; line-height: 1.5; margin: 0; }

p { margin: 0 0 14px; }

.num { font-variant-numeric: tabular-nums; }

/* ---------- icons ---------- */
.ico {
  width: 20px; height: 20px;
  flex: 0 0 auto;
  display: inline-block;
  vertical-align: -0.22em;
  overflow: visible;
}
.ico-sm { width: 16px; height: 16px; vertical-align: -0.18em; }
#sprite { position: absolute; }

/* ---------- header ---------- */
.site-header { padding: 52px 0 26px; margin-bottom: 34px; border-bottom: 1px solid var(--hairline); }

.sub {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}

section { margin: 0 0 60px; scroll-margin-top: 16px; }

.eyebrow {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px;
  letter-spacing: 0.16em;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 6px;
}

.lede { color: var(--ink-2); font-size: 15px; margin: 0 0 16px; }

.footnote { color: var(--muted); font-size: 13px; line-height: 1.65; margin: 12px 0 0; }

/* ---------- card shell ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px;
}

/* ---------- error banner ---------- */
#error-banner {
  display: none;
  background: #fdecec;
  color: #8d1f1f;
  border: 1px solid #d03b3b;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin: 20px 0;
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) #error-banner { background: #2a1414; color: #ffb4b4; }
}
#error-banner.show { display: block; }

/* ---------- conclusion ---------- */
.verdict-title {
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
  margin: 0 0 18px;
}
.verdict-title .ico { vertical-align: 0; }

.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.75;
  padding: 0 10px;
  border-radius: 99px;
  border: 1px solid var(--rule);
  color: var(--muted);
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.tag.pick { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.tag.grow { border-color: var(--c-2330); color: var(--c-2330); }
.tag.def  { border-color: var(--c-2886); color: var(--c-2886); }

.why { list-style: none; margin: 0; padding: 0; }
.why li {
  display: flex; align-items: flex-start; gap: 11px;
  font-size: 15px;
  color: var(--ink-2);
  padding: 11px 0;
  border-top: 1px solid var(--hairline);
}
.why li:first-child { border-top: 0; padding-top: 0; }
.why .ico { color: var(--muted); margin-top: 4px; }
.why b { font-weight: 700; color: var(--ink); }

.tiles {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 22px 0 4px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
}
.tile .k { font-size: 13px; color: var(--muted); display: block; line-height: 1.5; }
.tile .v {
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em;
  display: block; margin-top: 2px; line-height: 1.25;
}

.verdict .footnote { margin-top: 20px; }
.disclaimer { color: var(--muted); font-size: 13px; margin: 8px 0 0; }

/* ---------- table ---------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

table { border-collapse: collapse; width: 100%; font-size: 14px; }

th, td {
  padding: 11px 14px;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}

thead th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--surface);
  position: sticky;
  top: 0;
  letter-spacing: 0.02em;
}

th.name, td.name {
  text-align: left;
  position: sticky;
  left: 0;
  background: var(--surface);
  z-index: 2;
  font-variant-numeric: normal;
  font-weight: 400;
  box-shadow: 1px 0 0 var(--hairline);
}
thead th.name { z-index: 3; }

tbody tr:last-child td, tbody tr:last-child th { border-bottom: 0; }

tr.bench td, tr.bench th { color: var(--muted); }

.rowname { display: inline-flex; align-items: center; gap: 8px; }
.rowname .ico { width: 17px; height: 17px; }

.dot.bar {
  display: inline-block;
  width: 15px; height: 0;
  border-top: 2px dashed var(--c-TWII);
  flex: 0 0 auto;
}

td.best { font-weight: 700; color: var(--ink); }
td.best::after { content: " \25B2"; font-size: 0.6em; vertical-align: 0.24em; }

/* ---------- charts ---------- */
.chart-card { padding: 18px 16px 12px; }
.chart-box { position: relative; height: 340px; }
@media (max-width: 520px) { .chart-box { height: 290px; } }

.chart-tools { display: flex; justify-content: flex-end; margin-bottom: 8px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 99px; padding: 3px; }
.seg button {
  font: inherit;
  font-size: 13px;
  padding: 3px 15px;
  border: 0;
  border-radius: 99px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 700; }
.seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- drawdown heat grid ---------- */
.heat-wrap { margin-top: 28px; }
.heat th, .heat td { text-align: center; padding: 10px 12px; border-bottom: 0; }
.heat th.name, .heat td.name { text-align: left; }
.heat thead th { font-weight: 500; }
.heat td {
  background: rgba(var(--rose), var(--a, 0));
  box-shadow: inset 0 0 0 1px var(--surface);
}
.heat .pct { font-weight: 700; display: block; font-size: 14px; line-height: 1.4; }
.heat .rec { font-size: 11.5px; color: var(--ink-2); display: block; line-height: 1.4; }
.heat tr.bench td { background: rgba(var(--rose), calc(var(--a, 0) * .45)); }

.legend { display: flex; align-items: center; gap: 8px; }
.legend .ramp {
  width: 56px; height: 8px; border-radius: 99px;
  background: linear-gradient(90deg, rgba(var(--rose), .04), rgba(var(--rose), .38));
}

/* ---------- slider ---------- */
.pref-card { padding: 24px 24px 20px; }

.slider-row { display: flex; align-items: center; gap: 14px; }
.slider-row .end {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted); white-space: nowrap;
}
.slider-row .end .ico { width: 18px; height: 18px; }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  flex: 1; min-width: 0;
  height: 24px;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 6px; border-radius: 99px; background: var(--surface-2);
}
input[type="range"]::-moz-range-track { height: 6px; border-radius: 99px; background: var(--surface-2); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 24px; height: 24px; margin-top: -9px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
}
input[type="range"]::-moz-range-thumb {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
}
input[type="range"]:focus { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 6px var(--accent-soft); }
input[type="range"]:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 6px var(--accent-soft); }

.readout { text-align: center; font-size: 13px; color: var(--muted); margin: 10px 0 0; }

.rank { list-style: none; padding: 0; margin: 22px 0 0; display: flex; flex-direction: column; }
.rank li {
  display: grid; grid-template-columns: 1.4rem 1fr 2.4rem; gap: 12px;
  align-items: center;
  padding: 7px 0;
}
.rank .pos { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.rank .lbl { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; }
.rank .lbl .ico { width: 17px; height: 17px; }
.rank .bar-track {
  display: block; height: 6px; background: var(--surface-2);
  border-radius: 99px; margin-top: 6px; overflow: hidden;
}
.rank .bar-fill { display: block; height: 100%; border-radius: 99px; transition: width .2s ease; }
.rank .score { font-size: 14px; font-variant-numeric: tabular-nums; color: var(--ink-2); text-align: right; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.card-item { padding: 20px; }
.card-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.card-head .nm { font-size: 16px; font-weight: 700; }
.card-item .say { font-size: 14px; color: var(--ink-2); margin: 0 0 14px; line-height: 1.65; }
.card-item .chip {
  display: inline-block; font-size: 12px; color: var(--muted);
  background: var(--surface-2); border-radius: 99px; padding: 1px 10px;
  margin: -8px 0 12px;
}
.micro { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; border-top: 1px solid var(--hairline); padding-top: 12px; }
.micro .k { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.micro .v { display: block; font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.4; }

/* 首選那張橫跨兩欄，句子在左、數字在右，其餘四張排成 2×2 */
@media (min-width: 561px) {
  .cards .card-item:first-child {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    column-gap: 24px;
    align-items: center;
  }
  .cards .card-item:first-child .card-head { grid-column: 1 / -1; }
  .cards .card-item:first-child .say { margin: 0; }
  .cards .card-item:first-child .micro {
    border-top: 0;
    border-left: 1px solid var(--hairline);
    padding: 0 0 0 24px;
  }
}

/* ---------- method ---------- */
.method-box { border-top: 1px solid var(--hairline); border-bottom: 1px solid var(--hairline); }
.method-box summary {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  padding: 14px 2px;
  font-size: 16px;
  font-weight: 700;
}
.method-box summary::-webkit-details-marker { display: none; }
.method-box summary .chev { color: var(--muted); transition: transform .2s ease; }
.method-box[open] summary .chev { transform: rotate(180deg); }
.method { padding: 0 0 16px 1.15rem; margin: 0; color: var(--ink-2); font-size: 14px; }
.method li { margin-bottom: 6px; }

code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.86em;
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: 5px;
}

footer {
  border-top: 1px solid var(--hairline);
  padding-top: 24px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}
footer p { margin: 0 0 8px; }

/* ---------- mobile ---------- */
@media (max-width: 560px) {
  .wrap { padding: 0 16px 60px; }
  section { margin-bottom: 48px; }
  .card { padding: 20px; }
  .site-header { padding-top: 40px; }
  .tiles { grid-template-columns: 1fr; gap: 12px; }
  .tile { display: flex; justify-content: space-between; align-items: baseline; }
  .tile .v { font-size: 22px; margin-top: 0; }
  .cards { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
