:root {
  --navy: #31344d;        /* logo field, page background */
  --navy-deep: #262940;   /* sunken areas */
  --navy-line: #474b69;
  --gold: #c8bb8f;        /* crest outline, secondary accents */
  --cream: #ede5c8;       /* wing and letter fill, primary text */
  --cream-dim: #b9b39f;
  --whistle: #8fd0c4;     /* referee duty: the one colour outside the crest */
  --display: "Graduate", "Rockwell", serif;
  --body: "Barlow", system-ui, sans-serif;
  --num: "Barlow Condensed", "Barlow", system-ui, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--navy); }

body {
  margin: 0;
  color: var(--cream);
  font: 400 1.0625rem/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  padding: 0 max(1.25rem, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(1.25rem, env(safe-area-inset-left));
}

main, footer, .crest { max-width: 34rem; margin-inline: auto; }

a { color: var(--gold); text-underline-offset: 0.18em; }
a:focus-visible, summary:focus-visible { outline: 2px solid var(--whistle); outline-offset: 3px; border-radius: 4px; }

.crest { padding-top: max(1.25rem, env(safe-area-inset-top)); text-align: center; }
.crest img, .crest-anim { width: min(40vw, 12rem); height: auto; display: inline-block; }
.crest-anim svg { width: 100%; height: auto; display: block; }

h1, h2, h3 { font-family: var(--display); font-weight: 400; letter-spacing: 0.02em; margin: 0; }
h1 { font-size: clamp(1.9rem, 8vw, 2.6rem); line-height: 1.05; text-transform: lowercase; }
h1::first-letter { text-transform: uppercase; }
h2 { font-size: 1.45rem; margin-bottom: 0.35rem; }
h3 { font-size: 1.15rem; }

.loading { color: var(--cream-dim); }
.when { font: 700 1.05rem/1 var(--num); color: var(--gold); margin: 1.5rem 0 0.4rem; letter-spacing: 0.04em; }
.lead { color: var(--cream-dim); margin: 0.5rem 0 1.25rem; }
.sub { color: var(--cream-dim); margin: 0.15rem 0 0.9rem; font-size: 0.95rem; }
.muted { color: var(--cream-dim); }

section { margin-bottom: 2.75rem; }

/* ---------- the evening: time, opponent, court ---------- */
.events { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }

.event {
  display: grid;
  grid-template-columns: 4.6rem 1fr auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.8rem 0.8rem 0.8rem 1rem;
  border-radius: 14px 4px 4px 14px;
}
.event.match { background: var(--cream); color: var(--navy); }
.event.duty { border: 2px dashed var(--whistle); color: var(--cream); }

.clock { font: 700 2rem/1 var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.event.duty .clock { color: var(--whistle); }

.what p { margin: 0; }
.vs { font-weight: 600; font-size: 1.1rem; line-height: 1.25; }
.event.match .muted { color: #6b6c78; font-weight: 500; }
.meta { font-size: 0.875rem; opacity: 0.75; margin-top: 0.1rem !important; }

/* Court number drawn like a floor marking: a box with the centre line. */
.court {
  position: relative;
  width: 3.4rem; height: 3.9rem;
  border: 2px solid currentColor;
  display: grid; place-items: center; align-content: center;
  border-radius: 3px;
}
.court::before {
  content: ""; position: absolute; left: -2px; right: -2px; top: 50%;
  border-top: 2px solid currentColor; opacity: 0.35;
}
.court-word { font: 600 0.7rem/1 var(--num); letter-spacing: 0.06em; opacity: 0.7; }
.court-no { font: 700 1.75rem/1 var(--num); position: relative; background: inherit; }
.event.match .court { color: var(--navy); background: var(--cream); }
.event.duty .court { color: var(--whistle); background: var(--navy); }

.events.compact .event { padding-block: 0.55rem; }
.events.compact .clock { font-size: 1.6rem; }
.events.compact .court { height: 3.2rem; width: 3rem; }

/* ---------- whole evening ---------- */
.evening { margin-top: 0.9rem; }
.evening summary { cursor: pointer; color: var(--gold); font-weight: 500; padding: 0.4rem 0; }
.evening[open] summary { margin-bottom: 0.5rem; }
.slot h4 { font: 700 1.1rem/1 var(--num); color: var(--gold); margin: 1rem 0 0.35rem; }
.slot ul { list-style: none; margin: 0; padding: 0; font-size: 0.92rem; }
.slot li {
  display: grid; grid-template-columns: 1.6rem 1fr auto; gap: 0.6rem;
  padding: 0.35rem 0; border-bottom: 1px solid var(--navy-line);
}
.slot li .f { font: 700 1rem/1.35 var(--num); color: var(--cream-dim); text-align: right; }
.slot li .r { color: var(--cream-dim); text-align: right; }
.slot li.ours { color: var(--cream); font-weight: 600; }
.slot li.ours .f { color: var(--gold); }

/* ---------- later nights ---------- */
.night { padding-top: 1rem; }
.night + .night { border-top: 1px solid var(--navy-line); margin-top: 1.25rem; }

/* ---------- calendar ---------- */
.cal-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.cal-btn {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 2.9rem; padding: 0.5rem 0.75rem;
  font: 600 1rem/1.2 var(--body); color: var(--cream); text-decoration: none;
  background: transparent; border: 1.5px solid var(--gold); border-radius: 10px; cursor: pointer;
}
.cal-btn:hover { background: var(--navy-deep); }
.cal-btn:focus-visible { outline: 2px solid var(--whistle); outline-offset: 2px; }
#cal-apple { grid-column: 1 / -1; background: var(--gold); color: var(--navy); border-color: var(--gold); }
#cal-apple:hover { background: var(--cream); }
.cal-note { margin-top: 0.5rem; }
.cal-note:empty { display: none; }

.offline {
  max-width: 34rem; margin: 0.75rem auto 0; padding: 0.6rem 0.9rem;
  border: 1.5px solid #e8a15a; border-radius: 10px; font-size: 0.92rem;
}

/* ---------- results ---------- */
.sq {
  display: inline-grid; place-items: center; width: 1.35rem; height: 1.35rem; margin-left: 0.2rem;
  border-radius: 5px; font: 700 0.9rem/1 var(--num); font-variant-numeric: tabular-nums;
}
.sq.win { background: var(--whistle); color: #16332e; }
.sq.draw { background: var(--gold); color: var(--navy); }
.sq.loss { background: #5a5e7d; color: var(--cream); }
tr.ours .sq.loss { background: #8b8ea8; color: #fff; }
.games { white-space: nowrap; }
th.games-col, td.games-col { text-align: right; width: 1%; }
.legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin: 0.7rem 0 0; font-size: 0.85rem; color: var(--cream-dim); }
.legend .sq { margin: 0 0.25rem 0 0; vertical-align: -0.2rem; }

.night-head { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.night-pts { font: 700 1.05rem/1 var(--num); color: var(--gold); white-space: nowrap; }
.night.done { margin-top: 1.25rem; }
.night.done .events { margin-top: 0.6rem; }
.played {
  display: grid; grid-template-columns: 4.6rem 1fr auto; align-items: center; gap: 0.9rem;
  padding: 0.55rem 0.8rem 0.55rem 1rem; border-radius: 14px 4px 4px 14px;
}
.played.win { background: var(--cream); color: var(--navy); }
.played.draw { border: 2px solid var(--gold); }
.played.loss { border: 2px solid var(--navy-line); }
.played.win .muted { color: #6b6c78; }
.sets { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.2rem; font-size: 0.85rem; opacity: 0.8; }
.set-dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; }
.set-dot.w { background: #2f8f7f; }
.set-dot.d { background: var(--gold); }
.set-dot.l { background: #6d7090; }
.sets-text { margin-left: 0.2rem; }
.pts { display: grid; justify-items: center; min-width: 2.6rem; }
.pts-no { font: 700 1.9rem/1 var(--num); }
.pts-word { font-size: 0.7rem; opacity: 0.7; }

tr.group-break td {
  padding: 1rem 0.4rem 0.35rem; font: 600 0.8rem/1 var(--num); letter-spacing: 0.03em; color: var(--gold);
  border-bottom: 1px solid var(--gold);
}

/* ---------- standing ---------- */
.rank { margin: 0 0 0.75rem; font-size: 1.05rem; }
.rank-no { font: 700 2.6rem/1 var(--num); color: var(--gold); margin-right: 0.15rem; vertical-align: -0.15em; }
table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
th, td { padding: 0.5rem 0.4rem; text-align: left; border-bottom: 1px solid var(--navy-line); }
thead th { font: 600 0.85rem/1.2 var(--num); color: var(--cream-dim); letter-spacing: 0.03em; }
tbody th { font-weight: 500; }
.num { text-align: right; font-family: var(--num); font-size: 1.05rem; font-variant-numeric: tabular-nums; width: 3rem; }
td.total { font-weight: 700; }
tr.ours > * { background: var(--cream); color: var(--navy); }
tr.ours > :not(:last-child) { box-shadow: 1px 0 0 var(--cream); } /* hides hairline seams between cells */
tr.ours th, tr.ours td { border-bottom-color: transparent; font-weight: 700; }
tr.ours > :first-child { border-radius: 8px 0 0 8px; }
tr.ours > :last-child { border-radius: 0 8px 8px 0; }
.foot { font-size: 0.85rem; color: var(--cream-dim); margin-top: 0.6rem; }

footer {
  border-top: 1px solid var(--navy-line);
  padding: 1.25rem 0 2.5rem;
  font-size: 0.85rem; color: var(--cream-dim);
}
footer p { margin: 0 0 0.4rem; }

/* Small phones (iPhone SE, 320-389 px): give the opponent name the room. */
@media (max-width: 24.3rem) {
  .played { grid-template-columns: auto 1fr auto; gap: 0.65rem; padding: 0.5rem 0.6rem 0.5rem 0.75rem; }
  .sq { width: 1.15rem; height: 1.15rem; font-size: 0.8rem; margin-left: 0.12rem; }
  body { padding-left: max(0.9rem, env(safe-area-inset-left)); padding-right: max(0.9rem, env(safe-area-inset-right)); }
  .event { grid-template-columns: auto 1fr auto; gap: 0.65rem; padding: 0.7rem 0.6rem 0.7rem 0.75rem; }
  .clock, .events.compact .clock { font-size: 1.5rem; }
  .court, .events.compact .court { width: 2.6rem; height: 3rem; }
  .court-no { font-size: 1.4rem; }
  .vs { font-size: 1rem; }
  .meta { font-size: 0.8rem; }
  .slot li { grid-template-columns: 1.2rem 1fr; }
  .slot li .r { grid-column: 2; text-align: left; font-size: 0.85rem; margin-top: -0.2rem; }
}

@media (min-width: 40rem) {
  body { font-size: 1.125rem; }
  .event { grid-template-columns: 5.4rem 1fr auto; padding: 1rem 1rem 1rem 1.25rem; }
  .clock { font-size: 2.4rem; }
}

/* Desktop: tonight and our matches on the left, the standings and calendar on the right. */
@media (min-width: 64rem) {
  main, footer { max-width: 64rem; }
  main {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-rows: auto auto auto 1fr;
    column-gap: 4rem;
    align-items: start;
  }
  #next { grid-column: 1; grid-row: 1; }
  #later { grid-column: 1; grid-row: 2 / span 3; }
  #standing { grid-column: 2; grid-row: 1; margin-top: 1.5rem; }
  #agenda { grid-column: 2; grid-row: 2; }
}

/* The standing arrives: squares pop in row by row (see revealStanding in app.js). */
@media (prefers-reduced-motion: no-preference) {
  #standing.reveal-wait .sq { opacity: 0; transform: scale(0.3); }
  #standing.reveal-go .sq {
    animation: sq-pop 380ms cubic-bezier(0.2, 0.9, 0.3, 1.35) var(--d, 0ms) both;
  }
  #standing.reveal-go tr.ours > * { animation: ours-glow 900ms ease-out 200ms both; }
  @keyframes sq-pop {
    from { opacity: 0; transform: scale(0.3); }
    to { opacity: 1; transform: scale(1); }
  }
  @keyframes ours-glow {
    from { background: var(--gold); }
    to { background: var(--cream); }
  }
}
.count { font-variant-numeric: tabular-nums; }

/* The still logo waits while app.js swaps in the animation; shown again if that fails. */
@media (prefers-reduced-motion: no-preference) {
  .crest img { visibility: hidden; }
}
