/* Court Clock: one huge countdown, readable across a hall. Everything else stays small and out of its way. */
:root {
  --play: #0f7a3d; --play-ink: #ffffff;
  --warn: #f2a900; --warn-ink: #1a1300;
  --rest: #b3261e; --rest-ink: #ffffff;
  --panel: rgba(0, 0, 0, .55); --panel-ink: #ffffff;
  --sheet: #14181a; --sheet-2: #1f2629; --line: #333c40; --muted: #9aa7ac; --accent: #c7e83d;
  --digits: ui-rounded, "SF Pro Rounded", "Arial Rounded MT Bold", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: var(--sans); background: var(--play); color: var(--play-ink);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
  transition: background-color .4s ease;
}
body.warn { background: var(--warn); color: var(--warn-ink); }
body.rest { background: var(--rest); color: var(--rest-ink); }

/* the timer: as wide as the screen allows, leaving a strip for the info line */
main { position: fixed; inset: 0; display: grid; grid-template-rows: 1fr auto; place-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.time {
  font-family: var(--digits); font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.03em; line-height: 1;
  font-size: min(36vw, 80vh); white-space: nowrap;
}
.time.long { font-size: min(27vw, 80vh); } /* an hour or more: 1:00:00 */
body.idle .time, body.paused .time { opacity: .55; }
.info { width: 100%; display: flex; justify-content: center; gap: 2.2em; flex-wrap: wrap; padding: 0 1em .9em;
  font-size: clamp(14px, 3.2vh, 30px); font-weight: 650; opacity: .85; font-variant-numeric: tabular-nums; }
.info span { white-space: nowrap; }

/* the last few seconds: the whole screen pulses */
.flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
body.flashing .flash { animation: pulse 1s steps(1, end) infinite; }
@keyframes pulse { 0% { opacity: .85; } 50% { opacity: 0; } }

/* controls: a bar along the bottom, shown before starting and for a few seconds after a tap */
.controls { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translate(-50%, 0);
  display: flex; gap: 10px; padding: 10px; border-radius: 22px; background: var(--panel); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); transition: opacity .25s ease, transform .25s ease; max-width: calc(100vw - 24px); }
body.hide-ui .controls { opacity: 0; transform: translate(-50%, 20px); pointer-events: none; }
.ctl { min-height: 52px; padding: 0 18px; border: 0; border-radius: 14px; background: rgba(255, 255, 255, .14); color: var(--panel-ink);
  font: 700 17px var(--sans); white-space: nowrap; cursor: pointer; }
.ctl.go { background: #fff; color: #0b0f0d; min-width: 120px; font-size: 19px; }
.ctl:active { transform: scale(.97); }
body.idle #b-restart, body.idle #b-plus, body.idle #b-skip, body.idle #b-stop { display: none; }
@media (max-width: 560px) { .ctl { padding: 0 12px; font-size: 15px; } .ctl.go { min-width: 92px; } }

/* small corner buttons: always there, never loud */
.corner { position: fixed; top: max(10px, env(safe-area-inset-top)); width: 44px; height: 44px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .18); color: inherit; font-size: 22px; line-height: 44px; opacity: .55; cursor: pointer; }
.corner:hover, .corner:focus-visible { opacity: 1; }
.settings { right: max(12px, env(safe-area-inset-right)); }
.full { right: calc(max(12px, env(safe-area-inset-right)) + 54px); }

/* settings sheet */
.sheet { width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px); border: 1px solid var(--line); border-radius: 18px;
  background: var(--sheet); color: #eef3f4; padding: 0 18px 16px; font-size: 16px; user-select: text; -webkit-user-select: text; }
.sheet::backdrop { background: rgba(0, 0, 0, .6); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 6px; position: sticky; top: 0; background: var(--sheet); }
.sheet-head h2 { margin: 0; font-size: 20px; }
.x { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--sheet-2); color: inherit; font-size: 22px; cursor: pointer; }
.row { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row > label { font-weight: 650; color: var(--muted); }
.sheet input, .sheet select { font: 16px var(--sans); color: inherit; background: var(--sheet-2); border: 1px solid var(--line); border-radius: 10px; min-height: 40px; padding: 0 10px; }
.mmss input { width: 72px; text-align: center; }
#s-hours { width: 72px; text-align: center; }
.radios { display: grid; gap: 8px; }
.radios label { display: flex; align-items: center; gap: 8px; }
.radios input[type="radio"] { width: 20px; min-height: 20px; accent-color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 14px; }
.btn { min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--sheet-2); color: inherit; font: 650 15px var(--sans); cursor: pointer; }
.btn.primary { margin-left: auto; background: var(--accent); border-color: var(--accent); color: #172000; }
.btn.quiet { color: var(--muted); }
.note { margin: 10px 0 0; color: var(--muted); font-size: 14px; }
.note.small { font-size: 13px; }
@media (max-width: 480px) { .row { grid-template-columns: 1fr; gap: 6px; } }
@media (prefers-reduced-motion: reduce) { body { transition: none; } .controls { transition: none; } }
/* before starting, the info line sits above the Start button instead of under it */
body.idle .info { padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
body.idle .time { font-size: min(32vw, 58vh); }

/* pickleball court lines, faint, behind everything */
.court { position: fixed; left: 3vw; top: 5vh; width: 94vw; height: 90vh; fill: none; stroke: rgba(255, 255, 255, .16); stroke-width: 3;
  pointer-events: none; }
.court * { vector-effect: non-scaling-stroke; }
.court .net { stroke: rgba(255, 255, 255, .28); stroke-width: 5; stroke-dasharray: 2 10; }
body.warn .court { stroke: rgba(0, 0, 0, .14); }
body.warn .court .net { stroke: rgba(0, 0, 0, .22); }
main { z-index: 1; }

/* the change between phases: a band slams in diagonally, the word punches in, everything slides off */
.splash { position: fixed; inset: 0; z-index: 50; pointer-events: none; overflow: hidden; display: none; --band: #d7ec2c; --ink: #0b3d1e; }
.splash.go { display: block; }
.splash.rest { --band: #ffffff; --ink: #b3261e; }
.splash.done { --band: #ffffff; --ink: #111111; }
.band { position: absolute; left: -15%; right: -15%; top: 20%; height: 60%; background: var(--band); color: var(--ink);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5vh;
  box-shadow: 0 0 0 1.4vh rgba(255, 255, 255, .9), 0 0 0 3vh rgba(0, 0, 0, .35), 0 3vh 6vh rgba(0, 0, 0, .45);
  transform: skewY(-7deg) translateX(-130%); }
.splash.go .band { animation: band 1.7s linear forwards; }
.word { font-family: var(--digits); font-weight: 900; font-style: italic; text-transform: uppercase; letter-spacing: -.02em; line-height: .95;
  font-size: min(19vw, 30vh); text-shadow: 0 .05em 0 rgba(0, 0, 0, .18); white-space: nowrap; }
.sub { font-family: var(--digits); font-weight: 800; font-style: italic; text-transform: uppercase; letter-spacing: .08em;
  font-size: min(4.5vw, 7vh); opacity: .8; }
.splash.go .word { animation: word 1.7s linear forwards; }
.splash.go .sub { animation: word 1.7s .06s linear both; }
/* each step has its own easing: slam in (fast, then settle), hold (steady drift), and leave ACCELERATING so the exit
   never slows to a near-stop just before it's off screen */
@keyframes band {
  0% { transform: skewY(-7deg) translateX(-130%); animation-timing-function: cubic-bezier(.2, .9, .25, 1); }
  16% { transform: skewY(-7deg) translateX(0); animation-timing-function: linear; }
  78% { transform: skewY(-7deg) translateX(0); animation-timing-function: cubic-bezier(.6, 0, .9, .45); }
  100% { transform: skewY(-7deg) translateX(135%); }
}
@keyframes word {
  0%, 10% { transform: translateX(90vw) skewX(-14deg) scale(1.5); opacity: 0; animation-timing-function: cubic-bezier(.2, .9, .25, 1); }
  24% { transform: translateX(-3vw) skewX(-14deg) scale(.96); opacity: 1; animation-timing-function: ease-out; }
  30% { transform: translateX(0) skewX(-12deg) scale(1); animation-timing-function: linear; }
  78% { transform: translateX(2vw) skewX(-12deg) scale(1); animation-timing-function: cubic-bezier(.6, 0, .9, .45); }
  100% { transform: translateX(-120vw) skewX(-12deg) scale(1); opacity: 1; }
}
/* the screen gives a jolt as the word lands */
body.jolt main, body.jolt .court { animation: jolt .32s .38s ease-out; }
@keyframes jolt { 0%, 100% { transform: none; } 20% { transform: translate(-1.2vw, .8vh); } 45% { transform: translate(1vw, -.6vh); } 70% { transform: translate(-.5vw, .3vh); } }
@media (prefers-reduced-motion: reduce) {
  .splash.go .band, .splash.go .word, .splash.go .sub { animation: fadeinout 1.4s both; transform: skewY(-7deg); }
  .splash.go .word, .splash.go .sub { transform: none; }
  body.jolt main, body.jolt .court { animation: none; }
  @keyframes fadeinout { 0%, 100% { opacity: 0; } 15%, 80% { opacity: 1; } }
}
/* layering: court lines, then the timer, then the flash, then the buttons, then the transition band */
.flash { z-index: 2; }
.controls, .corner { z-index: 10; }

/* "put me on your home screen": a small card at the top of the start screen only */
.install { position: fixed; z-index: 20; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100vw - 140px)); display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 16px; background: rgba(10, 20, 14, .82); color: #fff; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3); font-size: 15px; line-height: 1.35; }
.install[hidden], body:not(.idle) .install { display: none; }
.install img { border-radius: 10px; flex: none; }
.install p { margin: 0; flex: 1; }
.install .btn { flex: none; min-height: 40px; background: rgba(255, 255, 255, .12); border-color: transparent; color: #fff; }
.install .btn.primary { background: #d7ec2c; color: #172000; }
.install .share { display: inline-block; padding: 0 4px; border: 1px solid rgba(255, 255, 255, .5); border-radius: 5px; font-weight: 700; }

/* ---------- rest: the countdown on the left, where-to-go map on the right ---------- */
.rotate { display: none; }
body.rest:not(.idle) main { grid-template-columns: 1.15fr 1fr; grid-template-rows: 1fr auto; column-gap: 2vw; }
body.rest:not(.idle) .time { font-size: min(20vw, 62vh); justify-self: center; }
body.rest:not(.idle) .info { grid-column: 1 / -1; }
body.rest:not(.idle) .rotate { display: grid; align-content: center; gap: 1.5vh; width: 100%; padding-right: 3vw; }
body.rest .court { opacity: 0; transition: opacity .4s; }
.rot-title { margin: 0; position: relative; height: 1.15em; font-family: var(--digits); font-weight: 900; font-style: italic;
  text-transform: uppercase; font-size: min(3.5vw, 8vh); letter-spacing: -.01em; overflow: hidden; padding: 0 .3em; }
/* sized to the map's column, not the screen, so the longest title ("Rock paper scissors") fits in the phone's wide rounded font */
body.rest:not(.idle) .rotate { container-type: inline-size; }
@supports (font-size: 1cqi) { .rot-title { font-size: min(6.4cqi, 8vh); } }
.rot-title span { position: absolute; left: 0; right: 0; text-align: center; white-space: nowrap; opacity: 0; transform: translateX(40%) skewX(-12deg);
  transition: transform .35s cubic-bezier(.2, .9, .25, 1), opacity .25s; }
.rotate[data-slide="0"] .t0, .rotate[data-slide="1"] .t1, .rotate[data-slide="2"] .t2 { opacity: 1; transform: skewX(-12deg); }
.t0, .rps-w { color: #d7ec2c; }
.rot-map { width: 100%; height: auto; max-height: 62vh; overflow: visible; }
.rot-map .courts rect { fill: rgba(255, 255, 255, .08); stroke: #fff; stroke-width: 3; }
.rot-map .net { stroke: #fff; stroke-width: 3; stroke-dasharray: 3 6; opacity: .8; }
.rot-map .nums text { fill: #fff; font: 900 26px var(--digits); }
/* arrows: drawn on, then flow */
.rot-map .arrows { opacity: 0; transition: opacity .3s; }
.rot-map .arrows path { fill: none; stroke-width: 10; stroke-linecap: round; stroke-dasharray: 18 12; }
.win-arrows path { stroke: #d7ec2c; }
.lose-arrows path { stroke: #fff; }
.rotate[data-slide="0"] .win-arrows, .rotate[data-slide="1"] .lose-arrows { opacity: 1; }
.rotate[data-slide="0"] .win-arrows path, .rotate[data-slide="1"] .lose-arrows path { animation: flow .6s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -30; } }
.rot-map .stay { fill: #fff; font: 800 italic 15px var(--digits); text-anchor: middle; text-transform: uppercase; letter-spacing: .06em; }
.win-arrows .stay { fill: #d7ec2c; }
/* rock paper scissors: the winner's end lights up */
.rot-map .rps { opacity: 0; transition: opacity .3s; }
.rotate[data-slide="2"] .rps { opacity: 1; }
.rot-map .rps .win { fill: #d7ec2c; transform-box: fill-box; transform-origin: center; }
.rotate[data-slide="2"] .rps .win { animation: glow 1.2s ease-in-out infinite alternate; }
@keyframes glow { from { opacity: .7; } to { opacity: 1; } }
.rot-map .rps-w { fill: #0b3d1e; font: 900 italic 17px var(--digits); text-anchor: middle; text-transform: uppercase; }
.rot-map .rps-l { fill: #fff; font: 800 italic 12px var(--digits); text-anchor: middle; text-transform: uppercase; opacity: .85; }
@media (prefers-reduced-motion: reduce) { .rotate * { animation: none !important; transition: none !important; } }
/* upright phone: map under the timer */
@media (orientation: portrait) {
  body.rest:not(.idle) main { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  body.rest:not(.idle) .time { font-size: min(30vw, 30vh); }
}
.linkish { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }

/* settings: a plain explanation under each one */
.hint { grid-column: 2; margin: 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
.btn-help { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.btn-help b { color: #eef3f4; }
@media (max-width: 480px) { .hint { grid-column: 1; } }

/* get ready: before game 1, a ball-yellow screen with the countdown */
body.ready { background: #d7ec2c; color: #0b3d1e; }
body.ready .court { stroke: rgba(11, 61, 30, .18); }
body.ready .court .net { stroke: rgba(11, 61, 30, .3); }

/* the get-ready band: dark green on the yellow screen */
.splash.ready { --band: #0b3d1e; --ink: #d7ec2c; }
/* after a refresh: a small notice until the first tap */
.resume-note { position: fixed; z-index: 30; left: 50%; top: max(14px, env(safe-area-inset-top)); transform: translateX(-50%); margin: 0;
  padding: 8px 16px; border-radius: 999px; background: rgba(0, 0, 0, .7); color: #fff; font: 700 15px var(--sans); white-space: nowrap; pointer-events: none; }
.resume-note[hidden] { display: none; }

/* compact settings: explanations only on request, two columns when there's room, tighter rows */
.sheet .hint, .sheet .btn-help { display: none; }
.sheet.explain .hint { display: block; }
.sheet.explain .btn-help { display: block; }
.sheet-head { padding: 10px 0 4px; gap: 10px; }
.sheet-head h2 { margin-right: auto; }
.explain-btn { font-size: 14px; white-space: nowrap; }
.sheet .row { grid-template-columns: 96px 1fr; gap: 4px 10px; padding: 6px 0; }
.sheet input, .sheet select { min-height: 36px; }
.mmss input, #s-hours { width: 60px; }
.radios { gap: 4px; }
.actions { padding-top: 8px; gap: 6px; }
.btn { min-height: 38px; padding: 0 12px; }
.note { margin-top: 6px; }
@media (min-width: 700px) {
  .sheet { width: min(900px, calc(100vw - 24px)); }
  .sheet .grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; }
}
.sheet { max-height: calc(100vh - 12px); padding-bottom: 8px; }

/* settings grouped: setup on top, Times beside Alerts, session and Done along the bottom */
.sheet .grid { display: block; }
.group h3 { margin: 8px 0 0; font: 800 12px var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--accent); }
.sheet .row { grid-template-columns: 84px 1fr; }
.setup-ctl, .horn-ctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.setup-ctl select { flex: 1 1 140px; min-width: 0; }
.horn-ctl select { flex: 1 1 120px; min-width: 0; }
.sheet .session-row { grid-template-columns: 84px 1fr auto; border-bottom: 0; }
.session-row .radios { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.session-row .hint { grid-column: 2 / -1; }
.sheet .group .row:last-child { border-bottom: 0; }
@media (min-width: 700px) {
  .sheet .grid { display: grid; grid-template-columns: 1fr 1fr; column-gap: 28px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }
}
@media (max-width: 480px) { .sheet .session-row { grid-template-columns: 1fr; } .session-row .hint { grid-column: 1; } }

/* the countdown fills its space; app.js measures the text and sets the size */
.time { width: 100%; text-align: center; }

/* phone held upright: ask for sideways (only on touch screens, so a narrow computer window isn't affected) */
.turn { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  .turn { position: fixed; inset: 0; z-index: 15; display: grid; place-content: center; justify-items: center; gap: 18px;
    padding: 32px; text-align: center; background: #0f7a3d; color: #fff; }
  .turn-phone { width: 64px; height: 110px; border: 6px solid #fff; border-radius: 14px; animation: turn 2.4s ease-in-out infinite; }
  .turn-big { margin: 0; font: 900 italic 30px var(--digits); text-transform: uppercase; }
  .turn-small { margin: 0; max-width: 320px; font: 600 16px/1.45 var(--sans); opacity: .85; }
  .corner { z-index: 16; }
  .install { width: calc(100vw - 24px); top: max(64px, calc(env(safe-area-inset-top) + 56px)); }
}
@keyframes turn { 0%, 25% { transform: rotate(0); } 50%, 75% { transform: rotate(-90deg); } 100% { transform: rotate(0); } }
@media (prefers-reduced-motion: reduce) { .turn-phone { animation: none; transform: rotate(-90deg); } }
/* narrow screens: the install card gets the full width, and the buttons wrap instead of running off the edge */
@media (max-width: 600px) { .install { width: calc(100vw - 24px); } }
.controls { flex-wrap: wrap; justify-content: center; }
/* centre the button bar without halving the room it has (it only wraps when the screen really is too narrow) */
.controls { left: 12px; right: 12px; margin-inline: auto; width: fit-content; max-width: calc(100vw - 24px); transform: none; }
body.hide-ui .controls { transform: translateY(20px); }

/* the app's own question box (instead of the phone's plain pop-up) */
.ask { width: min(420px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 20px; background: var(--sheet); color: #eef3f4;
  padding: 20px 20px 16px; box-shadow: 0 20px 60px rgba(0, 0, 0, .5); font: 16px/1.45 var(--sans); }
.ask::backdrop { background: rgba(0, 0, 0, .6); }
.ask h2 { margin: 0 0 6px; font: 900 italic 22px var(--digits); text-transform: uppercase; letter-spacing: -.01em; }
.ask p { margin: 0 0 12px; color: var(--muted); }
.ask p[hidden], .ask input[hidden] { display: none; }
.ask input { width: 100%; min-height: 44px; margin: 4px 0 12px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--sheet-2); color: inherit; font: 17px var(--sans); }
.ask-btns { display: flex; justify-content: flex-end; gap: 8px; }
.ask .btn { min-height: 44px; padding: 0 18px; font-size: 16px; }
.btn.danger { background: #d6453b; border-color: #d6453b; color: #fff; }

/* the club logo, bottom right: as big as the corner allows without crowding the countdown, softened corners */
.logo { position: fixed; z-index: 1; right: max(14px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom));
  height: min(19vh, 12vw); width: auto; border-radius: min(2.2vh, 1.4vw); pointer-events: none;
  box-shadow: 0 .6vh 2vh rgba(0, 0, 0, .25); }
/* the start screen's buttons sit at the bottom: keep the logo clear of them */
@media (max-width: 700px) { body.idle .logo { display: none; } }
