:root {
    color-scheme: light dark;
    --bg: #f3f5f8;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --text: #131820;
    --muted: #596273;
    --border: #d5dbe3;
    --accent: #0b5cad;
    --accent-text: #ffffff;
    --yes-bg: #d7f2dd;
    --yes-fg: #12512a;
    --no-bg: #fbdcdc;
    --no-fg: #8a1b1b;
    --maybe-bg: #fff0c2;
    --maybe-fg: #714500;
    --highlight: #fff3a8;
    --race-bg: #fde4cf;
    --race-fg: #8a3b00;
    --cell: 3.5rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0e1218;
        --surface: #171c24;
        --surface-2: #202732;
        --text: #e8ecf2;
        --muted: #9ba5b5;
        --border: #2d3644;
        --accent: #6db3f8;
        --accent-text: #08121e;
        --yes-bg: #173823;
        --yes-fg: #8fe5a6;
        --no-bg: #3e1b1b;
        --no-fg: #ff9d9d;
        --maybe-bg: #3b2e0c;
        --maybe-fg: #ffd77e;
        --highlight: #5a4b00;
        --race-bg: #43260f;
        --race-fg: #ffb98a;
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 1rem/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }

h1, h2 { margin: 0 0 .75rem; line-height: 1.2; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.05rem; }

main { max-width: 56rem; margin: 0 auto; padding-bottom: 2rem; }

/* Top bar */

.bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .25rem .75rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; color: var(--text); text-decoration: none; }

.bar-links { display: flex; align-items: center; gap: .25rem; }
.bar-links form { margin: 0; }

.bar-links a,
.link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 .65rem;
    font: inherit;
    color: var(--accent);
    background: none;
    border: 0;
    text-decoration: none;
    cursor: pointer;
}

.bar-links a[aria-current] { font-weight: 700; text-decoration: underline; }

/* Name picker and switcher */

.who {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .3rem;
    padding: .6rem .75rem;
}

.who-label { color: var(--muted); font-size: .9rem; margin-right: .15rem; }

.who button {
    min-height: 44px;
    min-width: 44px;
    padding: 0 .6rem;
    font: inherit;
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
}

.who button[aria-current] {
    color: var(--accent-text);
    background: var(--accent);
    border-color: var(--accent);
}

.hint, .notice, .legend, .flash { margin: .5rem .75rem; }
.hint { color: var(--muted); }

.notice {
    padding: .6rem .75rem;
    background: var(--surface-2);
    border-left: 4px solid var(--accent);
    border-radius: 4px;
}

.legend { display: flex; flex-wrap: wrap; gap: .25rem .9rem; font-size: .85rem; color: var(--muted); }

.flash {
    padding: .6rem .75rem;
    color: var(--no-fg);
    background: var(--no-bg);
    border-radius: 4px;
}

/* The planning table: it scrolls inside its own box, so the header row and the
   first column stay in view in both directions. */

.table-wrap {
    overflow: auto;
    overscroll-behavior-x: contain;
    max-height: 72dvh;
    background: var(--surface);
    border-block: 1px solid var(--border);
}

.table-wrap:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }

.plan {
    width: 100%;
    min-width: 23rem;
    table-layout: fixed;
    border-collapse: separate;
    border-spacing: 0;
}

.plan th,
.plan td {
    padding: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}

.plan thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 2.75rem;
    padding: 0 .15rem;
    font-size: .85rem;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    background: var(--surface-2);
}

.plan .when,
.plan .corner { width: 6.75rem; }

.plan .when {
    position: sticky;
    left: 0;
    z-index: 1;
    padding: .35rem .25rem .35rem .5rem;
    text-align: left;
    font-weight: 400;
    background: var(--surface-2);
    box-shadow: 1px 0 0 var(--border);
}

.plan thead .corner {
    left: 0;
    z-index: 3;
    padding-left: .5rem;
    text-align: left;
    color: var(--muted);
}

.when-head { display: flex; align-items: center; justify-content: space-between; gap: .1rem; }
.when-head form { margin: 0; }

.remove {
    display: block;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    font: inherit;
    font-size: 1.15rem;
    line-height: 1;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    touch-action: manipulation;
}

.remove:hover { color: var(--no-fg); background: var(--no-bg); }
.remove:focus-visible { outline: 3px solid var(--accent); outline-offset: -2px; }

.when .tag {
    display: block;
    margin-top: .15rem;
    font-size: .72rem;
    line-height: 1.2;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.when .tag-race {
    display: inline-block;
    padding: .05rem .35rem;
    font-weight: 700;
    color: var(--race-fg);
    background: var(--race-bg);
    border-radius: 4px;
}

.plan .is-race .when { box-shadow: inset 3px 0 0 var(--race-fg), 1px 0 0 var(--border); }

.when .day { display: block; font-weight: 700; font-size: .9rem; white-space: nowrap; }
.when .time { display: block; font-size: .78rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

.plan tbody tr { scroll-margin-top: 3rem; }

.cell {
    display: block;
    width: 100%;
    height: var(--cell);
    min-height: 44px;
    padding: 0;
    font: inherit;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--muted);
    background: transparent;
    border: 0;
    border-radius: 0;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.cell:focus-visible { outline: 3px solid var(--accent); outline-offset: -3px; }
.cell:active { filter: brightness(.9); }

.cell[data-status="yes"] { color: var(--yes-fg); background: var(--yes-bg); }
.cell[data-status="no"] { color: var(--no-fg); background: var(--no-bg); }
.cell[data-status="maybe"] { color: var(--maybe-fg); background: var(--maybe-bg); }

.plan .empty { padding: 1.25rem .75rem; color: var(--muted); }

.is-highlight th,
.is-highlight td { animation: highlight 3s ease-out 2; }

@keyframes highlight {
    0%, 60% { background: var(--highlight); }
}

@media (prefers-reduced-motion: reduce) {
    .is-highlight th,
    .is-highlight td { animation: none; background: var(--highlight); }
}

/* Cards and forms */

.card {
    margin: 1rem .75rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}

.narrow { max-width: 24rem; margin-inline: auto; }

label { display: block; margin-bottom: .25rem; font-size: .9rem; color: var(--muted); }

input,
select {
    width: 100%;
    min-height: 48px;
    padding: 0 .65rem;
    font: inherit;
    font-size: 1rem; /* 16px: iOS does not zoom in on focus */
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
}

input:focus-visible,
select:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin-bottom: .75rem; }
.field.date { grid-column: 1 / -1; }
.fields.extra { grid-template-columns: 1fr 1.5fr; }

.primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    margin-top: .75rem;
    font: inherit;
    font-weight: 700;
    color: var(--accent-text);
    background: var(--accent);
    border: 0;
    border-radius: 8px;
    text-decoration: none;
    cursor: pointer;
}

.fields + .primary,
.add-slot .primary { margin-top: .25rem; }

.error { margin: .5rem 0; padding-left: 1.1rem; color: var(--no-fg); }
p.error { padding-left: 0; }

.log { margin: 0; padding: 0; list-style: none; }
.log li { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.log li:last-child { border-bottom: 0; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: .25rem; }

@media (min-width: 40rem) {
    .fields { grid-template-columns: 2fr 1fr 1fr; }
    .field.date { grid-column: auto; }
    .primary { width: auto; padding: 0 2rem; }
    .plan .when, .plan .corner { width: 9rem; }
    .fields.extra { grid-template-columns: 1fr 2fr; }
}
