/* Bowling - one dark alley, one canvas, and a scoreboard that reads like a scoreboard. */
:root {
  --bg: #0b0e12; --panel: #141922; --panel2: #1b2230; --line: #273041;
  --ink: #e8edf5; --dim: #97a3b6; --accent: #f6b93b; --accent2: #4fc3f7;
  --strike: #ef5350; --spare: #66bb6a;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); }
body { overflow: hidden; -webkit-text-size-adjust: 100%; }
.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; }

#app { position: fixed; inset: 0; display: block; }
#gl { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

#topbar { position: absolute; top: max(8px, env(safe-area-inset-top)); right: 10px; display: flex; gap: 6px; z-index: 6; }

button { font: inherit; border-radius: 8px; border: 1px solid var(--line); cursor: pointer;
  padding: 7px 12px; background: var(--panel2); color: var(--ink); }
button:hover { border-color: #3a465c; background: #222b3b; }
button:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }
button.primary { background: var(--accent); color: #17202b; border-color: #d59a20; font-weight: 650; }
button.primary:hover { background: #ffc94f; }
button.minor { font-size: 13px; padding: 6px 10px; }
button[disabled] { opacity: 0.45; cursor: default; }

/* ---- scoreboard ---- */
#board { position: absolute; top: max(8px, env(safe-area-inset-top)); left: 10px; right: 10px;
  z-index: 5; display: flex; flex-direction: column; gap: 4px; pointer-events: none;
  max-width: min(920px, calc(100% - 290px)); }
.pl { display: flex; align-items: stretch; background: rgba(14,18,25,0.86); border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden; backdrop-filter: blur(3px); }
.pl.on { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(246,185,59,0.35); }
.pl .nm { flex: 0 0 84px; padding: 4px 8px; font-size: 12px; color: var(--dim); display: flex;
  align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.pl.on .nm { color: var(--accent); }
.pl .fr { flex: 1 1 0; display: grid; grid-template-columns: repeat(10, 1fr); }
.fx { border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.fx .bx { display: flex; height: 15px; }
.fx .bx span { flex: 1 1 0; font: 600 11px/15px var(--mono); text-align: center; color: var(--ink);
  border-left: 1px solid rgba(39,48,65,0.7); }
.fx .bx span:first-child { border-left: 0; }
.fx .bx span.x { color: var(--strike); }
.fx .bx span.s { color: var(--spare); }
.fx .bx span.sp { color: var(--accent2); }
.fx .cum { font: 700 13px/18px var(--mono); text-align: center; color: var(--ink);
  border-top: 1px solid var(--line); min-height: 18px; }
.pl .tot { flex: 0 0 46px; display: flex; align-items: center; justify-content: center;
  font: 700 16px/1 var(--mono); border-left: 1px solid var(--line); background: rgba(27,34,48,0.7); }

/* ---- readout + message ---- */
#readout { position: absolute; left: 10px; bottom: calc(var(--ctl-lift, 166px) + 10px); max-width: calc(100% - 20px); z-index: 5; display: flex; flex-wrap: wrap;
  gap: 6px 14px; font: 500 12px/1.5 var(--mono); color: var(--dim); pointer-events: none;
  background: rgba(11,14,18,0.6); padding: 5px 9px; border-radius: 7px; }
#readout span { white-space: nowrap; }
#ro-turn { color: var(--ink); }
#msg { position: absolute; left: 50%; top: 24%; transform: translate(-50%, -50%); z-index: 5;
  font: 600 clamp(15px, 2.6vw, 24px)/1.3 var(--font); text-align: center; padding: 10px 18px;
  background: rgba(11,14,18,0.72); border-radius: 10px; pointer-events: none; max-width: 80vw;
  transition: opacity 0.2s; }
#msg.quiet { opacity: 0; }

/* ---- controls ---- */
#controls { position: absolute; left: 10px; right: 10px; bottom: max(10px, env(safe-area-inset-bottom));
  z-index: 6; display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 8px 12px;
  background: rgba(14,18,25,0.9); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  backdrop-filter: blur(4px); }
.ctl { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.ctl label { font: 500 11.5px/1.3 var(--font); color: var(--dim); }
.ctl label b { color: var(--ink); font-variant-numeric: tabular-nums; }
.ctl-row { flex-direction: row; align-items: end; gap: 8px; }
.ctl-row button { flex: 1 1 0; }
input[type=range] { width: 100%; accent-color: var(--accent); height: 22px; margin: 0; }
input[type=range]:focus-visible { outline: 2px solid var(--accent2); outline-offset: 2px; }

/* ---- sheets ---- */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(4,6,9,0.72);
  display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; }
.sheet[hidden] { display: none; }
.sheet-in { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px 20px; max-width: 720px; width: 100%; max-height: 88vh; overflow: auto; }
.sheet h2 { margin: 0 0 10px; font-size: 19px; }
.sheet h3 { margin: 18px 0 6px; font-size: 14px; color: var(--accent); letter-spacing: 0.02em; }
.sheet p { margin: 8px 0; font-size: 13.5px; line-height: 1.6; color: #cfd8e6; }
.sheet .note { font-size: 12.5px; color: var(--dim); }
ul.facts { margin: 6px 0; padding-left: 18px; font-size: 13.5px; line-height: 1.65; color: #cfd8e6; }
ul.facts li { margin: 4px 0; }
ul.facts b { color: var(--ink); }
ul.src li { color: var(--dim); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13.5px; }
.row > label { flex: 0 0 168px; color: var(--dim); }
.row.check > label { flex: 1 1 auto; color: #cfd8e6; display: flex; gap: 8px; align-items: center; }
select { font: inherit; font-size: 13px; padding: 6px 8px; border-radius: 7px; background: var(--panel2);
  color: var(--ink); border: 1px solid var(--line); flex: 1 1 auto; min-width: 0; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#over-body table { width: 100%; border-collapse: collapse; font: 13px/1.5 var(--mono); }
#over-body td, #over-body th { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; }
#over-body th { color: var(--dim); font-weight: 600; }
#over-body td.n { text-align: right; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
  #board { max-width: calc(100% - 20px); top: 44px; }
  #topbar { top: 8px; left: 10px; right: 10px; justify-content: flex-end; }
  #readout { bottom: calc(var(--ctl-lift, 204px) + 8px); font-size: 11px; }
  #readout span { white-space: normal; }
  #over-body td, #over-body th { padding: 5px 4px; }
  #over-body table { font-size: 12px; }
  .pl .nm { flex: 0 0 56px; font-size: 11px; }
  .fx .bx span { font-size: 9.5px; }
  .fx .cum { font-size: 11px; }
}
@media (max-width: 560px) {
  #controls { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 10px; padding: 8px 10px; }
  .ctl-row { grid-column: 1 / -1; }
}
/* a phone on its side: put the scoreboard beside the buttons and tighten its rows */
@media (max-height: 460px) and (min-width: 600px) {
  #board { top: 8px; max-width: calc(100% - 290px); gap: 3px; }
  .fx .bx { height: 13px; }
  .fx .bx span { line-height: 13px; }
  .fx .cum { line-height: 15px; min-height: 15px; }
}
@media (prefers-reduced-motion: reduce) { #msg { transition: none; } }
