:root {
  color-scheme: light;
  --ink: #123047;
  --muted: #657b88;
  --brand: #a9e6ee;
  --brand-dark: #245d69;
  --line: #dce9ec;
  --panel: #ffffff;
  --shadow: 0 16px 44px rgba(40, 78, 95, 0.08);
  font-family: "Microsoft JhengHei", "Noto Sans TC", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: #f5fafb;
  min-width: 280px;
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(135deg, rgba(246, 251, 251, 0.96), rgba(238, 248, 251, 0.94) 55%, rgba(248, 248, 255, 0.96)),
    var(--ranking-background, linear-gradient(135deg, #effafa, #f5f4ff));
  background-size: cover;
  background-position: center;
  pointer-events: none;
}

button, select { font: inherit; }
button, a, select { -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
[hidden] { display: none !important; }

a:focus-visible, button:focus-visible, select:focus-visible, .ranking-table-wrap:focus-visible {
  outline: 3px solid #318699;
  outline-offset: 4px;
}

.ranking-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 26px 32px 20px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
  text-decoration: none;
  border-radius: 12px;
}

.logo-frame {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: #ffffff;
}

.site-logo {
  display: block;
  max-width: 64px;
  max-height: 64px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.logo-fallback { font-weight: 800; font-size: 26px; color: var(--brand-dark); }
.brand-label { font-size: 19px; font-weight: 700; letter-spacing: 0.04em; }
.return-link {
  padding: 11px 16px;
  border: 1px solid #d3e4e8;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.8);
  color: var(--brand-dark);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.return-link:hover { background: #eaf8fa; }
.return-link span { margin-left: 4px; }
.ranking-heading { padding: 48px 0 30px; }
.heading-label { margin: 0 0 12px; font-size: 12px; font-weight: 700; letter-spacing: 0.16em; color: var(--brand-dark); }
h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); line-height: 1.35; letter-spacing: 0.04em; }
.heading-note { margin: 14px 0 0; color: var(--muted); font-size: 15px; line-height: 1.7; }
.ranking-panel { border: 1px solid var(--line); border-radius: 20px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.ranking-filters { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; padding: 28px; background: #f0fafb; border-bottom: 1px solid var(--line); }
.filter-field { min-width: 0; }
.filter-field label { display: block; margin-bottom: 10px; font-size: 15px; font-weight: 700; }
.filter-field select {
  display: block;
  width: 100%;
  min-height: 50px;
  padding: 10px 36px 10px 14px;
  border: 1px solid #c7dce2;
  border-radius: 11px;
  background-color: #ffffff;
  color: var(--ink);
  cursor: pointer;
}

.filter-field select:disabled { cursor: default; color: var(--muted); background-color: #f8fbfc; opacity: 1; }
.ranking-results { min-width: 0; padding: 20px 28px; }
.results-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.results-heading h2 { margin: 0; font-size: 18px; line-height: 1.5; overflow-wrap: anywhere; }
.entry-count { flex-shrink: 0; padding: 5px 10px; border-radius: 20px; background: #edf8fa; color: var(--brand-dark); font-size: 13px; white-space: nowrap; }
.ranking-status { min-height: 180px; display: grid; place-items: center; text-align: center; padding: 32px 20px; border: 1px dashed var(--line); border-radius: 12px; color: var(--muted); line-height: 1.7; }
.ranking-status[data-state="error"] { color: #8c4237; background: #fff8f5; border-color: #edd8d1; }
.retry-button { display: block; min-height: 44px; margin: 16px auto 0; padding: 10px 24px; border: 1px solid #88c6d0; border-radius: 10px; background: var(--brand); color: var(--ink); cursor: pointer; font-weight: 700; }
.retry-button:hover { background: #91dce6; }
.ranking-table-wrap { width: 100%; max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; -webkit-overflow-scrolling: touch; }
.ranking-table { width: 100%; min-width: 980px; border-collapse: collapse; table-layout: fixed; font-size: 15px; }
.ranking-table th { background: #eaf5f7; color: #315966; text-align: left; font-weight: 700; padding: 10px 14px; }
.ranking-table th:first-child { border-radius: 10px 0 0 10px; }
.ranking-table th:last-child { border-radius: 0 10px 10px 0; }
.ranking-table td { padding: 10px 14px; border-bottom: 1px solid #e7eff1; vertical-align: middle; line-height: 1.4; overflow-wrap: anywhere; }
.ranking-table tbody tr:last-child td { border-bottom: none; }
.ranking-table tbody .athlete-even { background: #f5fafb; }
.ranking-table tbody .ranking-athlete-start:not(:first-child) td { border-top: 2px solid var(--line); }
.ranking-table .rank-column { width: 70px; text-align: center; }
.ranking-table .unit-column { width: 150px; }
.ranking-table .name-column { width: 110px; }
.ranking-table .placement-column { width: 82px; white-space: nowrap; }
.ranking-table .wins-column { width: 82px; text-align: center; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ranking-table .points-column { width: 108px; text-align: right; font-variant-numeric: tabular-nums; }
.ranking-table td.points-column { font-weight: 700; color: var(--brand-dark); }
.ranking-table .total-points-column { width: 100px; }
.ranking-table td.total-points-column { font-size: 18px; }
.rank-badge { display: inline-grid; place-items: center; min-width: 32px; min-height: 32px; padding: 2px 6px; border-radius: 50%; font-weight: 700; }
.rank-badge[data-rank="1"] { background: #fff0bd; color: #785700; }
.rank-badge[data-rank="2"] { background: #e9eff5; color: #4b6278; }
.rank-badge[data-rank="3"] { background: #ffe3d4; color: #885638; }
.site-footer { margin-top: 28px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.6; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 10; top: 10px; left: 12px; padding: 10px 14px; background: white; border: 2px solid var(--brand-dark); border-radius: 8px; transform: translateY(-180%); }
.skip-link:focus { transform: translateY(0); }

@media (max-width: 600px) {
  .ranking-shell { padding: 18px 16px 20px; }
  .site-header { gap: 12px; padding-bottom: 18px; }
  .site-brand { gap: 9px; }
  .logo-frame { width: 52px; height: 52px; flex-basis: 52px; border-radius: 12px; }
  .site-logo { max-width: 46px; max-height: 46px; }
  .logo-fallback { font-size: 22px; }
  .brand-label { font-size: 15px; letter-spacing: 0; }
  .return-link { padding: 10px; font-size: 12px; }
  .return-link span { display: none; }
  .ranking-heading { padding: 30px 0 24px; }
  .heading-label { font-size: 10px; }
  .heading-note { font-size: 14px; }
  .ranking-panel { border-radius: 16px; }
  .ranking-filters { gap: 18px; padding: 20px; grid-template-columns: 1fr; }
  .filter-field select { font-size: 16px; }
  .ranking-results { padding: 20px 14px; }
  .results-heading { margin-bottom: 12px; gap: 8px; }
  .results-heading h2 { font-size: 15px; }
  .entry-count { font-size: 12px; padding: 4px 8px; }
  .ranking-status { min-height: 150px; padding: 24px 12px; font-size: 14px; }
  .ranking-table { font-size: 13px; }
  .ranking-table th { padding: 9px 7px; }
  .ranking-table td { padding: 9px 7px; }
  .ranking-table .rank-column { width: 58px; }
  .ranking-table .unit-column { width: 135px; }
  .ranking-table .name-column { width: 92px; }
  .ranking-table .placement-column { width: 72px; }
  .ranking-table .wins-column { width: 72px; }
  .ranking-table .points-column { width: 88px; }
  .ranking-table .total-points-column { width: 88px; }
  .ranking-table td.total-points-column { font-size: 16px; }
  .rank-badge { min-width: 28px; min-height: 28px; }
}

@media (max-width: 350px) {
  .brand-label { font-size: 13px; }
  .return-link { padding: 9px 7px; font-size: 11px; }
}
