:root {
  --bg: #0e1320; --panel: #182036; --panel2: #202a45; --text: #eef1f8; --muted: #8f9bb5;
  --left: #f2653f; --right: #3d8ff2; --ok: #3ccf7a; --warn: #f5b942; --danger: #ef4d5d;
  --radius: 18px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; touch-action: manipulation;
  overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
button { border: 0; border-radius: 14px; background: var(--panel2); min-height: 52px; padding: 0 18px;
  font-weight: 600; cursor: pointer; }
button:active { transform: scale(.97); filter: brightness(1.15); }
button.primary { background: var(--ok); color: #06210f; }
button.accent { background: #ff7a3d; color: #2a0f02; }
button.danger { background: var(--danger); color: #fff; }
button.ghost { background: transparent; border: 2px solid var(--panel2); }
button:disabled { opacity: .4; }
input[type=text], input[type=number], select { background: var(--panel); border: 2px solid var(--panel2); border-radius: 14px;
  padding: 0 14px; min-height: 52px; width: 100%; font-size: 17px; }
input:focus { outline: 0; border-color: #ff7a3d; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* pages */
.page { max-width: 640px; margin: 0 auto; padding: calc(16px + var(--safe-t)) 16px calc(90px + var(--safe-b)); min-height: 100%; }
.hero { padding: 40px 0 24px; text-align: center; }
.hero .logo { font-size: 56px; }
.hero h1 { font-size: 34px; letter-spacing: -.5px; }
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; }
.topbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.topbar h2 { font-size: 22px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip { background: var(--panel2); border-radius: 99px; padding: 6px 12px; font-weight: 700; letter-spacing: 2px; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); flex: none; }
.dot.on { background: var(--ok); }
.nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--panel); padding-bottom: var(--safe-b);
  border-top: 1px solid var(--panel2); z-index: 5; }
.nav button { flex: 1; border-radius: 0; background: transparent; min-height: 62px; color: var(--muted); font-size: 13px;
  display: flex; flex-direction: column; gap: 2px; align-items: center; justify-content: center; }
.nav button span { font-size: 22px; }
.nav button.on { color: #ff7a3d; }
.start { width: 100%; min-height: 120px; font-size: 32px; border-radius: 28px; letter-spacing: 1px; }
.live-card { display: flex; align-items: center; gap: 12px; background: linear-gradient(135deg, #243153, #182036); }
.live-card .badge { background: var(--danger); border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 800; }

/* avatars */
.av { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 800;
  background-size: cover; background-position: center; color: #fff; font-size: 18px; text-shadow: 0 1px 2px #0006; }
.av.lg { width: 84px; height: 84px; font-size: 34px; }
.av.sm { width: 32px; height: 32px; font-size: 14px; }
.plist { display: flex; flex-direction: column; gap: 8px; }
.prow { display: flex; align-items: center; gap: 12px; background: var(--panel); border-radius: 14px; padding: 8px 12px; min-height: 60px; }
.prow .name { flex: 1; font-weight: 600; font-size: 17px; }
.me-tag { background: var(--ok); color: #06210f; border-radius: 6px; padding: 2px 6px; font-size: 11px; font-weight: 800; margin-left: 6px; }

/* stats */
table { width: 100%; border-collapse: collapse; }
th { text-align: right; color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 6px; }
td { text-align: right; padding: 8px 6px; border-top: 1px solid var(--panel2); font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
.form span { display: inline-block; width: 18px; height: 18px; line-height: 18px; text-align: center; border-radius: 4px; font-size: 11px;
  font-weight: 800; margin-left: 2px; }
.form .W { background: var(--ok); color: #06210f; } .form .L { background: var(--danger); color: #fff; }
.bar { height: 6px; background: var(--panel2); border-radius: 3px; overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--ok); }

/* board */
.board { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); z-index: 10; user-select: none; -webkit-user-select: none; }
.board .top { display: flex; align-items: center; gap: 10px; padding: calc(8px + var(--safe-t)) 12px 8px; }
.board .top .mid { flex: 1; text-align: center; font-weight: 700; }
.board .top .mid small { display: block; color: var(--muted); font-weight: 500; }
.board .top button { min-height: 44px; padding: 0 14px; }
.halves { flex: 1; display: flex; gap: 6px; padding: 0 6px; min-height: 0; }
.half { flex: 1; border-radius: 26px; display: flex; flex-direction: column; align-items: center; justify-content: space-between;
  padding: 14px 8px; position: relative; overflow: hidden; min-width: 0; }
.half.left { background: color-mix(in srgb, var(--left) 85%, #000); }
.half.right { background: color-mix(in srgb, var(--right) 85%, #000); }
.half:active:not(.ro) { filter: brightness(1.12); }
.half.ro { opacity: .92; }
.half .who { text-align: center; width: 100%; }
.half .who .avs { display: flex; justify-content: center; gap: 6px; margin-bottom: 6px; min-height: 44px; }
.half .who .nm { font-weight: 800; font-size: clamp(16px, 3.2vw, 26px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.half .score { font-size: min(34vh, 30vw); font-weight: 900; line-height: .9; font-variant-numeric: tabular-nums; letter-spacing: -4px; }
.half .score.bump { animation: bump .25s ease-out; }
@keyframes bump { 0% { transform: scale(1.25); } 100% { transform: scale(1); } }
.half .foot { display: flex; align-items: center; justify-content: space-between; width: 100%; min-height: 48px; }
.half .games { display: flex; gap: 6px; }
.half .games i { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff8; }
.half .games i.w { background: #fff; border-color: #fff; }
.half .serve { position: absolute; top: 10px; right: 12px; font-size: 26px; }
.half.left .serve { right: auto; left: 12px; }
.half .minus { min-height: 44px; min-width: 44px; padding: 0; background: #0004; font-size: 22px; }
.bar-bottom { display: flex; gap: 8px; padding: 8px 8px calc(8px + var(--safe-b)); }
.bar-bottom button { flex: 1; min-height: 56px; }
.bar-bottom .judge.on { background: var(--warn); color: #2b1d00; }
.banner { text-align: center; padding: 6px; background: var(--panel); color: var(--warn); font-weight: 600; font-size: 14px; }

/* sheets */
#sheet:empty { display: none; }
.scrim { position: fixed; inset: 0; background: #000a; z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 680px; max-height: 92vh; overflow: auto; border-radius: 26px 26px 0 0;
  padding: 18px 16px calc(24px + var(--safe-b)); border: 1px solid var(--panel2); }
.sheet h3 { font-size: 20px; margin-bottom: 12px; }
.sheet .close { float: right; min-height: 40px; padding: 0 14px; }
.sheet section { margin: 16px 0; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; font-weight: 600; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; }
.seg button { flex: 1 1 auto; min-height: 48px; }
.seg button.on { background: #ff7a3d; color: #2a0f02; }
.assign { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.assign button { display: flex; align-items: center; gap: 8px; text-align: left; padding: 6px 10px; min-height: 56px; border: 3px solid transparent; }
.assign button.L { border-color: var(--left); background: #f2653f33; } .assign button.R { border-color: var(--right); background: #3d8ff233; }
.assign button b { margin-left: auto; font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stepper { display: flex; align-items: center; gap: 8px; } .stepper output { flex: 1; text-align: center; font-size: 28px; font-weight: 800; }
.stepper button { min-width: 52px; padding: 0; font-size: 24px; }
.toggle, .sheet label.toggle { display: flex; align-items: center; justify-content: space-between; min-height: 48px; gap: 12px; }
.toggle input { width: 28px; height: 28px; flex: none; }
.qr { background: #fff; border-radius: 18px; padding: 10px; width: min(70vw, 280px); margin: 0 auto; display: block; }
.code-big { font-size: 40px; letter-spacing: 8px; font-weight: 900; text-align: center; margin: 12px 0 4px; }
.winner { position: absolute; inset: 0; z-index: 20; background: #000c; display: flex; align-items: center; justify-content: center; padding: 20px; }
.winner .box { background: var(--panel); border-radius: 28px; padding: 28px 22px; text-align: center; max-width: 440px; width: 100%; }
.winner .trophy { font-size: 64px; } .winner h2 { font-size: 30px; margin: 8px 0; } .winner .fs { font-size: 20px; margin-bottom: 18px; }
#toast { position: fixed; left: 50%; bottom: calc(100px + var(--safe-b)); transform: translateX(-50%); background: #000d; padding: 12px 18px;
  border-radius: 14px; z-index: 50; font-weight: 600; max-width: 90vw; text-align: center; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
input[type=file] { display: none; }

/* courtside tab */
.station-card { display: flex; gap: 14px; align-items: center; text-align: left; padding: 16px; min-height: 96px;
  background: linear-gradient(135deg, #243153, #182036); border-radius: var(--radius); font-weight: 400; }
.station-card .ic { font-size: 40px; }
.station-card b { font-size: 18px; }
.warn-card { border: 2px solid var(--warn); }
.rec-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--panel2); }
.rec-row:first-child { border-top: 0; }
.rec-row button, a.btn { min-height: 44px; min-width: 44px; padding: 0 10px; }
a.btn { display: inline-grid; place-items: center; background: var(--panel2); border-radius: 14px; color: inherit; text-decoration: none; }
.cam-ind { background: var(--warn); color: #2b1d00; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 800; white-space: nowrap; }

/* stations (shared) */
.station { position: fixed; inset: 0; display: flex; flex-direction: column; background: #000; z-index: 10; user-select: none; -webkit-user-select: none; }
.sbar { display: flex; align-items: center; gap: 10px; padding: calc(6px + var(--safe-t)) 10px 6px; background: var(--bg); z-index: 3; }
.sbar button { min-height: 44px; padding: 0 14px; }
.sbar .sname { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.seg.mini { flex-wrap: nowrap; align-items: center; gap: 4px; }
.seg.mini button { min-height: 40px; padding: 0 12px; font-size: 14px; flex: none; }

/* camera station */
.cam-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.cam-stage video, #cam-ov { position: absolute; inset: 0; width: 100%; height: 100%; }
.cam-stage video { object-fit: contain; background: #000; }
#cam-ov { pointer-events: none; touch-action: none; }
#cam-ov.drawing { pointer-events: auto; cursor: crosshair; }
.cam-stage > :not(video):not(canvas) { pointer-events: none; }
.cam-stage > .cam-setup, .cam-stage > .cam-block { pointer-events: auto; }
.cam-block { position: absolute; inset: 0; display: grid; place-items: center; background: #000d; padding: 16px; }
.cam-block[hidden] { display: none; }
.cam-block .box { background: var(--panel); border-radius: 24px; padding: 22px; max-width: 420px; width: 100%; text-align: center; }
.cam-block .big { font-size: 48px; }
.cam-block p { margin: 8px 0 16px; }
.cam-score { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #000b; padding: 6px 14px;
  border-radius: 99px; font-size: 18px; white-space: nowrap; }
.cam-rec { position: absolute; top: 10px; left: 10px; background: #000b; padding: 6px 12px; border-radius: 99px; font-weight: 800; font-variant-numeric: tabular-nums; }
.rec-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.cam-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; font-size: 18px; font-weight: 600; }
.cam-msg[hidden] { display: none; }
.cam-debug { position: absolute; left: 8px; bottom: 8px; margin: 0; max-width: min(520px, calc(100% - 16px)); background: #0008; color: #b9f5c9;
  font: 11px/1.4 ui-monospace, Menlo, Consolas, monospace; padding: 8px 10px; border-radius: 10px; white-space: pre-wrap; }
#cam-mask { position: absolute; right: 8px; bottom: 8px; width: min(32%, 240px); border: 2px solid #fff6; border-radius: 8px; image-rendering: pixelated; }
.cam-flash { position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%); text-align: center; opacity: 0; }
.cam-flash b { display: block; font-size: 56px; font-weight: 900; text-shadow: 0 2px 12px #000; }
.cam-flash small { font-size: 18px; font-weight: 700; text-shadow: 0 1px 6px #000; }
.cam-flash.show { animation: flash 2.2s ease-out; }
@keyframes flash { 0% { opacity: 0; transform: translate(-50%, -50%) scale(1.4); } 12%, 70% { opacity: 1; transform: translate(-50%, -50%) scale(1); } 100% { opacity: 0; } }
.cam-setup { position: absolute; left: 8px; right: 8px; bottom: 8px; background: #000c; border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.cam-setup[hidden] { display: none; }
.cam-setup .hint { font-weight: 600; }
.cam-setup .seg.mini { flex-wrap: wrap; }
.cam-controls { display: flex; gap: 6px; padding: 6px 6px calc(6px + var(--safe-b)); background: var(--bg); overflow-x: auto; }
.cam-controls button { flex: 1 1 0; min-width: 0; min-height: 58px; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 22px; padding: 0 4px; }
.cam-controls button span { font-size: 12px; }
.cam-controls button.on { background: #ff7a3d; color: #2a0f02; }
.cam-controls .rec-btn.on { background: var(--danger); color: #fff; }

/* display station */
.station.disp { background: var(--bg); }
.station.disp .sbar, .station.disp .disp-modes, .disp-hint { transition: opacity .3s; }
.station.disp:not(.awake) .sbar, .station.disp:not(.awake) .disp-modes, .station.disp:not(.awake) .disp-hint { opacity: 0; pointer-events: none; }
.disp-hint { position: absolute; left: 0; right: 0; bottom: calc(76px + var(--safe-b)); text-align: center; font-weight: 700; pointer-events: none;
  text-shadow: 0 1px 4px #000; }
.disp-score .half { cursor: pointer; }
.disp-score .half.tapped { animation: tapped .25s ease-out; }
@keyframes tapped { 0% { filter: brightness(1.35); } 100% { filter: none; } }
.station.disp .sbar { position: absolute; top: 0; left: 0; right: 0; }
.disp-modes { position: absolute; bottom: calc(10px + var(--safe-b)); left: 50%; transform: translateX(-50%); z-index: 3;
  background: var(--panel); padding: 6px; border-radius: 16px; }
.disp-score { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: calc(10px + var(--safe-t)) 0 calc(10px + var(--safe-b)); position: relative; }
.disp-score .disp-info { text-align: center; color: var(--muted); font-size: clamp(16px, 2.4vw, 28px); font-weight: 600; padding-bottom: 8px; }
.disp-score .half .score { font-size: min(52vh, 34vw); }
.disp-score .half .who .nm { font-size: clamp(20px, 4vw, 48px); }
.disp-win { position: absolute; left: 50%; bottom: 12%; transform: translateX(-50%); background: #000d; padding: 16px 32px; border-radius: 24px;
  font-size: clamp(28px, 5vw, 64px); font-weight: 900; white-space: nowrap; }
.disp-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; font-size: 22px; }
.disp-board { flex: 1; display: grid; grid-template-columns: 2fr 1fr; gap: 24px; padding: calc(24px + var(--safe-t)) 28px 28px; min-height: 0; overflow: auto; }
.disp-board h2 { font-size: clamp(22px, 2.6vw, 36px); margin-bottom: 12px; }
.disp-board table { font-size: clamp(16px, 1.8vw, 26px); }
.disp-board td { padding: 10px 8px; }
.disp-board .rank { font-size: 1.3em; text-align: center; width: 2.2em; }
.disp-board .recent { padding: 10px 0; border-top: 1px solid var(--panel2); font-size: clamp(14px, 1.4vw, 20px); }
.disp-join { display: flex; align-items: center; gap: 14px; margin-top: 18px; font-size: 18px; }
.disp-join img { width: 110px; background: #fff; border-radius: 12px; padding: 6px; }
.disp-join b { display: block; font-size: 32px; letter-spacing: 4px; }
@media (max-width: 760px) { .disp-board { grid-template-columns: 1fr; } }
.version { text-align: center; font-size: 12px; margin: 4px 0 0; opacity: .7; }
.team-switch { display: flex; align-items: center; gap: 6px; background: none; padding: 0; min-height: 44px; min-width: 0; flex: 1; text-align: left; }
.team-switch h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; }
.team-switch span { opacity: .6; }
