/* ============ MLB The Show Tracker — broadcast dark theme (mobile-first) ============ */
@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@400;500;600;700&family=Barlow:wght@300;400;500;600;700&family=Fira+Code:wght@400;500;600;700&display=swap');

:root {
  --bg: #0b0f17;
  --surface: #151b27;
  --surface-2: #1d2533;
  --border: #2a3342;
  --text: #e6edf3;
  --muted: #8b98a9;
  --accent: #4f8ef7;
  --win: #22c55e;
  --loss: #f05252;
  --gold: #f5a524;
  --scott: #4f8ef7;
  --alvin: #f5a524;
  --vincent: #34d399;
  --radius: 16px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.45), 0 1px 4px rgba(0,0,0,0.3);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --condensed: 'Barlow Condensed', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: 'Barlow', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  padding-bottom: calc(64px + var(--safe-b));
  min-height: 100dvh;
}

.mono { font-family: 'Fira Code', monospace; font-variant-numeric: tabular-nums; }
a { color: inherit; text-decoration: none; }
.wrap { max-width: 960px; margin: 0 auto; padding: 0 14px; }

/* ---------- Header ---------- */
header.site {
  position: sticky; top: 0; z-index: 30;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding-top: env(safe-area-inset-top, 0px);
}
.site-inner { display: flex; align-items: center; gap: 14px; height: 56px; }
.refresh-btn { margin-left: auto; background: none; border: none; color: var(--muted); cursor: pointer; width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: color .2s; }
.refresh-btn:active, .refresh-btn:hover { color: var(--accent); }
.refresh-btn svg { width: 19px; height: 19px; }
.refresh-btn.spinning svg { animation: spin .5s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.player-link { border-bottom: 1px dashed var(--border); color: inherit; font: inherit; padding: 0; cursor: pointer; touch-action: manipulation; }
.player-link:hover { color: var(--accent); border-bottom-color: var(--accent); }
.player-link.missing { cursor: default; border-bottom: none; }
.player-link.missing:hover { color: inherit; }
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--condensed); font-weight: 700; font-size: 19px; letter-spacing: 1px; text-transform: uppercase; }
.brand .brand-logo { width: 30px; height: 30px; border-radius: 8px; flex: none; display: block; }

/* top nav: 手機隱藏，桌面顯示 */
nav.tabs.top { display: none; }

/* ---------- Bottom nav (mobile) ---------- */
.bottom-tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex;
  background: rgba(17, 22, 33, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b);
}
.bottom-tabs a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; min-height: 58px; color: var(--muted); font-size: 11px; font-weight: 500;
  cursor: pointer; transition: color .15s; touch-action: manipulation; position: relative;
}
.bottom-tabs a svg { width: 23px; height: 23px; }
.bottom-tabs a.active { color: var(--accent); }
.bottom-tabs a.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px;
}
.bottom-tabs a:active { color: var(--text); }

/* ---------- Submit FAB（手機版右下角） ---------- */
.fab {
  position: fixed;
  right: 20px;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px) + 12px);
  width: 52px; height: 52px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 4px 16px rgba(79,142,247,0.45);
  z-index: 99;
  text-decoration: none;
}
.fab:active { opacity: 0.85; transform: scale(0.95); }

/* ---------- Generic ---------- */
.section-title {
  font-family: var(--condensed); font-size: 11px; text-transform: uppercase;
  letter-spacing: 2.5px; color: var(--muted); margin: 32px 0 12px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}
main.wrap { padding-top: 28px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }

/* ---------- Head-to-head hero ---------- */
/* ---------- Standings card ---------- */
.standings-card { padding: 0; box-shadow: var(--shadow); overflow: hidden; }
.standings-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.standings-tbl { border-collapse: collapse; font-size: 14px; white-space: nowrap; width: 100%; }
.standings-tbl thead th {
  color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1px; padding: 12px 14px; text-align: right;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.standings-tbl thead th.sl { text-align: left; padding-left: 18px; position: sticky; left: 0; background: var(--surface-2); z-index: 2; }
.standings-tbl td { padding: 15px 14px; border-bottom: 1px solid var(--border); text-align: right; font-size: 15px; }
.standings-tbl tr:last-child td { border-bottom: none; }
.standings-tbl td.sl { text-align: left; padding-left: 18px; position: sticky; left: 0; background: var(--surface); z-index: 1; }
.standings-tbl .pl-row { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.s-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.s-dot.scott { background: var(--scott); }
.s-dot.alvin { background: var(--alvin); }
.s-dot.vincent { background: var(--vincent); }
.standings-tbl .mono { font-family: 'Fira Code', monospace; font-variant-numeric: tabular-nums; }
.standings-tbl .gb { color: var(--muted); }
.standings-tbl .rec { color: var(--muted); }
.standings-tbl .strk { color: var(--muted); }
.standings-tbl .strk-w { color: var(--win); font-weight: 600; }
.standings-tbl .strk-l { color: var(--loss); font-weight: 600; }
.standings-tbl .diff-pos { color: var(--win); }
.standings-tbl .diff-neg { color: var(--loss); }

.h2h { padding: 24px 18px; box-shadow: var(--shadow); margin-bottom: 4px; }
.h2h-top { display: flex; align-items: center; justify-content: center; gap: clamp(10px, 4vw, 48px); }
.h2h-player { text-align: center; flex: 1; min-width: 0; }
.h2h-player .name { font-size: clamp(19px, 6vw, 34px); font-weight: 700; }
.h2h-player .wins { font-family: var(--condensed); font-size: clamp(46px, 16vw, 72px); font-weight: 700; line-height: 1; margin-top: 4px; letter-spacing: 1px; }
.h2h-player .wr { color: var(--muted); font-size: 13px; margin-top: 4px; }
.h2h-player .name.scott { color: var(--scott); }
.h2h-player .name.alvin { color: var(--alvin); }
.h2h-player .name.vincent { color: var(--vincent); }
.h2h-player.leader .wins { color: var(--win); }

/* ---------- Player comparison ---------- */
.compare { padding: 22px 18px; box-shadow: var(--shadow); margin-top: 16px; }
.cmp-title { text-align: center; color: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; margin-bottom: 20px; }
.cmp-stat { margin-bottom: 20px; }
.cmp-stat:last-child { margin-bottom: 0; }
.cmp-lab { font-size: 11px; color: var(--muted); text-align: center; margin-bottom: 8px; text-transform: uppercase; letter-spacing: .8px; }
.cmp-cols { display: flex; gap: 6px; margin-bottom: 6px; }
.cmp-col { flex: 1; text-align: center; }
.cmp-col .v { font-family: var(--condensed); font-size: 26px; font-weight: 700; color: var(--muted); display: block; letter-spacing: .5px; }
.cmp-col .pname { font-size: 11px; color: var(--muted); margin-top: 3px; display: block; font-weight: 600; }
.cmp-col .pname.s { color: var(--scott); }
.cmp-col .pname.a { color: var(--alvin); }
.cmp-col .pname.v { color: var(--vincent); }
.cmp-col.lead-s .v { color: var(--scott); }
.cmp-col.lead-a .v { color: var(--alvin); }
.cmp-col.lead-v .v { color: var(--vincent); }
.cmp-bar { height: 8px; border-radius: 4px; background: var(--surface-2); display: flex; overflow: hidden; }
.cmp-bar .seg-s { background: var(--scott); transition: width .3s; }
.cmp-bar .seg-a { background: var(--alvin); transition: width .3s; }
.cmp-bar .seg-v { background: var(--vincent); transition: width .3s; }
.h2h-vs { font-size: clamp(15px, 4vw, 22px); font-weight: 700; color: var(--muted); flex: none; }
.h2h-sub { text-align: center; color: var(--muted); font-size: 14px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 12px; }
.stat-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 8px; text-align: center; }
.stat-box .v { font-family: var(--condensed); font-size: clamp(24px, 6vw, 30px); font-weight: 700; letter-spacing: .5px; }
.stat-box .l { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .5px; margin-top: 4px; }

/* ---------- Game cards ---------- */
.game-card { padding: 16px 18px; margin-bottom: 10px; cursor: pointer; transition: border-color .2s, transform .15s, background .15s; box-shadow: var(--shadow); touch-action: manipulation; }
.game-card:active { transform: scale(.985); background: var(--surface-2); }
.game-card .gc-date { font-size: 12px; color: var(--muted); margin-bottom: 8px; letter-spacing: .5px; }
.gc-side { display: flex; align-items: center; gap: 11px; padding: 5px 0; }
.gc-side .tcolor { width: 5px; height: 30px; border-radius: 3px; flex: none; }
.gc-side .who { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.gc-side .who .pl { font-weight: 600; font-size: 15px; }
.gc-side .who .tm { font-size: 12px; color: var(--muted); }
.gc-side .score { margin-left: auto; font-family: var(--condensed); font-size: 30px; font-weight: 700; letter-spacing: .5px; }
.gc-side.win .score { color: var(--win); }
.gc-side.win .pl::after { content: 'W'; font-family: 'Fira Code', monospace; font-size: 10px; background: var(--win); color: #04210f; padding: 1px 5px; border-radius: 4px; margin-left: 7px; vertical-align: middle; font-weight: 700; }

/* ---------- Game detail ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 15px; margin-bottom: 16px; cursor: pointer; min-height: 44px; touch-action: manipulation; }
.back:active { color: var(--text); }
.detail-head { padding: 18px 16px; box-shadow: var(--shadow); margin-bottom: 8px; }
.dh-line { display: flex; align-items: center; gap: 12px; padding: 7px 0; }
.dh-line .tcolor { width: 6px; height: 36px; border-radius: 3px; flex: none; }
.dh-line .lbl { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.dh-line .lbl .pl { font-weight: 700; font-size: 17px; }
.dh-line .lbl .tm { font-size: 13px; color: var(--muted); }
.dh-line .runs { margin-left: auto; font-family: var(--condensed); font-size: 36px; font-weight: 700; letter-spacing: .5px; }
.dh-line.win .runs { color: var(--win); }
.pog { text-align: center; font-size: 13px; color: var(--gold); margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------- Scrollable tables w/ sticky first column ---------- */
.tbl-scroll, .linescore-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* line score */
.linescore-wrap { margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius); }
table.linescore { border-collapse: separate; border-spacing: 0; font-family: 'Fira Code', monospace; font-size: 14px; width: 100%; min-width: 420px; }
table.linescore th, table.linescore td { padding: 8px 7px; text-align: center; border-bottom: 1px solid var(--border); }
table.linescore tr:last-child td { border-bottom: none; }
table.linescore th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.linescore .team, table.linescore th.teamh {
  text-align: left; font-family: 'Fira Sans'; font-weight: 600; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface); z-index: 2; padding-left: 12px; padding-right: 12px;
}
table.linescore td.rhe { font-weight: 700; }
table.linescore .sep { border-left: 2px solid var(--border); }

/* box score tables */
.box-team { margin-top: 20px; }
.box-team h3 { font-size: 15px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.box-team h3 .tcolor { width: 4px; height: 17px; border-radius: 2px; }
.box-team .tbl-scroll { border: 1px solid var(--border); border-radius: var(--radius); }
table.stats { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; min-width: 430px; }
table.stats th, table.stats td { padding: 9px 7px; border-bottom: 1px solid var(--border); }
table.stats thead th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; background: var(--surface-2); }
table.stats th.l, table.stats td.l { text-align: left; }
table.stats th.n, table.stats td.n { text-align: right; font-family: 'Fira Code', monospace; font-variant-numeric: tabular-nums; width: 42px; }
table.stats .player {
  font-weight: 500; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface); z-index: 2; padding-left: 12px;
}
table.stats thead .player { background: var(--surface-2); }
table.stats td.player .pos { color: var(--muted); font-size: 12px; margin-left: 5px; }
table.stats tr.totals td { font-weight: 700; border-top: 2px solid var(--border); color: var(--text); }
table.stats tr.totals .player { background: var(--surface); }
table.stats tr:last-child td { border-bottom: none; }
table.stats td.hl { color: var(--gold); }
.hr-tag { font-size: 10px; background: var(--gold); color: #2a1c00; border-radius: 4px; padding: 0 5px; margin-left: 6px; font-family: 'Fira Code', monospace; font-weight: 700; }

.notes-line { font-size: 13px; color: var(--muted); margin-top: 14px; line-height: 1.8; }
.notes-line b { color: var(--text); font-weight: 600; }

/* ---------- Team / player ranking tables ---------- */
.tbl-card { border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.tbl-card .tbl-scroll { border: none; }
table.rank { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; min-width: 480px; }
table.rank th, table.rank td { padding: 11px 9px; border-bottom: 1px solid var(--border); text-align: right; }
table.rank tr:last-child td { border-bottom: none; }
table.rank thead th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; background: var(--surface-2); }
table.rank th.l, table.rank td.l { text-align: left; }
table.rank td.name {
  font-weight: 600; white-space: nowrap;
  position: sticky; left: 0; background: var(--surface); z-index: 2; padding-left: 12px;
}
table.rank thead th.l { position: sticky; left: 0; background: var(--surface-2); z-index: 2; padding-left: 12px; }
table.rank tbody tr:active td.name { background: var(--surface-2); }
table.rank td.num { font-family: 'Fira Code', monospace; font-variant-numeric: tabular-nums; }
table.rank .tcolor { display: inline-block; width: 4px; height: 14px; border-radius: 2px; margin-right: 8px; vertical-align: middle; }
table.rank td.name .team-tag { color: var(--muted); font-size: 11px; font-weight: 400; margin-left: 5px; }

/* ---------- Player detail bottom sheet ---------- */
.pm-modal { position: fixed; inset: 0; z-index: 100; display: none; align-items: flex-end; }
.pm-modal.open { display: flex; }
.pm-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); backdrop-filter: blur(4px); }
.pm-sheet {
  position: relative; z-index: 1; width: 100%;
  background: var(--surface); border: 1px solid var(--border); border-bottom: none;
  border-radius: 22px 22px 0 0;
  max-height: 78vh; overflow-y: auto;
  padding: 0 16px calc(20px + var(--safe-b));
  animation: pmUp .25s cubic-bezier(.32,.72,0,1);
}
@keyframes pmUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.pm-handle { width: 36px; height: 4px; background: var(--border); border-radius: 2px; margin: 12px auto 18px; }
.pm-header { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.pm-photo { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--surface-2); border: 2px solid var(--border); flex-shrink: 0; }
.pm-name { font-family: var(--condensed); font-size: 24px; font-weight: 700; letter-spacing: .5px; }
.pm-team { font-size: 13px; color: var(--muted); margin-top: 2px; }
.pm-section-title { font-family: var(--condensed); font-size: 11px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin: 18px 0 10px; }
.pm-owner-block { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
.pm-owner-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; margin-bottom: 12px; }
.pm-stats-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 2px; }
.pm-stat { text-align: center; }
.pm-v { font-family: var(--condensed); font-size: 20px; font-weight: 700; display: block; }
.pm-l { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; display: block; margin-top: 1px; }
.pm-mlb-btn { display: flex; align-items: center; justify-content: center; margin-top: 20px; padding: 15px; background: var(--accent); color: #fff; border-radius: 14px; font-weight: 600; font-size: 15px; text-decoration: none; touch-action: manipulation; }
.pm-mlb-btn:active { opacity: .8; }

.empty { text-align: center; color: var(--muted); padding: 50px 18px; }
.toggle {
  display: inline-flex; gap: 4px; background: var(--surface-2);
  border-radius: 14px; padding: 4px; margin-bottom: 20px;
  border: 1px solid var(--border);
}
.toggle button {
  background: none; border: none; color: var(--muted);
  font-family: 'Barlow', sans-serif; font-size: 14px; font-weight: 500;
  padding: 0 22px; min-height: 44px; border-radius: 10px;
  cursor: pointer; transition: background .18s, color .18s; touch-action: manipulation;
}
.toggle button.active { background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 2px 8px rgba(79,142,247,0.4); }
.scroll-hint { font-size: 11px; color: var(--muted); margin: 6px 2px 0; display: flex; align-items: center; gap: 5px; }

/* ---------- 對戰篩選 chips ---------- */
.filter-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 7px 16px;
  font-size: 13px; font-weight: 500; color: var(--muted);
  cursor: pointer; transition: background .15s, color .15s, border-color .15s;
  touch-action: manipulation;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.chip:active { opacity: .8; }

/* ---------- 玩家折疊區塊 ---------- */
.player-section { margin-bottom: 10px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.player-section-hd {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); padding: 14px 18px;
  cursor: pointer; user-select: none; list-style: none;
  font-weight: 600; font-size: 15px;
}
.player-section-hd::-webkit-details-marker { display: none; }
.player-section-hd .chevron {
  margin-left: auto; width: 18px; height: 18px; color: var(--muted);
  transition: transform .2s;
}
.player-section[open] > .player-section-hd .chevron { transform: rotate(180deg); }
.player-section .tbl-card { border-radius: 0; border: none; border-top: 1px solid var(--border); }
.player-section .empty { padding: 20px 18px; }

/* ============ Desktop (≥ 720px) ============ */
@media (min-width: 720px) {
  body { padding-bottom: 40px; }
  .wrap { padding: 0 20px; }
  .site-inner { height: 62px; gap: 18px; }
  .brand { font-size: 18px; }

  nav.tabs.top { display: flex; gap: 4px; margin-left: auto; }
  nav.tabs.top a {
    padding: 9px 15px; border-radius: 9px; font-size: 14px; font-weight: 500;
    color: var(--muted); cursor: pointer; transition: color .2s, background .2s; white-space: nowrap;
  }
  nav.tabs.top a:hover { color: var(--text); background: var(--surface-2); }
  nav.tabs.top a.active { color: #fff; background: var(--accent); }

  .bottom-tabs { display: none; }
  .fab { display: none; }
  nav.tabs.top a.submit-tab {
    background: var(--accent); color: #fff; font-weight: 600;
  }
  nav.tabs.top a.submit-tab:hover { background: #3d7de8; }

  .h2h { padding: 28px 24px; }
  .stat-row { gap: 12px; }
  .stat-box { padding: 18px; }
  .game-card { padding: 16px 18px; }
  .game-card:hover { border-color: var(--accent); transform: translateY(-2px); }
  .detail-head { padding: 22px 24px; }

  /* 桌面寬度夠，表格不需要 sticky 也不會擠，但保留無妨 */
  table.stats th.n, table.stats td.n { width: 48px; }
}

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