:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface-1: #ffffff;
  --border: #e2e4e8;
  --grid: #ececec;
  --text-primary: #191919;
  --text-secondary: #666666;
  --accent: #2370cd;
  --series-1: #257de0;
  --ref-line: #8a8a8a;
  --status-critical: #dc3c3d;
  --status-serious: #f18a59;
  --status-warning: #fbb315;
  --status-neutral: #9c9c9c;
  --badge-ink: #191919;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #111111;
    --surface-1: #191919;
    --border: #2e2e2e;
    --grid: #2a2a2a;
    --text-primary: #efefef;
    --text-secondary: #9c9c9c;
    --accent: #519ced;
    --series-1: #338ced;
    --ref-line: #7a7a7a;
    --status-neutral: #6e6e6e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111;
  --surface-1: #191919;
  --border: #2e2e2e;
  --grid: #2a2a2a;
  --text-primary: #efefef;
  --text-secondary: #9c9c9c;
  --accent: #519ced;
  --series-1: #338ced;
  --ref-line: #7a7a7a;
  --status-neutral: #6e6e6e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.6;
}
a { color: var(--accent); }
.wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--text-secondary); }

.site-header { background: var(--surface-1); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.header-row { display: flex; align-items: center; gap: 20px; height: 56px; }
.brand { font-weight: 700; font-size: 1.1rem; text-decoration: none; color: var(--text-primary); }
nav { display: flex; gap: 16px; flex: 1; }
nav a { text-decoration: none; color: var(--text-secondary); font-size: .95rem; }
nav a:hover { color: var(--text-primary); }
.ghost { background: none; border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; cursor: pointer; color: var(--text-primary); }

.hero { margin-top: 24px; padding: 24px; }
.hero h1 { font-size: clamp(1.5rem, 4vw, 2.2rem); margin: 0 0 8px; }
.lede { font-size: 1.05rem; max-width: 720px; color: var(--text-secondary); margin: 0 0 20px; }
.lede strong { color: var(--text-primary); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.stat { background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.stat .label { font-size: .85rem; color: var(--text-secondary); }
.stat .value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.demo-note { font-size: .85rem; color: var(--text-secondary); margin-top: 14px; }

.ad-slot {
  margin: 24px 0; min-height: 90px; border: 1px dashed var(--border); border-radius: 8px;
  display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: .85rem;
}

section { margin: 28px 0; }
h2 { font-size: 1.35rem; margin: 0 0 12px; }
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }

.filters { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.filters label, .analyze-form label { display: flex; flex-direction: column; font-size: .8rem; color: var(--text-secondary); gap: 4px; }
select, input {
  font: inherit; font-size: .95rem; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface-1); color: var(--text-primary); min-width: 130px;
}
button[type="submit"], .btn {
  font: inherit; background: var(--accent); color: #fff; border: none; border-radius: 8px;
  padding: 8px 18px; cursor: pointer; align-self: flex-end; text-decoration: none; display: inline-block;
}

.deal-list { display: grid; gap: 12px; }
.deal {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px;
  display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; align-items: center;
}
.deal-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.route { font-weight: 700; font-size: 1.1rem; }
.meta { font-size: .85rem; color: var(--text-secondary); }
.price-box { text-align: right; grid-row: span 2; }
.price { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.was { font-size: .85rem; color: var(--text-secondary); }
.deal-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.deal-actions button { font: inherit; font-size: .85rem; background: none; border: 1px solid var(--border); color: var(--text-primary); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.deal-actions button:hover { border-color: var(--accent); }
.deal-detail { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 12px; margin-top: 6px; }
.empty { color: var(--text-secondary); padding: 20px; text-align: center; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: .78rem; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; color: var(--badge-ink); white-space: nowrap;
}
.tier-bug { background: var(--status-critical); color: #fff; }
.tier-hot { background: var(--status-serious); }
.tier-good { background: var(--status-warning); }
.tier-normal { background: var(--status-neutral); color: #fff; }
.risk { font-size: .78rem; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; color: var(--text-secondary); }

.analyze-form { display: flex; flex-wrap: wrap; gap: 12px; margin: 12px 0 16px; }
.result-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 4px; }
.result-head .big { font-size: 1.4rem; font-weight: 700; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.metric { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.metric .label { font-size: .8rem; color: var(--text-secondary); }
.metric .value { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.advice { margin: 8px 0 0; }

.chart-wrap { margin-top: 8px; }
.chart-title { font-size: .9rem; font-weight: 600; margin: 0 0 4px; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .axis text { fill: var(--text-secondary); font-size: 11px; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; }
.chart .ref { stroke: var(--ref-line); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .ref-label, .chart .deal-label { fill: var(--text-secondary); font-size: 11px; }
.chart .deal-label { fill: var(--text-primary); font-weight: 600; }
.chart .deal-line { stroke: var(--text-primary); stroke-width: 1; stroke-dasharray: 2 3; }
.chart .deal-dot { fill: var(--text-primary); stroke: var(--surface-1); stroke-width: 2; }
.chart .cross { stroke: var(--text-secondary); stroke-width: 1; }
.chart .hover-dot { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .hit { fill: transparent; cursor: crosshair; }
details.table-view { margin-top: 6px; font-size: .85rem; }
details.table-view table { border-collapse: collapse; margin-top: 6px; }
details.table-view td, details.table-view th { padding: 2px 10px; border-bottom: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }

.tooltip {
  position: fixed; pointer-events: none; z-index: 50; background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: .82rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.15); font-variant-numeric: tabular-nums;
}

.aff-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; }
.aff { border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-decoration: none; color: var(--text-primary); display: block; }
.aff:hover { border-color: var(--accent); }
.aff .icon { font-size: 1.5rem; }
.aff .t { font-weight: 600; }
.aff .d { font-size: .85rem; color: var(--text-secondary); }
.aff .tag { font-size: .72rem; color: var(--text-secondary); }

.guide ol { padding-left: 1.3em; }
.guide li { margin-bottom: 8px; }
.tier-table { border-collapse: collapse; width: 100%; font-size: .92rem; }
.tier-table th, .tier-table td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }

.site-footer { border-top: 1px solid var(--border); margin-top: 40px; padding: 20px 0; font-size: .85rem; color: var(--text-secondary); }

@media (max-width: 600px) {
  nav { display: none; }
  .deal { grid-template-columns: 1fr; }
  .price-box { text-align: left; grid-row: auto; }
}

.filters .grow { flex: 1 1 240px; }
.filters .grow input { width: 100%; }
h2 .count { font-size: .9rem; font-weight: 400; margin-left: 6px; }

/* ---- 搜尋列 ---- */
.trip-opts { display: flex; gap: 8px; margin: 12px 0 10px; }
.trip-opts select { min-width: 0; border: none; background: transparent; font-weight: 600; padding-left: 0; }
.search-bar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end;
  background: var(--accent); padding: 8px; border-radius: 12px;
}
.search-bar .field {
  display: flex; flex-direction: column; flex: 1 1 150px; background: var(--surface-1);
  border-radius: 8px; padding: 6px 10px; font-size: .75rem; color: var(--text-secondary); gap: 2px;
}
.search-bar .field.date { flex: 0 1 160px; }
.search-bar .field input { border: none; padding: 2px 0; min-width: 0; width: 100%; font-size: 1rem; background: transparent; }
.search-bar .field input:focus { outline: none; }
.search-bar .field:focus-within { box-shadow: 0 0 0 2px var(--status-warning); }
.swap {
  align-self: stretch; border: none; border-radius: 8px; background: var(--surface-1); color: var(--text-primary);
  font-size: 1.2rem; padding: 0 12px; cursor: pointer;
}
.search-bar .search-btn {
  align-self: stretch; border: none; border-radius: 8px; background: var(--status-warning); color: #191919;
  font: inherit; font-weight: 700; font-size: 1.05rem; padding: 0 28px; cursor: pointer;
}
.hint { font-size: .82rem; margin: 8px 0 0; }
.hint.error { color: var(--status-critical); }
.results-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 8px; margin-bottom: 12px; }
.results-head h2 { margin: 0; }
.results-head .filters { margin: 0; }
.live-links {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 12px 16px; margin-bottom: 12px;
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; font-size: .9rem;
}
.live-links a { border: 1px solid var(--border); border-radius: 8px; padding: 4px 12px; text-decoration: none; }
.live-links a:hover { border-color: var(--accent); }
@media (max-width: 600px) {
  .search-bar .field, .search-bar .field.date { flex: 1 1 100%; }
  .swap { display: none; }
  .search-bar .search-btn { flex: 1 1 100%; padding: 10px; }
}

/* 語言 / 幣別 */
.header-tools { display: flex; align-items: center; gap: 8px; }
.header-tools select { width: auto; min-width: 0; padding: 4px 6px; font-size: .85rem; }
.lang-link { font-size: .9rem; color: var(--text-secondary); text-decoration: none; padding: 4px 8px; border: 1px solid var(--border, rgba(127,127,127,.3)); border-radius: 6px; }
.lang-link:hover { color: var(--text-primary); }
.lang-banner { display: flex; justify-content: center; align-items: center; gap: 12px; padding: 6px 12px; font-size: .9rem; background: var(--surface-2, rgba(37,125,224,.1)); }
.lang-banner[hidden] { display: none; }
@media (max-width: 600px) {
  .header-row { flex-wrap: wrap; height: auto; padding: 8px 0; gap: 8px 12px; }
  nav { order: 3; flex-basis: 100%; }
  .header-tools { margin-left: auto; }
}

/* 更新紀錄 */
.run-log { margin-bottom: 12px; font-size: .85rem; }
.run-log summary { cursor: pointer; color: var(--text-secondary); }
.run-log .table-scroll { overflow-x: auto; margin-top: 8px; }
.run-log table { border-collapse: collapse; width: 100%; white-space: nowrap; }
.run-log th, .run-log td { padding: 4px 10px; text-align: right; border-bottom: 1px solid rgba(127,127,127,.2); }
.run-log th:first-child, .run-log td:first-child { text-align: left; }
.run-log[hidden] { display: none; }
