/* ---------- tokens (same family as the Caffeine app) ---------- */
:root {
  color-scheme: light dark;
  --bg: #E9EDF4;
  --surface: #F8FAFD;
  --ink: #1C1F3A;
  --ink-2: #5A5F82;
  --ink-3: #8C91B0;
  --line: #D2D8E6;
  --brew: #17707A;          /* this app's accent */
  --sky-day: #F4F7FC;
  --sky-dusk: #9C95CF;
  --sky-night: #262B5E;
  --ok: #2E7660;
  --ok-bg: #DDEFE7;
  --good: #4F8A2B;
  --fair: #B0700F;
  --fair-bg: #F8EBD3;
  --warn: #B4382A;
  --warn-bg: #F7E1DC;
  --load: #6A4BB0;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --display: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", system-ui, sans-serif;
  --text: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0F1226;
    --surface: #171B38;
    --ink: #E9EBF7;
    --ink-2: #A3A8CB;
    --ink-3: #6D7299;
    --line: #2A2F57;
    --brew: #5FC9CF;
    --sky-day: #1E2348;
    --sky-dusk: #3A3775;
    --sky-night: #070919;
    --ok: #6CC6A6;
    --ok-bg: #173A33;
    --good: #A8D468;
    --fair: #F2B95A;
    --fair-bg: #3D2D12;
    --warn: #FF8A78;
    --warn-bg: #45201E;
    --load: #B9A2F5;
  }
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--display); line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
svg { width: 1.25em; height: 1.25em; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2.5px solid var(--brew); outline-offset: 2px; }
.muted { color: var(--ink-2); }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45em;
  min-height: 44px; padding: 0 1.1em;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.btn-primary:hover { border-color: var(--ink); opacity: .92; }
.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-2); padding: 0 .6em; }
.btn-quiet:hover { color: var(--ink); border-color: transparent; }
.btn-danger-quiet { background: transparent; color: var(--warn); border-color: transparent; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; }
.link { background: none; border: 0; padding: 0; color: var(--brew); font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.icon-btn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 50%; border: 0; background: transparent; color: var(--ink-2); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--line); }
.icon-btn:disabled { opacity: .3; cursor: default; background: transparent; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }
.field > span { font-size: .85rem; font-weight: 600; color: var(--ink-2); }
.field > span b { color: var(--ink); }
input[type=text], input:not([type]), input[type=password], input[type=number], input[type=time] {
  width: 100%; min-height: 46px; padding: 0 .85rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-s);
  font-size: 1rem;
}
input:focus { border-color: var(--brew); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--brew) 25%, transparent); }
input[type=range] { width: 100%; accent-color: var(--brew); min-height: 36px; }
.form-error { color: var(--warn); font-size: .9rem; margin: -.2rem 0 .7rem; }
.form-error:empty { display: none; }
.hint { color: var(--ink-2); font-size: .92rem; margin-bottom: .6rem; }

.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 999px; padding: .5em 1em; min-height: 38px; font-weight: 600; font-size: .92rem; color: var(--ink-2); cursor: pointer; }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(20, 24, 60, .15); }

/* ---------- auth ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; position: relative; overflow: hidden; }
.auth-sky { position: absolute; inset: auto 0 0 0; height: 46vh; background: linear-gradient(90deg, var(--sky-day) 0%, var(--sky-day) 45%, var(--sky-dusk) 72%, var(--sky-night) 100%); }
.auth-curve { position: absolute; inset: 0; width: 100%; height: 100%; }
.auth-curve path { stroke: var(--brew); stroke-width: 3; fill: none; vector-effect: non-scaling-stroke; opacity: .85; }
.auth-card { position: relative; width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius-l); padding: 32px 26px 24px; box-shadow: 0 24px 60px -30px rgba(20, 24, 70, .55); }
.auth-title { font-size: 2.6rem; font-weight: 800; letter-spacing: -0.03em; color: var(--brew); }
.auth-lede { color: var(--ink-2); margin: .4rem 0 1.4rem; }
.auth-switch { margin-top: 1rem; text-align: center; color: var(--ink-2); font-size: .95rem; }

/* ---------- app shell ---------- */
.app { max-width: 1080px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: calc(14px + env(safe-area-inset-top)) 0 10px; }
.wordmark { font-family: var(--display); font-weight: 800; font-size: 1.35rem; color: var(--brew); letter-spacing: -0.02em; }
.clock { margin-left: auto; text-align: right; line-height: 1.15; cursor: default; }
.clock time { display: block; font: 700 1.05rem var(--display); font-variant-numeric: tabular-nums; }
.clock small { font-size: .72rem; color: var(--ink-2); }
.clock small.off { color: var(--fair); }
.tabs { display: flex; gap: 4px; }
@media (min-width: 720px) { .tabs { margin-left: 18px; } }
.tabs button { display: flex; align-items: center; gap: .45em; border: 0; background: transparent; color: var(--ink-2); font-weight: 600; padding: .55em .9em; border-radius: 999px; cursor: pointer; }
.tabs button[aria-current=page] { background: var(--surface); color: var(--ink); }
@media (max-width: 719px) {
  .tabs {
    position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: saturate(1.6) blur(16px); -webkit-backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line); justify-content: space-around;
  }
  .tabs button { flex-direction: column; gap: 2px; font-size: .72rem; padding: .35em .6em; min-width: 64px; }
  .tabs button svg { width: 24px; height: 24px; }
  .tabs button[aria-current=page] { background: transparent; color: var(--brew); }
}
.netbar { display: flex; align-items: center; gap: .5em; background: var(--fair-bg); color: var(--ink); border-radius: var(--radius-m); padding: .6rem .9rem; margin: 0 0 10px; font-size: .9rem; }
.view-title { font-size: 1.6rem; margin: 10px 0 10px; }
.sec-title { font-size: 1.1rem; margin: 26px 0 10px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.save-state { font: 500 .82rem var(--text); color: var(--ink-3); }

/* ---------- day ---------- */
.day-nav { display: flex; align-items: center; gap: 4px; margin: 4px 0 6px -8px; }
.day-title { font-size: 1.35rem; min-width: 0; }
.view-today { display: grid; grid-template-columns: 1fr; gap: 0 36px; }
@media (min-width: 900px) {
  .view-today { grid-template-columns: minmax(0, 1fr) minmax(360px, 1.05fr); align-items: start; }
  .col-side .sec-title:first-child { margin-top: 8px; }
}
.score-block { display: flex; align-items: center; gap: 20px; padding: 10px 0 4px; }
.ring { width: 148px; height: 148px; flex: none; position: relative; }
.ring svg { width: 100%; height: 100%; stroke: none; display: block; }
.ring .num { position: absolute; inset: 0; display: grid; place-items: center; font: 800 2.7rem/1 var(--display); letter-spacing: -0.04em; }
.ring .num.none { color: var(--ink-3); font-size: 2.6rem; }
.now-label { color: var(--ink-2); font-weight: 600; font-size: .95rem; }
.score-verdict { font: 800 1.6rem/1.15 var(--display); letter-spacing: -0.02em; margin-top: 2px; }
.score-missing { color: var(--ink-2); font-size: .9rem; margin-top: .35rem; }
.band-great { color: var(--ok); } .band-good { color: var(--good); } .band-fair { color: var(--fair); } .band-rough { color: var(--warn); }

.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 16px; margin: 18px 0 8px; }
.facts div { border-left: 3px solid var(--line); padding-left: 10px; min-width: 0; }
.facts dt { color: var(--ink-2); font-size: .82rem; font-weight: 600; }
.facts dd { margin: 2px 0 0; font-family: var(--display); font-weight: 700; font-size: 1.2rem; line-height: 1.25; }
.facts dd small { display: block; font-family: var(--text); font-weight: 500; font-size: .82rem; color: var(--ink-2); }
.facts .good { border-color: var(--ok); }
.facts .mid { border-color: var(--fair); }
.facts .bad { border-color: var(--warn); }
.facts .load { border-color: var(--load); }
.sr-bars { display: grid; grid-template-columns: auto 1fr auto; gap: 3px 8px; align-items: center; margin-top: 4px; font: 600 .78rem var(--text); color: var(--ink-2); }
.sr-bars i { display: block; height: 7px; border-radius: 999px; background: color-mix(in srgb, var(--line) 70%, transparent); overflow: hidden; }
.sr-bars i b { display: block; height: 100%; border-radius: 999px; }

.breakdown { list-style: none; margin: 0; padding: 0; }
.breakdown li { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto; gap: 2px 10px; align-items: center; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.breakdown li:last-child { border-bottom: 0; }
.breakdown svg { color: var(--brew); width: 22px; height: 22px; grid-row: span 2; }
.breakdown .name { font-weight: 600; font-size: .95rem; display: flex; justify-content: space-between; gap: 8px; }
.breakdown .name small { color: var(--ink-2); font-weight: 500; font-size: .84rem; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown .lost { font: 700 1rem var(--display); text-align: right; grid-row: span 2; min-width: 3.4em; }
.breakdown .lost.zero { color: var(--ink-3); }
.breakdown .bar { height: 6px; border-radius: 999px; background: color-mix(in srgb, var(--line) 70%, transparent); overflow: hidden; }
.breakdown .bar i { display: block; height: 100%; border-radius: 999px; }
.breakdown li.off { opacity: .55; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 12px 12px 12px; min-width: 0; }
.card-wide { grid-column: 1 / -1; }
.card-head { display: grid; grid-template-columns: auto 1fr; column-gap: 8px; align-items: center; margin-bottom: 8px; }
.card-head svg { color: var(--brew); width: 22px; height: 22px; grid-row: span 2; }
.card-head b { font-weight: 700; font-size: .95rem; line-height: 1.2; }
.card-head small { color: var(--ink-2); font-size: .8rem; grid-column: 2; line-height: 1.3; }
.card-head:not(:has(svg)) small { grid-column: 1 / -1; }
.card input { min-height: 44px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper-val { font: 800 1.35rem var(--display); min-width: 2.9em; text-align: center; white-space: nowrap; }
.stepper .btn { min-height: 40px; padding: 0 .75em; font-size: .9rem; white-space: nowrap; }
#water-val { flex: 1; }
.stepper .icon-btn { border: 1px solid var(--line); }
.water-bar { height: 8px; border-radius: 999px; background: color-mix(in srgb, var(--line) 70%, transparent); margin-top: 10px; overflow: hidden; }
.water-bar i { display: block; height: 100%; width: 0; background: var(--brew); border-radius: 999px; transition: width .25s; }
.seg-food { display: flex; width: 100%; }
.seg-food button { flex: 1; padding: .5em .2em; font-size: .86rem; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: .3em .75em; font-size: .84rem; font-weight: 600; color: var(--ink-2); cursor: pointer; min-height: 34px; }
.chip.plus[aria-pressed=true] { border-color: var(--ok); color: var(--ok); background: var(--ok-bg); }
.chip.minus[aria-pressed=true] { border-color: var(--warn); color: var(--warn); background: var(--warn-bg); }
.linked-note { margin-top: 10px; font-size: .84rem; color: var(--ink-2); }
.linked { font-size: .9rem; }
.linked .big { font: 800 1.45rem/1.15 var(--display); display: block; }
.linked small { color: var(--ink-2); display: block; font-size: .82rem; }
.linked a { font-size: .84rem; display: inline-flex; gap: .3em; align-items: center; margin-top: 6px; }
.linked a svg { width: 1em; height: 1em; }
.manual-row { display: flex; gap: 8px; align-items: center; }
.manual-row input { flex: 1; min-width: 0; }
.check { display: flex; gap: .5rem; align-items: center; margin-top: 8px; font-size: .86rem; color: var(--ink-2); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--brew); }

.entries { list-style: none; margin: 0 0 8px; padding: 0; }
.entries li button {
  width: 100%; display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: .7rem;
  padding: .55rem .1rem; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer;
}
.entries svg { width: 22px; height: 22px; color: var(--brew); }
.entries .t { color: var(--ink-2); font-size: .84rem; display: block; }
.entries .v { font: 700 1rem var(--display); text-align: right; }
.entries .v small { display: block; font: 500 .78rem var(--text); color: var(--ink-2); }

@media (max-width: 420px) {
  .ring { width: 124px; height: 124px; }
  .ring .num { font-size: 2.2rem; }
  .score-block { gap: 14px; }
  .score-verdict { font-size: 1.35rem; }
}

/* ---------- history ---------- */
#view-history { max-width: 760px; }
.hist-chart { margin: 14px 0 4px; }
.hist-chart svg { display: block; width: 100%; height: auto; stroke: none; }
.hist-chart text { font: 600 11px var(--text); fill: var(--ink-2); }
.hist-chart .bar { cursor: pointer; }
.legend { display: flex; gap: 16px; font-size: .82rem; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: .4em; }
.lg-bar { width: 10px; height: 10px; border-radius: 2px; background: var(--good); display: inline-block; }
.lg-line { width: 14px; height: 0; border-top: 2.5px solid var(--load); display: inline-block; }
.day-list { list-style: none; margin: 0; padding: 0; }
.day-list button { width: 100%; display: grid; grid-template-columns: 52px 1fr auto; gap: 12px; align-items: center; padding: .6rem .1rem; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; cursor: pointer; }
.day-list .badge { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font: 800 .92rem var(--display); letter-spacing: -0.02em; color: #fff; }
.day-list .badge.none { background: var(--line); color: var(--ink-2); }
.day-list b { display: block; font-weight: 600; }
.day-list small { color: var(--ink-2); font-size: .84rem; display: block; }
.day-list .load-tag { font: 600 .8rem var(--text); color: var(--load); text-align: right; }

/* ---------- you ---------- */
.profile-form, .group-plain { max-width: 560px; }
.group { border: 0; padding: 0; margin: 18px 0 8px; }
.group legend, .group-plain h3 { font-family: var(--display); font-weight: 700; font-size: 1.1rem; margin-bottom: .7rem; padding: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.estimate { background: var(--surface); border-radius: var(--radius-m); padding: 1rem 1.1rem; margin: 6px 0 16px; border: 1px solid var(--line); max-width: 560px; }
.estimate dl { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; margin: 0; }
.estimate dt { color: var(--ink-2); }
.estimate dd { margin: 0; font-weight: 700; text-align: right; }
.estimate p { margin-top: .6rem; font-size: .88rem; color: var(--ink-2); }
.weight-row { display: grid; grid-template-columns: 26px 92px 1fr 3.2em; gap: 10px; align-items: center; padding: .25rem 0; }
.weight-row svg { color: var(--brew); width: 20px; height: 20px; }
.weight-row span { font-weight: 600; font-size: .92rem; }
.weight-row output { text-align: right; font: 700 .95rem var(--display); }
.group-plain { margin-top: 34px; padding-top: 22px; border-top: 1px solid var(--line); }
.how p, .how li { color: var(--ink-2); font-size: .93rem; }
.how b { color: var(--ink); }
.how ul { padding-left: 1.1rem; margin: .7rem 0; }
.how li { margin: .35rem 0; }
.how p + p { margin-top: .6rem; }

/* ---------- dialogs ---------- */
dialog { border: 0; padding: 0; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgba(10, 12, 35, .5); }
.sheet { width: min(520px, 100%); max-height: 92dvh; border-radius: var(--radius-l); margin: auto; }
.sheet form { padding: 18px 18px 20px; }
@media (max-width: 719px) {
  .sheet { margin: auto 0 0; max-width: 100%; width: 100%; border-radius: var(--radius-l) var(--radius-l) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .sheet[open] { animation: rise .22s ease-out; }
}
@keyframes rise { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 14px; }
.kinds button { display: flex; align-items: center; gap: .5em; min-height: 46px; padding: 0 .6rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); cursor: pointer; font-weight: 600; font-size: .88rem; }
.kinds button svg { color: var(--brew); width: 22px; height: 22px; }
.kinds button[aria-pressed=true] { border-color: var(--brew); color: var(--ink); box-shadow: inset 0 0 0 1px var(--brew); }
.rpe-scale { display: flex; justify-content: space-between; color: var(--ink-3); font-size: .78rem; }
.preview { font-size: .92rem; padding: .6rem .8rem; border-radius: var(--radius-s); margin: .2rem 0 .8rem; background: var(--bg); color: var(--ink-2); }
.preview:empty { display: none; }
.sheet-actions { display: flex; justify-content: space-between; gap: 10px; padding-top: 6px; }
.sheet-actions .btn-primary { margin-left: auto; min-width: 140px; }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .65rem 1rem; border-radius: 999px;
  font-weight: 600; font-size: .92rem; z-index: 50;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5); width: max-content; max-width: calc(100% - 32px);
}
@media (min-width: 720px) { .toast { bottom: 28px; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
