:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f2eee8;
  --text: #1f1d1a;
  --muted: #6f6a63;
  --border: #e6e0d8;
  --accent: #4a6fb3;
  --accent-text: #ffffff;
  --danger: #c2412f;

  --pee: #d9a21b;      --pee-bg: #fbf1d6;
  --poop: #8a5a3b;     --poop-bg: #f2e7de;
  --both: #a8742f;     --both-bg: #f6ecdc;
  --meal: #2f8a64;     --meal-bg: #e2f2ea;
  --accident: #c2412f; --accident-bg: #fbe5e1;
  --crate: #7b5aa6;    --crate-bg: #f0eaf7;
  --demo: #c4502f;     --demo-bg: #fbeae4;  --demo-text: #ffffff;

  --radius: 16px;
  --tabs-h: 64px;
  color-scheme: light;
}

/* Night mode: data-theme is set in index.html (saved choice, else the phone setting) */
:root[data-theme="dark"] {
  --bg: #171614;
  --surface: #211f1c;
  --surface-2: #2a2824;
  --text: #f1ede7;
  --muted: #a39d94;
  --border: #36332e;
  --accent: #9db6e8;
  --accent-text: #0f1d38;
  --danger: #ef7563;

  --pee: #f0c049;      --pee-bg: #3a3120;
  --poop: #c99572;     --poop-bg: #352a22;
  --both: #d9a35c;     --both-bg: #372e22;
  --meal: #5cc394;     --meal-bg: #1f3329;
  --accident: #ef7563; --accident-bg: #3d2420;
  --crate: #c4a8e8;    --crate-bg: #2e2640;
  --demo: #f2906e;     --demo-bg: #3a241d;  --demo-text: #2a120b;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
body.no-scroll { overflow: hidden; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }

/* Google Material Symbols, sized and coloured like text */
.icon { display: inline-block; width: 1.2em; height: 1.2em; line-height: 1; vertical-align: -0.25em; flex: none; }
.ms {
  font-family: 'Material Symbols Rounded'; font-weight: normal; font-style: normal;
  font-size: 1.2em; width: 1em; height: 1em; vertical-align: -0.2em;
  letter-spacing: normal; text-transform: none; white-space: nowrap; direction: ltr;
  -webkit-font-feature-settings: 'liga'; font-feature-settings: 'liga'; -webkit-font-smoothing: antialiased;
  font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  overflow: hidden;
}
.icon-svg { fill: currentColor; }
h1, h2 { margin: 0; }

.loading { text-align: center; color: var(--muted); padding-top: 40vh; }

.content {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(var(--tabs-h) + 88px + env(safe-area-inset-bottom));
}
.content.narrow { padding-bottom: 40px; }
.muted { color: var(--muted); }
.version { margin: 32px 0 0; text-align: center; font-size: 12px; color: var(--muted); opacity: .7; }

/* ── header ── */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; min-height: 44px; }
.top h1 { font-size: 28px; letter-spacing: -0.01em; }
.top .sub { color: var(--muted); font-size: 14px; }
.top-actions { display: flex; gap: 8px; }
.icon-btn.small { width: 36px; height: 36px; font-size: 15px; align-self: center; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: var(--surface-2); text-decoration: none; font-size: 18px; flex: none; color: var(--muted);
}

/* ── summary ── */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px; min-width: 0; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 15px; font-weight: 600; margin-top: 2px; letter-spacing: -0.01em; }
.today-counts { margin: -2px 2px 10px; color: var(--muted); font-size: 14px; }
.today-counts b { color: var(--text); }
.crate-banner {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
  padding: 12px 12px 12px 14px; border-radius: var(--radius);
  background: var(--crate-bg); border: 2px solid var(--crate);
}
.crate-icon { font-size: 26px; line-height: 1; color: var(--crate); }
.crate-text { flex: 1; min-width: 0; }
.crate-label { font-size: 14px; color: var(--muted); }
.crate-elapsed { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--crate); }
.btn.crate-end { background: var(--crate); border-color: var(--crate); color: var(--bg); min-width: 72px; }
.awake-line {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--border); font-size: 16px;
}
.awake-line b { font-variant-numeric: tabular-nums; }
.awake-icon { color: var(--pee); font-size: 16px; }
.awake-since { margin-left: auto; color: var(--muted); font-size: 14px; }
.hint .icon { color: var(--pee); }
.chip .icon { font-size: 15px; }
.chip.on .icon { color: inherit; }
.hint { margin: 10px 0 0; padding: 10px 12px; border-radius: 12px; background: var(--pee-bg); font-size: 15px; }

/* ── quick actions ── */
.actions { margin: 18px 0 8px; }
.group-gap { margin-top: 20px; }
.btn-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.log-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 66px; border-radius: var(--radius); border: 2px solid transparent;
  font-size: 18px; font-weight: 600;
  transition: transform .06s;
}
.log-btn .btn-icon { display: flex; gap: 2px; font-size: 24px; line-height: 1; color: var(--c); }
.log-btn:active { transform: scale(.97); }
.log-btn.wide { width: 100%; flex-direction: row; gap: 10px; }
/* Potty buttons are neutral grey; meal and crate keep their colour */
.log-btn.cat-pee, .log-btn.cat-poop, .log-btn.cat-both { background: var(--surface-2); border-color: var(--border); }
.log-btn.cat-pee .btn-icon, .log-btn.cat-poop .btn-icon, .log-btn.cat-both .btn-icon { color: var(--text); }
.log-btn.cat-meal { background: var(--meal-bg); border-color: color-mix(in srgb, var(--meal) 35%, transparent); }
.log-btn.cat-crate { background: var(--crate-bg); border-color: color-mix(in srgb, var(--crate) 35%, transparent); }
.log-btn.cat-crate.on { border-color: var(--crate); }

.secondary-row { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.secondary-row .btn { flex: 1; }
.secondary-row.add-row { margin-top: 20px; }
.add-row .btn { min-height: 44px; }
.btn.small { min-height: 36px; font-size: 14px; padding: 0 8px; white-space: nowrap; }
.accident-btn { color: var(--accident); }
.nothing-btn { color: var(--muted); }
.accident-btn .icon, .nothing-btn .icon { font-size: 15px; }
.accident-row { background: var(--accident-bg); border-radius: 12px; padding: 4px 4px 4px 14px; }
.accident-row .btn { min-height: 36px; font-size: 15px; }
.accident-row .icon-btn { width: 36px; height: 36px; }
.accident-row > span { font-weight: 600; color: var(--accident); }

/* ── buttons ── */
.btn {
  min-height: 48px; padding: 0 16px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 600;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.start { background: var(--demo); color: var(--demo-text); border-color: var(--demo); }
.btn.secondary { background: var(--surface-2); border-color: var(--surface-2); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); background: transparent; }
.btn.accident { background: var(--surface); border-color: transparent; }
.btn.link { background: none; border: 0; color: var(--muted); }
.btn.big { width: 100%; min-height: 56px; font-size: 17px; }
.btn:disabled { opacity: .6; }

/* ── timeline ── */
.section-title { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 24px 2px 8px; }
.timeline { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.timeline li + li { border-top: 1px solid var(--border); }
.ev {
  display: flex; align-items: center; gap: 10px; width: 100%;
  min-height: 52px; padding: 8px 14px; border: 0; background: none; text-align: left;
  border-left: 4px solid var(--c, var(--border));
}
.ev:active { background: var(--surface-2); }
.ev.pending { opacity: .6; }
.ev-time { width: 74px; flex: none; font-variant-numeric: tabular-nums; color: var(--muted); font-size: 15px; }
.ev-icon { width: 44px; flex: none; display: flex; justify-content: center; gap: 1px; color: var(--c); font-size: 18px; }
.ev-label { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev-who { color: var(--muted); font-size: 13px; flex: none; }
.cat-pee { --c: var(--pee); } .cat-poop { --c: var(--poop); } .cat-both { --c: var(--both); }
.cat-meal { --c: var(--meal); } .cat-accident { --c: var(--accident); } .cat-crate { --c: var(--crate); } .cat-nothing { --c: var(--muted); }
.ev.cat-nothing .ev-label { color: var(--muted); font-weight: 500; }
.ev.cat-accident .ev-label { color: var(--accident); }
.empty { color: var(--muted); padding: 14px; margin: 0; background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); text-align: center; }

/* ── history ── */
.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted); }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.day-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: 22px 2px 8px; }
.day-head h2 { font-size: 18px; }
.day-head span { color: var(--muted); font-size: 14px; }

/* ── insights ── */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.insight, .pattern, .empty-card, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.insight-value { font-size: 24px; font-weight: 700; margin: 2px 0; }
.insight-detail { font-size: 13px; color: var(--muted); }
.pattern p, .empty-card p { margin: 0 0 6px; }
.pattern + .pattern { margin-top: 10px; }

/* ── settings ── */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv span { color: var(--muted); }
.kv b { text-align: right; }
.pin { font-size: 20px; letter-spacing: .2em; font-variant-numeric: tabular-nums; }

/* ── welcome / forms ── */
.welcome { display: flex; flex-direction: column; gap: 14px; padding-top: 6vh; }
.welcome .brand { display: flex; justify-content: center; color: var(--accent); }
.welcome .brand .logo { width: 84px; height: 84px; }
.welcome h1 { font-size: 30px; text-align: center; }
form.welcome h1 { text-align: left; }
.welcome > p { text-align: center; margin: 0 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 15px; font-weight: 600; }
.field input, .text-input {
  min-height: 50px; padding: 0 14px; border-radius: 12px; width: 100%;
  border: 1px solid var(--border); background: var(--surface); font-size: 17px; font-weight: 400;
}
.field input:focus, .text-input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.welcome > .field-hint { text-align: left; margin: -6px 2px 0; font-size: 14px; color: var(--muted); }
.form-error { color: var(--danger); margin: 0; font-weight: 600; }
.demo-cta { display: flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; }
.welcome > .demo-note { margin: -6px 0 0; font-size: 14px; color: var(--muted); }
.jump-in {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--border);
}
.jump-in h2 { font-size: 16px; text-align: center; margin-bottom: 2px; }
.demo-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 0 0 12px; padding: 8px 12px; border-radius: 12px;
  background: var(--demo-bg); color: var(--text); font-size: 14px;
}
.demo-banner b { color: var(--demo); }
.demo-banner a { color: var(--demo); font-weight: 600; white-space: nowrap; }

/* ── bottom tabs ── */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  flex: 1; max-width: 186px; height: var(--tabs-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; font-size: 12px; font-weight: 600; color: var(--muted);
}
.tabs a .ms { font-size: 24px; font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24; }
.tabs a.on { color: var(--accent); }
.tabs a.on .ms { font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24; }

/* ── toast ── */
#toast {
  position: fixed; left: 50%; z-index: 20;
  bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
  display: flex; align-items: center; gap: 14px;
  width: max-content; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg);
  padding: 12px 14px 12px 18px; border-radius: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgb(0 0 0 / .2);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
#toast.error { background: var(--danger); color: #fff; }
#toast button { border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; padding: 6px 4px; }

/* ── bottom sheet ── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .4); }
.sheet {
  position: fixed; z-index: 31; left: 0; right: 0; bottom: 0;
  max-width: 560px; margin: 0 auto;
  height: min(92vh, 92dvh);
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: 20px 20px 0 0;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.sheet-head h2 { font-size: 20px; }
.field-label { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin: 14px 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip, .chip-input {
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); font-size: 15px; font-weight: 500;
}
.chip.on, .chip-input.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip-input { min-width: 0; flex: 1; }
.time-row { display: flex; gap: 8px; }
.time-row .text-input { flex: 1; }
.time-row .chip { min-height: 50px; }
.sheet-scroll { flex: 1; overflow-y: auto; margin: 0 -16px; padding: 0 16px 12px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.slots { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.slot {
  min-height: 44px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface);
  font-size: 14px; font-variant-numeric: tabular-nums; padding: 0 2px;
}
.slot.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
.sheet .form-error { margin: 8px 0; }
.sheet-foot { padding-top: 10px; border-top: 1px solid var(--border); }
.sheet-foot { display: flex; gap: 10px; }
.sheet-foot .btn.primary { flex: 1; min-height: 54px; font-size: 17px; }
