/* ============================================================
   CourtCrew – styles. Mobile-first; tablet & desktop enhance.
   ============================================================ */

/* Inter — self-hosted so it works offline and never calls out to another site. Licence: fonts/OFL-LICENSE.txt */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-wght-normal.woff2") format("woff2-variations"), url("../fonts/inter-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
/* rarer accented letters in names (ł, ő, ș…) — only downloaded if a name needs them */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 100 900; font-display: swap;
  src: url("../fonts/inter-latin-ext-wght-normal.woff2") format("woff2-variations"), url("../fonts/inter-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #eef1f9;
  --ink: #0b1426;
  --muted: #5b677f;
  --line: #dfe5f1;
  --brand: #0159f4;
  --brand-hover: #0047cc;
  --on-brand: #ffffff;
  --lime: #c6fc04;
  --on-lime: #0d1a00;
  --danger: #d92d3a;
  --warn: #f59e0b;
  --team-a: rgba(1, 89, 244, 0.08);
  --team-b: rgba(140, 190, 0, 0.13);
  --timer-bg: linear-gradient(160deg, #0b47c9 0%, #001335 72%);
  --shadow: 0 1px 2px rgba(11, 20, 38, 0.05), 0 10px 28px rgba(11, 20, 38, 0.07);
  --radius: 20px;
  --radius-sm: 14px;
  --nav-h: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000b24;
    --surface: #001335;
    --surface-2: #0b2257;
    --ink: #edf1ff;
    --muted: #93a8d0;
    --line: #163066;
    --brand: #0285fc;
    --brand-hover: #3aa0ff;
    --team-a: rgba(2, 133, 252, 0.16);
    --team-b: rgba(198, 252, 4, 0.09);
    --timer-bg: linear-gradient(160deg, #0a3fb0 0%, #001335 75%);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000b24;
  --surface: #001335;
  --surface-2: #0b2257;
  --ink: #edf1ff;
  --muted: #93a8d0;
  --line: #163066;
  --brand: #0285fc;
  --brand-hover: #3aa0ff;
  --team-a: rgba(2, 133, 252, 0.16);
  --team-b: rgba(198, 252, 4, 0.09);
  --timer-bg: linear-gradient(160deg, #0a3fb0 0%, #001335 75%);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 30px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--font);
  font-feature-settings: "cv05" 1, "cv08" 1; /* Inter alternates: lowercase l gets a tail and capital I gets serifs, so "Il1" can never be confused in names */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; font-feature-settings: inherit; color: inherit; }
button { touch-action: manipulation; cursor: pointer; }
h1, h2, h3, h4, p { margin: 0; }
h2 { font-size: 1.15rem; letter-spacing: -0.018em; font-weight: 750; }
h3 { font-size: 1rem; letter-spacing: -0.01em; font-weight: 700; }
a { color: var(--brand); }
small { color: var(--muted); }
.muted { color: var(--muted); font-size: 0.92rem; }
.hint { color: var(--muted); font-size: 0.85rem; margin-top: 8px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }

/* ---------------------------------------------------------- top bar & nav */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
}
/* The blur lives on a background layer: a backdrop-filter on the header itself would turn it into the
   containing block for the fixed bottom tab bar (which is a child of the header) and pin the bar to the top. */
.topbar::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 1.35rem; letter-spacing: -0.03em; }
.brand img { border-radius: 10px; display: block; }
.brand b { color: var(--brand); font-weight: 800; }
.top-actions { display: flex; gap: 6px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: space-around;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs a {
  position: relative; flex: 1; max-width: 140px;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 4px; border-radius: 14px;
  color: var(--muted); text-decoration: none; font-size: 0.74rem; font-weight: 700;
}
.tabs svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a.is-active { color: var(--brand); background: color-mix(in srgb, var(--brand) 12%, transparent); }
.tabs em {
  position: absolute; top: 2px; left: calc(50% + 8px);
  min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--brand); color: #fff; font: 700 0.68rem/18px var(--font); text-align: center; font-style: normal;
}

.icon-btn {
  width: 42px; height: 42px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

@media (min-width: 900px) {
  body { padding-bottom: 32px; }
  .topbar { padding-left: 28px; padding-right: 28px; }
  .tabs {
    position: static; padding: 4px; gap: 4px; border: 1px solid var(--line); border-radius: 16px;
    background: var(--surface); backdrop-filter: none; justify-content: center;
  }
  .tabs a { flex-direction: row; gap: 8px; max-width: none; padding: 8px 18px; font-size: 0.95rem; }
  .tabs svg { width: 20px; height: 20px; }
  .tabs em { position: static; margin-left: 2px; }
}

main { max-width: 1320px; margin: 0 auto; padding: 16px; }
@media (min-width: 900px) { main { padding: 24px 28px; } }

/* ---------------------------------------------------------- cards & buttons */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.count { color: var(--muted); font-weight: 600; font-size: 0.85rem; margin-left: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 18px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 700; text-decoration: none; transition: transform 0.06s, background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn svg { width: 22px; height: 22px; }
.btn-sm { min-height: 38px; padding: 0 13px; font-size: 0.9rem; border-radius: 12px; }
.btn-xl { min-height: 62px; font-size: 1.15rem; border-radius: 18px; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-lime { background: var(--lime); border-color: var(--lime); color: var(--on-lime); }
.btn-lime:hover { background: #d9ff4a; }
.btn-danger { color: var(--danger); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-row.center { justify-content: center; }
.btn-row.split > * { flex: 1; }

/* ---------------------------------------------------------- number badge */
.num {
  flex: none; display: inline-grid; place-items: center;
  min-width: 30px; height: 30px; padding: 0 6px; border-radius: 15px;
  background: hsl(var(--h, 220) 68% 42%); color: #fff;
  font-weight: 800; font-size: 0.92rem; font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------- empty state */
.empty { text-align: center; max-width: 520px; margin: 24px auto; padding: 36px 24px; }
.empty img { border-radius: 22px; margin-bottom: 14px; }
.empty h2 { font-size: 1.5rem; margin-bottom: 8px; }
.empty p { color: var(--muted); margin-bottom: 20px; }

/* ---------------------------------------------------------- play layout */
.play-grid { display: grid; gap: 14px; }
.col-timer, .col-courts { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.col-timer .card + .card, .col-courts .card + .card { margin-top: 0; }
@media (min-width: 1000px) {
  .play-grid { grid-template-columns: minmax(340px, 400px) 1fr; align-items: start; gap: 22px; }
  .col-timer { position: sticky; top: 88px; }
}

/* timer – always dark so it reads from across a court */
.timer { background: var(--timer-bg); color: #fff; border: 0; padding: 18px 18px 16px; position: relative; overflow: hidden; }
.timer::after {
  content: ""; position: absolute; right: -70px; top: -70px; width: 220px; height: 220px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(198, 252, 4, 0.28), rgba(198, 252, 4, 0) 70%); pointer-events: none;
}
.timer-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; position: relative; z-index: 1; }
.pill { display: inline-flex; align-items: baseline; gap: 4px; padding: 6px 14px; border-radius: 999px; background: var(--lime); color: var(--on-lime); font-weight: 800; font-size: 0.95rem; }
.pill small { color: inherit; opacity: 0.7; font-weight: 700; }
.pill--ghost { background: rgba(255, 255, 255, 0.12); color: #fff; font-weight: 700; font-size: 0.85rem; }
.pill--ghost.is-over { background: #ff5a5f; }
.time {
  font-weight: 800; letter-spacing: -0.04em; line-height: 1; text-align: center;
  font-size: clamp(76px, 24vw, 132px); font-variant-numeric: tabular-nums;
  margin: 14px 0 12px; position: relative; z-index: 1; text-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}
.bar { height: 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.16); overflow: hidden; position: relative; z-index: 1; }
.bar i { display: block; height: 100%; width: 100%; background: var(--lime); border-radius: 6px; transition: width 0.3s linear, background 0.3s; }
.timer.is-low .bar i { background: #ffb020; }
.timer.is-low .time { color: #ffd37a; }
.timer.is-crit .bar i { background: #ff5a5f; }
.timer.is-crit .time { color: #ff9a9d; animation: pulse 0.9s ease-in-out infinite; }
.timer.is-done .time { color: #ff9a9d; }
.timer.is-paused .time { opacity: 0.75; }
@keyframes pulse { 50% { transform: scale(1.04); } }

.timer-controls { display: grid; gap: 10px; margin-top: 16px; position: relative; z-index: 1; }
.timer-controls .btn-xl { width: 100%; }
.adj { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.timer .btn:not(.btn-primary):not(.btn-lime) { background: rgba(255, 255, 255, 0.12); border-color: transparent; color: #fff; }
.timer .btn:not(.btn-primary):not(.btn-lime):hover { background: rgba(255, 255, 255, 0.2); }
.timer .btn-primary { background: #fff; border-color: #fff; color: #001335; }
.timer .btn-primary:hover { background: #e9efff; }
.timer-bottom { display: flex; gap: 8px; margin-top: 10px; position: relative; z-index: 1; }
.timer-bottom .btn { flex: 1; padding: 0 10px; white-space: nowrap; }
.timer-bottom .btn-lime { flex: 1.5; }
.plan { margin-top: 12px; text-align: center; font-size: 0.82rem; color: rgba(255, 255, 255, 0.7); position: relative; z-index: 1; }

/* lookup */
.lbl { display: block; font-weight: 800; margin-bottom: 8px; }
.lookup input {
  width: 100%; min-height: 48px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
.lookup input:focus { border-color: var(--brand); background: var(--surface); }
.found { display: flex; align-items: center; gap: 12px; padding: 12px 0 2px; }
.found + .found { border-top: 1px solid var(--line); margin-top: 10px; }
.found-main { flex: 1; min-width: 0; }
.found-main .where { font-weight: 700; color: var(--brand); }
.found-main small { display: block; }
.court-badge {
  flex: none; min-width: 46px; height: 46px; padding: 0 8px; border-radius: 14px; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 800; font-size: 1.4rem;
}
.court-badge--bench { background: var(--surface-2); color: var(--muted); font-size: 0.8rem; }

/* selection bar */
/* floats over the page (never pushes the courts around, so the next tap lands where you aimed) */
.selectbar {
  position: fixed; z-index: 25; left: 12px; right: 12px; margin: 0 auto; max-width: 640px;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px);
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  background: var(--ink); color: var(--bg); border-radius: 18px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  animation: rise 0.18s ease-out;
}
@media (min-width: 900px) { .selectbar { bottom: 20px; } }
.selectbar div { flex: 1; min-width: 0; line-height: 1.25; }
.selectbar small { display: block; color: color-mix(in srgb, var(--bg) 70%, transparent); font-size: 0.78rem; }
.selectbar .btn { background: transparent; border-color: color-mix(in srgb, var(--bg) 40%, transparent); color: var(--bg); }

.banner {
  padding: 12px 16px; border-radius: var(--radius-sm); font-size: 0.92rem;
  background: color-mix(in srgb, var(--warn) 16%, var(--surface)); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent);
}

/* courts */
.courts { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); }
.court { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.court.is-idle { box-shadow: none; }
.court-head { display: flex; align-items: center; gap: 10px; padding: 12px 14px; }
.court-no { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--brand); color: #fff; font-weight: 800; }
.court-head h3 { flex: 1; font-size: 1.05rem; }
.court-meta { color: var(--muted); font-weight: 700; font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.team { padding: 8px 12px 12px; position: relative; }
.team-a { background: var(--team-a); }
.team-b { background: var(--team-b); }
.team-tag { display: block; font-size: 0.7rem; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 800; color: var(--muted); margin: 0 2px 6px; }
.seats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.net { position: relative; height: 22px; display: grid; place-items: center; background: var(--surface); }
.net::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; border-top: 3px dashed var(--line); }
.net span { position: relative; padding: 0 10px; background: var(--surface); font-size: 0.64rem; letter-spacing: 0.2em; font-weight: 800; color: var(--muted); }

/* chips (players on the board) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; min-width: 0; min-height: 50px; padding: 6px 12px 6px 7px;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
  text-align: left; font-weight: 700; box-shadow: 0 1px 2px rgba(11, 20, 38, 0.06);
  transition: transform 0.08s, box-shadow 0.15s, border-color 0.15s;
  cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.seats .chip { width: 100%; }
.chips .chip { max-width: 100%; }
.chip:hover { border-color: color-mix(in srgb, var(--brand) 50%, var(--line)); }
.chip.is-selected { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent); transform: scale(1.03); background: color-mix(in srgb, var(--brand) 10%, var(--surface)); }
.chip.is-dragging { opacity: 0.4; }
.chip.is-over { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 45%, transparent); }
.chip--open { border-style: dashed; background: transparent; box-shadow: none; color: var(--muted); font-weight: 600; cursor: pointer; }
.chip--open .plus { display: grid; place-items: center; width: 30px; height: 30px; flex: none; border-radius: 15px; background: var(--surface-2); font-size: 1.2rem; line-height: 1; }
.chip--rest { opacity: 0.65; cursor: pointer; }
.bench h3 { font-size: 1.05rem; }
.bench-hint { margin-top: 12px; }
.sub { margin: 16px 0 8px; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.bench.is-over { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 35%, transparent); }

/* ---------------------------------------------------------- players */
#view-players .card { max-width: 760px; margin: 0 auto; }
.add-form { display: flex; gap: 8px; }
.add-form input {
  flex: 1; min-width: 0; min-height: 50px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
.add-form input:focus { border-color: var(--brand); background: var(--surface); }
.plist { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 8px; }
.prow {
  display: flex; align-items: center; gap: 8px; padding: 6px 4px 6px 2px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface);
}
.prow.is-lifted { box-shadow: 0 10px 30px rgba(11, 20, 38, 0.25); border-color: var(--brand); position: relative; z-index: 2; transform: scale(1.015); }
.prow.is-resting { opacity: 0.6; }
.grip { width: 40px; height: 44px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; cursor: grab; touch-action: none; border-radius: 10px; flex: none; }
.grip svg { width: 22px; height: 22px; }
.pname { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 4px 0; display: flex; flex-direction: column; }
.pname strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pname small.on-court { color: var(--brand); font-weight: 700; }
.empty-row { text-align: center; padding: 24px; color: var(--muted); }

/* ---------------------------------------------------------- setup */
.setup-grid { display: grid; gap: 14px; max-width: 1100px; margin: 0 auto; }
.setup-grid .card + .card { margin-top: 0; }
@media (min-width: 800px) { .setup-grid { grid-template-columns: 1fr 1fr; align-items: start; } }
.setup-grid h2 { margin-bottom: 14px; }
.field { padding: 12px 0; border-top: 1px solid var(--line); }
.field:first-of-type { border-top: 0; padding-top: 0; }
.field label { font-weight: 700; display: block; }
.field-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.field-row small, .field small { display: block; }
.row { display: flex; gap: 8px; align-items: center; }
.field .row { margin-top: 6px; }
.field-row .row { margin-top: 0; }
.stepper { display: flex; align-items: center; gap: 6px; }
.step-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); font-size: 1.4rem; font-weight: 700; line-height: 1; }
.step-btn:active { transform: scale(0.94); }
.step-btn:disabled { opacity: 0.4; }
.step-val { display: flex; align-items: baseline; justify-content: center; gap: 6px; min-width: 100px; }
.step-val input {
  width: 3ch; min-width: 52px; text-align: right; border: 0; background: transparent; outline: none;
  font-weight: 800; font-size: 1.5rem; padding: 0; -moz-appearance: textfield; font-variant-numeric: tabular-nums;
}
.step-val input::-webkit-outer-spin-button, .step-val input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.step-val span { color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.presets, .alts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.chip-btn { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 0.9rem; }
.chip-btn.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }
.alts span { color: var(--muted); font-size: 0.82rem; font-weight: 700; margin-right: 2px; }

select {
  min-height: 42px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2);
}
.range { width: 160px; accent-color: var(--brand); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); cursor: pointer; }
.switch-row b { display: block; font-weight: 700; }
.switch-row small { display: block; }
.switch { position: relative; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; background: var(--line); border-radius: 16px; transition: background 0.2s; }
.switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); transition: transform 0.2s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 3px solid color-mix(in srgb, var(--brand) 60%, transparent); outline-offset: 2px; }

.suggest {
  margin-top: 8px; padding: 16px; border-radius: 18px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--brand) 14%, var(--surface)), color-mix(in srgb, var(--lime) 16%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--brand) 25%, var(--line));
}
.suggest--empty { color: var(--muted); font-size: 0.92rem; background: var(--surface-2); border-color: var(--line); }
.suggest-top { font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; color: var(--brand); }
.spark { color: #6f9d00; margin-right: 2px; }
.suggest-main { display: flex; align-items: baseline; gap: 8px; margin: 6px 0 8px; }
.suggest-main strong { font-size: 3rem; line-height: 1; letter-spacing: -0.04em; font-variant-numeric: tabular-nums; }
.suggest-main span { font-weight: 700; color: var(--muted); }
.suggest-points { margin: 0 0 4px; padding-left: 18px; font-size: 0.92rem; }
.suggest-points li + li { margin-top: 4px; }
.suggest .btn { margin-top: 12px; }
.applied { margin-top: 10px; font-weight: 800; color: #4f8f00; }
.install { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.install summary { cursor: pointer; font-weight: 700; }
.install p { margin-top: 8px; color: var(--muted); font-size: 0.92rem; }

/* ---------------------------------------------------------- sheet (dialog) */
.sheet {
  width: min(560px, 100%); max-height: min(86dvh, 720px); margin: auto auto 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  border: 0; border-radius: 26px 26px 0 0; background: var(--surface); color: var(--ink); box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.3);
  overflow: auto;
}
.sheet::backdrop { background: rgba(5, 10, 25, 0.55); backdrop-filter: blur(3px); }
.sheet[open] { animation: rise 0.22s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 26px; } }
.sheet-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.sheet-head > div, .sheet-head h3 { flex: 1; min-width: 0; }
.sheet-head h3 { font-size: 1.25rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet .field { border-top: 0; padding: 8px 0 12px; }
.sheet input[type=text], .sheet input:not([type]), .sheet input[type=search] {
  flex: 1; min-width: 0; width: 100%; min-height: 48px; padding: 0 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface-2); outline: none;
}
.sheet input:focus { border-color: var(--brand); background: var(--surface); }
.picklist { margin-top: 10px; display: grid; gap: 6px; }
.pick { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 6px 12px 6px 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); text-align: left; }
.pick:hover { border-color: var(--brand); }
.pick-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------- alarm overlay */
.alarm { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: #001335; animation: flash 1s steps(2, jump-none) infinite; }
@keyframes flash { 0% { background: #001335; } 100% { background: #b3141f; } }
@media (prefers-reduced-motion: reduce) { .alarm { animation: none; background: #b3141f; } .timer.is-crit .time { animation: none; } }
.alarm-box { width: min(480px, 100%); text-align: center; color: #fff; }
.alarm-bell { width: 96px; height: 96px; margin: 0 auto 8px; display: grid; place-items: center; border-radius: 50%; background: var(--lime); color: var(--on-lime); animation: ring 0.5s ease-in-out infinite alternate; }
.alarm-bell svg { width: 56px; height: 56px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@keyframes ring { from { transform: rotate(-14deg); } to { transform: rotate(14deg); } }
.alarm h2 { font-size: clamp(3.4rem, 18vw, 6rem); line-height: 1; letter-spacing: -0.04em; }
.alarm p { font-size: 1.2rem; margin: 6px 0 26px; opacity: 0.9; }
.alarm-actions { display: grid; gap: 12px; }
.btn-onDark { background: rgba(255, 255, 255, 0.16); border-color: transparent; color: #fff; }
.btn-onDark:hover { background: rgba(255, 255, 255, 0.26); }
body.alarm-on { overflow: hidden; }

/* ---------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px); z-index: 120;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 11px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 700; font-size: 0.92rem;
  box-shadow: var(--shadow); transition: opacity 0.2s, transform 0.2s; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { .toast { bottom: 28px; } }

/* smaller phones */
@media (max-width: 380px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .adj .btn { padding: 0 8px; font-size: 0.88rem; }
}

/* ============================================================
   Live sync
   ============================================================ */
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; margin-right: 2px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font-weight: 800; font-size: 0.8rem; text-decoration: none; letter-spacing: 0.02em; white-space: nowrap;
}
.sync-chip i, .sync-state i { width: 9px; height: 9px; border-radius: 50%; background: #9aa6c2; flex: none; }
.sync-chip.is-live i, .sync-state.is-live i { background: #19c37d; box-shadow: 0 0 0 0 rgba(25, 195, 125, 0.6); animation: live 2s infinite; }
.sync-chip.is-offline i, .sync-state.is-offline i { background: var(--warn); }
@keyframes live { 70% { box-shadow: 0 0 0 7px rgba(25, 195, 125, 0); } 100% { box-shadow: 0 0 0 0 rgba(25, 195, 125, 0); } }
@media (max-width: 420px) { .sync-chip { padding: 0 10px; font-size: 0.74rem; } }

.sync-card { grid-column: 1 / -1; }
.sync-card .field { margin-top: 14px; }
.sync-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.sync-top > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sync-top h2 { margin: 0; }
.setup-grid .sync-top h2 { margin-bottom: 0; }
.sync-state { display: inline-flex; align-items: center; gap: 7px; font-size: 0.82rem; font-weight: 700; color: var(--muted); }
.role-pill { padding: 4px 11px; border-radius: 999px; background: color-mix(in srgb, var(--brand) 14%, var(--surface)); color: var(--brand); font-size: 0.78rem; font-weight: 800; }
.sync-code {
  margin: 4px 0 12px; padding: 14px 10px; text-align: center; border-radius: 18px;
  background: var(--surface-2); border: 1px dashed color-mix(in srgb, var(--brand) 40%, var(--line));
  font: 800 clamp(2rem, 9vw, 3rem)/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: 0.08em; color: var(--brand);
  user-select: all; -webkit-user-select: all;
}
.sync-card p + .btn-row, .sync-card .btn-row + p, .sync-card p + p { margin-top: 12px; }
.sync-card .btn-row + .btn-row { margin-top: 14px; }

/* "My court" card */
.me-card { border: 2px solid var(--line); }
.me-card.is-playing { border-color: var(--brand); background: linear-gradient(160deg, color-mix(in srgb, var(--brand) 12%, var(--surface)), var(--surface)); }
.me-card--hint { border-style: dashed; box-shadow: none; }
.me-hint { color: var(--muted); font-size: 0.92rem; }
.me-hint b { color: var(--ink); }
.me-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.eyebrow { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase; color: var(--brand); }
.me-main { display: flex; align-items: center; gap: 12px; }
.me-main strong { font-size: 1.2rem; }
.me-main .court-badge { min-width: 62px; height: 62px; font-size: 2rem; border-radius: 18px; }
.link-btn { border: 0; background: none; padding: 4px 0; margin-top: 2px; color: var(--brand); font-weight: 700; font-size: 0.85rem; text-decoration: underline; text-underline-offset: 3px; }
.col-timer .me-card + #timerCard { margin-top: 0; }

/* view-only (players watching) */
body.readonly .chip { cursor: default; }
body.readonly .chip--open { pointer-events: none; opacity: 0.7; }
body.readonly .chip--rest { pointer-events: none; }
body.readonly .bench-hint,
body.readonly [data-action="autofill"],
body.readonly #addForm,
body.readonly #addForm + .hint,
body.readonly #playerHelp,
body.readonly [data-action="shuffle-order"],
body.readonly [data-action="sort-az"],
body.readonly .grip,
body.readonly .prow .icon-btn,
body.readonly .alarm [data-action="alarm-next"],
body.readonly .alarm [data-action="alarm-plus"] { display: none !important; }
body.readonly .pname { cursor: default; }

/* ============================================================
   Previous players (quick add)
   ============================================================ */
.roster { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.roster:empty { display: none; }
.roster-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.roster-head h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.roster-last { width: 100%; margin-bottom: 10px; min-height: 44px; }
.roster-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.name-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; max-width: 100%; padding: 0 14px 0 10px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; font-size: 0.95rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.name-chip b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: color-mix(in srgb, var(--brand) 15%, var(--surface)); color: var(--brand); font-size: 1rem; line-height: 1; }
.name-chip:hover { border-color: var(--brand); }
.name-chip:active { transform: scale(0.96); }
.name-chip.is-edit { padding-right: 4px; cursor: default; }
.name-chip.is-edit button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: var(--surface-2); color: var(--danger); font-size: 1.2rem; line-height: 1; }
.roster .link-btn { margin-top: 10px; }
.roster-head .link-btn { margin: 0; }
body.readonly .roster { display: none; }

/* ---------- typography ---------- */
.num, .time, .court-meta, .court-badge, .step-val input, .suggest-main strong, .count, .pill, .sync-code, #sessionClock {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1, "cv05" 1, "zero" 0;
}
.time { font-weight: 800; letter-spacing: -0.05em; }          /* the countdown: big, heavy, steady */
.chip, .btn, .name-chip, .tabs a { font-weight: 650; letter-spacing: -0.005em; }  /* variable font = in-between weights */
.chip .nm, .pname strong { font-weight: 650; }
.team-tag, .eyebrow, .roster-head h3 { letter-spacing: 0.08em; }
.hint, small, .muted { line-height: 1.45; }
