/* 學期錦標賽頁：沿用跑跑觀戰頁的 2008 賽道色（深藍底、黃／橘、白粗框），字型自架於 /fonts。
   投影（1920×1080）一屏放完、不捲動；手機 375 寬直式往下捲、無橫向捲動。最小字 14px。 */
@font-face { font-family: "Cubic 11"; src: url("/fonts/cubic11.woff2") format("woff2"); font-display: swap; }
@font-face { font-family: "Press Start 2P"; src: url("/fonts/press-start-2p-latin-400.woff2") format("woff2"); font-display: swap; }

:root {
  --night: #0b1638;
  --lane: #13235a;
  --lane-2: #1b2f73;
  --well: #0e1b4a;
  --line: #3a4f94;
  --ink: #ffffff;
  --ink-2: #c9d6f5;
  --gold: #ffcc1a;
  --silver: #dfe6f3;
  --bronze: #f0a86c;
  --flag: #ff8a1f;
  --go: #2f7bff;
  --bad: #ff8f8f;
  --on-bright: #10183a;
  --f-body: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  --f-pixel: "Cubic 11", var(--f-body);
  --f-num: "Press Start 2P", "Cubic 11", ui-monospace, monospace;
  --pad: clamp(16px, 2vw, 40px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; color: var(--ink); font-family: var(--f-body); line-height: 1.5;
  background:
    repeating-linear-gradient(90deg, transparent 0 118px, #ffffff08 118px 120px),
    radial-gradient(120% 60% at 20% 0%, #1d3584 0%, transparent 60%),
    var(--night);
}
a { color: var(--gold); }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.skip-link { position: absolute; left: 8px; top: -60px; z-index: 5; padding: 8px 12px; background: var(--gold); color: var(--on-bright); font-weight: 900; }
.skip-link:focus { top: 8px; }
[hidden] { display: none !important; }
p { margin: 0; }

/* ── 頂部 ── */
.checker { height: 14px; background: conic-gradient(#fff 25%, #10183a 0 50%, #fff 0 75%, #10183a 0) 0 0 / 14px 14px; border-bottom: 3px solid var(--gold); }
.masthead__inner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px; padding: 12px var(--pad) 8px; }
.brand__course { color: var(--ink-2); font-size: 1rem; font-weight: 700; }
.brand__title {
  margin: 0; font-family: var(--f-pixel); font-weight: 400; line-height: 1.1; letter-spacing: .06em;
  font-size: clamp(2.25rem, 3.4vw, 3.5rem); text-shadow: 4px 4px 0 var(--go), 8px 8px 0 #0006;
}
.live {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 6px 16px;
  border: 3px solid #fff; background: var(--lane); box-shadow: 0 0 0 3px var(--on-bright);
  font-weight: 900; font-size: clamp(1rem, 1.25vw, 1.5rem);
}
.live__lamp { width: 14px; height: 14px; background: var(--ink-2); flex: none; }
.live[data-state="live"] .live__lamp { background: var(--flag); animation: blink 1.2s steps(2, jump-none) infinite; }
.live[data-state="error"] .live__lamp { background: #ff6b6b; }
@keyframes blink { 50% { opacity: .25; } }

.legend { order: 2; margin-left: auto; color: var(--ink-2); font-weight: 700; font-size: 1rem; }
.legend:empty { display: none; }
.live { order: 2; }
.gap--more { padding: 8px 14px; background: var(--well); border: 2px dashed var(--line); color: var(--ink); font-size: 1.25rem; font-weight: 900; }

/* 整季賽程條：一週一格，計分站實線、非計分週虛線，本週金底 */
.season { order: 3; flex: 1 1 100%; min-width: 0; }
.season__list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(15, minmax(0, 1fr)); gap: 6px; }
.wk { display: grid; gap: 0; padding: 4px 6px; background: var(--lane); border: 2px solid var(--line); line-height: 1.25; min-width: 0; }
.wk__no { font-family: var(--f-num); font-size: 1rem; }
.wk__date { color: var(--ink-2); font-size: .875rem; font-weight: 700; }
.wk__what { font-weight: 900; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wk__what i { font-style: normal; color: var(--ink-2); margin-right: 4px; font-size: .875rem; }
.wk[data-kind="off"] { background: transparent; border-style: dashed; color: var(--ink-2); }
.wk[aria-current] { background: var(--gold); border-color: #fff; color: var(--on-bright); box-shadow: 0 0 0 3px var(--on-bright); }
.wk[aria-current] .wk__date, .wk[aria-current] .wk__what i { color: var(--on-bright); }

/* ── 版面 ── */
.layout { display: grid; gap: 20px; padding: 8px var(--pad) 32px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .layout { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; } .tower { grid-row: span 2; } .side--season { grid-column: 2; } }
@media (min-width: 1500px) { .layout { grid-template-columns: minmax(0, 1fr) 440px 400px; } .tower { grid-row: auto; } .side--season { grid-column: auto; } }
.h2 { margin: 0; font-family: var(--f-pixel); font-weight: 400; font-size: clamp(1.5rem, 2vw, 2.25rem); letter-spacing: .04em; }
.h3 { margin: 0 0 8px; font-family: var(--f-pixel); font-weight: 400; font-size: 1.5rem; letter-spacing: .04em; }

/* ── 本週榜 ── */
.tower { min-width: 0; }
.tower:focus { outline: none; }
.tower__head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 16px; margin-bottom: 8px; }
.tower__meta { color: var(--ink-2); font-size: 1rem; }
.findme { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-weight: 700; font-size: 1.125rem; }
.findme input {
  width: 7em; min-height: 44px; padding: 4px 12px; font: 400 1.25rem var(--f-num); color: var(--on-bright);
  background: #fff; border: 3px solid var(--gold); border-radius: 0;
}
.findme output { font-weight: 900; color: var(--gold); font-size: 1.25rem; }
.scope { margin: 6px 0 10px; color: var(--ink-2); font-size: 1rem; }

.cols, .row { display: grid; align-items: center; column-gap: 14px; grid-template-columns: 72px minmax(0, 1fr) auto 72px 104px; }
.cols { padding: 0 14px 4px 20px; color: var(--ink-2); font-size: 1rem; font-weight: 700; }
.cols span:last-child, .cols .cols__wins { text-align: right; }
.cols__races { min-width: calc(4 * 40px + 3 * 6px); }
.cols.no-races .cols__races { visibility: hidden; min-width: 0; }
.rows { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.row { position: relative; min-height: 62px; padding: 4px 14px; background: var(--lane); border-left: 6px solid var(--line); }
.row:nth-child(odd) { background: #152760; }
.rank { font-family: var(--f-num); font-size: 1.5rem; line-height: 1; display: grid; place-items: center; height: 48px; background: var(--well); border: 2px solid var(--line); }
.who { min-width: 0; line-height: 1.2; }
.who__nick { display: block; font-weight: 900; font-size: 1.625rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who__tag { color: var(--ink-2); font-size: 1.25rem; font-weight: 700; }
.who__tag b { color: var(--ink); font-weight: 900; }
.who__wins { display: none; color: var(--gold); font-weight: 900; }
.races { display: flex; gap: 6px; }
.pos { width: 40px; height: 40px; display: grid; place-items: center; font-family: var(--f-num); font-size: 1.125rem; background: var(--well); border: 2px solid var(--line); }
.pos--1 { background: var(--gold); border-color: var(--gold); color: var(--on-bright); }
.pos--dnf { color: var(--bad); border-style: dashed; font-family: var(--f-body); font-weight: 900; }
.pos--todo { border-style: dotted; }
.wins { text-align: right; font-family: var(--f-num); font-size: 1.25rem; }
.wins--0 { color: var(--ink-2); }
.total { font-family: var(--f-num); font-size: 2rem; text-align: right; line-height: 1; }
.row--p1 { border-left-color: var(--gold); background: linear-gradient(90deg, #ffcc1a33, var(--lane) 55%) !important; }
.row--p1 .rank { background: var(--gold); border-color: #fff; color: var(--on-bright); }
.row--p1 .total { color: var(--gold); }
.row--p2 { border-left-color: var(--silver); }
.row--p2 .rank { background: var(--silver); border-color: #fff; color: var(--on-bright); }
.row--p3 { border-left-color: var(--bronze); }
.row--p3 .rank { background: var(--bronze); border-color: #fff; color: var(--on-bright); }
.row--me { outline: 3px solid var(--gold); outline-offset: -3px; }
.row--me::after { content: "你"; position: absolute; right: -2px; top: -10px; padding: 0 6px; background: var(--gold); color: var(--on-bright); font-weight: 900; font-size: .875rem; }
.row--flash { animation: flash .9s steps(3, jump-none) 1; }
@keyframes flash { 0%, 66% { box-shadow: inset 0 0 0 3px var(--flag); } }
.gap { padding: 2px 14px; color: var(--ink-2); font-weight: 700; font-size: 1rem; text-align: center; }

.empty { padding: 28px 24px; border: 3px dashed var(--line); background: var(--well); font-size: 1.25rem; }
.empty__title { margin: 0 0 8px; font-family: var(--f-pixel); font-size: 1.75rem; color: var(--gold); }
.empty p:last-child { color: var(--ink-2); }
.note { margin-top: 12px; padding: 12px 16px; border-left: 6px solid #ff6b6b; background: var(--well); font-weight: 700; font-size: 1.125rem; }

/* ── 卡片 ── */
.side { display: grid; gap: 16px; min-width: 0; }
.card { padding: 16px 20px; background: var(--lane); border: 3px solid #fff; box-shadow: 0 0 0 3px var(--on-bright), 6px 6px 0 3px #0008; font-size: 1.25rem; }
.card > * + * { margin-top: 10px; }
.stage-format { font-weight: 700; }
.race-now { font-weight: 900; font-size: 1.375rem; color: var(--gold); }
.race-now:empty { display: none; }
.minihead { font-weight: 900; }
.fine { color: var(--ink-2); font-size: 1.0625rem; }
.teacher-note { padding: 8px 12px; border-left: 4px solid var(--flag); background: var(--well); font-size: 1rem; color: var(--ink-2); }
.steps { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.steps li { display: grid; place-items: center; min-height: 44px; font-size: 1rem; font-weight: 900; background: var(--well); border: 2px solid var(--line); color: var(--ink-2); }
.steps li[data-s="done"] { background: #22386f; color: var(--ink); }
.steps li[data-s="done"]::before { content: "✓ "; color: #6ee7a0; }
.steps li[data-s="now"] { background: var(--flag); border-color: #fff; color: var(--on-bright); }

.pts, .stage-pts { list-style: none; padding: 0; display: grid; gap: 4px; }
.pts { grid-template-columns: repeat(8, minmax(0, 1fr)); }
.stage-pts { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.pts li, .stage-pts li { display: grid; text-align: center; border: 2px solid var(--line); background: var(--well); }
.pts b, .stage-pts b { font-weight: 700; font-size: 1rem; padding: 2px 0; color: var(--ink-2); border-bottom: 2px solid var(--line); white-space: nowrap; }
.pts span, .stage-pts span { font-family: var(--f-num); font-size: 1.125rem; padding: 6px 0; }
.pts li:first-child, .stage-pts li:first-child { border-color: var(--gold); }
.pts li:first-child span, .stage-pts li:first-child span { color: var(--gold); }
.stage-pts li:nth-last-child(-n+3) { grid-column: span 1; }

.honors { list-style: none; padding: 0; display: grid; gap: 8px; }
.honors li { display: grid; grid-template-columns: 28px auto 1fr; align-items: center; gap: 10px; }
.honors b { font-weight: 900; }
.jersey { width: 28px; height: 24px; clip-path: polygon(25% 0, 75% 0, 100% 25%, 85% 40%, 85% 100%, 15% 100%, 15% 40%, 0 25%); }
.jersey--yellow { background: var(--gold); }
.jersey--green { background: #29c46b; }
.jersey--white { background: #fff; }

.enter { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 16px; align-items: center; }
.qr { width: 120px; height: 120px; padding: 6px; background: #fff; }
.qr canvas, .qr img { width: 100% !important; height: auto !important; image-rendering: pixelated; display: block; }
.enter__url { font-weight: 900; font-size: 1.375rem; word-break: break-all; }
.enter__url b { color: var(--gold); }
.enter__steps { color: var(--ink-2); font-size: 1.0625rem; margin-top: 4px; }
.enter__actions { display: flex; flex-wrap: wrap; gap: 12px; }
.btn {
  display: inline-grid; place-items: center; min-height: 48px; padding: 6px 20px; font-weight: 900; font-size: 1.125rem;
  text-decoration: none; border: 3px solid #fff; box-shadow: 0 0 0 3px var(--on-bright), 4px 4px 0 3px #0008;
  transition: transform .12s steps(2, jump-none);
}
.btn:hover { transform: translate(-2px, -2px); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 3px var(--on-bright); }
.btn--go { background: var(--gold); color: var(--on-bright); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }

/* ── 投影：名字與末三碼同一行，前 10（含並列）一屏放完 ── */
@media (min-width: 1100px) {
  .layout { padding-bottom: 12px; }
  .side { overflow-y: auto; align-content: start; }
  .brand__title { font-size: clamp(2.25rem, 3vw, 3rem); }
  .row { min-height: var(--row-min, 50px); padding: 2px 14px; }
  .rows { gap: 4px; }
  .rank { height: calc(var(--row-min, 50px) - 8px); }
  .who { display: flex; align-items: baseline; gap: 16px; }
  .who__nick { flex: 0 1 auto; }
  .who__tag { flex: none; }
  .tower__head { margin-bottom: 4px; }
  .scope { margin: 4px 0 6px; }
}

/* ── 矮螢幕投影（1280×720、1366×768）：縮頂部與列高，右側卡片欄自己捲（高度由 app.mjs 設） ── */
@media (min-width: 1100px) and (max-height: 820px) {
  .side { overflow-y: auto; align-content: start; }
  .checker { height: 10px; }
  .masthead__inner { padding-top: 6px; padding-bottom: 4px; gap: 6px 20px; }
  .brand__course { display: none; }
  .brand__title { font-size: 2rem; }
  .wk { padding: 2px 6px; grid-template-columns: auto 1fr; column-gap: 8px; align-items: baseline; }
  .wk__date { display: none; }
  .wk__no { font-size: .875rem; }
  .wk__what { font-size: .875rem; text-overflow: clip; }
  .wk__what i { display: none; }
  .layout { gap: 16px; padding-top: 4px; }
  .h2 { font-size: 1.5rem; }
  .findme input { min-height: 40px; font-size: 1rem; }
  .scope { margin: 2px 0 4px; font-size: .875rem; }
  .row { min-height: var(--row-min, 38px); }
  .who__nick { font-size: 1.25rem; }
  .who__tag { font-size: 1rem; }
  .pos { width: 32px; height: 32px; font-size: .875rem; }
  .total { font-size: 1.5rem; }
  .rank { font-size: 1.125rem; }
  .card { font-size: 1.0625rem; }
}

/* ── 手機（放最後，才會蓋過上面的預設值） ── */
@media (max-width: 760px) {
  .season__list { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 4px; }
  .wk { padding: 4px; }
  .wk__no { font-size: .875rem; }
  .wk__date { display: none; }
  .wk__what i { display: none; }
  .wk__what { font-size: .875rem; }
  .cols, .row { grid-template-columns: 40px minmax(0, 1fr) auto 52px; column-gap: 8px; }
  .cols { padding: 0 8px 4px 12px; font-size: .875rem; }
  .cols__races { min-width: calc(4 * 22px + 3 * 3px); }
  .cols .cols__wins, .row .wins { display: none; }
  .row { min-height: 56px; padding: 4px 8px; border-left-width: 4px; }
  .rank { font-size: .875rem; height: 36px; }
  .who__nick { font-size: 1.0625rem; }
  .who__tag { font-size: .875rem; }
  .who__wins { display: inline; }
  .who__tagl { display: none; }
  .races { gap: 3px; }
  .pos { width: 22px; height: 28px; font-family: var(--f-body); font-weight: 900; font-size: .875rem; }
  .total { font-size: 1.125rem; }
  .card { font-size: 1.0625rem; padding: 16px; }
  .fine, .teacher-note, .enter__steps { font-size: .9375rem; }
  .race-now { font-size: 1.125rem; }
  .pts b, .stage-pts b { font-size: .875rem; }
  .pts span, .stage-pts span { font-size: .875rem; }
  .enter { grid-template-columns: minmax(0, 1fr); }
  .qr { display: none; }
  .findme { font-size: 1rem; }
  .legend { order: 4; margin-left: 0; font-size: .875rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
