:root {
    --bg: #0d211c; --bg2: #071411; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #effcf7; --muted: #b5d6cb; --accent: #3fdcae; --accent-ink: #062a20; --field: rgba(255,255,255,.08);
    --soft: rgba(63,220,174,.14); --good: #63e6be; --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #fda4af;
    --dot: #9fb8b0; --avg: #3fdcae; --goal: #fbbf24; --up: #fdba74; --down: #63e6be;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f2fbf8; --bg2: #dff3ec; --card: #fff; --line: #c9e5da; --ink: #0d2a22; --muted: #46655b;
            --accent: #087f5b; --accent-ink: #fff; --field: #f4fbf8; --soft: #e1f7ef; --good: #087f5b; --warn: #8a5300; --warn-bg: #fff6e0; --bad: #b91c1c;
            --dot: #7d978f; --avg: #0b8a63; --goal: #b45309; --up: #c2410c; --down: #087f5b; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f2fbf8; --bg2: #dff3ec; --card: #fff; --line: #c9e5da; --ink: #0d2a22; --muted: #46655b;
            --accent: #087f5b; --accent-ink: #fff; --field: #f4fbf8; --soft: #e1f7ef; --good: #087f5b; --warn: #8a5300; --warn-bg: #fff6e0; --bad: #b91c1c;
            --dot: #7d978f; --avg: #0b8a63; --goal: #b45309; --up: #c2410c; --down: #087f5b; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #0d211c; --bg2: #071411; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #effcf7; --muted: #b5d6cb; --accent: #3fdcae; --accent-ink: #062a20; --field: rgba(255,255,255,.08);
    --soft: rgba(63,220,174,.14); --good: #63e6be; --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #fda4af;
    --dot: #9fb8b0; --avg: #3fdcae; --goal: #fbbf24; --up: #fdba74; --down: #63e6be;
    color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; padding: clamp(1rem,4vw,2.5rem) 1rem 4rem; display: flex; justify-content: center;
       font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--ink);
       background: var(--bg2) linear-gradient(180deg, var(--bg), var(--bg2) 900px) no-repeat; touch-action: manipulation; }
.app { width: min(560px, 100%); min-width: 0; display: flex; flex-direction: column; }
.col-side, .col-main { display: contents; }
.app > .topbar, .app > .back { order: 0; }
.app > header { order: 1; }
.store-warn { order: 2; }
.people { order: 2; }
.add { order: 3; }
.summary { order: 4; }
.goalset { order: 5; }
.share { order: 6; }
.list { order: 7; }
.settings { order: 8; }
.app > .faq { order: 9; }
.app > footer { order: 10; }
.report { display: none; }
header { text-align: center; margin-bottom: 1.1rem; }
h1 { margin: 0; font-size: 1.8rem; line-height: 1.2; letter-spacing: -.02em; }
.sub { margin: .4rem 0 0; color: var(--muted); font-size: 1rem; }
h2 { margin: 0 0 .7rem; font-size: 1.15rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 1.1rem; margin-bottom: .9rem; min-width: 0; }
label { display: block; margin: .9rem 0 .35rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
.lt { font-weight: 500; }
input[type=text], input[type=date] { width: 100%; min-width: 0; min-height: 48px; padding: .6rem .8rem; font: inherit; font-size: 1.05rem; color: var(--ink);
       background: var(--field); border: 1px solid var(--line); border-radius: 12px; }
#w, #w-st, #w-lb { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
input[type=date] { -webkit-appearance: none; appearance: none; display: block; }
input[type=date]::-webkit-date-and-time-value { text-align: left; }
input[aria-invalid="true"] { border-color: var(--bad); }
input:focus-visible, button:focus-visible, summary:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
::placeholder { color: var(--muted); opacity: .75; }
.hint { margin: .45rem 0 0; color: var(--muted); font-size: .88rem; }
.hint.top { margin: 0 0 .6rem; }
[hidden] { display: none !important; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .7rem; }
.field { min-width: 0; }

/* unit switches */
.units { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .35rem; padding: .25rem; border: 1px solid var(--line); border-radius: 14px; background: var(--field); }
.units.small { grid-template-columns: repeat(2, minmax(0, 1fr)); margin-top: .7rem; }
.unit-btn, .h-btn, .r-btn { min-height: 44px; padding: 0 .5rem; border: 0; border-radius: 10px; background: transparent; color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.unit-btn[aria-pressed="true"], .h-btn[aria-pressed="true"], .r-btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.add .units + .field > label, .add .units + .two label { margin-top: .8rem; }

/* buttons */
.primary, .secondary, .danger { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: .5rem .8rem; border-radius: 12px;
       font: inherit; font-weight: 700; text-align: center; text-decoration: none; cursor: pointer; line-height: 1.2; min-width: 0; overflow-wrap: anywhere; }
.primary { border: 0; background: var(--accent); color: var(--accent-ink); }
.add .primary { margin-top: 1rem; min-height: 54px; font-size: 1.1rem; }
.secondary { border: 1px solid var(--line); background: var(--field); color: var(--ink); font-weight: 600; }
.secondary.small, .primary.small { width: auto; min-height: 40px; padding: 0 .9rem; font-size: .92rem; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; }
.settings > .danger { margin-top: .7rem; }
.link { display: block; min-height: 44px; margin-top: .3rem; padding: 0 .1rem; border: 0; background: none; color: var(--accent); font: inherit; font-size: .95rem; font-weight: 600; text-align: left; cursor: pointer; }
.link.inline { display: inline; min-height: 0; margin: 0; padding: .55rem .2rem; text-decoration: underline; }
button:disabled, a[aria-disabled="true"] { opacity: .45; cursor: default; }
a[aria-disabled="true"] { pointer-events: none; }
.when-line { margin: .5rem 0 0; color: var(--muted); }
.when-line b { color: var(--ink); }
.check { display: flex; align-items: flex-start; gap: .55rem; margin: .9rem 0 0; color: var(--ink); font-weight: 600; cursor: pointer; line-height: 1.35; }
.check input { width: 22px; height: 22px; flex: none; margin: .05rem 0 0; accent-color: var(--accent); }
.check .lt { color: var(--muted); }

.err { margin: .4rem 0 0; color: var(--bad); font-weight: 600; font-size: .92rem; overflow-wrap: anywhere; }
.err:empty { margin: 0; }
.msg { margin: 0; color: var(--muted); font-size: .95rem; overflow-wrap: anywhere; }
.msg.show { margin-top: .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--soft); color: var(--ink); }
.msg p { margin: 0; }
.msg .msg-extra { margin-top: .35rem; color: var(--muted); }
.msg.bad { background: var(--warn-bg); }
.msg.bad .msg-extra { color: var(--ink); font-weight: 600; }
.msg .undo { margin-left: .2rem; font-weight: 700; color: var(--accent); }
.warn { padding: .7rem .85rem; border-radius: 12px; background: var(--warn-bg); color: var(--ink); border-left: 5px solid var(--warn); margin-bottom: .9rem; }

/* people */
.people { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .9rem; }
.person { flex: 1 1 8rem; min-width: 0; min-height: 48px; padding: .35rem .8rem; border: 2px solid var(--line); border-radius: 14px; background: var(--card); color: var(--ink);
       font: inherit; font-weight: 700; cursor: pointer; overflow-wrap: anywhere; }
.person[aria-pressed="true"] { border-color: var(--accent); background: var(--soft); }

/* progress */
.summary { border-color: var(--accent); }
.empty { text-align: center; padding: .6rem 0 .2rem; }
.big-label { margin: 0; text-align: center; color: var(--muted); font-weight: 600; font-size: .95rem; }
.big { margin: .1rem 0 0; font-size: clamp(2.3rem, 11vw, 3rem); font-weight: 800; letter-spacing: -.02em; color: var(--accent); line-height: 1.1; font-variant-numeric: tabular-nums; text-align: center; overflow-wrap: anywhere; }
.big.muted { color: var(--muted); font-size: 1.6rem; }
.meta { margin: .45rem 0 0; text-align: center; color: var(--muted); font-size: .92rem; overflow-wrap: anywhere; }
.goalbox { margin-top: .9rem; padding: .75rem .9rem; border-radius: 14px; background: var(--soft); border: 2px solid var(--accent); overflow-wrap: anywhere; }
.goalbox.warnbox { background: var(--warn-bg); border-color: var(--warn); }
.goalbox.ok { border-style: solid; }
.g-main { margin: 0; font-weight: 800; font-size: 1.12rem; line-height: 1.3; }
.g-sub { margin: .3rem 0 0; color: var(--muted); font-size: .93rem; }
.g-target { margin: .5rem 0 0; padding-top: .5rem; border-top: 1px solid var(--line); font-weight: 700; font-size: .95rem; }
.g-target.late { color: var(--bad); }
.goalbox .secondary.small { margin-top: .6rem; }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .9rem; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: .5rem .65rem; background: var(--field); min-width: 0; display: flex; flex-direction: column; }
.t-label { font-size: .8rem; font-weight: 600; color: var(--muted); line-height: 1.2; }
.t-val { font-size: 1.25rem; font-weight: 800; line-height: 1.25; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.t-sub { font-size: .8rem; color: var(--muted); line-height: 1.25; overflow-wrap: anywhere; }
.note-fast { margin-top: .8rem; padding: .6rem .75rem; border-radius: 12px; background: var(--warn-bg); border-left: 5px solid var(--warn); font-size: .92rem; font-weight: 600; }
.chart-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem .8rem; margin-top: 1rem; }
.small-h { margin: 0; font-size: .95rem; color: var(--muted); }
.ranges { display: grid; grid-template-columns: repeat(4, auto); gap: .25rem; padding: .2rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field); }
.r-btn { min-height: 38px; padding: 0 .6rem; font-size: .88rem; }
.chart { margin: .6rem 0 0; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .ax { fill: var(--muted); font-size: 12px; font-family: inherit; }
.chart .unit-ax { font-weight: 700; }
.chart .pt { fill: var(--dot); opacity: .85; }
.chart .avg-l { fill: none; stroke: var(--avg); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }
.chart .avg-pt { fill: var(--avg); }
.chart .goal-l { stroke: var(--goal); stroke-width: 2; stroke-dasharray: 7 5; }
figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .4rem; margin-top: .4rem; font-size: .85rem; color: var(--muted); }
.key { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-left: .3rem; }
.key:first-child { margin-left: 0; }
.key.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); }
.key.line { background: var(--avg); }
.key.goal { height: 0; border-top: 2px dashed var(--goal); }

/* share and settings buttons */
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .9rem; }
.share .tool-grid { margin-top: 0; }

/* weigh-ins: each one in its own box */
.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.entry { border: 1px solid var(--line); border-radius: 12px; padding: .55rem .7rem; background: var(--field); min-width: 0;
         display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: center; }
.entry.editing { display: block; outline: 3px solid var(--accent); outline-offset: 1px; }
.e-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .7rem; min-width: 0; }
.e-date { flex-basis: 100%; color: var(--muted); font-weight: 600; font-size: .88rem; }
.e-w { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.e-ch { font-size: .9rem; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.e-ch.down { color: var(--down); } .e-ch.up { color: var(--up); }
.e-note { flex-basis: 100%; font-size: .9rem; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.e-btns { display: flex; gap: .35rem; }
.e-edit label { margin: .5rem 0 .25rem; }
.e-edit .e-btns { margin-top: .7rem; }
.more-btn { margin-top: .7rem; }

/* questions */
.faq { margin-top: 1.2rem; }
.faq details { border: 1px solid var(--line); border-radius: 12px; margin: 0 0 .5rem; background: var(--card); }
.faq summary { cursor: pointer; padding: .75rem .9rem; font-weight: 600; min-height: 44px; }
.faq details p { margin: 0; padding: 0 .9rem .8rem; color: var(--muted); }
footer { margin-top: 1.4rem; text-align: center; font-size: .9rem; }
footer a { color: var(--muted); }

.back { display: inline-flex; align-items: center; gap: .4rem; min-height: 44px; margin: 0 0 .5rem; padding: 0 1rem 0 .8rem; border: 1px solid var(--line, rgba(127,127,127,.4)); border-radius: 999px; color: var(--muted, var(--mut, inherit)); font-size: .92rem; font-weight: 600; text-decoration: none; background: transparent; }
.back:hover { color: var(--ink, inherit); border-color: currentColor; }
.back:focus-visible { outline: 3px solid var(--accent, var(--acc, #fff)); outline-offset: 2px; }

/* narrow phones */
@media (max-width: 400px) {
    .tool-grid { grid-template-columns: minmax(0, 1fr); }
    .card { padding: 1rem .85rem; }
    .entry { padding: .5rem .55rem; }
    .chart-head { flex-direction: column; align-items: stretch; }
    .ranges { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .r-btn { padding: 0 .2rem; }
}
@media (max-width: 359px) {
    .entry { grid-template-columns: minmax(0, 1fr); }
    .e-btns { margin-top: .4rem; }
    .e-btns button { flex: 1; }
    .tiles { grid-template-columns: minmax(0, 1fr); }
    .unit-btn { font-size: .92rem; padding: 0 .2rem; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
}

/* printing: only the report */
@media print {
    body { background: #fff; color: #000; padding: 0; display: block; font-size: 11pt; }
    .app > *:not(.report) { display: none !important; }
    .app { display: block; width: 100%; }
    .report { display: block !important; }
    .report h2 { font-size: 16pt; margin: 0 0 .3rem; }
    .report p { margin: .1rem 0; }
    .report table { width: 100%; border-collapse: collapse; margin-top: .6rem; font-size: 9.5pt; }
    .report th, .report td { border: 1px solid #999; padding: 2px 5px; text-align: left; }
    .report thead { display: table-header-group; }
    .report tr { break-inside: avoid; }
    .report .r-foot { margin-top: .4rem; font-size: 9pt; color: #333; }
}

/* laptops and desktops: adding and the goal on the left, progress and sharing on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); column-gap: 1.5rem; align-items: start; }
    .app > * { grid-column: 1 / -1; }
    .col-main, .col-side { display: block; min-width: 0; }
    .app > .topbar { grid-row: 1; }
    .app > header { grid-row: 2; }
    .app > .store-warn { grid-row: 3; }
    .app > .people { grid-row: 4; justify-self: center; width: min(560px, 100%); }
    .app > .col-main { grid-column: 1; grid-row: 5; }
    .app > .col-side { grid-column: 2; grid-row: 5; }
    .app > .list { grid-row: 6; }
    .app > .settings { grid-row: 7; }
    .app > .faq { grid-row: 8; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 9; width: min(760px, 100%); justify-self: center; }
    .app > .report { grid-row: 10; }
    .entries { grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: .6rem; align-items: start; }
    .settings .tool-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    header h1 { font-size: 2.3rem; }
    .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
