/* Mood -- modern, calm, one accent. Light tokens on :root; dark via
   [data-theme=dark] or (no explicit light) prefers-color-scheme. No inline styles
   anywhere: data-driven values arrive as classes or CSSOM custom properties. */
:root {
  --bg: #f6f6f4; --card: #ffffff; --line: #e3e3de; --ink: #1b1b1f; --ink-2: #4a4a52; --dim: #6c6c75;
  --accent: #4f46e5; --accent-ink: #ffffff; --accent-soft: #eceafc;
  --field: #f1f1ee; --danger: #b42318; --warn: #8a5a00;
  --shadow: 0 1px 2px rgba(20,20,30,.06), 0 4px 16px rgba(20,20,30,.05);
  --c-sleep: #2a78d6; --c-t: #6250d6; --c-sex: #e87ba4; --c-z: #1baf7a; --c-cool: #eb6834; --c-neutral: #8d8d97;
  --m1: #cdeee6; --m2: #7fd1bf; --m3: #2aa88c; --m4: #0e6b57;
  --on-m1: #12362e; --on-m2: #0b2e27; --on-m3: #ffffff; --on-m4: #ffffff; --m0: #e9e9e5;
  --cool-ink: #b8430f;
  --r: 14px; --tap: 48px;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-theme="dark"] {
  --bg: #121214; --card: #1b1b1f; --line: #2c2c33; --ink: #f1f1f4; --ink-2: #c4c4cc; --dim: #9a9aa5;
  --accent: #8b85f0; --accent-ink: #14132b; --accent-soft: #26244a;
  --field: #232328; --danger: #ff8a7a; --warn: #e6b45a;
  --shadow: 0 1px 2px rgba(0,0,0,.4);
  --c-sleep: #3987e5; --c-t: #9085e9; --c-sex: #d55181; --c-z: #199e70; --c-cool: #d95926; --c-neutral: #7c7c88;
  --m1: #1b4a40; --m2: #237a66; --m3: #3fb597; --m4: #9fe3cf;
  --on-m1: #d6f3ea; --on-m2: #ffffff; --on-m3: #06241d; --on-m4: #06241d; --m0: #26262b;
  --cool-ink: #ff9a6b;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121214; --card: #1b1b1f; --line: #2c2c33; --ink: #f1f1f4; --ink-2: #c4c4cc; --dim: #9a9aa5;
    --accent: #8b85f0; --accent-ink: #14132b; --accent-soft: #26244a;
    --field: #232328; --danger: #ff8a7a; --warn: #e6b45a;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
    --c-sleep: #3987e5; --c-t: #9085e9; --c-sex: #d55181; --c-z: #199e70; --c-cool: #d95926; --c-neutral: #7c7c88;
    --m1: #1b4a40; --m2: #237a66; --m3: #3fb597; --m4: #9fe3cf;
    --on-m1: #d6f3ea; --on-m2: #ffffff; --on-m3: #06241d; --on-m4: #06241d; --m0: #26262b;
    --cool-ink: #ff9a6b;
  }
}
* { box-sizing: border-box; }
html { background: var(--bg); color-scheme: light dark; }
[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }
body { margin: 0; min-height: 100vh; color: var(--ink); font: 16px/1.45 var(--sans); -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
h1, h2, p, ul { margin: 0; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; font-weight: 650; }
.sub { color: var(--dim); font-size: .92rem; }
.pad { padding: 18px; text-align: center; }
.app { max-width: 640px; margin: 0 auto; padding: 14px 14px calc(96px + env(safe-area-inset-bottom)); }
.stack { display: flex; flex-direction: column; gap: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 36px; }
.day-head { display: flex; align-items: center; gap: 12px; padding: 4px 2px; }
.day-head > div { flex: 1; }
.check { width: 36px; height: 36px; border-radius: 50%; background: var(--m3); color: var(--on-m3); display: grid; place-items: center; font-weight: 700; }
.badge, .count { font-size: .85rem; padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count.cool, .cool-text { color: var(--cool-ink); }
.count.cool { background: transparent; border: 1px solid var(--c-cool); }

/* controls */
.btn { min-height: var(--tap); padding: 0 20px; border-radius: 12px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible, .mood-tile:focus-visible, .input:focus-visible, .strip-cell:focus-visible, .inc-row:focus-visible, .sev-tile:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.quiet { background: var(--field); color: var(--ink); border-color: var(--line); }
.btn.quiet:hover { border-color: var(--accent); filter: none; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: .92rem; }
.btn.block { width: 100%; }
.btn.cool { background: var(--c-cool); border-color: var(--c-cool); color: #fff; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 120px; }
.btn.step { width: var(--tap); min-width: var(--tap); padding: 0; font-size: 1.6rem; flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: var(--tap); padding: 0 16px; border-radius: 99px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font: inherit; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.add { border-style: dashed; color: var(--dim); }
.input { width: 100%; min-height: var(--tap); padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--field); color: var(--ink); font: inherit; }
.input::placeholder { color: var(--dim); }
textarea.input { resize: vertical; min-height: 84px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: .88rem; color: var(--ink-2); font-weight: 600; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note { font-size: .9rem; }
.note.err { color: var(--danger); }
.note.warn { color: var(--warn); }
.time-row { display: flex; align-items: center; gap: 10px; min-height: var(--tap); }
.grow { flex: 1; }
.list { display: flex; flex-direction: column; gap: 6px; }

/* mood tiles */
.moods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.mood-tile { min-height: 88px; border-radius: 14px; border: 2px solid transparent; font: inherit; font-weight: 600; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; }
.mood-tile .emo { font-size: 1.8rem; line-height: 1; }
.m1 { background: var(--m1); color: var(--on-m1); }
.m2 { background: var(--m2); color: var(--on-m2); }
.m3 { background: var(--m3); color: var(--on-m3); }
.m4 { background: var(--m4); color: var(--on-m4); }
.m0 { background: var(--m0); color: var(--dim); }
.mood-tile[aria-pressed="true"] { border-color: var(--ink); box-shadow: 0 0 0 3px var(--card), 0 0 0 5px var(--ink); }

/* incidents */
.inc-list { display: flex; flex-direction: column; gap: 6px; }
.inc-row { min-height: var(--tap); display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--line); border-left: 4px solid var(--c-cool);
  background: var(--field); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.inc-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.inc-sev { color: var(--cool-ink); font-weight: 600; }
.inc-meta { color: var(--dim); flex: 1; text-align: right; }
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(10,10,15,.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; background: var(--card); color: var(--ink); border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.sev { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sev-tile { min-height: 72px; border-radius: 12px; border: 2px solid var(--line); background: var(--field); color: var(--ink); font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.sev-tile[aria-pressed="true"] { border-color: var(--c-cool); background: var(--c-cool); color: #fff; font-weight: 600; }
.sheet-actions .btn { flex: 1; }

/* sleep stepper */
.stepper { display: flex; align-items: center; gap: 10px; justify-content: center; }
.hours { display: flex; align-items: baseline; gap: 6px; }
.input.big { width: 120px; text-align: center; font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.unit { color: var(--dim); font-size: 1.2rem; }
.nowline { font-size: 1rem; color: var(--ink-2); }

/* tab bar */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center; gap: 6px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line); }
.tab { flex: 1; max-width: 160px; min-height: var(--tap); border-radius: 12px; border: 1px solid transparent; background: transparent; color: var(--ink-2); font: inherit; font-weight: 600; cursor: pointer; }
.tab[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }

/* toast + tooltip */
.toast { position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: 90vw; }
.tip { position: fixed; z-index: 70; left: var(--tx, 0); top: var(--ty, 0); background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: .85rem; max-width: 260px; pointer-events: none; }

/* login */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.login { width: 100%; max-width: 380px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand.center { justify-content: center; }
.mark { font-size: 2rem; }
.brand-name { font-size: 1.5rem; font-weight: 700; }

/* history */
.strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(48px, 1fr)); gap: 6px; }
.strip-cell { position: relative; min-height: 48px; border-radius: 10px; border: 1px solid transparent; font: inherit; font-size: .85rem; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.strip-cell .bolt { position: absolute; top: 1px; right: 3px; font-size: .7rem; color: var(--c-cool); text-shadow: 0 0 2px var(--card), 0 0 2px var(--card); font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: .85rem; color: var(--ink-2); }
.lg { display: inline-flex; align-items: center; gap: 6px; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; }
.sw.c-sleep { background: var(--c-sleep); } .sw.c-t { background: var(--c-t); } .sw.c-sex { background: var(--c-sex); } .sw.c-neutral { background: var(--c-neutral); }
.sw.c-cool { background: var(--c-cool); }
.sw.round { border-radius: 50%; } .sw.dot { border-radius: 50%; }
.sw.dash { height: 0; border-top: 2px dashed var(--ink-2); border-radius: 0; width: 18px; }

/* charts */
.chartbox { width: 100%; min-height: 120px; }
.chart { display: block; max-width: 100%; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--ink-2); font-size: 11px; font-family: var(--sans); }
.chart .axis.sub { fill: var(--ink-2); }
.chart .val { fill: var(--ink); font-size: 12px; font-weight: 600; font-family: var(--sans); }
.chart .bar.c-sleep { fill: var(--c-sleep); } .chart .bar.c-t { fill: var(--c-t); } .chart .bar.c-sex { fill: var(--c-sex); } .chart .bar.c-neutral { fill: var(--c-neutral); }
.chart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.c-t { stroke: var(--c-t); }
.chart .dot.c-t { fill: var(--c-t); stroke: var(--card); stroke-width: 2; }
.chart .bar.c-z { fill: var(--c-z); } .chart .line.c-z { stroke: var(--c-z); } .chart .dot.c-z { fill: var(--c-z); stroke: var(--card); stroke-width: 2; }
.sw.c-z { background: var(--c-z); }
.chart .tick.c-sex { fill: var(--c-sex); }
.chart .target { stroke: var(--ink-2); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover { fill: var(--ink); fill-opacity: .06; }
.tableview { margin-top: 2px; }
.tableview summary { list-style: none; cursor: pointer; display: inline-flex; width: auto; }
.tableview summary::-webkit-details-marker { display: none; }
.tablewrap { overflow-x: auto; margin-top: 8px; max-height: 320px; overflow-y: auto; }
table { border-collapse: collapse; width: 100%; font-size: .88rem; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--ink-2); font-weight: 600; position: sticky; top: 0; background: var(--card); }

/* insights */
.progress { height: 10px; border-radius: 99px; background: var(--field); border: 1px solid var(--line); overflow: hidden; }
.progress i { display: block; height: 100%; width: calc(var(--pct, 0) * 1%); background: var(--accent); border-radius: 99px; }
.forecast { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.big { font-size: 1.7rem; font-weight: 700; }
.findings { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.finding { display: flex; gap: 12px; align-items: flex-start; }
.dots { display: inline-flex; gap: 3px; padding-top: 7px; flex: none; }
.dots i { width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--dim); }
.dots i.on { background: var(--accent); border-color: var(--accent); }
.plain, .taglist { padding-left: 18px; display: flex; flex-direction: column; gap: 6px; }
.taglist { list-style: none; padding: 0; }
.taglist li { display: flex; justify-content: space-between; gap: 10px; }
.heat { display: grid; grid-template-columns: 74px repeat(var(--cols, 3), 1fr); gap: 6px; align-items: stretch; }
.hm-col, .hm-row { font-size: .8rem; color: var(--ink-2); font-weight: 600; display: flex; align-items: center; }
.hm-col { justify-content: center; }
.hm { min-height: 64px; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .95rem; cursor: pointer; }
.hm b { font-size: 1.05rem; }
.hm-r { font-size: .72rem; opacity: .9; }
.hm-n { font-size: .75rem; color: var(--dim); }
.hm-empty { background: repeating-linear-gradient(135deg, var(--field) 0 6px, var(--line) 6px 8px); }
.strip-cell .mon { position: absolute; top: 2px; left: 4px; font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; opacity: .85; }
