:root {
    --bg: #161c3a; --bg2: #0b0f22; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f3f5ff; --muted: #bcc3e6; --accent: #91a7ff; --accent-ink: #0d1640; --field: rgba(255,255,255,.08);
    --soft: rgba(145,167,255,.15); --good: #69db7c; --good-bg: rgba(105,219,124,.13); --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #ffa8a8;
    --m1: #ff6b6b; --m2: #ff922b; --m3: #fcc419; --m4: #a9e34b; --m5: #51cf66; --face-ink: #1b1e2e; --soft-bg: rgba(252,196,25,.12);
    color-scheme: dark;
}
@media (prefers-color-scheme: light) {
    :root { --bg: #f5f7ff; --bg2: #e4e9fb; --card: #fff; --line: #d3daf3; --ink: #151a33; --muted: #4a5275;
            --accent: #4263eb; --accent-ink: #fff; --field: #f6f8ff; --soft: #e8edff; --good: #2b8a3e; --good-bg: #ebfbee; --warn: #8a5300; --warn-bg: #fff6e0; --bad: #c92a2a;
            --m1: #f03e3e; --m2: #fd7e14; --m3: #fab005; --m4: #82c91e; --m5: #37b24d; --face-ink: #1b1e2e; --soft-bg: #fff9db; color-scheme: light; }
}
:root[data-theme="light"] { --bg: #f5f7ff; --bg2: #e4e9fb; --card: #fff; --line: #d3daf3; --ink: #151a33; --muted: #4a5275;
            --accent: #4263eb; --accent-ink: #fff; --field: #f6f8ff; --soft: #e8edff; --good: #2b8a3e; --good-bg: #ebfbee; --warn: #8a5300; --warn-bg: #fff6e0; --bad: #c92a2a;
            --m1: #f03e3e; --m2: #fd7e14; --m3: #fab005; --m4: #82c91e; --m5: #37b24d; --face-ink: #1b1e2e; --soft-bg: #fff9db; color-scheme: light; }
:root[data-theme="dark"] {
    --bg: #161c3a; --bg2: #0b0f22; --card: rgba(255,255,255,.06); --line: rgba(255,255,255,.17);
    --ink: #f3f5ff; --muted: #bcc3e6; --accent: #91a7ff; --accent-ink: #0d1640; --field: rgba(255,255,255,.08);
    --soft: rgba(145,167,255,.15); --good: #69db7c; --good-bg: rgba(105,219,124,.13); --warn: #fbbf24; --warn-bg: rgba(251,191,36,.13); --bad: #ffa8a8;
    --m1: #ff6b6b; --m2: #ff922b; --m3: #fcc419; --m4: #a9e34b; --m5: #51cf66; --face-ink: #1b1e2e; --soft-bg: rgba(252,196,25,.12);
    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; }
.entry { order: 2; }
.cal { 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=time], input[type=datetime-local], select, textarea { 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; }
input[type=date], input[type=time], 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; }

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

.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.good { background: var(--good-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.2rem, 10vw, 2.8rem); font-weight: 800; color: var(--accent); line-height: 1.1; text-align: center; }
.big.muted { color: var(--muted); font-size: 1.6rem; }
.meta { margin: .5rem 0 0; text-align: center; overflow-wrap: anywhere; }
.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: 1.1rem 0 .45rem; font-size: .95rem; color: var(--muted); }
.effects { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; }
.eff { border: 1px solid var(--line); border-radius: 12px; padding: .45rem .65rem; background: var(--field); min-width: 0; }
.eff.none { color: var(--muted); font-size: .92rem; }
.eff-top { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: .1rem .6rem; }
.eff-name { font-weight: 700; overflow-wrap: anywhere; }
.eff-val { font-weight: 800; font-variant-numeric: tabular-nums; }
.eff-diff { font-weight: 800; font-variant-numeric: tabular-nums; padding: 0 .5rem; border-radius: 999px; border: 2px solid currentColor; }
.eff-diff.up { color: var(--good); } .eff-diff.down { color: var(--bad); } .eff-diff.flat, .eff-diff.few { color: var(--muted); }
.eff-main { display: block; font-size: .92rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.eff-sub { display: block; font-size: .85rem; color: var(--muted); overflow-wrap: anywhere; }

/* entry form */
.day-pick { display: grid; gap: .5rem; }
.for-line { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.for-line b { color: var(--ink); }
.day-btns { display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: .45rem; align-items: center; }
.day-btns input[type=date] { min-height: 40px; padding: .35rem .6rem; font-size: .95rem; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; margin: 0; }
.moods, .tagset { border: 0; margin: 1rem 0 0; padding: 0; min-width: 0; }
.moods legend, .tagset legend { padding: 0; margin: 0 0 .45rem; font-size: .9rem; font-weight: 600; color: var(--muted); }
.mood-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .35rem; }
.mood { display: flex; flex-direction: column; align-items: center; gap: .2rem; min-width: 0; min-height: 76px; padding: .4rem .15rem; border: 2px solid var(--line); border-radius: 14px;
        background: var(--field); color: var(--ink); font: inherit; font-size: .78rem; font-weight: 600; line-height: 1.15; cursor: pointer; text-align: center; }
.mood span { overflow-wrap: anywhere; }
.mood[aria-pressed="true"] { border-color: var(--accent); background: var(--soft); box-shadow: 0 0 0 2px var(--accent) inset; }
.face .f-bg { fill: var(--fc); } .face .f-ink { fill: var(--face-ink); } .face .f-mouth { fill: none; stroke: var(--face-ink); stroke-width: 2.6; stroke-linecap: round; }
.m1 { --fc: var(--m1); } .m2 { --fc: var(--m2); } .m3 { --fc: var(--m3); } .m4 { --fc: var(--m4); } .m5 { --fc: var(--m5); }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { min-height: 42px; max-width: 100%; padding: .3rem .8rem; border: 2px solid var(--line); border-radius: 999px; background: var(--field); color: var(--ink); font: inherit; font-size: .92rem; font-weight: 600; cursor: pointer; overflow-wrap: anywhere; text-align: left; }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.inline-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .5rem; }
.inline-row .secondary { width: auto; padding: 0 1.1rem; }
textarea { resize: vertical; min-height: 80px; line-height: 1.4; }
.entry .primary { margin-top: 1rem; min-height: 54px; font-size: 1.1rem; }
.msg.soft { background: var(--soft-bg); }
.msg.soft .msg-extra { color: var(--ink); }
.msg.good { background: var(--good-bg); }

/* calendar */
.cal-top { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .5rem; margin-bottom: .6rem; }
.cal-top h2 { margin: 0; text-align: center; }
.cal-top .secondary.small { width: 44px; padding: 0; font-size: 1.1rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: .3rem; }
.cal-w { text-align: center; font-size: .78rem; font-weight: 700; color: var(--muted); }
.cal-d { aspect-ratio: 1; min-height: 38px; min-width: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--field); color: var(--ink); font: inherit; font-size: .9rem; font-weight: 600; cursor: pointer; font-variant-numeric: tabular-nums; }
.cal-d.m1, .cal-d.m2, .cal-d.m3, .cal-d.m4, .cal-d.m5 { background: var(--fc); border-color: var(--fc); color: var(--face-ink); font-weight: 800; }
.cal-d.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.cal-d.sel { box-shadow: 0 0 0 3px var(--accent); }
.cal-d:disabled { opacity: .35; cursor: default; }
.cal-key { display: flex; flex-wrap: wrap; gap: .25rem .8rem; margin: .7rem 0 0; font-size: .82rem; color: var(--muted); }
.cal-key .k { display: inline-flex; align-items: center; gap: .3rem; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 4px; background: var(--fc); }

/* share and settings buttons */
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .5rem; margin-top: .9rem; }
.check { display: flex; align-items: center; gap: .55rem; margin: 0; color: var(--ink); font-weight: 600; cursor: pointer; min-height: 44px; }
.check input { width: 22px; height: 22px; flex: none; margin: 0; accent-color: var(--accent); }
.share .tool-grid { margin-top: .5rem; }
.tag-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.tl { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: .5rem; border: 1px solid var(--line); border-radius: 12px; padding: .3rem .4rem .3rem .65rem; background: var(--field); }
.tl.none { display: block; color: var(--muted); padding: .5rem .65rem; }
.tl-name { font-weight: 600; overflow-wrap: anywhere; }
.tl-n { font-size: .82rem; color: var(--muted); white-space: nowrap; }

/* list of days: each day in its own box */
.days { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.dy { border: 1px solid var(--line); border-left: 6px solid var(--fc); border-radius: 12px; padding: .5rem .6rem; background: var(--field); min-width: 0;
      display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: .6rem; align-items: start; }
.dy-main { min-width: 0; display: grid; gap: .15rem; }
.dy-head { display: flex; flex-wrap: wrap; align-items: center; gap: .1rem .55rem; }
.dy-date { font-weight: 700; }
.dy-mood { font-weight: 700; color: var(--muted); }
.dy-sleep { font-size: .9rem; color: var(--muted); }
.dy-tags { font-size: .9rem; overflow-wrap: anywhere; }
.dy-note { font-size: .9rem; color: var(--muted); font-style: italic; overflow-wrap: anywhere; white-space: pre-line; }
.dy-btns { display: flex; gap: .35rem; }

/* 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); }
    .day-btns { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .day-btns input[type=date] { grid-column: 1 / -1; }
    .mood { font-size: .7rem; min-height: 70px; }
    .mood svg { width: 34px; height: 34px; }
}
@media (max-width: 359px) {
    .dy { grid-template-columns: minmax(0, 1fr); }
    .dy-btns { margin-top: .4rem; }
    .dy-btns button { flex: 1; }
    .times-box .two, #times-box { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .mood-row { gap: .2rem; }
    .mood { padding: .35rem 0; }
}
@media (max-width: 360px) {
    .topbar .theme-toggle { padding: 0; width: 44px; justify-content: center; }
    .topbar .theme-toggle span { display: none; }
    .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: the day's form and settings on the left, the calendar, results and sharing on the right */
@media (min-width: 900px) {
    .app { width: min(1140px, 100%); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); 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 > .col-main { grid-column: 1; grid-row: 3; }
    .app > .col-side { grid-column: 2; grid-row: 3; }
    .app > .list { grid-row: 4; }
    .app > .faq { grid-row: 5; width: min(760px, 100%); justify-self: center; }
    .app > footer { grid-row: 6; width: min(760px, 100%); justify-self: center; }
    .app > .report { grid-row: 7; }
    .days { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: .7rem; align-items: start; }
    header h1 { font-size: 2.3rem; }
    .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .cal-d { aspect-ratio: auto; height: 44px; }
}
