:root {
  --bg: #131b1e;
  --surface: #1e282a;
  --surface-2: #172123;
  --line: #323d41;
  --text: #e9efee;
  --muted: #99a4a8;
  --teal: #31575a;
  --teal-text: #c6d8dc;
  --gold: #e6b64a;
  --gold-text: #2a1f00;
  --green: #5cc08a;
  --orange: #f0923a;
  --radius: 10px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
}
body {
  margin: 0;
  font:
    15px/1.35 system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
button,
input {
  font: inherit;
  color: inherit;
}
input,
textarea {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}
button {
  cursor: pointer;
}
button:disabled {
  cursor: default;
}

.ic {
  width: 20px;
  height: 20px;
  flex: none;
  vertical-align: middle;
}
.spin {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
.muted {
  color: var(--muted);
}
.small {
  font-size: 13px;
}
[hidden]:not(option) {
  display: none !important;
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 14px 12px 28px;
}

/* ---- buttons ---- */
.btn {
  display: inline-grid;
  place-items: center;
  min-width: 40px;
  height: 36px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--surface);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.btn:active:not(:disabled) {
  background: var(--surface);
}
.btn:disabled {
  color: #5d6467;
}
.btn.text {
  font-size: 14px;
  font-weight: 600;
  padding: 0 12px;
}

/* ---- header ---- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.day-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.day-nav .btn {
  width: 34px;
  min-width: 0;
  height: 36px;
  padding: 0;
}
.day-label {
  position: relative;
  min-width: 92px;
  height: 36px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  cursor: pointer;
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
}
.day-label.past {
  color: var(--gold);
}
.day-label input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  border: 0;
  padding: 0;
  cursor: pointer;
}
.day-label input::-webkit-calendar-picker-indicator {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}
.actions {
  display: flex;
  gap: 8px;
}
.actions .btn {
  width: 40px;
  height: 36px;
  padding: 0;
}
.actions .btn.on {
  color: var(--gold);
  border-color: var(--gold);
}
.meal {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
}
.meal-text {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.meal-link {
  color: inherit;
  text-decoration: none;
}
.meal .btn {
  width: 40px;
  height: 36px;
  padding: 0;
  flex: none;
}
.meal .btn .ic {
  width: 16px;
  height: 16px;
}
/* ---- match card: a racquetball court, front wall on the right ---- */
.match {
  background: var(--teal);
  border-radius: 12px;
  margin-top: 12px;
  padding: 12px 10px 14px;
}
.match:has(.court-floor) {
  background: var(--teal);
  /* 120% of the original 88px court. */
  height: calc(88px * 1.2);
  padding: 0;
  border: 3px solid #d6453d;
  overflow: hidden;
}
.court-floor {
  position: relative;
  height: 100%;
}
.ball,
.ball-trail {
  position: absolute;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  pointer-events: none;
}
.ball-trail {
  z-index: 2;
  background: #2eba62;
}
.ball-trail.a {
  opacity: 0.32;
}
.ball-trail.b {
  opacity: 0.18;
}
.ball-trail.c {
  opacity: 0.08;
}
.ball {
  z-index: 3;
  background: radial-gradient(circle at 32% 30%, #c5ecd3, #2eba62 42%, #134d29 78%);
  box-shadow:
    inset -1px -1.5px 2px rgba(19, 77, 41, 0.55),
    0 1px 2px rgba(0, 0, 0, 0.35);
  left: 22%;
  top: 30%;
}
@media (prefers-reduced-motion: reduce) {
  .ball-trail {
    display: none;
  }
}
.court-line,
.box-line {
  position: absolute;
  background: #d6453d;
  z-index: 0;
}
.court-line {
  top: 0;
  bottom: 0;
  width: 2px;
}
.court-line.service {
  left: 62.5%;
}
.court-line.short {
  left: 50%;
}
.court-line.receive {
  left: 37.5%;
  width: 0;
  background: none;
  border-left: 2px dotted #d6453d;
}
.box-line {
  left: 50%;
  width: 12.5%;
  height: 2px;
}
.box-line.a {
  top: 11%;
}
.box-line.b {
  top: 20%;
}
.box-line.c {
  bottom: 11%;
}
.box-line.d {
  bottom: 20%;
}
.teams {
  position: absolute;
  inset: 0;
  display: grid;
  align-items: center;
  z-index: 1;
}
.teams[data-sides='2'] {
  grid-template-columns: 37.5% 25% 37.5%;
  grid-template-rows: 1fr;
}
/* Both sides share the one row. Column 3 is placed first, and without an
   explicit row the other side wraps underneath and gets clipped. */
.teams[data-sides='2'] .team:nth-child(1) {
  grid-column: 3;
  grid-row: 1;
}
.teams[data-sides='2'] .team:nth-child(2) {
  grid-column: 1;
  grid-row: 1;
  flex-direction: row-reverse;
}
.teams[data-sides='3'] {
  /* The dotted line is the right edge of the left section. Center the stack there. */
  left: 18.75%;
  right: auto;
  width: max-content;
  max-width: calc(37.5% - 8px);
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 2px;
}
.team {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}
.team-names {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
}
.name {
  border: 0;
  background: none;
  padding: 0 6px;
  border-radius: 8px;
  font-size: 25px;
  font-weight: 700;
  line-height: 1.12;
  color: #fff;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name.sel {
  background: rgba(214, 69, 61, 0.14);
  box-shadow: 0 0 0 2px var(--gold);
}
.win {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--gold);
}
.win .ic {
  width: 26px;
  height: 26px;
}
.win:active {
  filter: brightness(0.9);
}
.teams[data-sides='3'] .name {
  font-size: 20px;
  padding: 0 2px;
}
.teams[data-sides='3'] .team {
  flex-direction: row-reverse;
  justify-content: flex-start;
  gap: 4px;
  max-width: 100%;
}
.teams[data-sides='3'] .win {
  width: 30px;
  height: 30px;
}
.teams[data-sides='3'] .win .ic {
  width: 22px;
  height: 22px;
}
.empty {
  text-align: center;
  color: var(--teal-text);
  margin: 18px 0;
}

/* ---- out row ---- */
.out-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  margin: 6px 0 10px;
}
.out-row:empty {
  display: none;
}
.out-row:empty + .players {
  margin-top: 14px;
}
.out-label {
  color: var(--muted);
}
.name.pill,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding: 3px 11px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
}
.name.pill.sel {
  box-shadow: 0 0 0 2px var(--gold);
  background: var(--surface);
}
.hint {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  text-align: right;
}
.warn {
  color: var(--gold);
}

/* ---- today's players: name and sit-out cup on one row ---- */
.players {
  display: flex;
  gap: 2px;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 4px;
}
.pchip {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.pchip-line {
  display: flex;
  align-items: center;
  gap: 4px;
}
.pchip .mark {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  font-size: 22px;
  line-height: 1;
  text-align: center;
}
.pchip .mark:empty {
  display: none;
}
.pchip .pname {
  border: 0;
  background: none;
  padding: 4px 1px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.pchip.away .pname {
  color: var(--muted);
}
.pchip .sit {
  width: 22px;
  min-width: 22px;
  height: 22px;
  padding: 0;
  flex: none;
  color: var(--muted);
  border-color: var(--line);
}
.pchip .sit .ic {
  width: 16px;
  height: 16px;
}
.pchip .sit.on {
  color: var(--gold);
}
.pchip.away .sit {
  opacity: 0.35;
}

/* ---- stats ---- */
.stats-sec {
  margin-top: 18px;
}
.stats-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.seg {
  display: flex;
  gap: 6px;
}
.seg .btn {
  height: 34px;
}
.seg .btn.on {
  background: var(--teal);
  border-color: var(--teal);
}
.period {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}
.period .btn {
  width: 34px;
  min-width: 0;
  height: 34px;
  padding: 0;
  border-color: var(--line);
}
#periodLabel {
  font-weight: 700;
  min-width: 72px;
  text-align: center;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

table.stats {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-variant-numeric: tabular-nums;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
.stats th,
.stats td {
  text-align: right;
  padding: 6px 10px;
  cursor: pointer;
}
.stats th {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
}
.stats th .sort-dir {
  margin-left: 4px;
  color: var(--text);
  font-weight: 700;
}
.stats th[aria-sort='ascending'],
.stats th[aria-sort='descending'] {
  color: var(--text);
}
.stats th:hover,
.stats td:hover {
  background: rgba(255, 255, 255, 0.04);
}
.stats td {
  border-top: 1px solid var(--line);
}
.stats th:first-child,
.stats td:first-child {
  text-align: left;
}
.stats td:first-child {
  font-weight: 600;
}
p.stats.empty {
  margin: 0;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.note {
  margin: 6px 2px 0;
  font-size: 12px;
  color: var(--muted);
}
.note:empty {
  display: none;
}
.btn.sm {
  width: 30px;
  min-width: 0;
  height: 28px;
  padding: 0;
  border-color: var(--line);
  color: var(--muted);
}
.btn.sm .ic {
  width: 15px;
  height: 15px;
}

.days {
  margin-top: 10px;
  display: grid;
  gap: 6px;
}
.day {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.day.viewing {
  border-color: var(--gold);
}
.day summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-height: 40px;
  padding: 6px 6px 8px 10px;
  font-size: 13px;
}
.standings {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 2px 12px;
  padding-left: 17px;
  color: var(--muted);
}
.standings b {
  color: var(--text);
  font-weight: 600;
}
.standings span {
  white-space: nowrap;
}
.standings .pts {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.day summary::-webkit-details-marker {
  display: none;
}
.day summary::before {
  content: '▶';
  font-size: 9px;
  color: var(--muted);
  transition: transform 0.15s;
}
.day[open] summary::before {
  transform: rotate(90deg);
}
.day-title {
  font-weight: 700;
  font-size: 14px;
}
.results {
  list-style: none;
  margin: 0;
  padding: 0 6px 4px 10px;
  font-size: 13px;
}
.results li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 0;
  border-top: 1px solid var(--line);
}
.results li b {
  color: var(--muted);
  font-weight: 600;
  min-width: 18px;
}
.results .res {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.results .res-line {
  min-width: 0;
}
.results time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.results .w {
  font-weight: 700;
}
.results .delta {
  font-weight: 600;
}
.results .delta.up {
  color: var(--green);
}
.results .delta.down {
  color: var(--orange);
}
.legacy {
  margin: 0;
  padding: 4px 10px 8px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

/* ---- toast ---- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 20;
  background: #0b1113;
  color: #fff;
  border: 1px solid var(--line);
  padding: 8px 10px 8px 14px;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  font-size: 14px;
  width: max-content;
  max-width: 92vw;
}
.toast .ic {
  width: 16px;
  height: 16px;
}
.toast button {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  border: 0;
  border-radius: 8px;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

dialog.ask {
  width: min(320px, calc(100vw - 32px));
  margin: auto;
  padding: 18px 16px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text);
}
dialog.ask p {
  margin: 0 0 16px;
  font-weight: 700;
  text-align: center;
}
dialog.ask p.ask-q {
  font-weight: 500;
}
dialog.ask strong {
  font-weight: 800;
}
dialog.ask .ask-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
dialog.sheet {
  width: min(560px, 100vw);
  max-height: 88vh;
  overflow: auto;
  margin: auto auto 0;
  padding: 12px 14px 20px;
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  background: var(--bg);
  color: var(--text);
}
@media (min-width: 600px) {
  dialog.sheet {
    margin: auto;
    border-radius: 16px;
  }
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.meal-hint,
.meal-taken {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}
.meal-who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 700;
}
.meal-who select,
.meal-item select {
  min-width: 64px;
  height: 36px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0 8px;
  font: inherit;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.meal-item select:disabled {
  opacity: 0.45;
}
#mealList.roster {
  flex-direction: column;
  flex-wrap: nowrap;
  gap: 0;
}
.meal-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 4px 0;
  border-top: 1px solid var(--line);
}
.meal-item .meal-name {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 700;
}
.meal-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  padding: 0;
  text-align: left;
}
.meal-avg {
  flex: none;
  color: var(--muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.roster .x {
  display: grid;
  place-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 2px;
}
.roster .x .ic {
  width: 15px;
  height: 15px;
}
.row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-top: 6px;
}
.row input,
#placeForm input {
  flex: 1;
  min-width: 0;
  width: 100%;
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}
.place-suggest {
  margin-top: 8px;
  max-height: 50vh;
  overflow: auto;
}
.place-suggest button {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  border-top: 1px solid var(--line);
  background: transparent;
  color: inherit;
  padding: 10px 2px;
  font: inherit;
}
.place-suggest .place-name {
  font-weight: 700;
}
.place-suggest .place-addr {
  color: var(--muted);
  font-size: 13px;
}
details.small {
  margin-top: 10px;
}
details ol {
  padding-left: 18px;
  margin: 6px 0;
}
code {
  font-size: 12px;
  background: var(--surface);
  padding: 0 3px;
  border-radius: 4px;
}
