/* ============================================================
   style.css — F1 深色主題
   學習重點：顏色、間距都放在 :root 的 CSS 變數（--xxx），
   要改主題色只要改這裡一處。
   ============================================================ */
:root {
  --bg: #0e0e12;
  --surface: #17171e;
  --surface-2: #20202a;
  --border: #2c2c38;
  --text: #f1f1f4;
  --muted: #9b9bab;
  --accent: #e10600;        /* F1 紅 */
  --purple: #c77dff;        /* F1 轉播用紫色表示「最快」 */
  --up: #3ddc84;
  --down: #ff6b6b;
  --gold: #f5c518;
  --silver: #c9ccd1;
  --bronze: #d08a4b;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.55;
  font-size: 15px;
}
a { color: inherit; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; color: var(--muted); font-weight: 600; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.warn { color: #ffb347; }

/* ---------- 頁首 ---------- */
.site-header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(14, 14, 18, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.header-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-top: 10px; padding-bottom: 6px; flex-wrap: wrap; }
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.brand-mark { background: var(--accent); color: #fff; padding: 2px 8px; border-radius: 6px; font-style: italic; letter-spacing: .5px; }
.header-tools { display: flex; gap: 8px; align-items: center; }
.season-picker { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .9rem; }
.data-status { margin: 0 0 8px; font-size: .8rem; color: var(--muted); }

select, .btn, .chip {
  font: inherit;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:hover, .chip:hover, select:hover { border-color: #4a4a58; }
.btn.disabled { opacity: .35; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- 賽季步驟圖 ---------- */
.timeline-section { margin: 20px 0 8px; }
.timeline-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.timeline-head h2 { margin: 0; }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.lg-done { background: var(--accent); }
.lg-next { background: #fff; box-shadow: 0 0 0 3px rgba(225, 6, 0, .5); }
.lg-todo { border: 2px solid #555; }

.timeline { position: relative; overflow-x: auto; padding: 8px 0 12px; scroll-behavior: smooth; scrollbar-width: thin; }
.steps { list-style: none; margin: 0; padding: 0; display: flex; }
.step { flex: 0 0 92px; position: relative; text-align: center; }
/* 串起各站的橫線：用每個步驟的 ::before 畫到前一個點 */
.step::before {
  content: ""; position: absolute; top: 36px; left: -50%; width: 100%; height: 3px;
  background: #3a3a46; z-index: 0;
}
.step:first-child::before { display: none; }
.step-done::before, .step-pending::before { background: var(--accent); }
.step a { display: flex; flex-direction: column; align-items: center; text-decoration: none; padding: 4px 2px; border-radius: 10px; }
.step a:hover { background: var(--surface); }
.step-round { font-size: .72rem; color: var(--muted); font-weight: 700; height: 18px; }
.sprint-tag { background: #ffb347; color: #111; font-size: .6rem; border-radius: 3px; padding: 0 3px; margin-left: 3px; vertical-align: 1px; }
.step-dot {
  width: 18px; height: 18px; border-radius: 50%; margin: 6px 0; position: relative; z-index: 1;
  background: var(--bg); border: 3px solid #555;
}
.step-done .step-dot { background: var(--accent); border-color: var(--accent); }
.step-pending .step-dot { background: var(--bg); border-color: var(--accent); }
.step-next .step-dot { background: #fff; border-color: #fff; animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(225, 6, 0, .7); }
  100% { box-shadow: 0 0 0 12px rgba(225, 6, 0, 0); }
}
.step-flag { font-size: 1.2rem; line-height: 1.2; }
.step-name { font-size: .78rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 88px; }
.step-sub { font-size: .7rem; color: var(--muted); white-space: nowrap; }
.step-todo .step-name, .step-todo .step-flag { opacity: .6; }
.step.is-active a { background: var(--surface-2); outline: 1px solid var(--accent); }

/* ---------- 分頁 ---------- */
.tabs {
  display: flex; gap: 4px; margin: 12px 0 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto; scrollbar-width: none;
}
.tabs a {
  padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap;
  border-bottom: 3px solid transparent; margin-bottom: -1px;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--text); border-bottom-color: var(--accent); }

.subtabs { display: flex; gap: 6px; margin: 12px 0; flex-wrap: wrap; }
.subtabs a { padding: 6px 14px; border-radius: 999px; background: var(--surface-2); text-decoration: none; color: var(--muted); font-weight: 600; }
.subtabs a.active { background: var(--accent); color: #fff; }

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  min-width: 0;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.card-grid .card { margin-bottom: 0; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.stat-card { border-top: 4px solid var(--c, var(--accent)); }
.big { font-size: 1.2rem; font-weight: 700; margin: .2em 0; }
.stat-line { margin: 0; color: var(--muted); }
.stat-line b { color: var(--text); font-size: 1.3rem; }
.more { display: inline-block; margin-top: 8px; color: var(--accent); text-decoration: none; font-weight: 600; font-size: .9rem; }
.more:hover { text-decoration: underline; }
.progress-text { color: var(--muted); margin: 16px 0; }
.countdown { font-size: 1.2rem; font-weight: 700; color: var(--accent); margin: .2em 0; }
.next-card { background: linear-gradient(135deg, rgba(225, 6, 0, .14), var(--surface) 60%); }

.podium { list-style: none; padding: 0; margin: 0; }
.podium li { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.podium .avatar { margin-right: 0; }
.podium-name { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.podium small { color: var(--muted); font-size: .75rem; }
.medal { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; font-size: .75rem; font-weight: 800; color: #111; }
.m1 { background: var(--gold); } .m2 { background: var(--silver); } .m3 { background: var(--bronze); }

/* ---------- 賽季提示 ---------- */
.season-banner { border-left: 4px solid var(--gold); }
.season-banner h3 { color: var(--text); }
.season-banner p { margin: 4px 0; }
.season-banner .more { margin: 0 0 0 10px; }

/* ---------- 接下來的賽程 ---------- */
.upcoming-card { border-left: 4px solid var(--accent); }
.upcoming-days { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 20px; }
.upcoming-day h4 { margin: 6px 0; font-size: .85rem; color: var(--accent); }
.upcoming-day ul { list-style: none; margin: 0; padding: 0; }
.upcoming-day li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-top: 1px solid var(--border); }
.upcoming-day li.is-race .up-name { font-weight: 800; }
.upcoming-day li.is-live { background: rgba(225, 6, 0, .12); border-radius: 6px; padding-left: 6px; }
.up-time { font-weight: 700; min-width: 3.2em; }
.up-name { flex: 1; display: flex; flex-direction: column; line-height: 1.3; }
.up-name small { color: var(--muted); font-size: .75rem; }
.live-badge { color: var(--accent); font-weight: 800; font-size: .8rem; white-space: nowrap; animation: blink 1.4s infinite; }
.upcoming-day .countdown { margin: 0; white-space: nowrap; font-size: .8rem; }
@keyframes blink { 50% { opacity: .4; } }

/* ---------- 表格 ---------- */
/* 表格太寬時，只在表格內部左右滑動，整頁不會跑版 */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data th {
  text-align: left; font-size: .75rem; color: var(--muted); font-weight: 600;
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data td { padding: 9px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data tbody tr:hover { background: var(--surface-2); }
.data .num { text-align: right; font-variant-numeric: tabular-nums; }
.data .pos { font-weight: 800; }
.data .pts b { font-size: 1rem; }
.data td.small { white-space: normal; min-width: 180px; }
tr.top1 .pos { color: var(--gold); }
tr.top2 .pos { color: var(--silver); }
tr.top3 .pos { color: var(--bronze); }
tr.champion td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.car-no { display: inline-block; min-width: 26px; color: var(--muted); font-family: var(--mono); font-size: .8rem; }
.bar { display: inline-block; width: 70px; height: 6px; background: var(--surface-2); border-radius: 3px; margin-left: 8px; vertical-align: middle; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--c); border-radius: 3px; }
.up { color: var(--up); font-weight: 700; }
.down { color: var(--down); font-weight: 700; }
.dnf { color: var(--down); font-weight: 600; }
.purple { color: var(--purple); font-weight: 700; }
.fastest-note { margin: 0 0 8px; color: var(--muted); }
.fastest-note b { color: var(--purple); }

.name-link { text-decoration: none; font-weight: 600; border-bottom: 1px dashed transparent; }
.name-link:hover { border-bottom-color: currentColor; color: #fff; }
.team-link { font-weight: 500; }
.team-dot { display: inline-block; width: 4px; height: 14px; border-radius: 2px; background: var(--c); margin-right: 7px; vertical-align: -2px; }

/* ---------- 分站成績 ---------- */
.round-nav { display: flex; gap: 8px; align-items: center; }
.round-nav select { flex: 1; min-width: 0; font-weight: 700; }
.round-meta { margin: 8px 0 0; font-size: .85rem; }
.empty { text-align: center; padding: 32px 16px; }

/* ---------- 賽程表 ---------- */
.schedule-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; }
.chip { border-radius: 999px; padding: 4px 14px; font-size: .9rem; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.schedule-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.race-card { margin: 0; transition: box-shadow .3s; }
.race-card header { display: flex; gap: 10px; align-items: flex-start; margin-bottom: 8px; }
.race-card h3 { color: var(--text); margin: 0; font-size: 1rem; }
.race-card p { margin: 2px 0 0; }
.race-title { flex: 1; min-width: 0; }
.round-badge { background: var(--surface-2); border-radius: 6px; padding: 2px 8px; font-weight: 800; font-size: .85rem; }
.state-badge { font-size: .72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.state-done .state-badge { background: rgba(225, 6, 0, .2); color: #ff8a80; }
.state-next { border-color: var(--accent); }
.state-next .state-badge { background: var(--accent); color: #fff; }
.state-done { opacity: .85; }
.race-card.is-target { box-shadow: 0 0 0 2px var(--accent); }
.sessions { width: 100%; border-collapse: collapse; font-size: .88rem; }
.sessions td { padding: 5px 4px; border-top: 1px solid var(--border); }
.sessions td:last-child { text-align: right; }
.sessions tr.past { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(155, 155, 171, .4); }
.sessions tr.is-race td { font-weight: 700; }

/* ---------- 圖表 ---------- */
.chart-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .82rem; color: var(--muted); margin-bottom: 8px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-box { position: relative; }
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; }
.chart .end-label { fill: var(--text); font-size: 11px; font-weight: 700; }
.chart .crosshair { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.chart .hover-dot { stroke: var(--surface); stroke-width: 2; }
.tooltip {
  position: absolute; top: 8px; pointer-events: none;
  background: #0b0b0f; border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: .8rem; min-width: 130px; box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.tip-title { color: var(--muted); margin-bottom: 4px; white-space: nowrap; }
.tip-row { display: flex; align-items: center; gap: 6px; }
.tip-row i { width: 12px; height: 2px; display: inline-block; }
.tip-row b { min-width: 30px; text-align: right; font-variant-numeric: tabular-nums; }
.tip-row span { color: var(--muted); }

/* ---------- 車手 / 車隊頁 ---------- */
.hero {
  display: flex; gap: 20px; align-items: center; margin: 24px 0 16px; padding: 20px;
  border-radius: var(--radius); background: linear-gradient(120deg, color-mix(in srgb, var(--c) 30%, transparent), var(--surface) 70%);
  border: 1px solid var(--border); border-left: 6px solid var(--c);
}
.hero h1 { font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 0 0 .2em; }
.hero p { margin: 0; }
.hero-no { float: right; font-size: clamp(2.4rem, 9vw, 4.5rem); font-weight: 900; font-style: italic; color: var(--c); line-height: 1; opacity: .9; margin-left: 12px; }
.hero-text { flex: 1; min-width: 0; }
.hero-driver { display: inline-flex; align-items: center; margin-right: 14px; }

/* ---------- 照片 ---------- */
/* 照片載入前顯示名字縮寫；載入後圖片蓋在上面 */
.avatar {
  position: relative; flex: 0 0 auto; display: inline-grid; place-items: center; overflow: hidden;
  vertical-align: middle; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
  font-weight: 700; margin-right: 8px;
}
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 20%; opacity: 0; transition: opacity .3s; }
.avatar.has-photo img { opacity: 1; }
.avatar.has-photo .avatar-initials { visibility: hidden; }
.avatar-round { border-radius: 50%; }
.avatar-square { border-radius: 8px; }
.avatar-square img { object-position: center; }
.avatar-sm { width: 28px; height: 28px; font-size: .65rem; }
.avatar-md { width: 56px; height: 56px; font-size: .95rem; }
.avatar-lg { width: 132px; height: 132px; font-size: 2rem; border: 3px solid var(--c, var(--border)); margin-right: 0; }
.avatar-lg.avatar-square { border-radius: 18px; }
.leader { display: flex; align-items: center; gap: 4px; }
.leader .big { margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; }
.stat b { font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat small { color: #6d6d7b; font-size: .7rem; }
.story p { max-width: 72ch; }
.story h2 small { color: var(--muted); font-weight: 500; font-size: .9rem; }
.tagline { font-size: 1.05rem; font-weight: 600; color: #fff; border-left: 3px solid var(--accent); padding-left: 10px; }
.highlights { padding-left: 1.2em; }
.highlights li { margin: 4px 0; }

.result-strip { display: flex; flex-wrap: wrap; gap: 6px; }
.strip-cell {
  display: flex; flex-direction: column; align-items: center; text-decoration: none;
  width: 58px; padding: 6px 2px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border);
}
.strip-cell small { font-size: .65rem; color: var(--muted); }
.strip-cell b { font-size: .95rem; }
.strip-cell.pts { background: #26303a; }
.strip-cell.pod { background: #3a3d44; border-color: var(--silver); }
.strip-cell.p1 { background: #3d3510; border-color: var(--gold); color: var(--gold); }
.strip-cell.dnf b { color: var(--down); }

.team-bars { display: flex; gap: 4px; align-items: flex-end; height: 170px; overflow-x: auto; padding-top: 18px; }
.tbar { flex: 1 0 26px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; text-decoration: none; }
.tbar-fill { width: 100%; background: var(--c); border-radius: 4px 4px 0 0; min-height: 2px; }
.tbar-val { font-size: .7rem; color: var(--muted); }
.tbar small { font-size: .65rem; color: var(--muted); margin-top: 4px; }
.tbar:hover .tbar-fill { filter: brightness(1.25); }

/* ---------- 輪胎策略 ---------- */
.ty-head { margin-bottom: 10px; }
.ty-head p { margin: 6px 0 0; }
.ty-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; color: var(--muted); }
.ty-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.ty-swatch {
  display: inline-grid; place-items: center; width: 22px; height: 14px; border-radius: 4px;
  background: var(--tc); color: var(--tt); font-size: .65rem; font-weight: 800; font-style: normal;
}
.ty-strat { color: var(--text); font-family: var(--mono); }
.ty-chart { display: grid; gap: 4px; }
/* 每一列：名次｜車手｜色條｜進站次數 */
.ty-row { display: grid; grid-template-columns: 40px 170px 1fr 44px; align-items: center; gap: 8px; min-height: 26px; }
.ty-pos { font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.ty-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ty-code { display: none; font-weight: 700; }
.ty-track { position: relative; height: 22px; background: var(--surface-2); border-radius: 5px; }
.ty-none { position: absolute; left: 8px; top: 2px; }
.ty-seg {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center; justify-content: center; gap: 3px;
  background: var(--tc); color: var(--tt); border-radius: 5px; font-size: .72rem; overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .35); /* 相鄰兩段之間留一條細縫，分得出換胎點 */
  cursor: default;
}
.ty-seg small { font-size: .65rem; opacity: .8; }
/* 舊胎（起跑時已經用過）用斜紋表示 */
.ty-seg.used, .ty-swatch.used {
  background-image: repeating-linear-gradient(135deg, rgba(0, 0, 0, .28) 0 3px, transparent 3px 7px);
  background-color: var(--tc);
}
.ty-seg:hover, .ty-seg:focus-visible { filter: brightness(1.15); outline: 2px solid #fff; outline-offset: -2px; z-index: 1; }
.ty-stops { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.ty-axis-row { min-height: 18px; }
.ty-axis { position: relative; height: 16px; font-size: .7rem; color: var(--muted); }
.ty-axis span { position: absolute; transform: translateX(-50%); }

/* ---------- 載入中 ---------- */
.loading { text-align: center; padding: 60px 0; color: var(--muted); }
.spinner {
  width: 36px; height: 36px; margin: 0 auto 12px; border-radius: 50%;
  border: 4px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.site-footer { color: var(--muted); font-size: .8rem; padding-top: 16px; padding-bottom: 32px; border-top: 1px solid var(--border); margin-top: 24px; }

/* ---------- Podcast 宣傳 ---------- */
.podcast-promo {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 24px 0 0; padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent); border-radius: var(--radius);
}
.podcast-icon { font-size: 1.6rem; line-height: 1; }
.podcast-text { display: flex; flex-direction: column; gap: 2px; flex: 1 1 260px; min-width: 0; }
.podcast-links { display: flex; gap: 8px; flex-wrap: wrap; }
.podcast-btn { border-color: var(--accent); white-space: nowrap; }
.podcast-btn:hover { background: var(--accent); border-color: var(--accent); }

/* ---------- 手機 ---------- */
@media (max-width: 600px) {
  body { font-size: 14px; }
  .podcast-links { width: 100%; }
  .podcast-btn { flex: 1 1 0; }
  .card { padding: 12px; }
  .two-col { grid-template-columns: 1fr; }
  .hero { flex-direction: column; align-items: flex-start; gap: 12px; }
  .hero-text { width: 100%; }
  .avatar-lg { width: 110px; height: 110px; }
  .step { flex-basis: 78px; }
  .data td, .data th { padding: 7px 6px; }
  .bar { display: none; }
  .hide-sm { display: none; }
  .ty-row { grid-template-columns: 30px 42px 1fr 34px; gap: 5px; }
  .ty-full { display: none; }
  .ty-code { display: inline; }
}

@media (prefers-reduced-motion: reduce) {
  .step-next .step-dot, .spinner, .live-badge { animation: none; }
  .timeline { scroll-behavior: auto; }
}
