:root {
    --bg: #fff7ed;
    --card: #fff;
    --text: #1e1b4b;
    --muted: #625d85;
    --line: #ece4f7;
    --primary: #7c3aed;
    --link: #6d28d9;
    --ok: #15803d;
    --ok-deep: #14532d;
    --warn: #d97706;
    --danger: #dc2626;
    --sun: #fde047;
    /* Amounts as text: the button colours are too dark to read on the dark card. */
    --ok-text: var(--ok);
    --danger-text: var(--danger);
    --shadow: 0 .25rem .75rem #4c1d951a;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1e1b4b;
        --card: #2e2a66;
        --text: #f5f3ff;
        --muted: #c4bfe6;
        --line: #48428a;
        --link: #c4b5fd;
        --ok-text: #4ade80;
        --danger-text: #fca5a5;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom));
    background: var(--bg);
    color: var(--text);
    font: 1.125rem/1.5 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: calc(1rem + env(safe-area-inset-top)) 1rem 1rem;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    border-radius: 0 0 1.5rem 1.5rem;
    color: #fff;
}

h1 { margin: 0; font-size: 1.5rem; }
h2 { margin: 0 0 .25rem; font-size: 1.1875rem; }
h3 { margin: 1rem 0 .5rem; font-size: 1rem; }
p { margin: 0 0 .5rem; }
a { color: var(--link); }

main { max-width: 46rem; margin: 0 auto; padding: 1rem; }

.who { display: flex; align-items: center; margin: 0; }
.bell { position: relative; display: inline-flex; align-items: center; justify-content: center; min-width: 2.75rem; min-height: 2.75rem; margin-left: .25rem; border-radius: 50%; font-size: 1.5rem; text-decoration: none; }
.bell[aria-current] { background: #ffffff33; }
.bell .badge { position: absolute; top: 0; right: -.25rem; }
.dot { display: inline-block; width: 1rem; height: 1rem; margin-right: .375rem; border-radius: 50%; border: 2px solid #fff; vertical-align: -.1em; }

.card, .task {
    display: block;
    margin-bottom: .875rem;
    padding: 1rem 1.125rem;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 1.25rem;
    box-shadow: var(--shadow);
}
.narrow { max-width: 24rem; margin-inline: auto; }
.scroll { overflow-x: auto; padding: .5rem; }
.muted { color: var(--muted); }
.flash { padding: .75rem 1rem; background: #fef3c7; color: #78350f; border-radius: 1.25rem; font-weight: 600; }
.hello h2 { font-size: 1.5rem; }
.hello p:last-child { margin: 0; }

.task {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-left: .625rem solid var(--primary);
    color: inherit;
    text-decoration: none;
}
.task { flex-wrap: wrap; }
.task > div { flex: 1 1 9rem; min-width: 0; }
.task .count { white-space: nowrap; }
.task.pending { border-left-color: var(--warn); }
.task.approved { border-left-color: var(--ok); opacity: .75; }
.task form { margin: 0; }
/* The reason field drops onto its own line rather than shrinking to a few letters in a narrow tile. */
.task .row > input { flex-basis: 8rem; }
/* Two buttons do not fit beside the text on a phone: the row then wraps under it. */
.task > .actions { display: flex; flex: none; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; margin-left: auto; max-width: 100%; }
/* The free times only matter when a parent has to approve. */
label:has(input[name="needs_approval"]:not(:checked)) + .free-times { display: none; }
.meta { margin: 0; color: var(--muted); font-size: 1rem; }
.reward, .badge {
    display: inline-block;
    padding: 0 .625rem;
    border-radius: 1rem;
    background: var(--sun);
    color: #713f12;
    font-weight: 700;
}
.badge { background: var(--danger); color: #fff; font-size: .75rem; }
.tick { color: var(--ok-text); font-size: 2.5rem; }
.balance { font-size: 1.1875rem; }
.balance strong, .amount { font-size: 1.625rem; }
.plus { color: var(--ok-text); }
.minus { color: var(--danger-text); }

label { display: block; margin-bottom: .75rem; font-weight: 600; }
label.inline { display: inline-flex; align-items: center; gap: .375rem; margin-right: 1rem; font-weight: 400; }
/* min-width: a fieldset is otherwise as wide as its widest child and pushes the form off a phone screen. */
fieldset { min-width: 0; margin: 0 0 .75rem; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: .75rem; }
fieldset label.inline { flex-wrap: wrap; max-width: 100%; }
fieldset label.inline select { flex: 1 1 10rem; min-width: 0; }
.row { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem; }
.row > * { flex: 1; }
.row > button { flex: 0 0 auto; }

input, select, textarea {
    display: block;
    width: 100%;
    min-height: 3rem;
    margin-top: .25rem;
    padding: .5rem .75rem;
    border: 2px solid var(--line);
    border-radius: .75rem;
    background: var(--bg);
    color: inherit;
    font: inherit;
}
input[type=checkbox], input[type=radio] { display: inline-block; width: 1.25rem; min-height: 1.25rem; margin: 0; }
input[type=color] { width: 4rem; padding: .25rem; }
.code { font-size: 2rem; letter-spacing: .5rem; text-align: center; }

button, .button {
    display: inline-block;
    min-height: 3rem;
    padding: .5rem 1.25rem;
    border: 0;
    border-radius: 1.5rem;
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}
button.check {
    min-width: 6.5rem;
    min-height: 4rem;
    background: var(--ok);
    box-shadow: 0 .3125rem 0 var(--ok-deep);
    font-size: 1.25rem;
}
button.check:active { box-shadow: 0 .0625rem 0 var(--ok-deep); transform: translateY(.25rem); }
button.secondary { background: transparent; color: var(--link); border: 2px solid currentColor; }
button.danger { background: var(--danger); }
.leftover { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem 1rem; padding: .625rem 0; border-top: 1px solid var(--line); }
.leftover > div { flex: 1 1 9rem; min-width: 0; }
.leftover .meta { display: block; }
.leftover form { margin: 0; }
.leftover .link { min-height: 2.75rem; color: var(--muted); }
.leftovers[open] > summary { margin-bottom: .5rem; }
button.small { min-height: 2.75rem; padding: .25rem 1rem; font-size: 1rem; }
.early { display: flex; flex-wrap: wrap; align-items: center; gap: .25rem 1rem; margin-top: .375rem; }
.early:empty { display: none; }
.early form { margin: 0; }
.early .link { min-height: 2.75rem; color: var(--muted); }
button.link { min-height: 0; padding: 0; background: none; color: inherit; font-weight: 400; text-decoration: underline; }
:focus-visible { outline: 3px solid var(--warn); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
    button { transition: transform .08s, box-shadow .08s; }
    button:active { transform: scale(.96); }
}

summary { cursor: pointer; font-weight: 600; }
details[open] > summary { margin-bottom: .75rem; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
tr:last-child > td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.narrow-only { display: none; }
/* On a phone a table with class "stack" reads as a list: the name with one line under it, the amount on the right. */
@media (max-width: 40rem) {
    .narrow-only { display: block; }
    .wide-only { display: none; }
    small.narrow-only { color: var(--muted); font-size: .9375rem; font-weight: 400; }
    .stack thead { display: none; }
    .stack tr { display: flex; align-items: baseline; justify-content: space-between; gap: .75rem; padding: .625rem .5rem; border-bottom: 1px solid var(--line); }
    .stack tr:last-child { border-bottom: 0; }
    .stack td { padding: 0; border: 0; }
    .stack td:first-child, .stack td.wide-only + td:not(.num) { min-width: 0; }
}

nav {
    position: fixed;
    inset: auto 0 0;
    display: flex;
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card);
    border-top: 1px solid var(--line);
    border-radius: 1.25rem 1.25rem 0 0;
    box-shadow: 0 -.25rem .75rem #4c1d951a;
}
nav a, nav button {
    position: relative;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    padding: .5rem .25rem .625rem;
    border-radius: 0;
    background: none;
    color: var(--muted);
    font-size: .875rem;
    font-weight: 400;
    text-align: center;
    text-decoration: none;
    white-space: nowrap;
}
nav a > span:first-child, nav button > span:first-child { display: block; font-size: 1.625rem; line-height: 1.3; }
nav a[aria-current], nav .current, nav [aria-expanded=true] { color: var(--link); font-weight: 700; box-shadow: inset 0 4px var(--primary); }
nav .badge { position: absolute; top: .25rem; left: 50%; margin-left: .375rem; }
.more { display: contents; }
.more form { display: contents; }
.more-button { display: none; }

/* Phone and tablet in portrait: what a parent needs now and then sits behind "Meer".
   js/app.js puts the panel above the bar, on the side its button is on. */
@media (max-width: 56.24rem) {
    .more-button { display: block; }
    .more {
        display: none;
        position: fixed;
        min-width: 14rem;
        overflow: hidden;
        background: var(--card);
        border: 1px solid var(--line);
        border-radius: 1.25rem 1.25rem 0 0;
        box-shadow: 0 -.25rem .75rem #4c1d951a;
    }
    .more.open { display: block; }
    .more a, .more button {
        display: flex;
        align-items: center;
        gap: .75rem;
        width: 100%;
        min-height: 3.25rem;
        padding: .5rem 1.125rem;
        border-top: 1px solid var(--line);
        font-size: 1.0625rem;
        text-align: left;
    }
    .more a:first-child { border-top: 0; }
    .more a > span:first-child, .more button > span:first-child { display: inline; font-size: 1.375rem; line-height: 1; }
    .more a[aria-current] { box-shadow: inset 4px 0 var(--primary); }
}

.actions { display: flex; flex: 0 0 auto !important; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: .5rem; }
.task .link { min-height: 2.75rem; color: var(--muted); }
.figures { display: flex; flex-wrap: wrap; gap: 1.5rem; margin: .5rem 0 1rem; }
.figures dt { color: var(--muted); font-size: .9375rem; }
.figures dd { margin: 0; font-size: 1.5rem; font-weight: 700; }
meter, progress { display: block; width: 100%; height: 1rem; margin-top: .25rem; accent-color: var(--ok); }
main > h2 { margin: 1.25rem 0 .5rem; }
.group { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.group small { color: var(--muted); font-size: 1rem; font-weight: 400; white-space: nowrap; }
.group .dot { border-color: var(--line); }

/* Agenda: one block per day. On a wide screen the days run in columns. */
.days > section > h2 { margin: 1.25rem 0 .5rem; }

/* Landscape tablet and wider: use the width. Cards become tiles in two or three columns;
   headings, the greeting and long lists keep the full width. */
@media (min-width: 60rem) {
    main {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(22rem, 1fr));
        column-gap: .875rem;
        align-items: start;
        max-width: 80rem;
    }
    main > * { grid-column: 1 / -1; }
    main > :is(.task, details.card:not(.leftovers), section.card:not(.hello), form.card:has(> h2)) { grid-column: auto; }
    .days { columns: 20rem; column-gap: .875rem; }
    .days > section { break-inside: avoid; }
    .days > section > h2 { margin-top: 0; padding-top: 1.25rem; }
    /* The task form: title, who and repeat on the left, the rest on the right. */
    form.card:has(> fieldset) { display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: dense; column-gap: 2rem; align-items: start; }
    form.card:has(> fieldset) > * { grid-column: 1; }
    form.card:has(> fieldset) > fieldset { grid-row: span 4; }
    form.card:has(> fieldset) > fieldset ~ * { grid-column: 2; }
}

/* A landscape tablet is short (about 520 px on a Galaxy Tab A11): a lower header and tab bar. */
@media (orientation: landscape) and (max-height: 40rem) {
    header { padding-top: calc(.5rem + env(safe-area-inset-top)); padding-bottom: .5rem; }
    nav a, nav button { padding: .375rem .25rem; }
    nav a > span:first-child, nav button > span:first-child { font-size: 1.375rem; line-height: 1.15; }
    body { padding-bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
    /* A child's bar has four buttons: room for the icon beside the label. A parent's nine do not fit that way. */
    nav:not(:has(.more-button)) :is(a, button) { display: flex; align-items: center; justify-content: center; gap: .5rem; min-height: 2.75rem; padding-block: 0; }
    nav:not(:has(.more-button)) :is(a, button) > span:first-child { display: inline; line-height: 1; }
    body:has(nav:not(:has(.more-button))) { padding-bottom: calc(3.5rem + env(safe-area-inset-bottom)); }
}
