/* Shared look for every board. Palette from coolors.co/palette/7e6c6c-f87575-ffa9a3-b9e6ff-5c95ff:
   coral for the home side and actions, cornflower blue for the away side, sky-blue LED clocks, blush highlights,
   on a deep blue ground darkened from the palette's cornflower so the board reads in a bright gym. Single dark look, like a real scoreboard. */
:root {
  --taupe: #7e6c6c;
  --coral: #f87575;
  --blush: #ffa9a3;
  --sky: #b9e6ff;
  --blue: #5c95ff;

  --bg: #0d1628;             /* cornflower, deepened */
  --panel: #142039;
  --panel-2: #1d2d4f;
  --line: #2d4371;
  --fg: #fbf6f5;
  --muted: #a9bbd9;          /* cornflower, lifted */
  --ink: #0d1628;            /* text on coral / sky fills */
  --home: var(--coral);
  --away: var(--blue);
  --led: var(--sky);         /* game clock */
  --shot: var(--coral);      /* shot clock */
  --accent: var(--coral);    /* primary buttons */
  --ok: var(--sky);
  --ink-on-accent: var(--ink);
  --f-score: "Big Shoulders Display", "Arial Narrow", Impact, sans-serif;
  --f-clock: "Share Tech Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --f-ui: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color-scheme: dark;
}
html, body { height: 100%; touch-action: manipulation; }
* { touch-action: manipulation; }
body {
  background: var(--bg); color: var(--fg); font-family: var(--f-ui);
  margin: 0; overflow: hidden; -webkit-tap-highlight-color: transparent;
  user-select: none; -webkit-user-select: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:disabled { opacity: .45; cursor: default; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.app { height: 100%; display: grid; grid-template-rows: auto auto 1fr auto; padding-inline: 16px; gap: 10px; box-sizing: border-box; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 8px; padding-top: 10px; min-width: 0; }
.chip { font-size: 13px; padding: 6px 12px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); letter-spacing: .04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chip strong { color: var(--fg); }
.chipbtn { flex: 0 0 auto; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); }
.chipbtn .swap { color: var(--blush); font-size: 12px; }
.chipbtn:active, .chip.rulebtn:active { background: var(--panel-2); }
.chip.rulebtn { flex-shrink: 20; cursor: pointer; font: inherit; font-size: 13px; }
.toast { position: fixed; left: 50%; top: calc(58px + env(safe-area-inset-top, 0px)); translate: -50% 0; z-index: 20; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); }
.stepper { display: flex; gap: 10px; align-items: center; justify-content: center; }
.stepper .btn { width: 56px; height: 56px; font-size: 26px; }
.num.big { width: 120px; font-size: 40px; padding: 6px; }
.seg.presets { justify-self: center; }
.topbar .spacer { flex: 1; }
.iconbtn { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); display: grid; place-items: center; }
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: var(--fg); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* sport switcher: a native dropdown styled as a chip */
.sportsel { flex: 0 1 auto; min-width: 64px; position: relative; display: inline-flex; }
.sportsel select {
  max-width: 100%; min-width: 0; text-overflow: ellipsis;
  appearance: none; -webkit-appearance: none; font: 700 13px var(--f-ui); color: var(--ink); background: var(--accent);
  border: 0; border-radius: 999px; padding: 7px 28px 7px 12px; cursor: pointer;
}
.sportsel::after { content: "▾"; position: absolute; right: 11px; top: 50%; translate: 0 -50%; color: var(--ink); font-size: 12px; pointer-events: none; }
.sportsel select option { color: var(--fg); background: var(--panel); }

.btn {
  min-height: 40px; padding: 0 16px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line);
  font-weight: 700; font-size: 15px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  color: var(--fg); text-decoration: none; box-sizing: border-box;
}
.btn.primary { background: var(--accent); color: var(--ink-on-accent); border-color: transparent; }
.btn.primary.running { background: var(--panel-2); color: var(--fg); border-color: var(--coral); }
.btn.danger { color: var(--coral); border-color: color-mix(in srgb, var(--coral) 50%, var(--line)); }

/* score reel: drag down = more points */
.score {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; min-height: 0; overflow: hidden; position: relative;
  box-shadow: inset 0 -6px 0 var(--tc); container-type: size; touch-action: none; cursor: ns-resize;
}
.reel { position: absolute; inset: 0; will-change: transform; }
.reel.snap { transition: transform .18s ease-out; }
.reel .n {
  position: absolute; left: 0; right: 0; top: 50%; text-align: center;
  font: 900 min(76cqh, 62cqw)/0.9 var(--f-score); color: var(--tc); font-variant-numeric: tabular-nums;
  transform: translateY(calc(-50% + 3cqh + var(--k) * 100cqh));
}
.reel .n.ghost { opacity: .22; }
.score.bump .reel .n:not(.ghost) { animation: bump .35s ease-out; }
@keyframes bump { 0% { scale: 1.12; } 100% { scale: 1; } }
.score .lead { position: absolute; top: 10px; left: 0; right: 0; text-align: center; font-size: 12px; letter-spacing: .14em; color: var(--muted); z-index: 1; pointer-events: none; }
.score .hint { position: absolute; right: 10px; top: 50%; translate: 0 -50%; display: grid; gap: 2px; color: var(--line); font-size: 14px; pointer-events: none; z-index: 1; }
.pts { display: grid; grid-template-columns: repeat(var(--cols, 3), 1fr); gap: 8px; }
.pts button {
  min-height: 52px; border-radius: 12px; font: 900 clamp(20px, 4.4vmin, 32px) var(--f-score); background: var(--panel-2); border: 1px solid var(--line);
}
.pts button.plus { background: color-mix(in srgb, var(--tc) 26%, var(--panel)); border-color: color-mix(in srgb, var(--tc) 60%, var(--line)); }
.pts button.minus { color: var(--muted); min-height: 40px; font-size: clamp(16px, 3.4vmin, 24px); }
.pts button:active { transform: translateY(1px); filter: brightness(1.2); }
.home { --tc: var(--home); }
.away { --tc: var(--away); }
.team .name {
  border: 0; background: transparent; color: var(--fg); font: 700 clamp(16px, 3.4vmin, 26px) var(--f-ui); text-align: center;
  width: 100%; padding: 4px 0; border-bottom: 3px solid var(--tc); border-radius: 0; user-select: text; -webkit-user-select: text; min-width: 0;
}

/* DJ strip */
.dj { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: stretch; padding-bottom: 12px; border-top: 1px solid var(--line); padding-top: 10px; }
.djlabel { display: grid; place-items: center; writing-mode: vertical-rl; font: 900 15px var(--f-score); letter-spacing: .3em; color: var(--muted); }
.pads { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.pads::-webkit-scrollbar { display: none; }
.pad {
  flex: 0 0 auto; width: 84px; min-height: 64px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line);
  display: grid; align-content: center; justify-items: center; gap: 2px; position: relative; font-size: 13px; font-weight: 700;
}
.pad .ico { font-size: 22px; line-height: 1; }
.pad .svgico svg { display: block; width: 1.1em; height: 1.1em; }
.pad kbd { position: absolute; top: 4px; right: 6px; font: 11px var(--f-clock); color: var(--muted); }
.pad.hit { background: var(--panel-2); border-color: var(--coral); }
.pad.music { width: 120px; border-style: dashed; color: var(--ok); }
.pad.music.on { border-style: solid; border-color: var(--ok); }
.pad.music small { font-size: 11px; color: var(--muted); max-width: 108px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* sheets & overlays */
.overlay { position: fixed; inset: 0; background: rgba(6, 11, 22, .76); display: grid; place-items: center; padding: 16px; z-index: 10; }
.overlay.parked { visibility: hidden; pointer-events: none; } /* keeps the music player alive while closed */
.sheet {
  width: min(560px, 100%); max-height: calc(100% - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  padding: 20px; box-sizing: border-box; display: grid; gap: 14px; user-select: text; -webkit-user-select: text;
}
.sheet h2 { margin: 0; font: 900 26px var(--f-score); letter-spacing: .04em; text-wrap: balance; }
.sheet h3 { margin: 4px 0 0; font-size: 13px; letter-spacing: .14em; color: var(--blush); }
.sheet p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.pane { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.row label { font-weight: 700; }
.row small { display: block; color: var(--muted); font-weight: 400; font-size: 12px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { padding: 8px 14px; font-weight: 700; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--ink); }
.num { width: 64px; padding: 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 18px var(--f-clock); text-align: center; }
.donate { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 14px; border-radius: 999px; text-decoration: none; font: 700 14px var(--f-ui); }
.donate.inset { color: var(--ink-on-accent); background: var(--sky, #b9e6ff); margin-top: 4px; }
.donate.quiet { color: var(--muted, #9fb0d0); font-weight: 400; font-size: 13px; padding: 4px; }
.donate:active { transform: scale(.97); }
.langsel { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 15px var(--f-ui); }
.txt { width: 100%; box-sizing: border-box; padding: 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 15px var(--f-ui); }
.switch { flex: 0 0 auto; position: relative; width: 50px; height: 30px; border-radius: 999px; background: var(--line); }
.switch[aria-checked="true"] { background: var(--coral); }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: var(--fg); transition: transform .15s; }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.inline { display: flex; gap: 8px; align-items: center; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.hr { height: 1px; background: var(--line); }
.tag { display: inline-block; justify-self: start; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--taupe); color: var(--fg); letter-spacing: .08em; }

.result { text-align: center; }
.result .tag { justify-self: center; }
.result .final { display: flex; justify-content: center; align-items: center; gap: 18px; font: 900 72px/1 var(--f-score); font-variant-numeric: tabular-nums; }
.result .final .h { color: var(--home); } .result .final .a { color: var(--away); }
.result .final .dash { color: var(--muted); font-size: 40px; }
.result .winner { font: 900 34px var(--f-score); letter-spacing: .04em; }
.result .actions { justify-content: center; }

.tabs { display: flex; gap: 6px; }
.tabs button { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); font-weight: 700; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--panel-2); color: var(--fg); border-color: var(--ok); }
.embed { min-height: 152px; border-radius: 12px; background: var(--bg); border: 1px dashed var(--line); display: grid; place-items: center; overflow: hidden; }
.embed > div { width: 100%; }
.embed iframe { display: block; width: 100%; border: 0; }
.embed .empty { padding: 16px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.6; }
.account { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.account .who { flex: 1; min-width: 0; color: var(--muted); font-size: 14px; }
.account .who strong { color: var(--fg); }
.lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; max-height: 220px; overflow-y: auto; }
.lists button { display: grid; grid-template-columns: 40px 1fr; gap: 8px; align-items: center; text-align: left; padding: 6px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); min-width: 0; }
.lists button.cur { border-color: var(--ok); }
.lists img, .lists .noimg { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; background: var(--panel-2); }
.lists .t { min-width: 0; font-size: 13px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lists .t small { display: block; font-weight: 400; color: var(--muted); }
.paste summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.paste .inline { margin-top: 8px; }
.sheet p.note { font-size: 12px; }
.tracks { display: grid; gap: 4px; max-height: 180px; overflow-y: auto; }
.tracks button { text-align: left; padding: 8px 10px; border-radius: 8px; background: var(--bg); border: 1px solid transparent; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tracks button.cur { border-color: var(--ok); color: var(--ok); }
.player { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.player input[type=range] { flex: 1; min-width: 120px; accent-color: var(--coral); }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 13px; color: var(--muted); }
.keys kbd { font: 12px var(--f-clock); color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; }

@media (max-width: 400px) { #ruleChip { display: none; } } /* too narrow to read; the settings button opens the same sheet */
@media (max-width: 520px) {
  .app { gap: 8px; }
  .pts { gap: 6px; }
  .pts button { min-height: 44px; }
  .pts button.minus { min-height: 36px; }
  .pad { width: 72px; min-height: 58px; }
  .score .hint { display: none; }
  .sportsel select { padding: 7px 22px 7px 9px; font-size: 12px; }
  .sportsel select { max-width: 132px; }
  .row:has(> .seg) { grid-template-columns: 1fr; } /* label above long option buttons */
  .row > .seg { justify-self: start; }
  .sportsel::after { right: 8px; }
}
/* landscape phones: slimmer top bar and DJ strip so the scores keep their room */
@media (orientation: landscape) and (max-height: 540px) {
  .topbar { padding-top: 6px; }
  .topbar .iconbtn { width: 34px; height: 34px; }
  .dj { padding-top: 6px; padding-bottom: 6px; }
  .djlabel { display: none; }
  .dj { grid-template-columns: 1fr; }
  .pad { min-height: 46px; width: 70px; font-size: 12px; }
  .pad .ico { font-size: 18px; }
  .pad.music small { display: none; }
}
@media (prefers-reduced-motion: reduce) { .score.bump .reel .n { animation: none; } .switch::after { transition: none; } .reel.snap { transition: none; } }

/* ---------- live sharing (js/share.js) ---------- */
.sharebtn .code { display: none; }
.sharebtn.live { width: auto; padding: 0 10px 0 8px; display: flex; gap: 6px; border-color: var(--ok); }
.sharebtn.live .code { display: inline; font: 700 14px var(--f-clock); letter-spacing: .12em; color: var(--ok); }
.sharebtn.live svg { stroke: var(--ok); }
.sharebtn.watch { border-color: var(--blush, #ffa9a3); }
.sharebtn.watch .code, .sharebtn.watch svg { color: var(--blush, #ffa9a3); stroke: var(--blush, #ffa9a3); }
.sharebtn.ask { position: relative; }
.sharebtn.ask::after { content: ""; position: absolute; top: -3px; right: -3px; width: 10px; height: 10px; border-radius: 50%; background: var(--coral); border: 2px solid var(--bg); }
body.viewonly .board .pts, body.viewonly .clockctl, body.viewonly .ctl { opacity: .45; }
body.viewonly .board .score, body.viewonly input.name { cursor: default; }
#shareOv .sheet, #meOv .sheet { gap: 12px; }
.shbody { display: grid; gap: 12px; }
.btn.wide { width: 100%; }
.lbl { font-size: 13px; letter-spacing: .08em; color: var(--muted); }
.muted { color: var(--muted); }
.joinrow { display: flex; gap: 10px; }
.codein { box-sizing: border-box; flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--fg);
  font: 700 24px var(--f-clock); letter-spacing: .4em; text-transform: uppercase; text-align: center; user-select: text; -webkit-user-select: text; }
.codebox { display: grid; justify-items: center; gap: 2px; padding: 12px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.codebox small { color: var(--muted); font-size: 13px; }
.bigcode { font: 900 56px var(--f-clock); letter-spacing: .25em; padding-left: .25em; color: var(--ok); line-height: 1.1; }
.sharerow { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.members { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.members li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.members li.off { opacity: .5; }
.members li.req { border-color: var(--coral); }
.members .av { font-size: 24px; line-height: 1; }
.members .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.members .nm small { color: var(--muted); margin-left: 4px; }
.members .tag { font-size: 12px; color: var(--muted); white-space: nowrap; }
.members li.req .tag { color: var(--coral); }
.mebtn { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); color: var(--fg); text-align: left; font: inherit; }
.mebtn .av { font-size: 28px; line-height: 1; }
.mebtn span { display: grid; }
.mebtn small { color: var(--muted); font-size: 12px; }
.avatars { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatars .av { aspect-ratio: 1; font-size: 26px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; padding: 0; }
.avatars .av[aria-pressed="true"] { border-color: var(--ok); background: var(--panel-2); box-shadow: 0 0 0 2px var(--ok) inset; }
.mename { box-sizing: border-box; width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg); color: var(--fg); font: 16px var(--f-ui); user-select: text; -webkit-user-select: text; }
.sharetoast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom, 0px)); translate: -50% 0; z-index: 40; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--ok); font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .35); text-align: center; }
@media (max-width: 520px) { .avatars { grid-template-columns: repeat(4, 1fr); } .bigcode { font-size: 46px; } }
@media (max-width: 520px) {
  .sharebtn.live { padding: 0 8px; }
  .sharebtn.live svg { display: none; }
  .sharebtn.live .code { font-size: 13px; letter-spacing: .06em; }
}
@media (max-width: 520px) { body.shared #targetChip .lbl, body.shared #targetChip .swap { display: none; } body.viewonly #targetChip { display: none; } }
/* the share sheet never grows wider than the screen: grid and flex children may shrink below their content */
.shbody { grid-template-columns: minmax(0, 1fr); }
.shbody > *, #meOv .sheet > * { min-width: 0; }
.codein { width: 0; }
.joinrow .btn { flex: 0 0 auto; }
/* narrow phones: the target chip gives up its label first, then shrinks, so the share and settings buttons stay on screen */
@media (max-width: 430px) { #targetChip { flex-shrink: 1; min-width: 0; } #targetChip .lbl { display: none; } }
@media (max-width: 380px) { .topbar .chipbtn { flex-shrink: 1; min-width: 0; } .topbar .chipbtn .swap { display: none; } .topbar { gap: 6px; } }
.sharerow .btn, .actions .btn { min-width: 0; white-space: normal; }
.members .tag { flex-shrink: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
