:root {
    --bg: #0d1117;
    --bg-2: #161b22;
    --bg-3: #1f2630;
    --line: #2a313c;
    --text: #e6edf3;
    --muted: #8b949e;
    --dim: #6e7681;
    --accent: #58a6ff;
    --user: #7ee787;
    --food: #f0b86e;
    --exercise: #d2a8ff;
    --warn: #f85149;
    --warn-bg: rgba(248, 81, 73, 0.10);
    --now: #58a6ff;
    --future-bg: rgba(163, 113, 247, 0.09);
    --future-edge: rgba(163, 113, 247, 0.55);
    --hdr-h: 110px;
    --radius: 8px;
    font-size: 15px;
}

/* Phones: everything is sized in rem, so this scales the whole UI (like 133% zoom, minus the
   squeezed layout). */
@media (max-width: 760px) {
    :root { font-size: 20px; }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

body { overscroll-behavior-y: contain; }

button, input, select, textarea { font: inherit; color: inherit; }

/* ---------- header ---------- */

#hdr {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 10;
    background: rgba(13, 17, 23, 0.96);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
    padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
}

.hdr-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--accent);
}

.clock {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(6rem, 1fr));
    gap: 6px;
    margin-top: 8px;
}

.stat {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 8px;
    min-width: 0;
}

.stat .k {
    font-size: 0.72rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat .v {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.stat.warn { border-color: var(--warn); }
.stat.warn .v { color: var(--warn); }

/* ---------- log ---------- */

#log {
    padding-top: var(--hdr-h);
    padding-bottom: 50vh;
}

.loading, .empty {
    padding: 24px;
    color: var(--muted);
    text-align: center;
}

.day {
    position: sticky;
    top: var(--hdr-h);
    z-index: 5;
    background: var(--bg-3);
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 4px 12px;
    border-bottom: 1px solid var(--line);
}

.hour {
    display: flex;
    gap: 10px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--line);
    min-height: 40px;
}

.hour.future { opacity: 0.75; }
.hour.future .h-clock { color: var(--muted); }

.hour.now {
    border-left: 3px solid var(--now);
    padding-left: 9px;
    background: rgba(88, 166, 255, 0.06);
}

.hour.lean { background: var(--warn-bg); }
.hour.lean .h-clock { color: var(--warn); }

.h-time {
    flex: 0 0 5.6rem;
    display: flex;
    flex-direction: column;
    font-variant-numeric: tabular-nums;
}

.h-clock { font-weight: 600; }

.h-rel {
    font-size: 0.72rem;
    color: var(--dim);
}

.hour.now .h-rel { color: var(--now); font-weight: 700; }

.h-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.h-items {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.h-items:empty { display: none; }

.chip {
    display: inline-flex;
    gap: 6px;
    align-items: baseline;
    border: 1px solid var(--line);
    background: var(--bg-2);
    border-radius: 999px;
    padding: 1px 10px;
    font-size: 0.88rem;
    cursor: pointer;
}

.chip .t { color: var(--muted); font-size: 0.75rem; }
.chip .sync {
    color: var(--accent);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.chip .tm { color: var(--dim); font-size: 0.7rem; }
.chip.cont { opacity: 0.65; border-style: dashed; }
.chip.food { border-color: rgba(240, 184, 110, 0.45); }
.chip.food .n { color: var(--food); }
.chip.exercise { border-color: rgba(210, 168, 255, 0.45); }
.chip.exercise .n { color: var(--exercise); }

.h-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 2px 12px;
    font-size: 0.82rem;
    font-variant-numeric: tabular-nums;
}

.metric .k { color: var(--dim); margin-right: 3px; }
.metric .d { color: var(--dim); font-size: 0.75rem; font-style: normal; }

/* collapsed runs of quiet hours */
.hour.group { cursor: pointer; background: var(--bg-2); }
.hour.group:hover { background: var(--bg-3); }
.hour.group .h-clock { font-size: 0.82rem; white-space: nowrap; }
.hour.group .h-rel { color: var(--accent); }
.hour.group.lean { background: var(--warn-bg); }

/* Future (projected) rows: purple tint and edge, so scrolling past NOW is obvious. Muscle stays red. */
.hour.future, .hour.group.future { background: var(--future-bg); box-shadow: inset 3px 0 0 var(--future-edge); }
.hour.group.future:hover { background: rgba(163, 113, 247, 0.16); }
.hour.future.lean, .hour.group.future.lean { background: var(--warn-bg); }
.day.future { background: #251d38; box-shadow: inset 3px 0 0 var(--future-edge); }

.group-head {
    padding: 2px 12px;
    font-size: 0.75rem;
    color: var(--accent);
    background: var(--bg-2);
    border-bottom: 1px solid var(--line);
    cursor: pointer;
}

.h-add {
    flex: 0 0 auto;
    align-self: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    line-height: 1;
    cursor: pointer;
    opacity: 0.45;
}

.hour:hover .h-add, .h-add:focus { opacity: 1; border-color: var(--accent); color: var(--accent); }

@media (hover: none) {
    .h-add { opacity: 0.8; }
}

.log-end {
    padding: 16px;
    text-align: center;
    color: var(--dim);
    font-size: 0.85rem;
}

.hdr-top select {
    background: var(--bg-2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 5px 8px;
    color-scheme: dark;
}

/* status: user-entered vs extrapolated */
.metric.src-extrapolated .n { color: var(--muted); font-style: italic; }
.metric.src-user { cursor: pointer; }
.metric.src-user .n { color: var(--user); font-weight: 600; }
.metric.src-user .k::before { content: "\25CF "; color: var(--user); font-size: 0.6rem; vertical-align: middle; }
.metric.lean .n { color: var(--warn); font-style: normal; font-weight: 700; }
.metric.stored .n { color: var(--food); }
.metric.drift .n { color: var(--exercise); font-style: normal; }

/* ---------- compact rows: reserve gauge + tags; details on tap ---------- */

.hour { min-height: 34px; padding-top: 5px; padding-bottom: 5px; align-items: center; }
.hour:not(.group) { cursor: pointer; }
.hour .h-metrics { display: none; }
.hour.open .h-metrics { display: flex; }
.hour.open { background: var(--bg-2); }

.h-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 20px;
}

.rb {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 0 1 24rem;
    min-width: 0;
}

.rb-track {
    flex: 1;
    height: 8px;
    background: var(--bg-3);
    border-radius: 4px;
    overflow: hidden;
}

.rb-fill { height: 100%; border-radius: 4px; }
.lvl-high .rb-fill { background: #3fb950; }
.lvl-mid .rb-fill { background: #d29922; }
.lvl-low .rb-fill { background: #f0883e; }
.lvl-empty .rb-fill { background: var(--warn); }

.rb-n {
    min-width: 3rem;
    text-align: right;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    color: var(--muted);
}

.rb.src-user .rb-n { color: var(--user); font-weight: 600; }
.lvl-empty .rb-n { color: var(--warn); }
.rb .d { color: var(--dim); font-size: 0.75rem; font-variant-numeric: tabular-nums; }
.rb-liver { color: var(--dim); font-size: 0.75rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.rb-liver.empty { color: var(--warn); }
#burn-google .err { color: var(--warn); }
#burn-google a { color: var(--accent); }

.tag {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 1px 6px;
    border-radius: 4px;
    white-space: nowrap;
}

.tag.fed { color: var(--food); border: 1px solid rgba(240, 184, 110, 0.4); }
.tag.muscle { color: var(--warn); border: 1px solid var(--warn); font-weight: 700; }
.tag.rebuild { color: var(--user); border: 1px solid var(--user); }

.chip.rec { border-color: rgba(126, 231, 135, 0.4); }
.chip.rec .n { color: var(--user); font-weight: 600; }

.day {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.day-stats {
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.82rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.day-stats b { color: var(--text); font-weight: 600; }
.day-stats .d { color: var(--dim); margin-left: 4px; }

.hdr-sub {
    margin-top: 6px;
    font-size: 0.78rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

.hdr-sub b { color: var(--text); font-weight: 500; }

.calc { margin-left: 6px; color: var(--user); font-variant-numeric: tabular-nums; text-transform: none; }
.calc.bad { color: var(--warn); }

/* ---------- buttons ---------- */

.btn {
    border: 1px solid var(--line);
    background: var(--bg-2);
    border-radius: var(--radius);
    padding: 6px 12px;
    cursor: pointer;
}

.btn:hover { background: var(--bg-3); }
.btn-ghost { background: transparent; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #0d1117; font-weight: 600; }
.btn-primary:hover { background: #79b8ff; }
.btn-danger { border-color: var(--warn); color: var(--warn); background: transparent; }

#fab {
    position: fixed;
    right: 18px;
    bottom: calc(env(safe-area-inset-bottom) + 18px);
    z-index: 20;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #0d1117;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
    touch-action: none;           /* press-and-slide into the menu */
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* ---------- dialog ---------- */

dialog {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-2);
    color: var(--text);
    padding: 16px;
    width: min(440px, calc(100vw - 24px));
}

dialog::backdrop { background: rgba(0, 0, 0, 0.6); }

dialog h2 { margin: 0 0 12px; font-size: 1.1rem; }

dialog label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
    color: var(--muted);
    font-size: 0.85rem;
}

dialog input, dialog select, dialog textarea {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: 1rem;
    color-scheme: dark;
}

dialog input:focus, dialog select:focus, dialog textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.unit { color: var(--dim); }

.quick-hours {
    display: flex;
    gap: 6px;
    margin: -4px 0 10px;
}

.time-pair { display: flex; gap: 8px; }
.time-pair label { flex: 1; min-width: 0; }

.form-error { color: var(--warn); min-height: 1.2em; font-size: 0.85rem; }

.actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 8px;
}

.actions .spacer { flex: 1; }

/* ---------- forecast view ---------- */

#forecast { padding-top: var(--hdr-h); padding-bottom: 24px; }

.fc-row {
    display: grid;
    grid-template-columns: minmax(6.4rem, 8.7rem) minmax(6.4rem, 8rem) 3.9rem minmax(8rem, 13.3rem) 6rem 1fr;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    font-variant-numeric: tabular-nums;
}

.fc-row.fc-week { cursor: pointer; background: var(--bg-2); }
.fc-row.fc-week:hover { background: var(--bg-3); }
.fc-row.sub { padding-left: 28px; font-size: 0.9rem; }
.fc-row.sub .fc-date { color: var(--muted); }
.fc-row.lean { background: var(--warn-bg); }
.fc-row .tag { justify-self: start; }

.fc-date { display: flex; flex-direction: column; }
.fc-label { font-weight: 500; }
.fc-when { color: var(--dim); font-size: 0.72rem; }
.fc-w b { font-size: 1.05rem; }
.fc-w .d { color: var(--dim); font-size: 0.78rem; margin-left: 2px; }
.fc-bf b { font-weight: 600; }
.fc-comp { color: var(--muted); font-size: 0.82rem; }
.fc-food { color: var(--muted); font-size: 0.82rem; text-align: right; white-space: nowrap; }
.fc-food b { color: var(--food); font-weight: 500; }
.fc-food.fast { color: var(--dim); font-style: italic; }

.fc-intro {
    margin: 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg-2);
    color: var(--muted);
    font-size: 0.85rem;
}

.fc-intro p { margin: 8px 0 0; }
.fc-intro b { color: var(--text); }
.fc-now { color: var(--text); font-size: 1rem; }
.fc-change { margin-top: 4px; font-variant-numeric: tabular-nums; }
.fc-plan { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; color: var(--text); }
.fc-plan select, .fc-plan input {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 8px;
    color: var(--text);
    color-scheme: dark;
}
.fc-plan input[type=number] { width: 5.5rem; }
.fc-days { display: inline-flex; gap: 2px; }
.fc-day {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--dim);
    padding: 4px 7px;
    font: inherit;
    cursor: pointer;
}
.fc-day.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.fc-jump {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    color: var(--text);
}

.fc-jump input {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 4px 8px;
    color-scheme: dark;
}

@media (max-width: 760px) {
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; margin-top: 6px; }
    .stat { padding: 2px 8px; }
    .hdr-top { gap: 6px; }
    .hdr-top .clock { display: none; }
    .hdr-top select { margin-left: auto; min-width: 0; }
    .hdr-top .btn { padding: 4px 8px; }
    .hdr-sub { font-size: 0.7rem; margin-top: 4px; }
    .chip { border-radius: 12px; }
    .h-time { flex-basis: 4.4rem; }
    .hour.group .h-clock { font-size: 0.7rem; }
    .chip { flex-wrap: wrap; }
}

@media (max-width: 560px) {
    .fc-row { grid-template-columns: 1fr auto auto; row-gap: 2px; }
    .fc-comp { grid-column: 1 / 3; }
    .fc-food { grid-column: 3; }
    .fc-row .tag { grid-column: 1 / -1; }
}

.hint { margin: -2px 0 10px; color: var(--dim); font-size: 0.78rem; }

dialog label.check {
    flex-direction: row;
    align-items: center;
    gap: 8px;
    color: var(--text);
}

dialog label.check input { width: 18px; height: 18px; margin: 0; }

/* ---------- "+" menu ---------- */

/* Anchored just above the floating "+" so a press can slide straight up into it (Food nearest). */
dialog.menu {
    width: min(340px, calc(100vw - 24px));
    max-height: calc(100vh - env(safe-area-inset-bottom) - 100px);
    overflow-y: auto;
    margin: auto 12px calc(env(safe-area-inset-bottom) + 84px) auto;
    padding: 10px 12px 4px;
    user-select: none;
    -webkit-user-select: none;
}
.menu-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.menu-title { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; margin: 0 4px; }
.menu-head .menu-cancel { width: auto; padding: 4px 10px; }

.menu-btn {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    width: 100%;
    margin-bottom: 6px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
    text-align: left;
}

.menu-btn:hover, .menu-btn.hover { background: var(--bg-3); }
.menu-btn.hover { box-shadow: 0 0 0 2px var(--accent); }
.menu-btn b { font-size: 1rem; }
.menu-btn span { color: var(--muted); font-size: 0.8rem; }
.menu-btn.food { border-left-color: var(--food); }
.menu-btn.exercise { border-left-color: var(--exercise); }
.menu-btn.burn { border-left-color: #ff9b73; }
.menu-btn.dexa { border-left-color: var(--user); }

.chip.burn .q { color: var(--muted); font-size: 0.85em; }

/* ---------- food dialog ---------- */

#food-dialog { width: min(520px, calc(100vw - 24px)); }
.fd-choose input[type="search"] { width: 100%; box-sizing: border-box; margin-bottom: 8px; }

.food-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 38vh;
    overflow-y: auto;
}

.food-list:empty { display: none; }
#food-online { margin-top: 10px; }

.food-row {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg);
}

.food-row.online { flex-direction: column; padding: 8px 10px; gap: 6px; }

.fr-pick {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    min-width: 0;
}

.fr-pick:hover { background: var(--bg-3); }
.fr-name { font-weight: 500; }
.fr-brand { color: var(--muted); font-weight: 400; font-size: 0.85em; }
.fr-meta { color: var(--muted); font-size: 0.8rem; font-variant-numeric: tabular-nums; }

.fr-edit {
    border: none;
    border-left: 1px solid var(--line);
    background: none;
    color: var(--muted);
    padding: 0 12px;
    cursor: pointer;
}

.fr-edit:hover { color: var(--text); background: var(--bg-3); }
.fr-empty { color: var(--dim); font-size: 0.85rem; padding: 6px 2px; }
.fr-empty.bad { color: var(--warn); }

.fr-bases { display: flex; flex-wrap: wrap; gap: 6px; }

.basis {
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--bg-2);
    padding: 3px 10px;
    font-size: 0.8rem;
    cursor: pointer;
    font-variant-numeric: tabular-nums;
}

.basis:hover { border-color: var(--food); }
.basis b { color: var(--food); }
.basis span { color: var(--muted); }

.food-actions { display: flex; gap: 8px; margin-top: 8px; }
.fd-credit { margin-top: 6px; color: var(--dim); font-size: 0.75rem; }
.fd-credit a { color: var(--muted); }

.picked {
    border: 1px solid var(--line);
    border-left: 4px solid var(--food);
    border-radius: var(--radius);
    background: var(--bg);
    padding: 10px 12px;
    margin-bottom: 12px;
}

.pk-name { font-weight: 600; }
.pk-meta { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.pk-links { display: flex; gap: 14px; margin-top: 6px; }

.link {
    border: none;
    background: none;
    padding: 0;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.85rem;
}

.food-total { margin: -4px 0 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.food-total b { color: var(--food); font-size: 1.05rem; }

.chip .q { color: var(--muted); }
.chip .p { color: var(--user); font-size: 0.78em; font-variant-numeric: tabular-nums; }

/* Digestion categories */
.dg-fast   { --dg: #f778ba; }
.dg-medium { --dg: #8b949e; }
.dg-slow   { --dg: #56d4dd; }
.dg-toxin  { --dg: #f85149; }
.dg {
    display: inline-block;
    margin-left: 6px;
    padding: 0 5px;
    border: 1px solid var(--dg);
    border-radius: 4px;
    color: var(--dg);
    font-size: 0.72em;
    font-weight: 500;
    line-height: 1.4;
    vertical-align: 1px;
}
.dg-field { display: block; margin-bottom: 12px; color: var(--muted); font-size: 0.85rem; }
.dg-field .hint { margin: 6px 0 0; }
.dg-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 4px; }
.dg-pick button {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 7px 4px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--bg-3);
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
}
.dg-pick button small { color: var(--dim); font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.dg-pick button.on { border-color: var(--dg); color: var(--dg); background: color-mix(in srgb, var(--dg) 14%, var(--bg-3)); }
.dg-pick button.on small { color: var(--dg); }

[hidden] { display: none !important; }
