/* Court — design system, plan §6.6.
   Dark first; light flips surface/ink and keeps the accent. */

:root {
  --bg: #0B0F14;      --surface: #141A21;  --raised: #1B232C;
  --line: #232E3A;    --ink: #E6EDF3;      --muted: #8B98A5;
  --accent: #C8F751;  /* shuttle lime — energetic, not another SaaS blue */
  --accent-ink: #10160B;
  --good: #3DDC91;    --warn: #FFB454;     --gone: #47525F;
  --radius: 14px;     --radius-lg: 20px;   --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px -12px rgba(0,0,0,.6);
  --tap: 44px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F6F8FA;    --surface: #FFFFFF;  --raised: #F0F3F6;
    --line: #D8DEE6;  --ink: #10161D;      --muted: #5B6774;
    --accent: #A8DC22; --accent-ink: #10160B;
    --gone: #C3CBD4;
    --shadow: 0 1px 2px rgba(16,22,29,.06), 0 8px 24px -14px rgba(16,22,29,.22);
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F6F8FA;      --surface: #FFFFFF;  --raised: #F0F3F6;
  --line: #D8DEE6;    --ink: #10161D;      --muted: #5B6774;
  --accent: #A8DC22;  --gone: #C3CBD4;
  --shadow: 0 1px 2px rgba(16,22,29,.06), 0 8px 24px -14px rgba(16,22,29,.22);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  /* Times, prices and countdowns must not jitter as they tick. */
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- shell ---------- */

.app {
  max-width: 780px; margin: 0 auto; min-height: 100%; width: 100%;
  display: flex; flex-direction: column; min-width: 0;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}

header.top {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -.01em; }
.brand svg { display: block; }
.brand .sub { font-weight: 500; color: var(--muted); font-size: 12px; }
.grow { flex: 1; }

.iconbtn {
  width: var(--tap); height: 36px; display: grid; place-items: center;
  background: transparent; border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; color: var(--muted);
}
.iconbtn:hover { color: var(--ink); border-color: var(--muted); }

/* ---------- next game strip ---------- */

.next {
  margin: 14px 16px 0; padding: 13px 15px; border-radius: var(--radius);
  background: linear-gradient(180deg, var(--raised), var(--surface));
  border: 1px solid var(--line); box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.next .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.next b { font-weight: 650; }
.next .when { color: var(--muted); font-size: 13px; }

/* ---------- date chips ---------- */

main, main > div { min-width: 0; max-width: 100%; }
.dates {
  display: flex; gap: 8px; padding: 14px 16px 4px;
  overflow-x: auto; scrollbar-width: none; scroll-snap-type: x proximity;
}
.dates::-webkit-scrollbar { display: none; }
.chip {
  flex: none; scroll-snap-align: start;
  min-width: 62px; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--line);
  cursor: pointer; text-align: center; line-height: 1.25;
  transition: background .12s ease, border-color .12s ease, transform .12s ease;
}
.chip:active { transform: scale(.97); }
.chip .dow { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.chip .dom { font-size: 17px; font-weight: 650; }
.chip[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
.chip[aria-pressed="true"] .dow { color: color-mix(in srgb, var(--accent-ink) 70%, transparent); }

/* ---------- filters ---------- */

.filters { display: flex; gap: 8px; padding: 10px 16px 2px; align-items: center; flex-wrap: wrap; }
.pill { white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.pill {
  padding: 6px 11px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 13px; cursor: pointer;
}
.pill[aria-pressed="true"] { color: var(--ink); border-color: var(--muted); background: var(--raised); }
.range { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--muted); }
.range input[type=range] { width: 104px; accent-color: var(--accent); }

/* ---------- the court grid (§6.3) ---------- */

.venue { min-width: 0; margin: 16px 16px 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; }
.venue > header {
  position: sticky; top: 0; display: flex; align-items: baseline; gap: 8px;
  padding: 11px 14px; background: var(--raised); border-bottom: 1px solid var(--line);
}
.venue h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: -.01em; }
.venue .meta { font-size: 12px; color: var(--muted); }
.venue .price { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--accent); }

.gridwrap { overflow-x: auto; scroll-snap-type: x proximity; }
.gridwrap::-webkit-scrollbar { height: 8px; }
.gridwrap::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }

table.grid { border-collapse: separate; border-spacing: 0; width: max-content; min-width: 100%; }
table.grid th, table.grid td { padding: 0; }
/* Spacing lives on the td, not the cell: a <button> shrink-wraps its content
   even at display:block, so margins on .cell made every free (button) cell a
   narrow pill while booked (span) cells filled the column. */
table.grid td { padding: 2px 3px; }
table.grid thead th {
  position: sticky; top: 0; background: var(--surface); z-index: 2;
  font: 500 11px/1 system-ui; color: var(--muted); padding: 9px 0 7px;
  min-width: 54px; scroll-snap-align: start;
}
table.grid tbody th {
  position: sticky; left: 0; z-index: 3; background: var(--surface);
  text-align: left; font: 500 12px/1 system-ui; color: var(--muted);
  padding: 0 12px 0 14px; white-space: nowrap;
  border-right: 1px solid var(--line);
}
.cell {
  --c: var(--gone);
  display: block; width: 100%; height: 30px; margin: 0; padding: 0;
  border-radius: 7px;
  /* Mix against the surface, not transparent: compositing lime over a dark
     ground gives olive, which reads as neither free nor booked. */
  background: color-mix(in srgb, var(--c) 20%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--c) 46%, var(--surface));
  position: relative; cursor: default;
  transition: background .1s ease, border-color .1s ease;
}
.cell.free    { --c: var(--accent); cursor: pointer; }
.cell.scarce  { --c: var(--warn);   cursor: pointer; }
.cell.gone    { --c: var(--gone); }
.cell.pending { --c: var(--muted); }
/* Free is the answer the grid exists to give, so it is stated, not hinted.
   A 26% lime tint over a dark ground reads olive — neither free nor booked. */
.cell.free   { background: color-mix(in srgb, var(--c) 78%, var(--surface));
               border-color: var(--c); }
.cell.scarce { background: color-mix(in srgb, var(--c) 70%, var(--surface));
               border-color: var(--c); }
.cell.free:hover, .cell.scarce:hover {
  background: color-mix(in srgb, var(--c) 46%, var(--surface));
  border-color: var(--c);
}
/* Booked recedes: it is the default state of a busy centre and must not shout. */
.cell.gone, .cell.pending {
  background: var(--surface);
  border-color: color-mix(in srgb, var(--line) 80%, var(--surface));
}
/* Colour is never the only signal (§6.8): each state carries a distinct fill. */
.cell.gone::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: repeating-linear-gradient(45deg, transparent 0 3px,
              color-mix(in srgb, var(--gone) 32%, transparent) 3px 5px);
}
/* Colour is never the only signal (§6.8): scarce carries a dot, booked a hatch. */
.cell.scarce::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(circle at 50% 50%,
              color-mix(in srgb, var(--accent-ink) 55%, transparent) 0 2.5px, transparent 2.5px);
}
.cell.pending::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: repeating-linear-gradient(90deg, transparent 0 4px,
              color-mix(in srgb, var(--muted) 40%, transparent) 4px 5px);
}

.summary {
  padding: 11px 14px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.summary b { color: var(--ink); font-weight: 600; }

.legend { display: flex; gap: 14px; padding: 12px 18px 0; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 15px; height: 13px; border-radius: 4px; display: inline-block; position: relative; flex: none; }

/* ---------- watches ---------- */

.card {
  margin: 14px 16px 0; padding: 14px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
.watch { display: flex; align-items: flex-start; gap: 12px; }
.watch .body { flex: 1; min-width: 0; }
.watch h3 { margin: 0 0 3px; font-size: 15px; font-weight: 650; }
.watch p { margin: 0; font-size: 13px; color: var(--muted); }
.days { display: flex; gap: 5px; margin: 10px 0 0; flex-wrap: wrap; }
.day {
  width: 34px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--muted); font-size: 12px; cursor: pointer;
}
.day[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }

label.field { display: block; margin: 12px 0 0; font-size: 12px; color: var(--muted); }
label.field input, label.field select {
  width: 100%; margin-top: 5px; padding: 9px 11px; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--line);
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius-sm);
  background: var(--accent); color: var(--accent-ink); border: 0;
  font-weight: 650; cursor: pointer; width: 100%;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); font-weight: 500; }
.btn.danger { background: transparent; border: 1px solid var(--line); color: var(--warn); font-weight: 500; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ---------- empty / loading ---------- */

.empty { margin: 18px 16px; padding: 26px 18px; text-align: center; color: var(--muted); font-size: 14px; }
.empty svg { opacity: .5; margin-bottom: 10px; }
.empty b { color: var(--ink); display: block; margin-bottom: 4px; font-weight: 600; }

/* Handing the key to an installed app that a link cannot reach (iOS gives it
   its own storage sandbox, and a tapped link opens Safari instead). */
.paste { margin-top: 16px; text-align: left; }
.paste input {
  width: 100%; box-sizing: border-box; min-height: 44px; padding: 10px 12px;
  font: inherit; font-size: 16px;            /* 16px stops iOS zooming on focus */
  color: var(--ink); background: var(--raised);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.paste input::placeholder { color: var(--muted); }
.paste input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.paste .btn { width: 100%; }

.skel { background: var(--surface); border-radius: var(--radius); margin: 16px; height: 132px;
        border: 1px solid var(--line); position: relative; overflow: hidden; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--muted) 12%, transparent), transparent);
  animation: sweep 1.3s infinite;
}
@keyframes sweep { to { transform: translateX(100%); } }

/* ---------- bottom nav ---------- */

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs button {
  background: none; border: 0; cursor: pointer; color: var(--muted);
  padding: 9px 0 7px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; min-height: var(--tap);
}
nav.tabs button[aria-current="page"] { color: var(--accent); }

/* ---------- sheet ---------- */

.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51;
  background: var(--surface); border-top: 1px solid var(--line);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  max-width: 780px; margin: 0 auto; box-shadow: var(--shadow);
  animation: rise .18s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(14px); opacity: .6; } }
.sheet .handle { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 6px auto 14px; }
.sheet h3 { margin: 0 0 2px; font-size: 17px; }
.sheet .meta { color: var(--muted); font-size: 13px; margin: 0 0 16px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--raised); border: 1px solid var(--line); color: var(--ink);
  padding: 11px 16px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow);
  animation: rise .2s ease;
}

@media (prefers-reduced-motion: reduce) {
  *, *::after { animation: none !important; transition: none !important; }
}

/* Aggregate venues (Ethos) report N-of-M in one cell rather than naming courts. */
.cell.count {
  display: grid; place-items: center;
  font: 650 12px/1 system-ui; color: var(--accent-ink);
}
.cell.count::after { content: none; }
.cell.scarce.count { color: var(--accent-ink); }

/* ---------- games ---------- */
.sectionhead {
  margin: 22px 16px 2px; font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .08em;
}
.ref {
  margin: 10px 0 0; font: 600 12px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--muted); background: var(--bg); border: 1px solid var(--line);
  border-radius: 7px; padding: 8px 10px; display: inline-block;
}
.attendees { margin: 10px 0 0; font-size: 13px; color: var(--good); }

/* ---------- centre picker ---------- */
.pill.add { border-style: dashed; color: var(--accent); border-color: var(--accent); }
.sheet.tall { max-height: 82vh; display: flex; flex-direction: column; }
.sheet .search {
  width: 100%; padding: 11px 13px; margin: 4px 0 10px; border-radius: var(--radius-sm);
  background: var(--bg); border: 1px solid var(--line);
}
.centrelist { overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.centre {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 2px; border-bottom: 1px solid var(--line);
}
.centre:last-child { border-bottom: 0; }
.centre .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.centre strong { font-weight: 600; font-size: 14px; }
.centre .meta { font-size: 12px; color: var(--muted); }
.centre .pill[aria-pressed="true"] { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

/* Available to screen readers, invisible on screen. Not display:none — that is
   skipped by assistive tech as well as by sighted users (§6.8). */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
  border: 0;
}

/* ---------- offline ---------- */
.offline {
  margin: 14px 16px 0; padding: 10px 13px; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
  border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--surface));
  color: var(--ink); font-size: 13px;
}

/* ---------- update toast + venue picker in the watch form ---------- */
.toast.update { display: flex; align-items: center; gap: 10px; padding: 9px 10px 9px 16px; }
.toastbtn {
  border: 0; background: var(--accent); color: var(--accent-ink);
  font: 600 13px/1 system-ui; padding: 8px 12px; border-radius: 999px; cursor: pointer;
}
.toastbtn.ghost { background: transparent; color: var(--muted); font-weight: 500; }
.venuepick { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
label.field .hint { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ---------- alert history ---------- */
ul.alerts { list-style: none; margin: 0; padding: 0; }
ul.alerts li {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
ul.alerts li:last-child { border-bottom: 0; }
ul.alerts .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
ul.alerts strong { font-size: 14px; font-weight: 600; }
ul.alerts .meta { font-size: 12px; color: var(--muted); }
ul.alerts .acted {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 13px; flex: none;
}

/* ---------- install offer (§6.9) ---------- */
.card.install { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.sharehint {
  display: flex; align-items: center; gap: 10px; padding: 11px 13px;
  background: var(--bg); border: 1px dashed var(--line); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--ink);
}
.sharehint .shareicon {
  font-size: 17px; color: var(--accent); line-height: 1;
}

/* ---------- the hold screen (§6.4) ---------- */
.scrim.hold { background: var(--bg); opacity: .96; }
.holdscreen {
  position: fixed; inset: 0; z-index: 60; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px;
  padding: 32px 24px calc(32px + env(safe-area-inset-bottom));
  max-width: 480px; margin: 0 auto; text-align: center;
}
.holdscreen .ring {
  --frac: 1;
  width: 216px; height: 216px; border-radius: 50%; margin-bottom: 28px;
  display: grid; place-content: center; position: relative;
  background:
    conic-gradient(var(--accent) calc(var(--frac) * 360deg), transparent 0),
    radial-gradient(closest-side, var(--bg) 79%, transparent 80%);
  transition: background .9s linear;
}
.holdscreen .ringtime {
  font: 700 46px/1 system-ui; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}
.holdscreen .ringlabel { font-size: 13px; color: var(--muted); margin-top: 6px; }
.holdscreen.urgent .ring { background:
    conic-gradient(var(--warn) calc(var(--frac) * 360deg), transparent 0),
    radial-gradient(closest-side, var(--bg) 79%, transparent 80%); }
.holdscreen.urgent .ringtime { color: var(--warn); }
.holdwhere { margin-bottom: 26px; }
.holdwhere strong { font-size: 17px; font-weight: 650; display: block; }
.holdwhere .when { color: var(--muted); font-size: 14px; margin-top: 3px; }
.holdwhere .price { color: var(--accent); font-weight: 600; margin-top: 6px; }
.holdscreen .btn { max-width: 320px; }
.holdscreen .btn.ghost { margin-top: 10px; border: 0; color: var(--muted); }

/* The ring is the only real animation in the app; it earns its place. */
@media (prefers-reduced-motion: reduce) {
  .holdscreen .ring { transition: none; background: var(--surface); }
}
