/* ==========================================================
   Choreboard base styles
   The UI stays quiet and neutral so each person's colour is
   what stands out on the board.
   ========================================================== */

:root {
    --bg:        #EDF1F4;
    --surface:   #FFFFFF;
    --surface-2: #F6F8FA;
    --ink:       #22303C;
    --muted:     #687786;
    --line:      #D9E0E6;
    --primary:   #1F6F78;
    --primary-ink: #FFFFFF;
    --danger:    #B4433A;
    --ok:        #2E7D5B;
    --me:        #5B7FD6;

    --radius-lg: 22px;   /* panels */
    --radius:    14px;   /* tiles, inputs */
    --radius-sm: 9px;
    --shadow:    0 1px 2px rgba(34,48,60,.06), 0 6px 20px rgba(34,48,60,.06);

    --font-display: 'Fredoka', 'Nunito', 'Trebuchet MS', system-ui, sans-serif;
    --font-body:    'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

    color-scheme: light;
    box-sizing: border-box;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg:        #151B21;
        --surface:   #1E262E;
        --surface-2: #252F38;
        --ink:       #E5EBF0;
        --muted:     #95A3B0;
        --line:      #33404B;
        --primary:   #5FB3BC;
        --primary-ink: #0F1A1C;
        --danger:    #E2766C;
        --ok:        #6CC59B;
        --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg:        #151B21;
    --surface:   #1E262E;
    --surface-2: #252F38;
    --ink:       #E5EBF0;
    --muted:     #95A3B0;
    --line:      #33404B;
    --primary:   #5FB3BC;
    --primary-ink: #0F1A1C;
    --danger:    #E2766C;
    --ok:        #6CC59B;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    color-scheme: dark;
}

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

html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--ink);
    font: 400 1rem/1.55 var(--font-body);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

h1, h2, h3 {
    font-family: var(--font-display);
    font-weight: 600;
    line-height: 1.15;
    letter-spacing: -0.01em;
    margin: 0 0 .5em;
}
h1 { font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.2rem); }
h2 { font-size: 1.35rem; }
p  { margin: 0 0 1em; max-width: 65ch; }
a  { color: var(--primary); }
img { max-width: 100%; }

:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* ---------- Top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem clamp(1rem, 3vw, 2rem);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: env(safe-area-inset-top, 0px);
    z-index: 10;
}
.brand {
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    color: var(--ink);
    text-decoration: none;
    font: 600 1.2rem var(--font-display);
}
.mark { width: 28px; height: 28px; }

.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav a, .nav .link {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .45rem .8rem;
    border-radius: 999px;
    color: var(--ink);
    text-decoration: none;
    font: 500 .95rem var(--font-body);
}
.nav a:hover, .nav .link:hover { background: var(--surface-2); }
.dot { width: .7rem; height: .7rem; border-radius: 50%; display: inline-block; }

/* ---------- Layout ---------- */

.page {
    max-width: 1200px;
    margin: 0 auto;
    padding: clamp(1rem, 3vw, 2rem);
}
.center {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}
.panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: clamp(1.25rem, 3vw, 2rem);
}
.muted { color: var(--muted); }
form.inline { display: inline; margin: 0; }

/* ---------- Forms ---------- */

.field { display: grid; gap: .35rem; margin-bottom: 1rem; align-content: start; }
.field label { font-weight: 600; font-size: .92rem; }
.field .hint { font-size: .85rem; color: var(--muted); }

input[type=text], input[type=password], input[type=number], select, textarea {
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: var(--surface-2);
    border: 1.5px solid var(--line);
    border-radius: var(--radius);
    padding: .7rem .9rem;
    transition: border-color .15s, background .15s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background: var(--surface);
}

.check { display: flex; align-items: center; gap: .55rem; margin: .25rem 0 1.25rem; cursor: pointer; }
.check input { width: 1.15rem; height: 1.15rem; flex: none; margin: 0; accent-color: var(--primary); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .45rem;
    font: 600 1rem var(--font-body);
    padding: .75rem 1.3rem;
    border-radius: var(--radius);
    border: 0;
    cursor: pointer;
    background: var(--primary);
    color: var(--primary-ink);
    transition: filter .15s, transform .05s;
    text-decoration: none;
}
.btn:hover  { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.block  { width: 100%; }
.btn.ghost  { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: var(--danger); color: #fff; }

button.link {
    background: none;
    border: 0;
    cursor: pointer;
}

/* ---------- Messages ---------- */

.flash, .error {
    border-radius: var(--radius);
    padding: .75rem 1rem;
    margin-bottom: 1rem;
    font-weight: 500;
}
.flash-ok    { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); color: var(--ok); }
.flash-error, .error { background: color-mix(in srgb, var(--danger) 13%, var(--surface)); color: var(--danger); }

/* ---------- Login / setup card ---------- */

.auth {
    width: 100%;
    max-width: 400px;
}
.auth h1 { margin-bottom: .25rem; }
.auth .lead { color: var(--muted); margin-bottom: 1.5rem; }

/* A few sample chore tiles, as if just dropped on the board */
.tiles {
    display: flex;
    gap: .5rem;
    margin: -.25rem 0 1.5rem;
    flex-wrap: wrap;
}
.tile {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    border-radius: var(--radius);
    font: 500 .9rem var(--font-body);
    color: #fff;
    box-shadow: 0 2px 0 rgba(0,0,0,.12);
}
.tile b {
    font: 600 .8rem var(--font-display);
    background: rgba(255,255,255,.25);
    border-radius: 999px;
    padding: .05rem .45rem;
}
.tiles .tile:nth-child(1) { background: #5B7FD6; transform: rotate(-2deg); }
.tiles .tile:nth-child(2) { background: #4FA38A; transform: rotate(1.5deg); }
.tiles .tile:nth-child(3) { background: #E0796B; transform: rotate(-1deg); }

/* ---------- Admin ---------- */

.sr {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.tabs {
    display: flex;
    gap: .25rem;
    padding: .3rem;
    margin-bottom: 1.5rem;
    background: var(--surface);
    border-radius: 999px;
    box-shadow: var(--shadow);
    overflow-x: auto;
    scrollbar-width: none;
    width: fit-content;
    max-width: 100%;
}
.tabs a {
    padding: .5rem 1rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    white-space: nowrap;
}
.tabs a:hover { color: var(--ink); background: var(--surface-2); }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--bg); }

.head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}
.head h1, .head h2 { margin: 0; }
h2.section { margin-top: 2rem; }

.btn.small { padding: .45rem .85rem; font-size: .9rem; border-radius: var(--radius-sm); }
.btn.ghost:hover { background: var(--surface-2); filter: none; }

/* List rows (people, chores) */
.rows { display: grid; gap: .5rem; }
.row {
    display: grid;
    grid-template-columns: auto 1fr auto auto auto;
    align-items: center;
    gap: 1rem;
    padding: .85rem 1rem;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--ink);
    text-decoration: none;
}
a.row:hover { outline: 2px solid var(--line); }
.row.inactive { opacity: .62; }
.row .main { display: grid; min-width: 0; }
.row .main strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .stat { font-size: .9rem; white-space: nowrap; }
.row .tags { display: flex; gap: .35rem; }
.row-actions { display: flex; gap: .4rem; justify-content: flex-end; }
.rows .row:has(.order) { grid-template-columns: auto 1fr auto auto; }

.avatar {
    width: 2.5rem; height: 2.5rem;
    border-radius: 12px;
    display: grid; place-items: center;
    color: #fff;
    font: 600 .95rem var(--font-display);
}
.badge {
    font-size: .78rem;
    font-weight: 600;
    padding: .15rem .55rem;
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary) 14%, var(--surface));
    color: var(--primary);
}
.badge.off { background: var(--surface-2); color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: .35rem; font-weight: 600; }

.order { display: grid; gap: .15rem; }
.icon-btn {
    display: grid; place-items: center;
    width: 1.9rem; height: 1.5rem;
    border: 0; border-radius: 7px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: .7rem;
}
button.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.tile.neutral {
    background: var(--surface-2);
    color: var(--ink);
    box-shadow: inset 0 0 0 1.5px var(--line);
    width: fit-content;
    max-width: 100%;
}
.tile.neutral b { background: var(--line); }

/* Forms in panels */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem 2.5rem;
}
.form-narrow { max-width: 560px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend {
    font: 600 1.1rem var(--font-display);
    margin-bottom: .75rem;
    padding: 0;
}
.form-grid .actions { grid-column: 1 / -1; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: .5rem; }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.hint { display: block; font-size: .85rem; color: var(--muted); }
fieldset > .hint, fieldset > p.hint { margin-top: .6rem; }

.preview { display: grid; gap: .5rem; justify-items: start; margin: .5rem 0 1rem; }
.preview .tile { transform: none; }

.swatches { display: flex; flex-wrap: wrap; gap: .5rem; }
.swatch { position: relative; cursor: pointer; }
.swatch input[type=radio] { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.swatch span {
    display: grid; place-items: center;
    width: 2.4rem; height: 2.4rem;
    border-radius: 12px;
    background: var(--c);
    color: rgba(255,255,255,.9);
    font: 600 .85rem var(--font-display);
    transition: transform .12s;
}
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--c); transform: scale(1.05); }
.swatch input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 4px; }
.swatch.custom input[type=color] {
    width: 2.4rem; height: 2.4rem;
    padding: 0; border: 1.5px dashed var(--muted);
    border-radius: 12px;
    background: none;
    cursor: pointer;
}
.swatch.custom input[type=color]::-webkit-color-swatch-wrapper { padding: 4px; }
.swatch.custom input[type=color]::-webkit-color-swatch { border: 0; border-radius: 8px; }
.swatch.custom input[type=color]::-moz-color-swatch { border: 0; border-radius: 8px; }

/* Toggle switch */
.toggle {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .9rem;
    align-items: start;
    padding: .9rem 0;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    position: relative;
}
.toggle input { position: absolute; opacity: 0; width: 2.8rem; height: 1.6rem; margin: 0; cursor: pointer; }
.toggle .switch {
    width: 2.8rem; height: 1.6rem;
    border-radius: 999px;
    background: var(--line);
    position: relative;
    transition: background .15s;
    margin-top: .1rem;
}
.toggle .switch::after {
    content: '';
    position: absolute; top: .2rem; left: .2rem;
    width: 1.2rem; height: 1.2rem;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,.25);
    transition: transform .15s;
}
.toggle input:checked + .switch { background: var(--primary); }
.toggle input:checked + .switch::after { transform: translateX(1.2rem); }
.toggle input:focus-visible + .switch { outline: 3px solid var(--primary); outline-offset: 2px; }

.danger-zone { margin-top: 1.5rem; box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--danger) 35%, transparent); }
.danger-zone h2 { color: var(--danger); }
.row-form { display: flex; gap: .75rem; align-items: end; flex-wrap: wrap; }
.row-form .field { margin: 0; flex: 1 1 220px; }

/* Activity log */
.filters { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters select { width: auto; padding: .5rem 2rem .5rem .8rem; }
.log { list-style: none; margin: 0; padding: 0; }
ol.log.panel { padding: .5rem clamp(1.25rem, 3vw, 2rem); }
.log-day {
    font: 600 .95rem var(--font-display);
    color: var(--muted);
    padding: 1rem 0 .35rem;
}
.log-item {
    display: grid;
    grid-template-columns: 4.5rem 1fr;
    gap: .75rem;
    padding: .55rem 0;
    border-top: 1px solid var(--line);
}
.log-item time { color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; }
.log-item.removed span { color: var(--danger); }
.log-item.removed .chip { color: var(--ink); }
.pager { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 1rem; }

/* Overview */
.summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.summary a { color: var(--ink); text-decoration: none; }
.summary a:hover { outline: 2px solid var(--line); }
.summary strong { display: block; font: 600 2rem/1.1 var(--font-display); }
.getting-started { margin-bottom: 1.5rem; }
.steps { margin: 0; padding-left: 1.3rem; display: grid; gap: .4rem; }
.steps li.done a { color: var(--muted); text-decoration: line-through; }
.empty { text-align: center; display: grid; justify-items: center; gap: .5rem; }
.empty p { margin: 0 auto; }

/* ---------- Board ---------- */

.board-page .page { max-width: 1440px; }

.board-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.board-head h1 { margin: 0; }
.board-head p { margin: .2rem 0 0; }
.week-nav { display: flex; gap: .5rem; flex-wrap: wrap; }
.week-nav .btn { padding: .55rem 1rem; }

.notice {
    background: var(--surface);
    border-radius: var(--radius);
    padding: .75rem 1rem;
    box-shadow: var(--shadow);
    max-width: none;
}

.board {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.25rem;
    align-items: start;
}
.has-palette .board { grid-template-columns: 230px minmax(0, 1fr); }

/* Palette */
.palette {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.1rem;
    position: sticky;
    top: calc(env(safe-area-inset-top, 0px) + 5rem);
    max-height: calc(100vh - 6.5rem);
    overflow-y: auto;
}
.palette-title { font-size: 1.1rem; margin: 0 0 .2rem; }
.palette-hint { font-size: .85rem; color: var(--muted); margin: 0 0 .9rem; }
.palette-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.empty-palette { text-align: center; display: grid; gap: .6rem; justify-items: center; }
.empty-palette p { margin: 0; }

.pal-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .6rem .7rem;
    border: 0;
    border-radius: var(--radius);
    background: var(--c);
    color: var(--on);
    font: 500 .95rem var(--font-body);
    text-align: left;
    cursor: grab;
    box-shadow: 0 2px 0 rgba(0,0,0,.14);
    transition: transform .12s, box-shadow .12s;
    touch-action: manipulation;
}
.pal-btn:hover { transform: translateY(-1px); box-shadow: 0 3px 0 rgba(0,0,0,.14); }
.pal-btn b {
    font: 600 .82rem var(--font-display);
    background: color-mix(in srgb, var(--on) 18%, transparent);
    border-radius: 999px;
    padding: .1rem .5rem;
    flex: none;
}
.pal-btn[aria-pressed="true"] {
    outline: 3px solid var(--on);
    outline-offset: -3px;
    box-shadow: 0 0 0 3px var(--surface), 0 0 0 6px var(--c);
}
.drag-chosen .pal-btn { cursor: grabbing; }
.drag-ghost { opacity: .45; }

/* "Logging for" (admins) */
.for-whom { margin-bottom: 1rem; }
.for-whom legend { font: 600 .9rem var(--font-body); margin-bottom: .45rem; }
.people { display: flex; flex-wrap: wrap; gap: .35rem; }
.person { position: relative; cursor: pointer; }
.person input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.person span {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .3rem .7rem;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--ink);
    box-shadow: inset 0 0 0 1.5px var(--line);
}
.person span::before {
    content: '';
    width: .6rem; height: .6rem;
    border-radius: 50%;
    background: var(--c);
}
.person input:checked + span { background: var(--c); color: var(--on); box-shadow: none; }
.person input:checked + span::before { background: var(--on); opacity: .6; }
.person input:focus-visible + span { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Week grid */
.week {
    display: grid;
    grid-template-columns: repeat(7, minmax(132px, 1fr));
    gap: .6rem;
    overflow-x: auto;
    padding: 3px 3px 6px;   /* room for the today outline */
}

.day {
    container-type: inline-size;
    background: var(--surface);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: .7rem .55rem .55rem;
    min-height: 340px;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    transition: box-shadow .15s, background .15s;
}
.day.today { box-shadow: 0 0 0 2.5px var(--primary), var(--shadow); }
.day.locked { background: color-mix(in srgb, var(--surface) 55%, var(--bg)); box-shadow: none; }
.day.future .day-list { opacity: .5; }

.day-head {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "name total" "date total";
    padding: 0 .25rem;
}
.day-name { grid-area: name; font: 600 1.02rem/1.2 var(--font-display); }
.day-name .short { display: none; }
@container (max-width: 170px) {
    .day-name .long { display: none; }
    .day-name .short { display: inline; }
}
.day-date { grid-area: date; font-size: .85rem; color: var(--muted); }
.today .day-date { color: var(--primary); font-weight: 600; }
.day-total {
    grid-area: total;
    align-self: center;
    font: 600 1.25rem var(--font-display);
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}
.day-total:not(:empty)::after { content: ' p'; font-size: .8rem; font-weight: 500; }

.day-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .35rem;
    flex: 1;
    min-height: 3rem;
    border-radius: var(--radius);
}

/* A logged chore */
.entry {
    position: relative;
    background: var(--c);
    color: var(--on);
    border-radius: 12px;
    padding: .45rem .55rem .4rem;
    box-shadow: 0 2px 0 rgba(0,0,0,.13);
    display: grid;
    gap: .1rem;
}
.entry-title { font: 500 .9rem/1.25 var(--font-body); overflow-wrap: anywhere; padding-right: 1rem; }
.entry-icon { margin-right: .3rem; }
.entry-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .4rem;
    font-size: .76rem;
    opacity: .85;
}
.entry-meta b {
    font: 600 .76rem var(--font-display);
    background: color-mix(in srgb, var(--on) 18%, transparent);
    border-radius: 999px;
    padding: 0 .4rem;
}
.entry.movable { cursor: grab; }
.entry.movable:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.entry.drag-chosen { cursor: grabbing; box-shadow: 0 8px 20px rgba(0,0,0,.25); }
.entry.drag-ghost { opacity: .35; }
.entry.pending { opacity: .6; }
.entry.removing { opacity: .4; pointer-events: none; }
.entry.just-added { animation: drop-in .32s cubic-bezier(.3,1.5,.6,1); }
@keyframes drop-in { from { transform: scale(.85); opacity: .4; } to { transform: none; opacity: 1; } }

.tile-remove {
    position: absolute;
    top: .2rem; right: .2rem;
    width: 1.45rem; height: 1.45rem;
    border-radius: 50%;
    border: 0;
    background: color-mix(in srgb, var(--on) 16%, transparent);
    color: var(--on);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity .12s;
}
.entry:hover .tile-remove, .tile-remove:focus-visible { opacity: 1; }
@media (hover: none) { .tile-remove { opacity: .7; } }

/* Where a chore can go, while dragging or after tapping one */
.drop-here {
    display: none;
    border: 2px dashed var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
    color: var(--primary);
    border-radius: var(--radius);
    padding: .55rem;
    font: 600 .85rem var(--font-body);
    cursor: pointer;
}
.placing .day:not(.locked) .drop-here { display: block; }
.placing .day:not(.locked),
.dragging .day:not(.locked) { cursor: copy; background: color-mix(in srgb, var(--primary) 5%, var(--surface)); }
.dragging .day:not(.locked) .day-list { outline: 2px dashed color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
.dragging .day.locked, .placing .day.locked { opacity: .55; }

/* Toast */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(1.25rem + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 1rem;
    max-width: calc(100vw - 2rem);
    padding: .7rem .8rem .7rem 1.1rem;
    border-radius: 999px;
    background: var(--ink);
    color: var(--bg);
    box-shadow: 0 8px 30px rgba(0,0,0,.25);
    font-weight: 500;
}
.toast[hidden] { display: none; }
.toast.error { background: var(--danger); color: #fff; border-radius: var(--radius); }
.toast-action {
    border: 0;
    border-radius: 999px;
    padding: .35rem .9rem;
    background: color-mix(in srgb, var(--bg) 18%, transparent);
    color: inherit;
    font: 600 .9rem var(--font-body);
    cursor: pointer;
}

/* Medium screens: let the week scroll sideways rather than squash */
@media (max-width: 1100px) {
    .has-palette .board { grid-template-columns: 200px minmax(0, 1fr); }
}

/* Phones: days stacked, palette as a tray at the bottom */
@media (max-width: 760px) {
    .has-palette .board { grid-template-columns: 1fr; }
    .has-palette main.page { padding-bottom: 11rem; }

    .week { grid-template-columns: 1fr; overflow: visible; }
    .day { min-height: 0; padding: .7rem; }
    .day-head { grid-template-areas: "name total" "date total"; }
    .day-list { flex-direction: row; flex-wrap: wrap; min-height: 2.6rem; }
    .entry { flex: 0 1 auto; min-width: 7.5rem; }
    .day.locked:not(.today) .day-list:empty { display: none; }

    .palette {
        position: fixed;
        left: 0; right: 0; bottom: 0;
        top: auto;
        z-index: 30;
        max-height: none;
        border-radius: 22px 22px 0 0;
        padding: .75rem .75rem calc(.75rem + env(safe-area-inset-bottom, 0px));
        box-shadow: 0 -6px 24px rgba(0,0,0,.14);
        overflow: visible;
    }
    .palette-title { display: none; }
    .palette-hint { font-size: .8rem; margin-bottom: .5rem; }
    .palette-hint .hint-more { display: none; }
    .palette-list {
        display: flex;
        gap: .45rem;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        padding-bottom: .2rem;
        scrollbar-width: none;
    }
    .pal { flex: none; scroll-snap-align: start; }
    .pal-btn { width: auto; white-space: nowrap; }
    .for-whom { margin-bottom: .5rem; }
    .for-whom legend { display: none; }
    .people { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }

    .toast { bottom: calc(10rem + env(safe-area-inset-bottom, 0px)); }

    .day { scroll-margin-top: 4.5rem; }
}

/* ---------- Scoreboard (on the board) ---------- */

.board-main { display: grid; gap: 1rem; min-width: 0; }

.scoreboard {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: .9rem 1rem 1rem;
}
.sb-radio { position: absolute; opacity: 0; pointer-events: none; }
.sb-head { display: flex; align-items: center; gap: .75rem 1rem; flex-wrap: wrap; margin-bottom: .75rem; }
.sb-title { font-size: 1.1rem; margin: 0; }
.sb-tabs { display: flex; gap: .2rem; background: var(--surface-2); padding: .2rem; border-radius: 999px; }
.sb-tabs label {
    padding: .3rem .8rem;
    border-radius: 999px;
    font-size: .88rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    white-space: nowrap;
}
.sb-tabs label:hover { color: var(--ink); }
.sb-tabs .short { display: none; }
#sb-week:checked  ~ .sb-head label[for="sb-week"],
#sb-month:checked ~ .sb-head label[for="sb-month"],
#sb-year:checked  ~ .sb-head label[for="sb-year"] { background: var(--ink); color: var(--bg); }
#sb-week:focus-visible  ~ .sb-head label[for="sb-week"],
#sb-month:focus-visible ~ .sb-head label[for="sb-month"],
#sb-year:focus-visible  ~ .sb-head label[for="sb-year"] { outline: 3px solid var(--primary); outline-offset: 2px; }
.sb-more { margin-left: auto; font-size: .9rem; font-weight: 600; }

.sb-list { display: none; list-style: none; margin: 0; padding: 0; gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
#sb-week:checked  ~ .sb-panels .sb-week,
#sb-month:checked ~ .sb-panels .sb-month,
#sb-year:checked  ~ .sb-panels .sb-year { display: grid; }

.sb-row a {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "rank name points" "bar bar bar" "count count count";
    align-items: center;
    gap: .25rem .5rem;
    padding: .6rem .7rem;
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--ink);
    text-decoration: none;
    height: 100%;
}
.sb-row a:hover { box-shadow: inset 0 0 0 1.5px var(--line); }
.sb-row.me a { box-shadow: inset 0 0 0 2px var(--c); }
.sb-rank {
    grid-area: rank;
    display: grid; place-items: center;
    width: 1.5rem; height: 1.5rem;
    border-radius: 50%;
    background: var(--c);
    color: #fff;
    font: 600 .8rem var(--font-display);
    text-shadow: 0 0 2px rgba(0,0,0,.35);
}
.sb-row.lead .sb-rank { box-shadow: 0 0 0 2px var(--surface-2), 0 0 0 4px #E7B53C; }
.sb-name { grid-area: name; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-points { grid-area: points; font-size: .85rem; color: var(--muted); white-space: nowrap; }
.sb-points b { font: 600 1.25rem var(--font-display); color: var(--ink); }
.sb-bar { grid-area: bar; height: .4rem; border-radius: 999px; background: var(--line); overflow: hidden; }
.sb-bar span { display: block; height: 100%; background: var(--c); border-radius: inherit; transition: width .3s; }
.sb-count { grid-area: count; font-size: .78rem; color: var(--muted); }

/* ---------- Stats pages ---------- */

.person-title { display: flex; align-items: center; gap: .75rem; }
.avatar.big { width: 3rem; height: 3rem; font-size: 1.3rem; border-radius: 15px; }

.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.chip-link {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .4rem .85rem;
    border-radius: 999px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--ink);
    text-decoration: none;
    font-weight: 600;
    font-size: .92rem;
}
.chip-link[aria-current="page"] { background: var(--c, var(--ink)); color: var(--on, var(--bg)); }
.chip-link[aria-current="page"] .dot { background: var(--on) !important; opacity: .6; }

.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
    margin-bottom: 1.25rem;
}
.stat-card { padding: 1rem 1.1rem; display: grid; gap: .1rem; }
.stat-card .label { font-size: .85rem; font-weight: 600; color: var(--muted); }
.stat-card strong { font: 600 1.9rem/1.15 var(--font-display); }
.stat-card small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.stat-card .sub { font-size: .82rem; color: var(--muted); }

.seg { display: flex; gap: .2rem; background: var(--surface-2); padding: .2rem; border-radius: 999px; flex-wrap: wrap; }
.seg a {
    padding: .35rem .85rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
    font-size: .88rem;
    white-space: nowrap;
}
.seg a:hover { color: var(--ink); }
.seg a[aria-current="page"] { background: var(--ink); color: var(--bg); }

.chart-panel { margin-bottom: 1.25rem; }
.chart-box { position: relative; height: clamp(240px, 40vh, 380px); }
.chart-empty { padding: 2rem 0; text-align: center; margin: 0 auto; }
.as-table { margin-top: 1rem; }
.as-table summary { cursor: pointer; color: var(--muted); font-weight: 600; font-size: .9rem; }

.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .93rem; margin-top: .5rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
thead th { font-size: .82rem; color: var(--muted); font-weight: 600; }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.as-table td { text-align: right; font-variant-numeric: tabular-nums; }
.ranking a.chip { color: var(--ink); text-decoration: none; }
.ranking a.chip:hover { text-decoration: underline; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; }
.stats-grid h2 { font-size: 1.15rem; }
.top-chores { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.top-chores li { display: grid; grid-template-columns: minmax(0, 11rem) 1fr auto; gap: .75rem; align-items: center; }
.tc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.tc-bar { height: .55rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.tc-bar span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.tc-num { font-size: .85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

@media (max-width: 760px) {
    /* Scoreboard becomes a slim strip that stays at the top while scrolling the days */
    .board-page .topbar { position: static; }
    .scoreboard {
        position: sticky;
        top: env(safe-area-inset-top, 0px);
        z-index: 20;
        padding: .5rem .6rem;
        border-radius: 18px;
        min-width: 0;
        display: flex;
        align-items: center;
        gap: .5rem;
    }
    .sb-head { margin: 0; flex: none; }
    .sb-title, .sb-more { display: none; }
    .sb-tabs .long { display: none; }
    .sb-tabs .short { display: inline; }
    .sb-tabs label { padding: .3rem .55rem; font-size: .8rem; }
    .sb-panels { flex: 1; min-width: 0; }
    .sb-list { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: max-content; overflow-x: auto; scrollbar-width: none; gap: .35rem; }
    .sb-row a {
        grid-template-columns: auto auto auto;
        grid-template-areas: "rank name points";
        padding: .3rem .6rem .3rem .3rem;
        border-radius: 999px;
        gap: .4rem;
    }
    .sb-bar, .sb-count { display: none; }
    .sb-points b { font-size: 1rem; }
}

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

@media (max-width: 720px) {
    .row { grid-template-columns: auto 1fr; gap: .4rem .9rem; }
    .row .stat, .row .tags, .row-actions { grid-column: 2; }
    .row-actions { justify-content: flex-start; }
    .rows .row:has(.order) { grid-template-columns: auto 1fr; }
    .row .order { grid-row: span 3; }
}

@media (max-width: 560px) {
    .topbar { flex-wrap: wrap; }
    .nav { width: 100%; justify-content: space-between; gap: 0; }
    .nav a, .nav .link { padding: .4rem .55rem; font-size: .92rem; }
    .field-pair { grid-template-columns: 1fr; gap: 0; }
    .log-item { grid-template-columns: 3.2rem 1fr; }
    .tabs { flex-wrap: wrap; border-radius: 20px; width: 100%; }
    .tabs a { padding: .45rem .8rem; }
}
