/* Metabolism Predictor — dark theme, phone-first, thumb-friendly */
:root {
  --bg: #0b0f14;
  --surface: #141b22;
  --surface-2: #1c2630;
  --line: #27333f;
  --text: #e7eef4;
  --muted: #8aa0b2;
  --water: #38bdf8;   /* drink */
  --water-d: #0ea5e9;
  --wee: #f5b53d;     /* tinkle */
  --wee-d: #d9941a;
  --good: #34d399;
  --bad: #f87171;
  --accent: #a78bfa;
  --radius: 18px;
  --tap: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* make the `hidden` attribute win over display rules below (modals, toggles, inputs) */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
  -webkit-user-select: none; user-select: none;
  min-height: 100vh;
}

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: linear-gradient(180deg, rgba(11,15,20,.98), rgba(11,15,20,.82));
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 650; font-size: 15px; letter-spacing: .2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 0 rgba(0,0,0,0); }
.dot.online { background: var(--good); }
.confidence {
  font-size: 11.5px; color: var(--muted); background: var(--surface-2);
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--line);
}

main { padding: 14px 16px 8px; max-width: 560px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.section-title { font-size: 13px; color: var(--muted); font-weight: 600; margin: 20px 2px 10px; text-transform: uppercase; letter-spacing: .6px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card-title { margin: 0 0 12px; font-size: 14px; font-weight: 650; }
.muted { color: var(--muted); }
.small { font-size: 12px; line-height: 1.5; }

/* prediction card */
.predict-card { background: linear-gradient(160deg, var(--surface-2), var(--surface)); }
.predict-top { display: flex; align-items: center; gap: 16px; }
.gauge { position: relative; width: 112px; height: 112px; flex: 0 0 auto; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge-bg { fill: none; stroke: var(--surface-2); stroke-width: 10; }
.gauge-fill { fill: none; stroke: var(--wee); stroke-width: 10; stroke-linecap: round;
  stroke-dasharray: 327; stroke-dashoffset: 327; transition: stroke-dashoffset .5s ease, stroke .4s; }
.gauge-label { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.gauge-pct { font-size: 24px; font-weight: 750; }
.gauge-sub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.predict-info { flex: 1 1 auto; min-width: 0; }
.predict-caption { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.predict-time { font-size: 30px; font-weight: 780; line-height: 1.1; margin: 2px 0; }
.predict-window { font-size: 12.5px; color: var(--muted); }
.predict-count { font-size: 13px; color: var(--wee); font-weight: 600; margin-top: 4px; }
.predict-card.overdue .gauge-fill { stroke: var(--bad); }
.predict-card.overdue .predict-count { color: var(--bad); }

/* big buttons */
.btn-row { display: flex; gap: 10px; }
.btn-row.wrap { flex-wrap: wrap; }
.toggle-row { display: flex; gap: 10px; margin-top: 10px; }
.big-btn {
  flex: 1 1 0; min-height: 84px; border: none; border-radius: var(--radius);
  background: linear-gradient(160deg, var(--water), var(--water-d)); color: #04212e;
  font-weight: 700; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; cursor: pointer; transition: transform .06s, filter .15s; touch-action: manipulation;
}
.big-btn:active { transform: scale(.96); filter: brightness(1.08); }
.big-btn .bb-main { font-size: 30px; line-height: 1; }
.big-btn .bb-unit { font-size: 13px; opacity: .8; }
.big-btn.ghost { background: var(--surface-2); color: var(--text); border: 1px dashed var(--line); }

.chip {
  flex: 1 1 0; min-height: 44px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 14px; font-weight: 600; cursor: pointer;
  transition: all .12s; touch-action: manipulation;
}
.chip[data-on="true"] { background: rgba(167,139,250,.18); border-color: var(--accent); color: var(--text); }

/* tinkle */
.tinkle-btn {
  width: 100%; min-height: 148px; border: none; border-radius: 24px;
  background: radial-gradient(130% 130% at 50% 0%, var(--wee), var(--wee-d));
  color: #2a1a02; font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; cursor: pointer; position: relative; overflow: hidden;
  transition: transform .06s; touch-action: none; user-select: none;
  box-shadow: 0 10px 30px -14px rgba(245,181,61,.7);
}
.tinkle-btn.holding { transform: scale(.98); background: radial-gradient(130% 130% at 50% 0%, #ffd27a, var(--wee)); }
.tinkle-main { font-size: 40px; line-height: 1; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.tinkle-sub { font-size: 13px; opacity: .85; font-weight: 600; }
.link-btn { display: block; margin: 10px auto 0; background: none; border: none; color: var(--accent); font-size: 14px; cursor: pointer; }

/* recent log */
.log { list-style: none; margin: 0; padding: 0; }
.log li { display: flex; align-items: center; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.log li:last-child { border-bottom: none; }
.log .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 15px; flex: 0 0 auto; }
.log .ic.drink { background: rgba(56,189,248,.16); }
.log .ic.void { background: rgba(245,181,61,.16); }
.log .ic.diaper_change { background: rgba(167,139,250,.16); }
.log .li-main { flex: 1 1 auto; }
.log .li-sub { color: var(--muted); font-size: 12px; }
.log .li-time { color: var(--muted); font-size: 12px; }
.log .undo { background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; padding: 4px 6px; }

/* tiles */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 13px; }
.tile .t-val { font-size: 24px; font-weight: 750; }
.tile .t-lab { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

/* charts */
canvas { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 11.5px; color: var(--muted); }
.legend .sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.sw.water { background: var(--water); } .sw.void { background: var(--wee); }
.sw.fill { background: var(--accent); } .sw.fc { background: #4b5b6b; }

.daynight { display: flex; gap: 12px; }
.daynight .dn { flex: 1; background: var(--surface-2); border-radius: 12px; padding: 12px; text-align: center; }
.daynight .dn .v { font-size: 20px; font-weight: 700; }
.daynight .dn .l { font-size: 11.5px; color: var(--muted); }

/* settings rows */
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: none; }
.row.col { flex-direction: column; align-items: stretch; }
.row.switch span { font-weight: 600; }
.row input[type="number"], .row input[type="url"], .row input[type="text"], .row input[type="password"], .row select {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font-size: 15px; min-width: 110px; text-align: right;
}
.row.col input { text-align: left; }
#view-settings details { margin-top: 10px; } #view-settings details summary { cursor: pointer; padding: 6px 0; } #view-settings .btn-row { margin-top: 8px; } #accRename .btn, #accGuest .btn, #view-settings details .btn { margin-top: 8px; }
input[type="checkbox"] { width: 50px; height: 30px; appearance: none; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; position: relative; cursor: pointer; }
input[type="checkbox"]::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--muted); transition: .15s; }
input[type="checkbox"]:checked { background: rgba(52,211,153,.25); border-color: var(--good); }
input[type="checkbox"]:checked::after { left: 25px; background: var(--good); }

.btn { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 12px; padding: 12px 16px; font-size: 14px; font-weight: 600; cursor: pointer; }
.btn.primary { background: var(--water); color: #04212e; border: none; }
.btn.danger { color: var(--bad); border-color: rgba(248,113,113,.4); }
.btn:active { filter: brightness(1.1); }

/* tab bar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: flex; background: rgba(20,27,34,.96); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bot);
}
.tab { flex: 1; background: none; border: none; color: var(--muted); font-size: 18px; padding: 10px 0 8px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tab span { font-size: 11px; font-weight: 600; }
.tab.active { color: var(--water); }

/* FDA disclaimer — intentionally 6px; sits at the very bottom of the content,
   with enough bottom padding to clear the fixed tab bar. */
.fda { font-size: 6px; line-height: 1.4; color: #4a5964; text-align: center;
  padding: 18px 10px calc(96px + var(--safe-bot)); }

/* modal + toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; padding: 24px; }
.modal-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; width: 100%; max-width: 320px; }
.modal-box h3 { margin: 0 0 14px; }
.modal-box input { width: 100%; background: var(--surface-2); border: 1px solid var(--line); color: var(--text); border-radius: 12px; padding: 14px; font-size: 20px; text-align: center; margin-bottom: 14px; }
.toast { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); background: var(--surface-2); color: var(--text); border: 1px solid var(--line); padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 60; box-shadow: 0 8px 24px -12px #000; }

/* honour an explicit light preference if a user flips it (kept minimal; app is dark by design) */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) { /* app stays dark on purpose for night bathroom trips */ }
}
