/* =========================================================================
   The $100 Challenge — stylesheet.

   Everything is driven by four scales declared once on :root: space, radius,
   type and elevation. Nothing below hard-codes a padding, a corner or a
   shadow — if a value looks wrong it is wrong in the scale, not in the rule,
   which is what keeps two dozen components sitting on the same rhythm.

   The palette is a five-step neutral ramp (ink → surface-3) plus exactly two
   player hues and three status hues. Text colours are picked so every pairing
   in use clears WCAG AA on the surface it sits on.
   ========================================================================= */

:root {
    /* ---- neutral ramp, darkest first ---- */
    --ink: #07090e;              /* dark text for coloured fills */
    --bg: #0a0d14;               /* page */
    --surface: #10141e;          /* cards, nav */
    --surface-2: #161c29;        /* insets inside a card */
    --surface-3: #1e2534;        /* hover on an inset */

    --border: #1e2431;           /* hairline between surfaces */
    --border-strong: #2b3446;    /* a border that must be seen */

    --text: #eef1f7;
    --text-dim: #9aa4b8;         /* 6.0:1 on --surface */
    --text-faint: #6b7488;       /* decorative only, never load-bearing */

    /* ---- players ---- */
    --p1: #5c93f7;
    --p2: #e5a343;

    /* ---- status ---- */
    --ok: #3fbf8f;
    --bad: #f2586b;
    --warn: #e5a343;
    --accent: var(--p1);

    /* ---- space: a 4px base, used for every gap, margin and padding ---- */
    --s1: 4px;
    --s2: 8px;
    --s3: 12px;
    --s4: 16px;
    --s5: 20px;
    --s6: 24px;
    --s7: 32px;
    --s8: 44px;
    --s9: 64px;

    /* ---- radius ---- */
    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-xl: 18px;
    --r-full: 999px;

    /* ---- elevation ---- */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.3), 0 20px 48px rgba(0, 0, 0, 0.4);

    /* ---- type ---- */
    --display: 'Instrument Serif', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
    --ui: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial,
        sans-serif;

    --t-micro: 0.72rem;
    --t-small: 0.82rem;
    --t-body: 0.9rem;
    --t-lead: 1rem;

    --ease: cubic-bezier(0.2, 0, 0.2, 1);
    --speed: 160ms;

    /* Height of the sticky nav, so the sticky rails can clear it. */
    --nav-h: 58px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--ui);
    font-size: var(--t-body);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Every figure in this app is compared against another figure. */
    font-variant-numeric: tabular-nums;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--speed) var(--ease);
}
a:hover { text-decoration: underline; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}
button:focus-visible { outline-color: var(--text); }

.p1 { --player: var(--p1); }
.p2 { --player: var(--p2); }

/* The colour classes double as text colours wherever a name is printed. */
span.p1, td.p1, a.p1 { color: var(--p1); }
span.p2, td.p2, a.p2 { color: var(--p2); }

/* ---- shells --------------------------------------------------------- */

.wrap {
    max-width: 780px;
    margin: 0 auto;
    padding: var(--s7) var(--s5) var(--s9);
}
/* The dashboard needs room for its feed and log rails. */
.wrap-wide { max-width: 1320px; }

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

.topnav {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: var(--s6);
    padding: var(--s3) var(--s5);
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(140%) blur(12px);
    -webkit-backdrop-filter: saturate(140%) blur(12px);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.brand {
    font-family: var(--display);
    font-size: 1.4rem;
    letter-spacing: 0.01em;
    color: var(--text);
    white-space: nowrap;
}
.brand:hover { text-decoration: none; color: var(--text); }

.navlinks {
    display: flex;
    align-items: center;
    gap: var(--s1);
    flex: 1;
    flex-wrap: wrap;
}
.navlinks a {
    position: relative;
    color: var(--text-dim);
    font-size: var(--t-body);
    font-weight: 500;
    padding: var(--s2) var(--s3);
    border-radius: var(--r-sm);
    transition: color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.navlinks a:hover {
    color: var(--text);
    background: var(--surface-2);
    text-decoration: none;
}
.navlinks a.active { color: var(--text); }
/* An underline drawn as a pseudo-element keeps the link's own box — and so its
   hover fill and focus ring — the same shape as every other link's. */
.navlinks a.active::after {
    content: '';
    position: absolute;
    left: var(--s3);
    right: var(--s3);
    bottom: 2px;
    height: 2px;
    border-radius: var(--r-full);
    background: var(--accent);
}

.navuser {
    display: flex;
    align-items: center;
    gap: var(--s3);
    color: var(--text-dim);
    font-size: var(--t-small);
}
.navuser-name {
    color: var(--text-dim);
    font-weight: 500;
    padding: var(--s1) var(--s2);
    border-radius: var(--r-sm);
}
.navuser-name:hover {
    color: var(--text);
    background: var(--surface-2);
    text-decoration: none;
}

/* ---- banners -------------------------------------------------------- */

.commit-banner,
.rules-banner {
    padding: var(--s3) var(--s5);
    font-size: var(--t-body);
    line-height: 1.5;
}

.commit-banner {
    background: color-mix(in srgb, var(--warn) 12%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
    color: var(--warn);
    text-align: center;
}
.commit-banner a {
    color: var(--warn);
    font-weight: 600;
    text-decoration: underline;
}

/* The scoring notice. Dismissed per user server-side, so unlike a flash it
   stays put until it is actually closed. */
.rules-banner {
    display: flex;
    align-items: flex-start;
    gap: var(--s4);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}
.rules-banner-text {
    flex: 1;
    min-width: 0;
    max-width: 78ch;
}
.rules-banner-text strong {
    display: block;
    margin-top: var(--s2);
    color: var(--text);
}
.rules-banner-text strong:first-child { margin-top: 0; }
/* Each rule already starts its own block via the strong above it, so the <br>
   separating them would only add a stray blank line. */
.rules-banner-text br { display: none; }

.rules-banner-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1.3rem;
    line-height: 1;
    padding: var(--s1) var(--s2);
    border-radius: var(--r-sm);
    cursor: pointer;
    transition: color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.rules-banner-close:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 8%, transparent);
}

/* ---- type scale ----------------------------------------------------- */

h1 {
    font-family: var(--display);
    font-size: clamp(2rem, 1.4rem + 2.2vw, 2.75rem);
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 1.08;
    margin: 0 0 var(--s2);
}
h2 {
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.005em;
    margin: 0 0 var(--s4);
}
p { margin: 0 0 var(--s3); }
p:last-child { margin-bottom: 0; }

.muted { color: var(--text-dim); }
.small { font-size: var(--t-small); }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.page-header { margin-bottom: var(--s6); }
.page-header p { margin: 0; }
/* A section heading that follows a card needs air above it, or it reads as part
   of the card it is actually introducing the next block after. */
.card + h2,
table + h2 { margin-top: var(--s7); }

/* Uppercase micro-labels. Tracking is what makes small caps legible. */
.score-label,
.todos-title,
.rail-section-title,
.feed-day,
.hero-kicker,
.cal-head-cell,
.you-tag {
    font-size: var(--t-micro);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}

/* ---- hero (pre-season) ---------------------------------------------- */

.hero {
    text-align: center;
    padding: var(--s9) var(--s6);
}
.hero-title {
    font-family: var(--display);
    font-size: clamp(2.6rem, 1.6rem + 4vw, 4rem);
    font-weight: 400;
    letter-spacing: -0.015em;
    line-height: 1;
    margin: var(--s3) 0 var(--s4);
}
.hero-sub {
    color: var(--text-dim);
    font-size: var(--t-lead);
    max-width: 44ch;
    margin: 0 auto;
}
.hero-sub strong { color: var(--text); font-weight: 600; }

/* ---- flashes -------------------------------------------------------- */

.flashes {
    display: flex;
    flex-direction: column;
    gap: var(--s2);
    margin-bottom: var(--s5);
}
.flash {
    padding: var(--s3) var(--s4);
    border-radius: var(--r-md);
    background: var(--surface-2);
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-sm);
    font-size: var(--t-body);
}
.flash-error {
    border-color: color-mix(in srgb, var(--bad) 45%, transparent);
    background: color-mix(in srgb, var(--bad) 12%, var(--surface));
}
.flash-success {
    border-color: color-mix(in srgb, var(--ok) 42%, transparent);
    background: color-mix(in srgb, var(--ok) 10%, var(--surface));
}

/* ---- cards ---------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s6);
    margin-bottom: var(--s5);
    box-shadow: var(--shadow-sm);
}
.card:last-child { margin-bottom: 0; }

/* ---- race strip ----------------------------------------------------- */

.race { padding: var(--s6); }
.race-heads {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--s4);
    margin-bottom: var(--s3);
}
.race-name {
    font-size: var(--t-small);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--player);
}
.race-verdict {
    color: var(--text-dim);
    font-size: var(--t-small);
    text-align: center;
}
.race-track {
    height: 8px;
    border-radius: var(--r-full);
    background: var(--p2);
    overflow: hidden;
}
.race-fill {
    height: 100%;
    background: var(--player);
    border-right: 2px solid var(--surface);
    transition: width 400ms var(--ease);
}
.race-money {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--s4);
    margin-top: var(--s3);
}
.race-amount {
    font-family: var(--display);
    font-size: 1.9rem;
    line-height: 1.1;
    color: var(--player);
}
.race-amount-tied { color: var(--text-faint); }

/* ---- player cards --------------------------------------------------- */

.leaderboard {
    display: flex;
    flex-direction: column;
    gap: var(--s5);
}
.player-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s6);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}
/* A hairline of the player's colour along the top edge, rather than a thick
   left rule: it reads as a card header without eating horizontal space. */
.player-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto;
    height: 2px;
    background: linear-gradient(
        90deg,
        var(--player, var(--border-strong)),
        color-mix(in srgb, var(--player, var(--border-strong)) 15%, transparent)
    );
}

.player-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--s5);
}
.player-head h2 {
    margin: 0;
    font-family: var(--display);
    font-size: 1.7rem;
    font-weight: 400;
    letter-spacing: -0.005em;
    line-height: 1.15;
}
/* The name block takes the slack, so the score stays pinned to the right edge. */
.player-ident { flex: 1; min-width: 0; }
.player-link { color: var(--text); }
.player-link:hover { color: var(--player); text-decoration: none; }
.you-tag {
    margin-left: var(--s1);
    vertical-align: 0.25em;
    color: var(--text-faint);
}

/* `contain` inside a fixed-height frame: the whole photo is always visible, and
   both cards keep the same banner height however the source is shaped. */
.player-photo {
    display: block;
    width: 100%;
    height: 200px;
    object-fit: contain;
    border-radius: var(--r-md);
    background: var(--surface-2);
    border: 1px solid var(--border);
    margin-bottom: var(--s5);
}

.score { text-align: right; flex-shrink: 0; }
.score-num {
    font-family: var(--display);
    font-size: 3.2rem;
    line-height: 0.9;
    letter-spacing: -0.02em;
}
.score-label { display: block; margin-top: var(--s2); }

.pill {
    display: inline-block;
    font-size: var(--t-micro);
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 3px var(--s2);
    border-radius: var(--r-full);
    margin-top: var(--s2);
    border: 1px solid transparent;
}
.pill-ok {
    background: color-mix(in srgb, var(--ok) 13%, transparent);
    border-color: color-mix(in srgb, var(--ok) 28%, transparent);
    color: var(--ok);
}
.pill-warn {
    background: color-mix(in srgb, var(--warn) 13%, transparent);
    border-color: color-mix(in srgb, var(--warn) 30%, transparent);
    color: var(--warn);
}
a.pill-warn:hover {
    text-decoration: none;
    background: color-mix(in srgb, var(--warn) 22%, transparent);
}

.goal-list { margin: var(--s4) 0 0; padding-left: var(--s5); }
.goal-list li { margin-bottom: var(--s2); }
.goal-list li:last-child { margin-bottom: 0; }

/* ---- week box ------------------------------------------------------- */

.week-box {
    margin: var(--s5) 0 var(--s4);
    padding: var(--s4);
    background: var(--surface-2);
    border-radius: var(--r-md);
}
.week-box-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--s3);
    font-size: var(--t-small);
}
.week-box-row:first-child { margin-bottom: var(--s2); }
/* Only the verdict lives on this row, so it aligns to the right edge under the
   count it resolves. */
.week-box-verdict { margin-top: var(--s2); justify-content: flex-end; }

.week-verdict { font-weight: 600; font-size: var(--t-small); }
.week-perfect { color: var(--ok); }
.week-gone { color: var(--bad); }
.week-live { color: var(--warn); }

.bar {
    height: 6px;
    border-radius: var(--r-full);
    overflow: hidden;
    background: color-mix(in srgb, var(--text) 9%, transparent);
}
/* Only once the week can no longer be perfect does the unfilled part go red —
   up to that point an incomplete bar is just an unfinished week, not a loss. */
.bar-lost {
    background: repeating-linear-gradient(
        -45deg,
        color-mix(in srgb, var(--bad) 30%, transparent) 0 5px,
        color-mix(in srgb, var(--bad) 10%, transparent) 5px 10px
    );
}
.bar-secured {
    height: 100%;
    background: var(--player, var(--accent));
    border-radius: var(--r-full);
    transition: width 400ms var(--ease);
}

/* ---- components (3-state) ------------------------------------------- */

.components {
    display: flex;
    flex-direction: column;
    margin-top: var(--s4);
}
.component {
    display: flex;
    align-items: baseline;
    gap: var(--s3);
    padding: var(--s2) 0;
    font-size: var(--t-body);
    border-top: 1px solid var(--border);
}
.component:first-child { border-top: none; padding-top: 0; }
.c-mark {
    width: 14px;
    text-align: center;
    font-weight: 700;
    flex-shrink: 0;
}
.c-met .c-mark { color: var(--ok); }
.c-open .c-mark { color: var(--warn); }
.c-missed .c-mark { color: var(--bad); }
.c-missed .component-label { color: var(--text-faint); text-decoration: line-through; }
.component-label { flex: 1; min-width: 0; }
.component-count {
    color: var(--text-dim);
    font-size: var(--t-small);
    text-align: right;
}

/* ---- quick check-in ------------------------------------------------- */

.quick-checkin {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--s4);
    margin-top: var(--s4);
    padding: var(--s3) var(--s4);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    flex-wrap: wrap;
}
.quick-checkin span { font-size: var(--t-body); color: var(--text-dim); }

/* ---- week dots ------------------------------------------------------ */

.week-dots {
    display: flex;
    gap: var(--s2);
    margin-top: var(--s4);
}
.wd {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: var(--t-micro);
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-faint);
    border: 1px solid var(--border-strong);
    transition: transform var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.wd-clean { background: var(--ok); color: var(--ink); border-color: var(--ok); }
.wd-slipped { background: var(--bad); color: var(--ink); border-color: var(--bad); }
/* Elapsed but never logged: clean, so it reads green — outlined rather than
   filled to keep it distinct from a day someone actually checked in. */
.wd-assumed { background: transparent; color: var(--ok); border-color: var(--ok); }
.wd-future { opacity: 0.3; }
.wd-today { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
a.wd:hover {
    border-color: var(--accent);
    color: var(--text);
    text-decoration: none;
    transform: translateY(-1px);
}

/* ---- todos ---------------------------------------------------------- */

.todos { margin-top: var(--s5); }
.todos-title { display: block; margin-bottom: var(--s2); }
.todo {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: var(--s2);
    padding: var(--s3) var(--s4);
    margin-bottom: var(--s2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    color: var(--text);
    font-size: var(--t-body);
}
.todo:last-child { margin-bottom: 0; }
/* Todos are buttons (they scroll to the log rail) — strip the button chrome so
   they still read as the same rows. */
button.todo {
    width: 100%;
    text-align: left;
    font: inherit;
    font-size: var(--t-body);
    font-weight: 400;
    cursor: pointer;
    transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
button.todo:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    text-decoration: none;
    filter: none;
}
button.todo:active { transform: none; }
.todo-urgent {
    border-color: color-mix(in srgb, var(--bad) 55%, transparent);
    color: var(--bad);
    font-weight: 600;
}
button.todo.todo-urgent:hover { border-color: var(--bad); }

.prospect {
    margin-top: var(--s4);
    padding-left: var(--s3);
    border-left: 2px solid var(--warn);
    font-size: var(--t-body);
    color: var(--warn);
}

/* ---- streak row ----------------------------------------------------- */

.streak-row {
    display: flex;
    align-items: center;
    gap: var(--s2);
    margin-top: var(--s5);
    flex-wrap: wrap;
}
.streak {
    font-size: var(--t-micro);
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--text-dim);
    padding: var(--s1) var(--s3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-full);
}

/* ---- disclosures ---------------------------------------------------- */

details.recent { margin-top: var(--s5); }
details.recent summary,
.rail-entries > summary,
.scoring-info summary {
    cursor: pointer;
    list-style: none;
}
details.recent summary::-webkit-details-marker,
.rail-entries > summary::-webkit-details-marker,
.scoring-info summary::-webkit-details-marker { display: none; }

details.recent summary,
.rail-entries > summary {
    color: var(--text-dim);
    font-size: var(--t-small);
}
details.recent summary:hover,
.rail-entries > summary:hover { color: var(--text); }

/* A rotating caret is the only affordance these have, so it has to be drawn. */
details.recent summary::before,
.rail-entries > summary::before,
.scoring-info summary::before {
    content: '›';
    display: inline-block;
    width: 1em;
    color: var(--text-faint);
    transition: transform var(--speed) var(--ease);
}
details[open] > summary::before { transform: rotate(90deg); }

.scoring-info summary {
    font-weight: 600;
    font-size: var(--t-lead);
}
.scoring-info[open] summary { margin-bottom: var(--s4); }
.scoring-list { margin: 0; padding-left: var(--s5); }
.scoring-list li {
    margin-bottom: var(--s3);
    font-size: var(--t-body);
    color: var(--text-dim);
    max-width: 70ch;
}
.scoring-list li:last-child { margin-bottom: 0; }
.scoring-list strong { color: var(--text); }
.scoring-list em { color: var(--ok); font-style: normal; font-weight: 600; }

/* ---- tables --------------------------------------------------------- */

.table-scroll { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: var(--s3);
    font-size: var(--t-small);
}
table th,
table td {
    text-align: left;
    padding: var(--s2) var(--s3) var(--s2) 0;
    border-bottom: 1px solid var(--border);
}
table th {
    color: var(--text-dim);
    font-weight: 600;
    font-size: var(--t-micro);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
table tbody tr:last-child td { border-bottom: none; }
table td:first-child { white-space: nowrap; }

/* ---- forms ---------------------------------------------------------- */

input,
select,
button {
    font-family: inherit;
    font-size: var(--t-body);
    padding: var(--s2) var(--s3);
    border-radius: var(--r-sm);
    border: 1px solid var(--border-strong);
    background: var(--surface-2);
    color: var(--text);
    transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
input:hover,
select:hover { border-color: var(--text-faint); }
input:focus,
select:focus { border-color: var(--accent); }
/* The date picker's own icon is near-black on a dark field without this. */
input[type='date']::-webkit-calendar-picker-indicator { filter: invert(0.7); }

button {
    cursor: pointer;
    background: var(--accent);
    border: 1px solid transparent;
    color: var(--ink);
    font-weight: 600;
    padding: var(--s2) var(--s4);
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn-slip { background: var(--bad); color: var(--ink); }

.linklike {
    background: none;
    border: none;
    color: var(--text-dim);
    font-weight: 500;
    padding: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-size: var(--t-small);
    cursor: pointer;
}
.linklike:hover { color: var(--text); filter: none; }
.linklike:active { transform: none; }
.linklike.danger { color: var(--bad); }

.inline-form {
    display: flex;
    flex-direction: column;
    gap: var(--s3);
    margin-bottom: var(--s4);
}
.inline-form label,
.login-card label {
    display: flex;
    flex-direction: column;
    gap: var(--s1);
    font-size: var(--t-micro);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-dim);
}
/* The label's small caps must not be inherited by the value the user types. */
.inline-form label input,
.inline-form label select,
.login-card label input {
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
}

.nutrition-form {
    padding: var(--s4);
    background: var(--surface-2);
    border-radius: var(--r-md);
}
.form-heading strong { font-size: var(--t-lead); font-weight: 600; }
.form-heading .pill { margin-top: var(--s2); }
.button-row { display: flex; gap: var(--s3); }

.entry-actions { display: flex; gap: var(--s3); align-items: baseline; }
.edit-details summary { list-style: none; }
.edit-details summary::-webkit-details-marker { display: none; }
.edit-form {
    display: flex;
    gap: var(--s2);
    margin-top: var(--s2);
    flex-wrap: wrap;
}
.edit-form input[type='number'] { width: 72px; }
.edit-form input[type='text'] { width: 150px; }

.form-error {
    margin-top: var(--s4);
    padding: var(--s3) var(--s4);
    border-radius: var(--r-md);
    background: color-mix(in srgb, var(--bad) 12%, var(--surface));
    border: 1px solid color-mix(in srgb, var(--bad) 40%, transparent);
    color: var(--bad);
    font-size: var(--t-body);
}
.field-hint {
    margin-top: var(--s1);
    text-transform: none;
    letter-spacing: normal;
    font-weight: 400;
}

/* ---- login ---------------------------------------------------------- */

.login-card {
    max-width: 380px;
    margin: 8vh auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-xl);
    padding: var(--s7);
    text-align: center;
    box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 0 0 var(--s2); }
.login-card p { color: var(--text-dim); font-size: var(--t-small); }
.login-card form {
    display: flex;
    flex-direction: column;
    gap: var(--s4);
    margin-top: var(--s6);
    text-align: left;
}
.login-card button { margin-top: var(--s1); padding: var(--s3) var(--s4); }

/* ---- feed ----------------------------------------------------------- */

.feed { display: flex; flex-direction: column; gap: var(--s2); }
.feed-day { display: block; margin: var(--s4) 0 var(--s1); }
.feed-day:first-child { margin-top: 0; }
.feed-item {
    display: flex;
    gap: var(--s3);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 2px solid var(--player, var(--border-strong));
    border-radius: var(--r-md);
    padding: var(--s3);
}
.feed-own { background: var(--surface); }
.feed-body { min-width: 0; }
.feed-body > div:first-child { line-height: 1.45; }

/* The status mark: a dot, sized and nudged to sit on the first line's cap
   height rather than on its baseline. */
.feed-mark {
    flex-shrink: 0;
    width: 7px;
    height: 7px;
    margin-top: 0.5em;
    border-radius: 50%;
    background: var(--text-faint);
}
.feed-mark-workout { background: var(--accent); }
.feed-mark-clean { background: var(--ok); }
.feed-mark-slip { background: var(--bad); }

/* ---- calendar ------------------------------------------------------- */

.cal-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--s4);
    flex-wrap: wrap;
    margin-top: var(--s3);
}
.cal-users { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.pill-link {
    font-size: var(--t-small);
    font-weight: 500;
    color: var(--player, var(--text-dim));
}

.cal-legend {
    display: flex;
    gap: var(--s5);
    flex-wrap: wrap;
    align-items: center;
}
.cal-legend .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: var(--s1);
    vertical-align: middle;
}
.cal-dot-clean { background: var(--ok); }
.cal-dot-slipped { background: var(--bad); }
/* Matches the dashed outline .cal-unlogged puts on the day cell itself. */
.cal-dot-assumed { border: 1px dashed var(--border-strong); }

/* The card is the calendar frame: zero padding so the lattice runs edge to edge. */
.cal-card { padding: 0; overflow: hidden; }

.cal-month-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--s4) var(--s5);
    border-bottom: 1px solid var(--border);
}
.cal-month-name {
    font-family: var(--display);
    font-size: 1.6rem;
    letter-spacing: -0.005em;
}
.cal-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--r-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: var(--t-lead);
}
.cal-nav-btn:hover {
    background: var(--surface-3);
    border-color: var(--border-strong);
    text-decoration: none;
}
.cal-nav-off { opacity: 0.25; pointer-events: none; }

/* One contiguous lattice: header cells are children 1-7, so :nth-child(7n)
   strips the right border on the header's last cell and every Sunday alike. */
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.calendar-grid > *:nth-child(7n) { border-right: none; }

.cal-head-cell {
    text-align: center;
    padding: var(--s2) 0;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.cal-day {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 90px;
    padding: var(--s2);
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: inherit;
    transition: background var(--speed) var(--ease);
}
a.cal-day:hover { background: var(--surface-3); text-decoration: none; }
.cal-day.cal-outside,
.cal-day.cal-off-season { background: var(--bg); }
.cal-day.cal-outside .cal-day-num,
.cal-day.cal-off-season .cal-day-num { color: var(--text-faint); font-weight: 400; }
.cal-day.cal-today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-day.cal-nut-clean { background: color-mix(in srgb, var(--ok) 13%, var(--surface)); }
.cal-day.cal-nut-slipped { background: color-mix(in srgb, var(--bad) 13%, var(--surface)); }
a.cal-day.cal-nut-clean:hover { background: color-mix(in srgb, var(--ok) 22%, var(--surface)); }
a.cal-day.cal-nut-slipped:hover { background: color-mix(in srgb, var(--bad) 22%, var(--surface)); }
.cal-day.cal-unlogged { outline: 1px dashed var(--border-strong); outline-offset: -4px; }

/* Corner status dot — survives colour-vision deficiencies where the tint alone
   doesn't. */
.cal-day.cal-nut-clean::after,
.cal-day.cal-nut-slipped::after {
    content: '';
    position: absolute;
    top: var(--s2);
    right: var(--s2);
    width: 6px;
    height: 6px;
    border-radius: 50%;
}
.cal-day.cal-nut-clean::after { background: var(--ok); }
.cal-day.cal-nut-slipped::after { background: var(--bad); }

.cal-day-num { font-size: var(--t-small); font-weight: 600; line-height: 1.2; }
.cal-day.cal-today .cal-day-num { color: var(--accent); font-weight: 700; }

.cal-workouts {
    margin-top: auto;
    padding-top: var(--s1);
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}
.cal-workout-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 17px;
    height: 17px;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--ink);
    font-size: var(--t-micro);
    font-weight: 700;
}

/* ---- dashboard three-column layout ---------------------------------- */

/* Feed on the left, standings in the middle, log on the right. Below 1200px the
   rails fold: first the feed drops under the other two, then everything stacks
   with the log ahead of the feed, since logging is the thing you came to do. */
.dash-layout {
    display: grid;
    gap: var(--s5);
    align-items: start;
    grid-template-columns: 300px minmax(0, 1fr) 340px;
    grid-template-areas: 'feed main log';
}
.dash-main { grid-area: main; min-width: 0; }
.dash-rail-feed { grid-area: feed; }
.dash-rail-log { grid-area: log; }

.dash-rail {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: var(--s5);
    min-width: 0;
    box-shadow: var(--shadow-sm);
}
.rail-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s3);
    margin-bottom: var(--s4);
    padding-bottom: var(--s3);
    border-bottom: 1px solid var(--border);
}
.rail-head h2 {
    margin: 0;
    font-size: var(--t-micro);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-dim);
}
.rail-more { color: var(--text-dim); font-size: var(--t-small); white-space: nowrap; }
.rail-more:hover { color: var(--text); }

.rail-section {
    margin-top: var(--s5);
    padding-top: var(--s5);
    border-top: 1px solid var(--border);
}
.rail-section-title { display: block; margin-bottom: var(--s3); }

/* In the rail the forms sit directly on the panel, without a second card edge. */
.dash-rail .nutrition-form { padding: 0; background: none; }
.dash-rail .inline-form { margin-bottom: 0; }
.dash-rail .button-row { flex-wrap: wrap; }

.feed-compact { gap: var(--s1); }
.feed-compact .feed-item { padding: var(--s2) var(--s3); font-size: var(--t-small); }
.feed-compact .feed-mark { margin-top: 0.45em; }

/* ---- entry management inside the log rail ---------------------------- */

.rail-entries[open] > summary { margin-bottom: var(--s3); }
.rail-entry-list { list-style: none; margin: 0; padding: 0; }
.rail-entry {
    padding: var(--s2) 0;
    border-top: 1px solid var(--border);
    font-size: var(--t-small);
}
.rail-entry:first-child { border-top: none; }
.rail-entry-row {
    display: flex;
    align-items: baseline;
    gap: var(--s2);
    flex-wrap: wrap;
}
.rail-entry-date { color: var(--text-dim); white-space: nowrap; }
.rail-entry-label { flex: 1; min-width: 0; }
.rail-entry-actions { display: flex; gap: var(--s2); white-space: nowrap; }
.rail-entry-detail { margin-top: 2px; }
/* The rail is narrow, so the edit fields wrap rather than scroll sideways. */
.dash-rail .edit-form input[type='text'] { width: 100%; }

@media (min-width: 1200px) {
    /* Long standings shouldn't strand the rails off-screen. The nav is sticky,
       so the rails have to start below it. */
    .dash-rail {
        position: sticky;
        top: calc(var(--nav-h) + var(--s5));
        max-height: calc(100vh - var(--nav-h) - var(--s7));
        overflow-y: auto;
        overscroll-behavior: contain;
    }
}
@media (max-width: 1199px) {
    .dash-layout {
        grid-template-columns: minmax(0, 1fr) 320px;
        grid-template-areas: 'main log' 'feed feed';
    }
}
@media (max-width: 860px) {
    .dash-layout {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas: 'main' 'log' 'feed';
    }
}

/* ---- account -------------------------------------------------------- */

.account-card { max-width: 440px; }
.account-card .inline-form { margin-top: var(--s5); margin-bottom: 0; }

/* ---- responsive ----------------------------------------------------- */

@media (max-width: 720px) {
    /* Three flex children wrapping arbitrarily reads as a broken bar. Pinned to
       a two-row grid instead: identity and account on top, links underneath,
       scrolling sideways rather than stacking. */
    .topnav {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas: 'brand user' 'links links';
        gap: var(--s2) var(--s3);
        padding: var(--s3) var(--s4);
    }
    .brand { grid-area: brand; align-self: center; }
    .navuser { grid-area: user; align-self: center; }
    .navlinks {
        grid-area: links;
        flex-wrap: nowrap;
        overflow-x: auto;
        scrollbar-width: none;
        margin: 0 calc(-1 * var(--s4));
        padding: 0 var(--s4);
    }
    .navlinks::-webkit-scrollbar { display: none; }
    .navlinks a { white-space: nowrap; }
}

@media (max-width: 640px) {
    .wrap { padding: var(--s5) var(--s4) var(--s8); }
    .card,
    .player-card,
    .dash-rail,
    .race { padding: var(--s5) var(--s4); }
    .rules-banner,
    .commit-banner { padding: var(--s3) var(--s4); }
    .login-card { margin: var(--s6) auto; padding: var(--s6) var(--s5); }
    .hero { padding: var(--s7) var(--s4); }
}

@media (max-width: 480px) {
    .player-head { flex-direction: column; gap: var(--s3); }
    .score { text-align: left; }
    .score-num { font-size: 2.6rem; }
    .player-photo { height: 168px; }
    .navuser span { display: none; }
    .cal-day { min-height: 60px; padding: var(--s1); }
    .cal-head-cell { font-size: 0.6rem; letter-spacing: 0.04em; }
    .cal-month-name { font-size: 1.3rem; }
    .cal-workout-chip { width: 14px; height: 14px; font-size: 0.6rem; }
    .race-amount { font-size: 1.4rem; }
    .race-heads,
    .race-money { gap: var(--s2); }
    .week-dots { justify-content: space-between; width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
