/* 終點計時 — 跑道邊的計時儀器
   相機是舞台；其他都是覆蓋在上面的柏油色半透明面板。
   琥珀色只留給「時間」：輔助線、游標、秒數、標記。 */

@font-face { font-family: "Barlow Condensed"; font-weight: 500; font-display: swap; src: url(fonts/barlow-condensed-latin-500-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 700; font-display: swap; src: url(fonts/barlow-condensed-latin-700-normal.woff2) format("woff2"); }
@font-face { font-family: "Barlow Condensed"; font-weight: 800; font-display: swap; src: url(fonts/barlow-condensed-latin-800-normal.woff2) format("woff2"); }

:root {
  --asphalt: #202326;
  --asphalt-glass: rgba(32, 35, 38, .72);
  --lane-white: #f3f5ef;
  --cinder: #8a9096;
  --amber: #ffb21e;
  --infield: #1f8a4c;
  --flag: #d9382c;
  --seam: rgba(243, 245, 239, .14);
  --num: "Barlow Condensed", "PingFang TC", system-ui, sans-serif;
  --text: -apple-system, "PingFang TC", "Noto Sans TC", system-ui, sans-serif;
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: #000; color: var(--lane-white);
  font: 15px/1.5 var(--text); overscroll-behavior: none; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
button:disabled { opacity: .4; }
.hidden { display: none !important; }
.view { display: none; position: fixed; inset: 0; }
.view.active { display: block; }

/* 共用按鈕 */
.glass-btn { min-height: 40px; padding: 6px 14px; border-radius: 20px; border: 1px solid var(--seam);
  background: var(--asphalt-glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); font-size: 15px; }
.glass-btn b { font-family: var(--num); font-weight: 800; color: var(--amber); font-size: 18px; margin-left: 2px; }
.plain-btn { min-height: 48px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--seam);
  background: rgba(243, 245, 239, .06); font-size: 16px; }
.plain-btn.quiet { border-color: transparent; background: none; color: var(--cinder); }
.plain-btn.danger { color: #ff8a80; }
button:active { transform: scale(.97); }

/* ---------- 拍攝 ---------- */
#video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }

#guide { position: absolute; top: 0; bottom: 0; left: 50%; width: 56px; margin-left: -28px; touch-action: none; }
.guide-line { position: absolute; left: 27px; top: 0; bottom: 0; width: 2px; background: var(--amber);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .45); }
.guide-grip { position: absolute; left: 10px; top: 40%; width: 36px; height: 64px; border-radius: 18px;
  background: var(--amber); box-shadow: 0 2px 10px rgba(0, 0, 0, .5); }
.guide-grip::before, .guide-grip::after { content: ""; position: absolute; top: 18px; bottom: 18px; width: 2px; background: rgba(32, 35, 38, .7); }
.guide-grip::before { left: 13px; } .guide-grip::after { right: 13px; }
#guide.locked .guide-grip { display: none; }

.hud { position: absolute; left: 0; right: 0; top: 0; z-index: 2; display: flex; align-items: center;
  justify-content: space-between; gap: 8px; padding: calc(var(--st) + 10px) 12px 10px; pointer-events: none; }
.hud > * { pointer-events: auto; }
.readings { display: flex; gap: 6px; flex-wrap: wrap; }
.reading { padding: 4px 10px; border-radius: 14px; background: var(--asphalt-glass); font-size: 13px; color: #d5d9dd;
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
#fpsChip { font-family: var(--num); font-weight: 700; font-size: 15px; color: var(--lane-white); }
.hud-actions { display: flex; gap: 6px; }

#clock { position: absolute; left: 0; right: 0; top: calc(var(--st) + 58px); text-align: center; pointer-events: none; z-index: 2; }
#clockNum { display: inline-block; padding: 0 18px; border-radius: 14px; background: var(--asphalt-glass);
  font: 800 76px/1.1 var(--num); color: var(--amber); font-variant-numeric: tabular-nums; letter-spacing: .01em; }

#camGate { position: absolute; inset: 0; z-index: 3; display: grid; place-items: end center; padding: 24px 16px calc(var(--sb) + 24px);
  background: linear-gradient(transparent 30%, rgba(0, 0, 0, .7)); }
.gate-card { width: 100%; max-width: 420px; padding: 22px 20px; border-radius: 22px; background: var(--asphalt); border: 1px solid var(--seam); }
.gate-card h1 { margin: 0 0 6px; font: 800 34px/1.1 var(--num); letter-spacing: .02em; }
.gate-card p { margin: 0 0 18px; color: #c4c9ce; }
.go-btn { width: 100%; min-height: 56px; border: 0; border-radius: 16px; background: var(--infield); font-size: 18px; font-weight: 700; }

.dock { position: absolute; left: 0; right: 0; bottom: 0; z-index: 2; display: flex; flex-direction: column; gap: 10px;
  padding: 10px 12px calc(var(--sb) + 12px); }
#raceName { width: 100%; padding: 10px 14px; border-radius: 14px; border: 1px solid var(--seam);
  background: var(--asphalt-glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); font-size: 15px; }
#raceName::placeholder { color: #aab0b6; }
.start-btn, .stop-btn { position: relative; width: 100%; height: 104px; border: 0; border-radius: 26px; overflow: hidden;
  font: 800 40px/1 var(--text); letter-spacing: .3em; text-indent: .3em; user-select: none; -webkit-user-select: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .45); }
.start-btn { background: var(--infield); }
.stop-btn { background: var(--flag); }
/* 起跑按鈕上的白色分道線：按鈕本身就是一段跑道 */
.start-btn::before { content: ""; position: absolute; inset: 0;
  background: repeating-linear-gradient(90deg, transparent 0 calc(12.5% - 2px), rgba(255, 255, 255, .18) calc(12.5% - 2px) 12.5%); }
.start-btn span, .stop-btn span { position: relative; }
#liveStrip { width: 100%; height: 72px; border-radius: 12px; background: #000; border: 1px solid var(--seam); }

/* ---------- 回放 ---------- */
#review.active { display: flex; flex-direction: column; background: var(--asphalt); }
#frameView { position: relative; flex: 1; min-height: 0; background: #000; overflow: hidden; }
#preview { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
#previewGuide { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--amber); opacity: .85; }
#previewNone { position: absolute; inset: 0; display: grid; place-items: center; color: var(--cinder); }
.hud-title { flex: 1; text-align: center; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-shadow: 0 1px 6px rgba(0, 0, 0, .8); }

#stripWrap { position: relative; height: 27vh; background: #000; border-top: 2px solid var(--lane-white); }
#strip { width: 100%; height: 100%; display: block; touch-action: none; }
#cursor { position: absolute; top: 0; bottom: 0; left: 50%; width: 2px; margin-left: -1px; background: var(--amber); pointer-events: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5); }
#cursor::before { content: ""; position: absolute; top: 0; left: -7px; border: 8px solid transparent; border-top-color: var(--amber); border-bottom: 0; }

.console { padding: 8px 12px calc(var(--sb) + 8px); display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; }
.readout { display: flex; flex-direction: column; line-height: 1; }
#tRead { font: 800 54px/1 var(--num); color: var(--amber); font-variant-numeric: tabular-nums; }
#frameInfo { font: 500 14px/1.3 var(--num); color: var(--cinder); margin-top: 2px; }
.steps { display: grid; grid-template-columns: 1fr 1.6fr 1fr; gap: 6px; }
.steps button { min-height: 60px; border-radius: 14px; border: 1px solid var(--seam); background: rgba(243, 245, 239, .07);
  font: 700 22px/1 var(--num); }
.steps .mark-btn { background: var(--lane-white); color: var(--asphalt); border: 0; font: 800 20px/1 var(--text); }
.jumps { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.jumps button { min-height: 44px; border-radius: 12px; border: 1px solid var(--seam); background: none; color: #d5d9dd; font-size: 16px; }

/* ---------- 紀錄 ---------- */
#history.active { overflow-y: auto; background: var(--asphalt); }
.page-bar { position: sticky; top: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: calc(var(--st) + 10px) 12px 10px; background: var(--asphalt); border-bottom: 2px solid var(--lane-white); z-index: 1; }
.page-bar h2 { margin: 0; font-size: 17px; }
.page-bar .glass-btn { justify-self: start; }
#histList { padding: 4px 0 calc(var(--sb) + 20px); }
.hist-item { display: block; width: 100%; text-align: left; padding: 14px 16px; border: 0; border-bottom: 1px solid var(--seam); background: none; }
.hist-item b { display: block; font-size: 17px; font-weight: 600; }
.hist-item span { color: var(--cinder); font-size: 14px; }
.empty { padding: 40px 20px; color: var(--cinder); text-align: center; }

/* ---------- Sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-end; background: rgba(0, 0, 0, .5); }
.sheet { width: 100%; max-height: 92vh; overflow-y: auto; padding: 14px 14px calc(var(--sb) + 14px);
  background: var(--asphalt); border-radius: 22px 22px 0 0; border-top: 1px solid var(--seam); }
.sheet.tall { max-height: 86vh; display: flex; flex-direction: column; }
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.sheet-head h3 { margin: 0; font-size: 19px; }
.sheet-time { font: 800 44px/1 var(--num); color: var(--amber); font-variant-numeric: tabular-nums; }
.sheet-q { color: #c4c9ce; font-size: 17px; flex: 1; }
.sheet-row { display: flex; gap: 8px; margin-top: 12px; }
.sheet-row .plain-btn { flex: 1; }

/* 道次選擇：一排並列的跑道，白線分隔，道次號碼像漆在跑道上 */
.track { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; height: 150px; border-radius: 14px; overflow: hidden;
  background: #9c3b2a; border: 2px solid var(--lane-white); }
.track button { border: 0; border-left: 2px solid var(--lane-white); background: none; color: var(--lane-white);
  font: 800 44px/1 var(--num); display: flex; flex-direction: column; align-items: center; justify-content: flex-end; padding-bottom: 14px; }
.track button:first-child { border-left: 0; }
.track button:active { background: rgba(255, 255, 255, .18); }
.track button i { width: 70%; height: 6px; border-radius: 3px; margin-top: 10px; }

.result-list { list-style: none; margin: 0; padding: 0; flex: 1; overflow-y: auto; }
.result-list li { display: grid; grid-template-columns: 34px 58px 1fr auto; align-items: center; gap: 8px;
  padding: 10px 2px; border-bottom: 1px solid var(--seam); }
.rank { font: 800 24px/1 var(--num); color: var(--cinder); text-align: center; }
.lane-tag { font: 700 18px/1 var(--num); padding: 6px 0; border-radius: 8px; text-align: center; background: #9c3b2a; border-bottom: 4px solid; }
.lane-tag.none { background: rgba(243, 245, 239, .08); font: 500 13px/1.4 var(--text); border-bottom-color: transparent; }
.rtime { font: 800 30px/1 var(--num); color: var(--amber); font-variant-numeric: tabular-nums; }
.row-actions { display: flex; gap: 4px; }
.row-actions button { min-height: 38px; padding: 4px 10px; border-radius: 10px; border: 1px solid var(--seam); background: none; font-size: 14px; }
.hint { color: var(--cinder); font-size: 14px; margin: 8px 2px; }

.field { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; color: #c4c9ce; font-size: 14px; }
.field select, .field input[type=number] { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--seam);
  background: rgba(243, 245, 239, .06); font-size: 16px; color: var(--lane-white); }
.field.check { flex-direction: row; align-items: center; gap: 10px; color: var(--lane-white); font-size: 15px; }
.field.check input { width: 22px; height: 22px; accent-color: var(--amber); flex: none; }
#detailImgWrap { overflow-x: auto; background: #000; border-radius: 12px; margin-bottom: 8px; flex: none; }
#detailImg { height: 200px; display: block; }

#toast { position: fixed; left: 50%; top: calc(var(--st) + 64px); transform: translateX(-50%); z-index: 20; max-width: 88vw;
  padding: 10px 16px; border-radius: 14px; background: var(--lane-white); color: var(--asphalt); font-size: 15px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .4); text-align: center; pointer-events: none; }

@media (prefers-reduced-motion: reduce) { button:active { transform: none; } }

/* ---------- 每趟紀錄、狀態燈、方向 ---------- */
.status { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 6px 14px 6px 10px; border-radius: 20px;
  border: 1px solid var(--seam); background: var(--asphalt-glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  font-size: 15px; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.status i { width: 12px; height: 12px; border-radius: 50%; background: var(--cinder); flex: none; }
.status.ok i { background: #3ddc84; box-shadow: 0 0 0 4px rgba(61, 220, 132, .22); }
.status.warn i { background: var(--amber); box-shadow: 0 0 0 4px rgba(255, 178, 30, .22); }
.status.bad i { background: var(--flag); }
#btnDir { font: 800 22px/1 var(--num); min-width: 52px; }

#dirHint { position: absolute; top: 50%; left: 0; right: 0; transform: translateY(-50%); pointer-events: none;
  text-align: center; font: 800 120px/1 var(--num); color: rgba(243, 245, 239, .16); letter-spacing: .4em; }

.heat-chip { display: flex; align-items: baseline; gap: 10px; width: 100%; padding: 10px 16px; border-radius: 16px;
  border: 1px solid var(--seam); background: var(--asphalt-glass); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); text-align: left; }
.heat-chip b { font-size: 19px; font-weight: 700; flex: none; }
.heat-chip span { color: #aab0b6; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heat-chip span.named { color: var(--lane-white); font-size: 16px; }

.dir-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.dir-btn { display: flex; flex-direction: column; align-items: center; gap: 6px; min-height: 140px; justify-content: center;
  border-radius: 18px; border: 2px solid var(--lane-white); background: #9c3b2a; font-size: 17px; font-weight: 600; }
.dir-btn .arrow { font: 800 64px/1 var(--num); }

.export-bar { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; padding: 12px 12px 0; }
.plain-btn.primary { background: var(--lane-white); color: var(--asphalt); border: 0; font-weight: 700; }
.hint.pad { padding: 0 14px; }
.hist-day { position: sticky; top: calc(var(--st) + 62px); z-index: 1; margin: 0; padding: 10px 16px 6px; background: var(--asphalt);
  font-size: 15px; color: var(--cinder); font-weight: 600; border-bottom: 1px solid var(--seam); }
.heat-row { display: block; width: 100%; text-align: left; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--seam); background: none; }
.heat-row header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.heat-row header b { font-size: 18px; }
.heat-row header span { color: var(--cinder); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.heat-row header time { margin-left: auto; color: var(--cinder); font: 500 15px/1 var(--num); }
.heat-times { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.heat-times span { display: inline-flex; align-items: baseline; gap: 5px; }
.heat-times em { font: 700 15px/1 var(--num); font-style: normal; padding: 3px 6px; border-radius: 5px; background: #9c3b2a; border-bottom: 3px solid; }
.heat-times em.none { background: rgba(243, 245, 239, .1); border-bottom-color: transparent; font-family: var(--text); font-size: 12px; }
.heat-times strong { font: 800 24px/1 var(--num); color: var(--amber); font-variant-numeric: tabular-nums; }
.heat-empty { color: var(--cinder); font-size: 14px; }
