:root {
    --bg: #221013; --bg2: #14080a; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #fff4f4; --muted: #e2bcbf; --accent: #ff7a7a; --accent-ink: #3b0b0e; --field: rgba(255,255,255,.08);
    --soft: rgba(255,122,122,.13); --good: #4ade80; --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #fda4af;
    --sys: #ff8a8a; --dia: #7cc4ff; --limit: #fbbf24;
    --l-low: #60a5fa; --l-normal: #4ade80; --l-elevated: #facc15; --l-s1: #fb923c; --l-s2: #f87171; --l-severe: #e879f9;
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #fff7f7; --bg2: #fde8e8; --card: #fff; --line: #f0d0d0; --ink: #2a1012; --muted: #6e4448;
            --accent: #c62828; --accent-ink: #fff; --field: #fff6f6; --soft: #ffe9e9; --good: #15803d; --warn: #8a5300; --warn-bg: #fff6e0; --bad: #b91c1c;
            --sys: #c62828; --dia: #1d5fa0; --limit: #b45309;
            --l-low: #2563eb; --l-normal: #15803d; --l-elevated: #a16207; --l-s1: #c2410c; --l-s2: #dc2626; --l-severe: #a21caf; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #fff7f7; --bg2: #fde8e8; --card: #fff; --line: #f0d0d0; --ink: #2a1012; --muted: #6e4448;
            --accent: #c62828; --accent-ink: #fff; --field: #fff6f6; --soft: #ffe9e9; --good: #15803d; --warn: #8a5300; --warn-bg: #fff6e0; --bad: #b91c1c;
            --sys: #c62828; --dia: #1d5fa0; --limit: #b45309;
            --l-low: #2563eb; --l-normal: #15803d; --l-elevated: #a16207; --l-s1: #c2410c; --l-s2: #dc2626; --l-severe: #a21caf; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #221013; --bg2: #14080a; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #fff4f4; --muted: #e2bcbf; --accent: #ff7a7a; --accent-ink: #3b0b0e; --field: rgba(255,255,255,.08);
    --soft: rgba(255,122,122,.13); --good: #4ade80; --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #fda4af;
    --sys: #ff8a8a; --dia: #7cc4ff; --limit: #fbbf24;
    --l-low: #60a5fa; --l-normal: #4ade80; --l-elevated: #facc15; --l-s1: #fb923c; --l-s2: #f87171; --l-severe: #e879f9;
    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; }
.people { order: 2; }
.add { order: 3; }
.summary { order: 4; }
.share { order: 5; }
.list { order: 6; }
.settings { order: 7; }
.app > .faq { order: 8; }
.app > footer { order: 9; }
.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; }
h3 { margin: 0 0 .5rem; font-size: 1rem; }
.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], input[type=datetime-local], select { 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; }
#sys, #dia { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
input[type=date], input[type=datetime-local] { -webkit-appearance: none; appearance: none; display: block; }
input[type=date]::-webkit-date-and-time-value, input[type=datetime-local]::-webkit-date-and-time-value { text-align: left; }
input[aria-invalid="true"] { border-color: var(--bad); }
select option { color: #111; background: #fff; }
input:focus-visible, button:focus-visible, select: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; }
.two .field > label:first-child { margin-top: .2rem; }
.add h2 + .two .field > label:first-child { margin-top: 0; }

/* 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; }
.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 .8rem; font-size: .9rem; }
#swap { margin-top: .6rem; }
.danger { border: 1px solid var(--bad); background: transparent; color: var(--bad); font-weight: 600; 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; }
.when-line { margin: .4rem 0 0; color: var(--muted); }
.when-line b { color: var(--ink); }
.check { display: flex; align-items: flex-start; gap: .55rem; margin: 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); }
.period .field > label { margin-top: 0; }
.check-field { margin-top: .8rem; }

.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 p:first-child { color: var(--bad); font-weight: 700; }
.msg.bad .msg-extra { color: var(--ink); font-weight: 600; }
.msg .undo { margin-left: .2rem; font-weight: 700; }

/* 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); }

/* summary */
.summary { border-color: var(--accent); }
.empty { text-align: center; padding: .6rem 0 .2rem; }
.big { margin: .6rem 0 0; font-size: clamp(2.4rem, 11vw, 3.1rem); font-weight: 800; letter-spacing: -.02em; color: var(--accent); line-height: 1.1; font-variant-numeric: tabular-nums; text-align: center; }
.big .unit { font-size: 1rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.big.muted { color: var(--muted); font-size: 1.6rem; }
.lvl { margin: .5rem auto 0; width: fit-content; max-width: 100%; padding: .3rem .85rem; border-radius: 999px; font-weight: 700; text-align: center; overflow-wrap: anywhere;
       color: var(--lc, var(--ink)); border: 2px solid var(--lc, var(--line)); }
[data-level="low"] { --lc: var(--l-low); } [data-level="normal"] { --lc: var(--l-normal); } [data-level="elevated"] { --lc: var(--l-elevated); }
[data-level="s1"] { --lc: var(--l-s1); } [data-level="s2"] { --lc: var(--l-s2); } [data-level="severe"] { --lc: var(--l-severe); }
.meta { margin: .5rem 0 0; text-align: center; overflow-wrap: anywhere; }
#skip-note { color: var(--muted); font-size: .92rem; }
.target { margin: .5rem 0 0; text-align: center; font-weight: 700; }
.target.ok { color: var(--good); } .target.no { color: var(--bad); }
.warn { margin: .8rem 0 0; padding: .6rem .75rem; border-radius: 12px; background: var(--warn-bg); color: var(--ink); font-weight: 600; border-left: 5px solid var(--l-severe); }
.tiles { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: 1rem; }
.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.35rem; 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; }
.small-h { margin: 1rem 0 .4rem; font-size: .95rem; color: var(--muted); }
.counts { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.counts li { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: center; font-size: .92rem; }
.c-name { overflow-wrap: anywhere; }
.c-n { font-weight: 800; font-variant-numeric: tabular-nums; }
.track { grid-column: 1 / -1; height: 8px; border-radius: 99px; background: var(--field); overflow: hidden; margin-top: .15rem; }
.bar { display: block; height: 100%; background: var(--lc); border-radius: 99px; }
.chart { margin: 1rem 0 0; }
.chart svg { display: block; width: 100%; height: auto; aspect-ratio: 600 / 240; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .limit { stroke: var(--limit); stroke-width: 1.5; stroke-dasharray: 6 5; }
.chart .ax { fill: var(--muted); font-size: 13px; font-family: inherit; }
.chart .pl { fill: none; stroke-width: 2.5; stroke-linejoin: round; }
.chart .pl.sys, .chart .pt.sys { stroke: var(--sys); } .chart .pt.sys { fill: var(--sys); }
.chart .pl.dia, .chart .pt.dia { stroke: var(--dia); } .chart .pt.dia { fill: var(--dia); }
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.sys { background: var(--sys); } .key.dia { background: var(--dia); }
.key.line { height: 0; border-top: 2px dashed var(--limit); }

/* 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; }

/* readings list: each day and each reading in its own box */
.day { border: 1px solid var(--line); border-radius: 14px; padding: .7rem .75rem .75rem; margin-top: .7rem; background: var(--field); }
.day:first-child { margin-top: 0; }
.day-h { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: .2rem .6rem; }
.tag { font-size: .78rem; font-weight: 700; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 0 .5rem; }
.part-h { margin: .6rem 0 .35rem; font-size: .88rem; font-weight: 700; color: var(--muted); display: flex; flex-wrap: wrap; gap: .2rem .6rem; }
.part-avg { font-weight: 600; color: var(--ink); }
.rds { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.rd { border: 1px solid var(--line); border-left: 6px solid var(--lc, var(--line)); border-radius: 12px; padding: .45rem .6rem; background: var(--card); min-width: 0;
      display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: center; }
.rd-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: .1rem .6rem; min-width: 0; }
.rd-time { color: var(--muted); font-weight: 600; font-size: .9rem; font-variant-numeric: tabular-nums; }
.rd-val { font-size: 1.2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.rd-lvl { font-size: .85rem; font-weight: 700; color: var(--lc); }
.rd-info { font-size: .88rem; color: var(--muted); }
.rd-note { flex-basis: 100%; font-size: .9rem; color: var(--muted); font-style: italic; overflow-wrap: anywhere; }
.rd-btns { display: flex; gap: .35rem; }
.rd-edit { display: block; border-left-width: 1px; outline: 3px solid var(--accent); outline-offset: 1px; }
.rd-edit label { margin: .5rem 0 .25rem; }
.rd-edit .rd-btns { 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); }
    #more-box .two, .rd-edit .two { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .day { padding: .6rem .5rem .6rem; }
    .rd-edit { padding: .45rem .55rem .6rem; }
    .rd-edit input[type=datetime-local] { font-size: 1rem; padding: .6rem .5rem; }
}
@media (max-width: 359px) {
    .rd { grid-template-columns: minmax(0, 1fr); }
    .rd-btns { margin-top: .4rem; }
    .rd-btns button { flex: 1; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    #sys, #dia { font-size: 1.3rem; }
    .field > label .lt { display: block; }
}

/* printing: only the report with the summary and the table */
@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 .r-big { font-size: 14pt; font-weight: 700; }
    .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 settings on the left, the average, sharing and the list on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); 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 > .people { grid-row: 3; justify-self: center; width: min(560px, 100%); }
    .app > .col-main { grid-column: 1; grid-row: 4; }
    .app > .col-side { grid-column: 2; grid-row: 4; }
    .app > .list { grid-row: 5; }
    .app > .faq { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 7; width: min(760px, 100%); justify-self: center; }
    .app > .report { grid-row: 8; }
    #days { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: .8rem; align-items: start; }
    .day, .day:first-child { margin-top: 0; }
    header h1 { font-size: 2.3rem; }
    .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
