:root {
  color-scheme: dark;
  --ink: #e7ebf4;
  --muted: #8b94a8;
  --paper: #0d1117;
  --surface: #161b22;
  --surface-soft: #1c222c;
  --surface-strong: #232a36;
  --line: #2a313d;
  --line-soft: #232a36;
  --blue: #60a5fa;
  --teal: #2dd4bf;
  --red: #f87171;
  --gold: #fbbf24;
  --green: #4ade80;
  --shadow: 0 14px 32px rgba(0, 0, 0, 0.4);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(13, 17, 23, 0) 0, var(--paper) 580px),
    var(--paper);
}

button,
input,
select {
  font: inherit;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--paper);
  color: var(--muted);
  font-size: 14px;
  z-index: 9999;
  transition: opacity 0.3s ease;
}
.loading.fade-out {
  opacity: 0;
  pointer-events: none;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

.no-season {
  padding: 80px 20px;
  text-align: center;
  color: var(--muted);
}
.no-season h2 {
  font-size: 1.6rem;
  margin: 0 0 12px;
  color: var(--ink);
}

.hero {
  position: relative;
  min-height: 72vh;
  display: grid;
  align-items: end;
  overflow: hidden;
}

.hero__image {
  position: absolute;
  inset: 0;
  background-image: url("assets/hero.jpg");
  background-position: center bottom;
  background-size: cover;
  transform: scale(1.01);
  filter: brightness(0.78) saturate(0.92);
}

.hero__shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(5, 8, 14, 0.5) 0%, rgba(5, 8, 14, 0.3) 38%, rgba(5, 8, 14, 0.96) 100%),
    linear-gradient(90deg, rgba(5, 8, 14, 0.65), rgba(5, 8, 14, 0.15));
}

.hero__content {
  position: relative;
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 34vh 20px 28px;
  color: #f4f6fb;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--gold);
}

.hero .eyebrow {
  font-size: clamp(1.35rem, 6vw, 2.15rem);
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  max-width: 760px;
  margin-bottom: 8px;
  font-size: clamp(2.15rem, 9vw, 5.4rem);
  line-height: 1.02;
  letter-spacing: 0;
  text-wrap: balance;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}

.hero__subtitle {
  margin: 0 0 22px;
  font-size: clamp(2.15rem, 9vw, 5.4rem);
  line-height: 1.02;
  font-weight: 900;
}

.hero__stats,
.stat-grid,
.standing-grid {
  display: grid;
  gap: 10px;
}

.hero__stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  max-width: 720px;
}

.stat-pill {
  min-height: 72px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(20, 26, 38, 0.55);
  backdrop-filter: blur(10px);
}

.hero__history-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 14px;
  min-height: 40px;
  padding: 0 18px;
  border: 1px solid rgba(251, 191, 36, 0.45);
  border-radius: 999px;
  background: rgba(20, 26, 38, 0.55);
  backdrop-filter: blur(10px);
  color: var(--gold);
  font-weight: 900;
  text-decoration: none;
}
.hero__history-link:hover {
  border-color: var(--gold);
  background: rgba(251, 191, 36, 0.12);
}

.stat-pill strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1;
}

.stat-pill span {
  display: block;
  margin-top: 6px;
  font-size: 0.78rem;
  color: rgba(244, 246, 251, 0.75);
}

main {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 0 14px 44px;
}

html {
  /* 分頁切換是整塊內容替換，瀏覽器的 scroll anchoring 會在跳轉後再補償位置造成偏移 */
  overflow-anchor: none;
}

.controls {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  padding: 12px 0 10px;
  background: rgba(13, 17, 23, 0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.search,
.select {
  display: flex;
  align-items: center;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.search {
  padding: 0 12px;
  gap: 8px;
}

.search__icon {
  color: var(--blue);
  font-weight: 800;
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.search input::placeholder {
  color: var(--muted);
}

.select {
  padding-left: 10px;
  overflow: hidden;
}

.select__label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.select select {
  min-height: 42px;
  border: 0;
  outline: 0;
  padding: 0 28px 0 8px;
  background: transparent;
  color: var(--ink);
}

.select select option {
  background: var(--surface);
  color: var(--ink);
}

.tabs {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
  display: none;
}

.tab {
  flex: 0 0 auto;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 800;
  cursor: pointer;
}

.tab[aria-selected="true"] {
  color: #0d1117;
  border-color: var(--blue);
  background: var(--blue);
}

.overview,
.group-panel,
.schedule,
.schedule-chart,
.rules {
  margin-top: 22px;
}

.overview {
  display: grid;
  gap: 12px;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.45rem;
}

.overview__grid,
.next-list {
  display: grid;
  gap: 10px;
}

.next-banner {
  position: relative;
  margin-bottom: 12px;
  padding: 14px 18px;
  border-radius: 12px;
  border: 1px solid rgba(96, 165, 250, 0.35);
  background: linear-gradient(135deg, rgba(96, 165, 250, 0.12), rgba(52, 211, 153, 0.08));
  overflow: hidden;
}
.next-banner--soon {
  border-color: rgba(251, 191, 36, 0.55);
  background: linear-gradient(135deg, rgba(251, 191, 36, 0.18), rgba(248, 113, 113, 0.08));
}
.next-banner--live {
  border-color: rgba(248, 113, 113, 0.65);
  background: linear-gradient(135deg, rgba(248, 113, 113, 0.22), rgba(248, 113, 113, 0.08));
  animation: nextBannerPulse 1.6s ease-in-out infinite;
}
@keyframes nextBannerPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.35); }
  50% { box-shadow: 0 0 0 8px rgba(248, 113, 113, 0); }
}
.next-banner__head {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
  font-size: 13px;
}
.next-banner__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted, #94a3b8);
  font-weight: 600;
}
.next-banner__countdown {
  font-weight: 800;
  font-size: 20px;
  color: #f8fafc;
  background: rgba(15, 23, 42, 0.4);
  padding: 6px 14px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.next-banner__match + .next-banner__match {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed rgba(148, 163, 184, 0.25);
}
.next-banner__teams {
  font-size: 20px;
  font-weight: 800;
  color: var(--text, #f8fafc);
  margin: 4px 0 6px;
}
.next-banner__teams em {
  font-style: normal;
  font-weight: 500;
  color: var(--muted, #94a3b8);
  margin: 0 8px;
  font-size: 16px;
}
.next-banner__meta {
  font-size: 13px;
  color: var(--muted, #94a3b8);
  line-height: 1.5;
}

.team__placeholder {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted, #94a3b8);
  background: rgba(148, 163, 184, 0.12);
  border-radius: 999px;
  vertical-align: middle;
}
.next-banner__teams .team__placeholder { font-size: 12px; }

.overview__grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.info-tile,
.group-summary,
.match-card,
.day-block,
.rule-card,
.next-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.info-tile {
  padding: 14px;
}

.info-tile span,
.card-label,
.match-meta,
.rule-card summary span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.info-tile strong {
  display: block;
  margin-top: 4px;
  font-size: 1.55rem;
}

.group-summary {
  padding: 16px;
}

.group-summary__head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.group-summary h2 {
  margin: 0 0 6px;
  font-size: 1.4rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tag,
.status,
.phase {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 900;
  white-space: nowrap;
}

.tag {
  color: var(--blue);
  background: rgba(96, 165, 250, 0.16);
}

.phase {
  color: var(--teal);
  background: rgba(45, 212, 191, 0.16);
}

.status {
  color: var(--red);
  background: rgba(248, 113, 113, 0.16);
}

.status.done {
  color: var(--green);
  background: rgba(74, 222, 128, 0.16);
}

.stat-grid,
.standing-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.prelim-progress {
  margin: 0 0 14px;
  padding: 10px 14px;
  background: rgba(96, 165, 250, 0.08);
  border: 1px solid rgba(96, 165, 250, 0.25);
  border-radius: 10px;
}
.prelim-progress-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 14px;
  margin-bottom: 6px;
  color: var(--muted, #94a3b8);
}
.prelim-progress-label strong {
  color: var(--text, #e2e8f0);
  font-size: 15px;
}
.prelim-progress-bar {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
}
.prelim-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #60a5fa, #34d399);
  transition: width 0.4s ease;
}

.prelim-board {
  display: grid;
  gap: 12px;
}

.prelim-group {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.prelim-group h3 {
  margin: 0;
  padding: 10px 12px;
  color: #0d1117;
  background: var(--teal);
  font-size: 0.98rem;
}

.prelim-head,
.prelim-row {
  display: grid;
  grid-template-columns: 42px minmax(72px, 1fr) 32px 32px 32px 44px;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 10px;
}

.prelim-head {
  color: var(--muted);
  background: var(--surface-strong);
  font-size: 0.75rem;
  font-weight: 900;
}

.prelim-row {
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
}

.prelim-row span,
.prelim-row strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.prelim-row span:not(:first-child),
.prelim-row strong {
  text-align: center;
}

.prelim-row span:nth-child(2) {
  text-align: left;
  font-weight: 900;
}

.mini-stat,
.standing {
  min-width: 0;
  padding: 10px;
  border-radius: 8px;
  background: var(--surface-strong);
}

.standing--冠軍,
.standing--亞軍,
.standing--季軍,
.standing--殿軍 {
  border: 2px solid rgba(251, 191, 36, 0.55);
  background: rgba(251, 191, 36, 0.12);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.45);
}

.standing--冠軍 .card-label,
.standing--亞軍 .card-label,
.standing--季軍 .card-label,
.standing--殿軍 .card-label {
  color: var(--gold);
  font-size: 1rem;
}

.standing--冠軍 strong,
.standing--亞軍 strong,
.standing--季軍 strong,
.standing--殿軍 strong {
  color: #fcd34d;
  font-size: 1.22rem;
}

.chart-card {
  margin: 0 0 18px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
}

.chart-scroll {
  overflow-x: auto;
  background: #fff; /* 掃描圖（紙本 JPG）需要白底 */
}
.chart-scroll--bracket {
  background: var(--surface); /* 自動對戰圖用深色，與整體布景一致 */
}

.chart-scroll img {
  display: block;
  width: 100%;
  min-width: 720px;
  height: auto;
}

.mini-stat strong,
.standing strong {
  display: block;
  margin-top: 4px;
}

.standing strong {
  overflow-wrap: anywhere;
}

.day-block {
  margin-bottom: 14px;
  overflow: hidden;
}

.day-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-strong);
}

.day-title h3 {
  margin: 0;
  font-size: 1rem;
}

.day-title span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

/* 已賽完的比賽日：details 收合版 */
.day-block--folded > summary.day-title {
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.day-block--folded > summary.day-title::-webkit-details-marker { display: none; }
.day-block--folded > summary.day-title span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.day-caret {
  font-style: normal;
  font-size: 0.75rem;
  transition: transform 0.15s;
  transform: rotate(-90deg);
}
.day-block--folded[open] .day-caret { transform: rotate(0deg); }
.day-block--folded:not([open]) > summary.day-title { border-bottom: 0; }

.match-list {
  display: grid;
  gap: 0;
}

.match-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: none;
  padding: 14px;
  background: var(--surface-soft);
  margin: 8px 12px;
  transition: border-color 0.15s, background 0.15s;
}

.match-card:hover {
  border-color: var(--line-strong, #3a4252);
  background: var(--surface-strong);
}

.match-card:last-child {
  margin-bottom: 12px;
}

.match-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.match-meta {
  margin-right: auto;
}

.teams {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.team {
  min-width: 0;
  min-height: 44px;
  padding: 10px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  text-align: center;
}

.team.winner {
  border-color: var(--gold);
  background: rgba(251, 191, 36, 0.16);
  box-shadow: inset 0 0 0 2px rgba(251, 191, 36, 0.4);
}

.team__name {
  display: block;
  font-size: 1rem;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.scorebox {
  min-width: 76px;
  min-height: 44px;
  padding: 8px 10px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #f4f6fb;
  background: #050811;
  font-size: 1.18rem;
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.55);
  border: 1px solid var(--line);
}

.scorebox--done {
  background: var(--red);
  color: #1a0c0c;
  border-color: var(--red);
}

.scorebox--pending {
  color: var(--muted);
  background: var(--surface-strong);
  border-color: var(--line);
  box-shadow: none;
}

.next-card {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.next-card strong {
  font-size: 1rem;
}

.rules {
  display: grid;
  gap: 10px;
}

.rule-card {
  overflow: hidden;
}

.rule-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  cursor: pointer;
  font-weight: 900;
}

.rule-card summary::marker {
  color: var(--blue);
}

.rule-body {
  padding: 0 14px 14px;
  display: grid;
  gap: 14px;
}

.rule-body h3 {
  margin: 0 0 8px;
  font-size: 0.95rem;
}

.rule-body ul {
  margin: 0;
  padding-left: 1.2rem;
}

.rule-body li {
  margin-bottom: 6px;
  color: #c4cad8;
}

.empty-state {
  padding: 28px 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(22, 27, 34, 0.6);
}

.footer {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 18px 14px 28px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.footer span {
  grid-column: 2;
  text-align: center;
}

.footer a {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--blue);
  background: var(--surface);
  font-weight: 900;
  text-decoration: none;
}

.footer a:first-of-type {
  grid-column: 1;
  justify-self: start;
}

.footer__links {
  grid-column: 1;
  justify-self: start;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 歷年成績頁：明顯的「回賽程首頁」主按鈕 */
.footer a.footer__home {
  grid-column: 1;
  justify-self: start;
  min-height: 46px;
  padding: 0 22px;
  font-size: 1rem;
  background: var(--blue);
  border-color: var(--blue);
  color: #0d1117;
  border-radius: 999px;
}
.footer a.footer__home:hover {
  filter: brightness(1.1);
}

.footer a:last-of-type {
  grid-column: 3;
  justify-self: end;
}

@media (min-width: 760px) {
  .hero {
    min-height: 76vh;
  }

  .hero__content {
    padding-inline: 30px;
  }

  main,
  .footer {
    padding-inline: 24px;
  }

  .overview {
    grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr);
    align-items: start;
  }

  .overview.overview--single {
    grid-template-columns: 1fr;
  }

  .group-summary {
    padding: 20px;
  }

  .stat-grid,
  .standing-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .prelim-board {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .match-card {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    gap: 16px;
    align-items: center;
  }

  .match-top {
    margin-bottom: 0;
  }
}

@media print {
  :root { color-scheme: light; }
  html, body {
    background: white !important;
    color: black !important;
    font-size: 11pt;
  }
  body {
    background-image: none !important;
  }
  .loading { display: none !important; }
  .hero { min-height: auto !important; display: block !important; padding: 6mm 8mm !important; }
  .hero__image, .hero__shade { display: none !important; }
  .hero__content { padding: 0 !important; color: black !important; }
  .hero__content h1, .hero__subtitle { text-shadow: none !important; font-size: 16pt !important; line-height: 1.2 !important; margin: 0 !important; }
  .hero__subtitle { font-size: 14pt !important; font-weight: 700 !important; }
  .hero .eyebrow { color: black !important; font-size: 10pt !important; }
  .hero__stats { display: none !important; }
  .controls { display: none !important; }
  .overview, .next-list { display: none !important; }
  main { padding: 0 8mm !important; max-width: none !important; }
  .section-heading h2 { font-size: 14pt !important; color: black !important; }
  .eyebrow { color: #666 !important; }
  .info-tile, .group-summary, .day-block, .next-card {
    background: white !important;
    border: 1px solid #999 !important;
    box-shadow: none !important;
  }
  .group-summary {
    page-break-inside: avoid;
  }
  .day-block {
    page-break-inside: avoid;
    margin-bottom: 6mm !important;
  }
  .day-title {
    background: #f0f0f0 !important;
    border-bottom: 1px solid #999 !important;
    padding: 3mm 4mm !important;
  }
  .day-title h3 { color: black !important; font-size: 11pt !important; }
  .day-title span { color: #555 !important; }
  .match-card {
    background: white !important;
    border-color: #ccc !important;
    box-shadow: none !important;
    padding: 3mm 4mm !important;
    page-break-inside: avoid;
  }
  .match-meta, .card-label { color: #555 !important; }
  .scorebox {
    color: black !important;
    background: white !important;
    border: 1px solid #555 !important;
    box-shadow: none !important;
    font-size: 11pt !important;
  }
  .scorebox--done {
    background: white !important;
    color: black !important;
    border: 2px solid black !important;
  }
  .scorebox--pending {
    background: #f0f0f0 !important;
    color: #555 !important;
    border: 1px dashed #999 !important;
  }
  .team {
    background: white !important;
    border: 1px solid #999 !important;
    color: black !important;
  }
  .team.winner {
    background: #fff7c2 !important;
    border-color: #d4a017 !important;
    color: black !important;
    box-shadow: none !important;
  }
  .tag, .phase, .status {
    background: white !important;
    border: 1px solid #999 !important;
    color: black !important;
    font-weight: 700 !important;
  }
  .status.done {
    background: #e6f5e6 !important;
    color: black !important;
  }
  .prelim-group { border: 1px solid #999 !important; background: white !important; }
  .prelim-group h3 { background: #d0d0d0 !important; color: black !important; }
  .prelim-head { background: #f0f0f0 !important; color: black !important; }
  .prelim-row { border-top: 1px solid #ccc !important; }
  .standing { background: white !important; border: 1px solid #ccc !important; }
  .standing--冠軍, .standing--亞軍, .standing--季軍, .standing--殿軍 {
    background: #fff7c2 !important;
    border: 2px solid #d4a017 !important;
  }
  .standing--冠軍 .card-label, .standing--亞軍 .card-label,
  .standing--季軍 .card-label, .standing--殿軍 .card-label,
  .standing--冠軍 strong, .standing--亞軍 strong,
  .standing--季軍 strong, .standing--殿軍 strong {
    color: black !important;
  }
  .chart-card { border: 1px solid #999 !important; background: white !important; box-shadow: none !important; }
  .chart-scroll img { max-width: 100% !important; min-width: 0 !important; }
  .rule-card { background: white !important; border: 1px solid #999 !important; box-shadow: none !important; }
  .rule-card summary { color: black !important; }
  .rule-body li { color: black !important; }
  .schedule-chart, .rules { page-break-before: auto; }
  .footer { display: none !important; }
  a[href^="#"] { display: none !important; }
}

.my-classes-bar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}
.my-classes-bar:empty { display: none; }
.my-classes-bar button {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
}
.my-classes-bar button.active {
  background: var(--blue);
  color: #0d1117;
  border-color: var(--blue);
}
.my-classes-bar .chip-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 4px 8px;
  min-height: 0;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal[hidden] { display: none; }
.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 8, 14, 0.75);
  backdrop-filter: blur(4px);
}
.modal__panel {
  position: relative;
  width: min(420px, 100%);
  max-height: 86vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
  color: var(--ink);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.modal__sub {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 14px;
}
.modal__actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  align-items: center;
}
.modal__actions button {
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--line);
}
.modal__actions button.primary {
  background: var(--blue);
  color: #0d1117;
  border-color: var(--blue);
}
.modal__actions button.ghost {
  background: transparent;
  color: var(--ink);
}

.my-classes-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px;
}
.my-classes-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft, var(--surface));
  cursor: pointer;
  font-size: 0.92rem;
}
.my-classes-list label:has(input:checked) {
  border-color: var(--blue);
  background: rgba(96, 165, 250, 0.15);
}
.my-classes-list input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}
.my-classes-list .empty-hint {
  grid-column: 1 / -1;
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 700px) {
  .hero { min-height: 56vh; }
  .hero__content { padding: 18vh 20px 22px; }

  .tabs {
    flex-wrap: wrap;
    overflow-x: visible;
    gap: 6px;
  }

  .next-banner { padding: 12px 14px; }
  .next-banner__teams { font-size: 17px; line-height: 1.35; }
  .next-banner__teams em { margin: 0 6px; font-size: 14px; }
  .next-banner__meta { font-size: 12px; }
  .prelim-progress { padding: 8px 12px; }
  .prelim-progress-label { font-size: 13px; }
}

@media (max-width: 430px) {
  .hero { min-height: 50vh; }
  .hero__content { padding: 14vh 20px 18px; }

  .hero__image {
    background-size: auto 180%;
    background-position: center bottom;
  }

  .hero__stats,
  .overview__grid {
    grid-template-columns: 1fr 1fr;
  }

  .stat-pill:last-child,
  .overview__grid .info-tile:last-child {
    grid-column: 1 / -1;
  }

  .controls {
    grid-template-columns: 1fr;
  }

  .select {
    width: 100%;
  }

  .select select {
    flex: 1;
  }

  .teams {
    grid-template-columns: 1fr;
  }

  .scorebox {
    width: auto;
    min-height: 38px;
    padding: 7px 12px;
    justify-self: center;
  }
}

/* ---- 對戰圖（自動產生，深色卡片風） ---- */
.bracket {
  position: relative;
  display: flex;
  gap: 28px;
  padding: 12px 8px;
  width: max-content;
  min-width: 100%;
}
.bracket__lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.bracket__lines path {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
}
.bracket__round {
  display: flex;
  flex-direction: column;
  width: 180px;
  flex: none;
}
.bracket__round-title {
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}
.bracket__cards {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  gap: 14px;
}
.bracket-match {
  position: relative;
  z-index: 1;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
.bracket-match__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 8px;
}
.bracket-match__badge {
  color: var(--gold);
  font-weight: 700;
}
.bracket-team {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
  font-size: 15px;
}
.bracket-team + .bracket-team {
  border-top: 1px solid var(--line-soft);
}
.bracket-team--win .bracket-team__name,
.bracket-team--win .bracket-team__score {
  color: var(--teal);
  font-weight: 800;
}
.bracket-team--pending .bracket-team__name {
  color: var(--muted);
  font-size: 13.5px;
}
.bracket-team__score {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.bracket-match__score {
  margin-top: 6px;
  font-size: 13px;
  color: var(--muted);
}

.bracket__round--champion {
  width: 150px;
}
.bracket-champion {
  display: flex;
  align-items: center;
  gap: 10px;
  border-color: rgba(251, 191, 36, 0.5);
  background: rgba(251, 191, 36, 0.08);
  font-weight: 900;
  font-size: 17px;
  color: var(--gold);
}
.bracket-champion__trophy {
  font-size: 24px;
}

.bracket-third {
  margin: 4px 8px 12px;
  max-width: 300px;
}
.bracket-third__label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}
.bracket-third .bracket-match {
  border-style: dashed;
}

/* 手機：樹狀圖改直式逐輪排列，免左右捲動 */
@media (max-width: 720px) {
  .bracket {
    flex-direction: column;
    width: auto;
    min-width: 0;
    gap: 22px;
    padding: 8px 4px;
  }
  .bracket__lines {
    display: none;
  }
  .bracket__round,
  .bracket__round--champion {
    width: auto;
  }
  .bracket__round-title {
    text-align: left;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--line-soft);
  }
  .bracket__cards {
    gap: 10px;
  }
  .bracket-third {
    max-width: none;
    margin: 14px 4px;
  }
}

/* ---- 預賽對戰表（交叉矩陣） ---- */
.crosstable-board {
  display: grid;
  gap: 14px;
  margin-top: 14px;
}
.crosstable-group {
  /* grid 子項預設 min-width:auto，會被表格的 min-width 撐開而擠爆手機版面；
     設 0 讓內層 .crosstable-scroll 的橫向捲軸接手 */
  min-width: 0;
}
.crosstable-group h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--muted);
}
.crosstable-scroll {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.crosstable {
  border-collapse: collapse;
  width: 100%;
  min-width: 420px;
  font-size: 13.5px;
}
.crosstable th,
.crosstable td {
  border: 1px solid var(--line-soft);
  padding: 8px 10px;
  text-align: center;
  white-space: nowrap;
}
.crosstable thead th {
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 700;
}
.crosstable tbody th {
  background: var(--surface-strong);
  text-align: left;
  font-weight: 700;
}
.crosstable__corner {
  border-top: none;
  border-left: none;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.crosstable-legend {
  margin: -4px 0 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 12.5px;
}
.crosstable-legend__chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface);
  font-weight: 700;
}
.crosstable-legend__chip .crosstable__rank { margin-right: 0; }
.crosstable__rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  margin-right: 8px;
  border-radius: 6px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
}
.crosstable__rank--top {
  background: rgba(251, 191, 36, 0.18);
  color: var(--gold);
}
/* 搜尋命中的隊伍列 */
.prelim-row.is-hit {
  background: rgba(96, 165, 250, 0.14);
  box-shadow: inset 3px 0 0 #60a5fa;
}
.bracket-team.is-hit,
.bracket-champion.is-hit {
  /* 疊色不蓋掉勝隊綠字與冠軍金卡的既有配色 */
  box-shadow: inset 0 0 0 999px rgba(96, 165, 250, 0.12);
  border-radius: 6px;
}
.crosstable tr.is-hit th {
  background: rgba(96, 165, 250, 0.2);
  color: #93c5fd;
}
.crosstable tr.is-hit td {
  /* 用 inset box-shadow 疊色，保留勝敗格原本的底色 */
  box-shadow: inset 0 0 0 999px rgba(96, 165, 250, 0.08);
}

.crosstable__self {
  background:
    linear-gradient(to top right, transparent calc(50% - 1px), var(--line) calc(50% - 1px), var(--line) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--surface-soft);
}
.crosstable__pending { color: var(--muted); }
.crosstable__cell { font-variant-numeric: tabular-nums; font-weight: 700; }
.crosstable__cell--win { color: var(--teal); background: rgba(45, 212, 191, 0.08); }
.crosstable__cell--lose { color: var(--red); background: rgba(248, 113, 113, 0.07); }
.crosstable__cell--draw { color: var(--gold); }

/* ---- 歷年成績頁 ---- */
.history-hero {
  padding: 48px 20px 28px;
  text-align: center;
  background: linear-gradient(180deg, var(--surface) 0, var(--paper) 100%);
  border-bottom: 1px solid var(--line-soft);
}
.history-hero__school {
  margin: 0;
  font-size: clamp(20px, 4.5vw, 28px);
  font-weight: 700;
  letter-spacing: 0.12em;
}
.history-hero h1 {
  margin: 8px 0 10px;
  font-size: clamp(34px, 8vw, 52px);
  letter-spacing: 0.04em;
}
.history-hero__subtitle {
  margin: 0;
  font-size: clamp(17px, 3.5vw, 21px);
  font-weight: 700;
  color: var(--gold);
}

.history-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
  display: grid;
  gap: 28px;
}

.history-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.history-chip {
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}
.history-chip:hover {
  border-color: var(--blue);
  color: var(--ink);
}
.history-chip--active {
  border-color: var(--blue);
  background: rgba(96, 165, 250, 0.14);
  color: var(--blue);
}

.history-expand {
  margin-top: 14px;
  width: 100%;
  min-height: 42px;
  border: 1px dashed var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  cursor: pointer;
}
.history-expand:hover {
  border-color: var(--blue);
  color: var(--blue);
}

.history-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
}

.history-event {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
}
.history-event__title {
  margin: 0 0 14px;
  font-size: 20px;
  color: var(--gold);
}

.history-season + .history-season {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line-soft);
}
.history-season__title {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

.podium-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr));
  gap: 16px;
}

.podium-card {
  margin: 0;
  background: var(--surface-soft);
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.podium-card figcaption {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.podium-label {
  font-size: 13px;
  color: var(--muted);
}
.podium-team {
  font-size: 17px;
  font-weight: 700;
}
.podium-original {
  margin-top: 4px;
  font-size: 13px;
  color: var(--blue);
  text-decoration: none;
}
.podium-original:hover {
  text-decoration: underline;
}

.podium-photo {
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  padding: 0;
  background: var(--surface-strong);
  cursor: pointer;
}
.podium-photo:hover {
  border-color: var(--blue);
}
.podium-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.podium-photo--empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  cursor: default;
  opacity: 0.55;
}

.photo-modal__panel {
  /* 蓋掉 .modal__panel 的 420px 小對話框寬度，燈箱要近全螢幕 */
  width: min(96vw, 1400px);
  max-height: 94vh;
  padding: 12px 16px 16px;
}
.photo-modal__img {
  width: 100%;
  max-height: 80vh;
  object-fit: contain;
  border-radius: 10px;
  background: var(--paper);
}
.photo-modal__caption {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}
.photo-modal__original {
  display: inline-flex;
  align-items: center;
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  text-decoration: none;
  font-size: 14px;
}
.photo-modal__original:hover {
  border-color: var(--blue);
}
