:root {
  color-scheme: light dark;
  --bg: #f2f4f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #5b6577;
  --line: #dfe4ec;
  --accent: #0b6bcb;
  --accent-text: #ffffff;
  --ok-bg: #e7f6ec;
  --ok-text: #14602f;
  --bad-bg: #fdecec;
  --bad-text: #9b1c1c;
  --warn-bg: #fff5d9;
  --warn-text: #7a5200;
  --pick: #e6f1fd;
  /* The notch / Dynamic Island, the home indicator and the rounded corners in landscape. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #141d2e;
    --text: #e8edf5;
    --muted: #9aa7bb;
    --line: #26324a;
    --accent: #4aa3f5;
    --accent-text: #06121f;
    --ok-bg: #10321d;
    --ok-text: #8fe0aa;
    --bad-bg: #3a1616;
    --bad-text: #ffb1b1;
    --warn-bg: #3a2e0c;
    --warn-text: #ffd97a;
    --pick: #17304d;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* No double-tap zoom and no 300 ms wait before a tap counts; pinch zoom still works. */
  touch-action: manipulation;
  background: var(--bg);
}
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: calc(14px + var(--safe-top)) calc(14px + var(--safe-right)) calc(28px + var(--safe-bottom)) calc(14px + var(--safe-left));
}

h1 { font-size: 22px; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 13px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
p { margin: 0 0 10px; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; min-height: 44px; }
.top h2 { margin: 0; }
.who { color: var(--muted); font-size: 15px; display: flex; align-items: center; gap: 4px; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.muted { color: var(--muted); font-size: 15px; }

label { display: block; font-size: 15px; color: var(--muted); margin: 14px 0 6px; }
label:first-child { margin-top: 0; }
input, select, button { font: inherit; color: inherit; margin: 0; }
/* 17px on every field: below 16px iOS zooms the page in when a field takes focus. */
input[type=text], input[type=password], input[type=date], select {
  display: block;
  width: 100%;
  min-width: 0;
  height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background-color: var(--bg);
  font-size: 17px;
  -webkit-appearance: none;
  appearance: none;
}
select {
  padding-right: 40px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 21px) 50%, calc(100% - 15px) 50%;
  background-size: 6px 6px;
  background-repeat: no-repeat;
  text-overflow: ellipsis;
}
/* iOS centres a date field's text and lets an empty one collapse. */
input[type=date] { text-align: left; line-height: 48px; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
select:disabled, input:disabled { opacity: .55; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  min-height: 50px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  font-weight: 500;
  -webkit-user-select: none;
  user-select: none;
  -webkit-appearance: none;
  appearance: none;
}
button:active:not(:disabled) { opacity: .7; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.wide { width: 100%; margin-top: 18px; }
button.link { border: 0; background: none; color: var(--accent); min-height: 44px; padding: 0 8px; font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
.card.alt button.wide { margin-top: 0; }
textarea.line {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background-color: var(--bg);
  color: inherit;
  font: 13px/1.4 ui-monospace, Menlo, Consolas, monospace;
  overflow-wrap: anywhere;
  resize: none;
}
.row { display: flex; gap: 10px; margin-top: 16px; }
.row > * { flex: 1; }

.note { padding: 14px; border-radius: 12px; margin-bottom: 14px; font-size: 16px; overflow-wrap: anywhere; }
.note.ok { background: var(--ok-bg); color: var(--ok-text); }
.note.bad { background: var(--bad-bg); color: var(--bad-text); }
.note.warn { background: var(--warn-bg); color: var(--warn-text); }


.form { max-width: 520px; margin-left: auto; margin-right: auto; }
.form .field + .field { margin-top: 14px; }
.field { min-width: 0; }
.field.go { display: flex; align-items: flex-end; }
.field.go button { margin-top: 0; }
.form .field.go { margin-top: 18px; }
/* Above an open day the pickers sit side by side, so another brand or date is one tap away. */
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding: 14px 16px; }
@media (min-width: 760px) { .filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 190px 130px; } }
.hint { margin: 6px 0 0; font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
@media (min-width: 560px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 980px) { .stats { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
.stat { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px; min-width: 0; }
.stat.done { border-left-color: var(--ok-text); }
.stat.hold { border-left-color: var(--warn-text); }
.stat span { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.stat b { display: block; font-size: 19px; line-height: 1.25; margin-top: 4px; overflow-wrap: anywhere; }
.stat small { display: block; font-size: 13px; color: var(--muted); margin-top: 2px; }

/* One line per player. On a phone the grid slides sideways inside its card; the page itself never does. */
.grid { margin: 0 -16px -16px; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 0 0 15px 15px; }
table { width: 100%; border-collapse: collapse; font-size: 15px; font-variant-numeric: tabular-nums; }
th, td { padding: 0 12px; height: 48px; text-align: left; white-space: nowrap; border-top: 1px solid var(--line); }
th { background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
th.r, td.r { text-align: right; }
th.c, td.c { width: 48px; padding: 0 0 0 16px; }
th.n, td.n { color: var(--muted); padding-right: 4px; }
td .muted { font-size: 13px; }
tr.pick { cursor: pointer; }
tr.on td { background: var(--pick); }
table input[type=checkbox] { display: block; width: 22px; height: 22px; margin: 0; accent-color: var(--accent); }

.check { display: flex; align-items: center; gap: 12px; min-height: 44px; margin: 14px 0 0; font-size: 16px; color: var(--text); }
.check input { width: 24px; height: 24px; flex: none; accent-color: var(--accent); }

/* Stays above the home indicator while the list scrolls under it. */
.bar {
  position: -webkit-sticky; position: sticky; bottom: 0; z-index: 2;
  margin: 0 calc(-14px - var(--safe-right)) calc(-28px - var(--safe-bottom)) calc(-14px - var(--safe-left));
  padding: 12px calc(14px + var(--safe-right)) calc(12px + var(--safe-bottom)) calc(14px + var(--safe-left));
  background: var(--card);
  border-top: 1px solid var(--line);
}
.bar button.wide { margin-top: 0; }
.bar .note { margin-bottom: 10px; }

dialog {
  border: 1px solid var(--line); border-radius: 18px; background: var(--card); color: var(--text);
  padding: 20px; width: min(92vw, 440px); max-height: 85dvh; overflow: auto;
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h1 { margin-bottom: 12px; }
.code { letter-spacing: .3em; text-align: center; font-size: 24px !important; font-variant-numeric: tabular-nums; }

/* On a phone a question comes up from the bottom, where the thumb is. */
@media (max-width: 600px) {
  dialog {
    width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; border-width: 1px 0 0;
    padding: 22px calc(18px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  }
}
@media (prefers-reduced-motion: no-preference) {
  dialog[open] { animation: rise .18s ease-out; }
  @keyframes rise { from { transform: translateY(16px); opacity: 0; } }
}

.cb { position: relative; min-width: 0; }
.cb select { display: none; }
input.cb-input {
  padding-right: 40px; text-overflow: ellipsis;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 21px) 50%, calc(100% - 15px) 50%;
  background-size: 6px 6px; background-repeat: no-repeat;
}
.cb-list {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: 4px; list-style: none; max-height: 280px; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
}
.cb-list[hidden] { display: none; }
.cb-list li { padding: 11px 12px; border-radius: 8px; cursor: pointer; overflow-wrap: anywhere; }
.cb-list li.on { font-weight: 600; }
.cb-list li.active, .cb-list li:hover { background: var(--pick); }
.cb-list li.none { color: var(--muted); cursor: default; }
.cb-list li.none:hover { background: none; }

.narrow { max-width: 400px; margin: 0 auto; }
@media (min-width: 760px) { .narrow { margin-top: 8vh; } }

/* With a mouse the thumb-sized fields and buttons a phone needs only look oversized. */
@media (hover: hover) and (pointer: fine) and (min-width: 760px) {
  body { font-size: 15px; }
  h1 { font-size: 20px; }
  input[type=text], input[type=password], input[type=date], select { height: 40px; font-size: 15px; border-radius: 10px; }
  input[type=date] { line-height: 38px; }
  button { min-height: 40px; border-radius: 10px; }
  button.link { min-height: 32px; }
  label, .muted, .who { font-size: 14px; }
  .note { padding: 10px 12px; font-size: 14px; }
  .code { font-size: 20px !important; }
  .card { padding: 18px; border-radius: 14px; }
  .grid { margin: 0 -18px -18px; }
  th, td { height: 40px; font-size: 14px; }
  th { font-size: 12px; }
  .form { max-width: 440px; }
}

/* On a wide screen a site id needs a short field, not a full row. */
@media (min-width: 700px) { #site { max-width: 240px; } }
