/*
 * Light is the base palette; dark is redefined twice on purpose -- once for the
 * system preference and once for the manual [data-theme] override -- so the
 * toggle wins in both directions. Deliberately not using light-dark(): an
 * unsupported browser would lose every colour at once.
 *
 * Surfaces are translucent and sit over the fixed aurora ground painted by
 * body::before. Only the bars and sheets carry backdrop-filter; cards use plain
 * alpha, which looks the same over a soft gradient and costs nothing on a phone.
 */
:root {
  color-scheme: light;
  --bg: #eef0f6;
  --glow-1: rgba(91, 71, 245, .10);
  --glow-2: rgba(16, 133, 95, .07);
  --glow-3: rgba(194, 105, 26, .045);
  --surface: rgba(255, 255, 255, .74);
  --surface-2: rgba(15, 23, 42, .055);
  --surface-strong: #ffffff;
  --line: rgba(15, 23, 42, .11);
  --edge: rgba(255, 255, 255, .9);
  --text: #10131c;
  --muted: #4d5468;
  --accent: #4a34e0;
  --accent-soft: rgba(74, 52, 224, .12);
  --on-accent: #ffffff;
  --stress: #883d06;
  --poop: #6d4728;
  --life: #046745;
  --food: #a32259;
  --med: #5a31a0;
  --danger: #b02020;
  --backdrop: rgba(16, 19, 28, .32);
  --row-tint: 8%;
  --row-tint-press: 16%;
  --shadow: 0 1px 2px rgba(16, 19, 28, .06), 0 8px 24px rgba(16, 19, 28, .07);
  --shadow-lift: 0 2px 6px rgba(16, 19, 28, .08), 0 18px 48px rgba(16, 19, 28, .14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --bar-height: 86px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-xl: 28px;
  --ease: cubic-bezier(.2, .8, .2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #090c15;
    --glow-1: rgba(120, 96, 255, .22);
    --glow-2: rgba(0, 189, 158, .14);
    --glow-3: rgba(255, 118, 62, .10);
    --surface: rgba(255, 255, 255, .055);
    --surface-2: rgba(255, 255, 255, .10);
    --surface-strong: #151a27;
    --line: rgba(255, 255, 255, .11);
    --edge: rgba(255, 255, 255, .14);
    --text: #eef1fa;
    --muted: #c9d0df;
    --accent: #c2b8ff;
    --accent-soft: rgba(194, 184, 255, .16);
    --on-accent: #0a0714;
    --stress: #ffb073;
    --poop: #c99a6b;
    --life: #6fe3b8;
    --food: #ffa6c9;
    --med: #cdbbf8;
    --danger: #ffa3a3;
    --backdrop: rgba(4, 6, 12, .62);
    --row-tint: 6%;
    --row-tint-press: 12%;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
    --shadow-lift: 0 2px 8px rgba(0, 0, 0, .5), 0 24px 60px rgba(0, 0, 0, .5);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #090c15;
  --glow-1: rgba(120, 96, 255, .22);
  --glow-2: rgba(0, 189, 158, .14);
  --glow-3: rgba(255, 118, 62, .10);
  --surface: rgba(255, 255, 255, .055);
  --surface-2: rgba(255, 255, 255, .10);
  --surface-strong: #151a27;
  --line: rgba(255, 255, 255, .11);
  --edge: rgba(255, 255, 255, .14);
  --text: #eef1fa;
  --muted: #c9d0df;
  --accent: #c2b8ff;
  --accent-soft: rgba(194, 184, 255, .16);
  --on-accent: #0a0714;
  --stress: #ffb073;
  --poop: #c99a6b;
  --life: #6fe3b8;
  --food: #ffa6c9;
  --med: #cdbbf8;
  --danger: #ffa3a3;
  --backdrop: rgba(4, 6, 12, .62);
  --row-tint: 6%;
  --row-tint-press: 12%;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px rgba(0, 0, 0, .35);
  --shadow-lift: 0 2px 8px rgba(0, 0, 0, .5), 0 24px 60px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-x: contain;
  padding-bottom: calc(var(--bar-height) + var(--safe-bottom));
}

/*
 * The aurora ground. A fixed pseudo-element rather than background-attachment,
 * which iOS renders unreliably inside a scrolling document.
 */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(88vw 56vh at 16% 4%, var(--glow-1), transparent 68%),
    radial-gradient(76vw 48vh at 96% 26%, var(--glow-2), transparent 66%),
    radial-gradient(96vw 52vh at 42% 96%, var(--glow-3), transparent 70%),
    var(--bg);
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

/* One focus treatment for the whole app, so nothing loses its ring. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 8px;
}

/* ---------- glass primitives ---------- */

.glass {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
}

/* ---------- top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  padding: calc(var(--safe-top) + 12px) 12px 12px;
  display: grid;
  gap: 12px;
}

.toprow { display: flex; align-items: center; gap: 8px; }

.periods {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 3px;
  flex: 1;
  min-width: 0;
}

#theme,
#menu-open {
  flex: none;
  width: 44px;
  height: 44px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: transform .18s var(--ease), color .18s var(--ease);
}

#theme:active,
#menu-open:active { transform: scale(.93); color: var(--text); }
#theme svg, #menu-open svg { width: 20px; height: 20px; display: block; }

.periods button {
  background: none;
  border: 0;
  border-radius: 11px;
  padding: 9px 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 590;
  letter-spacing: -.01em;
  transition: background .2s var(--ease), color .2s var(--ease);
}

.periods button.active {
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: var(--shadow);
}

.datenav {
  display: grid;
  /* minmax(0, 1fr) so the date pill can shrink; a bare 1fr refuses to go below
     min-content and pushes the next-day button off the right edge on iOS. */
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: center;
}

.datenav button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  height: 46px;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  display: grid;
  place-items: center;
  transition: transform .18s var(--ease), color .18s var(--ease);
}

.datenav button:active { transform: scale(.93); color: var(--text); }
.datenav button svg { width: 20px; height: 20px; display: block; }

.datefield {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 46px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  /* backstop: clip rather than let a stubborn native control widen the page */
  overflow: hidden;
}

#date {
  background: none;
  border: 0;
  padding: 0;
  height: 100%;
  min-width: 0;
  width: auto;
  flex: 1 1 auto;
  text-align: center;
  font-weight: 590;
}

/* ---------- report body ---------- */

.datenav[hidden], .daybar[hidden] { display: none; }

.daybar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
}

#range {
  text-align: center;
  font-size: 15px;
  font-weight: 620;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.daybar-right { justify-self: end; display: flex; align-items: center; gap: 8px; }

#pending {
  background: color-mix(in srgb, var(--stress) 16%, transparent);
  border: 1px solid color-mix(in srgb, var(--stress) 40%, var(--line));
  border-radius: 999px;
  color: var(--stress);
  font-size: 12px;
  font-weight: 620;
  padding: 4px 10px;
  white-space: nowrap;
}

#pending[hidden] { display: none; }

.event.pending { opacity: .62; border-style: dashed; }

#today {
  justify-self: end;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 620;
  padding: 6px 13px;
  min-height: 32px;
  transition: transform .18s var(--ease);
}

#today:active { transform: scale(.94); }
#today[hidden] { display: none; }

/*
 * touch-action: pan-y claims the horizontal pan for the swipe handler. Without
 * it iOS hands that direction to its own back-forward overscroll and cancels
 * the touch sequence, so the swipe never completes. min-height keeps the swipe
 * surface a full screen even on a day with two entries on it.
 */
main {
  padding: 16px 12px 28px;
  touch-action: pan-y pinch-zoom;
  min-height: 62svh;
}
.empty { text-align: center; padding: 56px 0; }

/* ---------- bento stats ---------- */

.stats {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-bottom: 18px;
}

.stat {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 14px 6px 12px;
  text-align: center;
  display: grid;
  gap: 3px;
}

/* A soft light source along the top edge, the way glass catches a highlight. */
.stat::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--edge), transparent);
}

.stat-value {
  font-size: 26px;
  font-weight: 680;
  letter-spacing: -.03em;
  line-height: 1.1;
}

.stat-label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 620;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ---------- timeline ---------- */

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 9px; }

/*
 * Each category tints its whole row -- surface, border and a bar down the left
 * edge -- so five kinds are told apart at a glance and not only by the icon.
 * --tint falls back to --line for anything without a kind class.
 */
.event {
  --tint: var(--line);
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 52px 40px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  background: color-mix(in srgb, var(--tint) var(--row-tint), var(--surface));
  border: 1px solid color-mix(in srgb, var(--tint) 26%, var(--line));
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 12px 12px 12px 15px;
  min-height: 64px;
  text-align: left;
  width: 100%;
  transition: transform .18s var(--ease), background .18s var(--ease);
}

.event::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--tint);
}

.event.stress { --tint: var(--stress); }
.event.poop   { --tint: var(--poop); }
.event.food   { --tint: var(--food); }
.event.med    { --tint: var(--med); }
.event.life   { --tint: var(--life); }

.event { cursor: pointer; }
.event.pending { cursor: default; }
.event:active { transform: scale(.985); background: color-mix(in srgb, var(--tint) var(--row-tint-press), var(--surface)); }

/* The kind reads from a tinted medallion instead of a hard rule down the side. */
.event-icon {
  width: 40px;
  height: 40px;
  border-radius: 13px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--text);
}

.event .event-icon { background: color-mix(in srgb, var(--tint) 24%, transparent); }
.event.poop .event-icon { color: var(--poop); }

.event-time {
  color: var(--muted);
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 590;
  align-self: center;
}

.event-icon.emoji { font-size: 20px; line-height: 1; }
.event-icon .glyph { width: 26px; height: 13px; }

.event-main { display: grid; gap: 2px; min-width: 0; }
.event-title { font-weight: 600; letter-spacing: -.015em; }
.event-comment { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }

/* ---------- range report ---------- */

.bristol {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 18px;
}

.bristol h2 {
  margin: 0 0 12px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 620;
}

.bristol-row {
  display: grid;
  grid-template-columns: minmax(0, 165px) minmax(0, 1fr) 24px;
  gap: 8px;
  align-items: center;
  margin-bottom: 7px;
  font-size: 14px;
}

.bristol-type {
  color: var(--muted);
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 7px;
  align-items: center;
  overflow: hidden;
}

.bristol-type span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bristol-type .glyph { width: 28px; height: 14px; color: var(--poop); }
.bar { background: var(--surface-2); border-radius: 999px; height: 8px; overflow: hidden; }

.bar-fill {
  background: linear-gradient(90deg, color-mix(in srgb, var(--poop) 65%, transparent), var(--poop));
  height: 100%;
  border-radius: 999px;
}

.bristol-count { text-align: right; font-variant-numeric: tabular-nums; font-weight: 590; }

table.days { width: 100%; table-layout: fixed; border-collapse: collapse; font-size: 14px; }
table.days th:nth-child(1) { width: 72px; }
table.days th:nth-child(2) { width: 68px; }
table.days th:nth-child(3) { width: 58px; }

table.days th {
  text-align: left;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 620;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

table.days td { padding: 11px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.days tr.blank td { color: var(--muted); }
.day-cell { width: 74px; }
.life-cell { color: var(--muted); overflow-wrap: anywhere; }
.day-cell, table.days td { overflow-wrap: anywhere; }

.daylink {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 620;
}

/* ---------- trends ---------- */

.caution {
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text);
}

.insight {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 9px;
  display: grid;
  gap: 7px;
}

.insight-head { display: flex; align-items: center; gap: 9px; }
.insight-label { font-weight: 640; letter-spacing: -.015em; overflow-wrap: anywhere; }

.insight-n {
  color: var(--muted);
  font-size: 12px;
  font-weight: 590;
  margin-left: auto;
  white-space: nowrap;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 9px;
}

.insight-stat { font-size: 14px; display: flex; gap: 6px; align-items: baseline; }
.insight-stat .metric { color: var(--muted); min-width: 92px; }
.insight-stat .up { color: var(--stress); font-weight: 620; }
.insight-stat .down { color: var(--life); font-weight: 620; }
.insight-stat .flat { color: var(--muted); }

/* ---------- action bar ---------- */

.actionbar {
  position: fixed;
  left: 10px; right: 10px;
  bottom: calc(10px + var(--safe-bottom));
  z-index: 6;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 6px;
  background: color-mix(in srgb, var(--surface-strong) 78%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lift);
}

/* Icon only: the name lives in aria-label, so nothing is lost to a reader. */
.actionbar .add {
  border: 0;
  border-radius: 18px;
  background: none;
  padding: 6px 2px;
  min-height: 56px;
  display: grid;
  justify-items: center;
  align-content: center;
  transition: transform .18s var(--ease), background .18s var(--ease);
}

/* The tile carries the category colour so the label can stay plain text at
   full contrast -- colour is decoration here, never the only signal. */
.actionbar .tile {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  color: var(--tint);
  background: color-mix(in srgb, var(--tint) 20%, transparent);
  border: 1px solid color-mix(in srgb, var(--tint) 42%, transparent);
  transition: background .18s var(--ease), color .18s var(--ease);
}

.actionbar .tile svg { width: 22px; height: 22px; display: block; }

.actionbar .stress { --tint: var(--stress); }
.actionbar .poop   { --tint: var(--poop); }
.actionbar .food   { --tint: var(--food); }
.actionbar .med    { --tint: var(--med); }
.actionbar .life   { --tint: var(--life); }

.actionbar .add:active { transform: scale(.94); background: var(--surface-2); }
.actionbar .add:active .tile { background: color-mix(in srgb, var(--tint) 40%, transparent); }

/* ---------- chips as tags ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chips:empty { display: none; }

.chip {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 14px;
  font-weight: 560;
  padding: 8px 14px;
  min-height: 36px;
  transition: transform .16s var(--ease), background .16s var(--ease), color .16s var(--ease);
}

.chip:active { transform: scale(.94); }
.menu-body a, .daylink, summary { cursor: pointer; }

.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

/* ---------- detail disclosure ---------- */

#detail-field { border-top: 1px solid var(--line); padding-top: 14px; }
#detail-field[hidden] { display: none; }

#detail-field summary {
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  min-height: 32px;
}

.detail-grid { display: grid; gap: 14px; padding-top: 12px; }
.detail-grid input[type="range"] { width: 100%; accent-color: var(--accent); }
.detail-grid output { font-weight: 400; }

/* ---------- entry sheet ---------- */

dialog {
  width: 100%;
  max-width: min(560px, 100%);
  margin: auto auto 0;
  padding: 0;
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  background: color-mix(in srgb, var(--surface-strong) 88%, transparent);
  backdrop-filter: saturate(180%) blur(28px);
  -webkit-backdrop-filter: saturate(180%) blur(28px);
  color: var(--text);
  box-shadow: var(--shadow-lift);
}

dialog::backdrop { background: var(--backdrop); backdrop-filter: blur(3px); }

.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 16px 12px 12px;
  border-bottom: 1px solid var(--line);
  background: inherit;
}

/* The grabber says "this sheet can be dismissed" without spending a control. */
.sheet-head::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  transform: translateX(-50%);
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-head strong { font-size: 16px; font-weight: 640; letter-spacing: -.015em; }
.sheet-head button { background: none; border: 0; color: var(--accent); font-weight: 620; padding: 6px; }
.sheet-head button:first-child { justify-self: start; }
.sheet-head #save { justify-self: end; }
.sheet-head #save:disabled { color: var(--muted); }

.sheet-body {
  padding: 16px 14px calc(22px + var(--safe-bottom));
  display: grid;
  gap: 16px;
  max-height: 70vh;
  overflow-y: auto;
  overflow-x: hidden; /* stops a stubborn native control scrolling the sheet sideways */
}

/* overflow:hidden is the backstop -- a native control that still refuses to
   shrink gets clipped to the card instead of overhanging its right edge. */
.field { display: grid; gap: 7px; min-width: 0; overflow: hidden; }
.field[hidden] { display: none; }
.field.row { grid-template-columns: minmax(0, 1fr) auto; align-items: center; }

.field label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.field.row label { text-transform: none; font-size: 15px; letter-spacing: -.01em; color: var(--text); }

/*
 * iOS date/time controls size themselves from an internal shadow DOM, and
 * min-width on the input cannot reach it -- ::-webkit-date-and-time-value keeps
 * its own intrinsic width and margins and pushes the field past its container.
 * Blink's shadow DOM differs, so this never reproduces in desktop Chrome.
 */
/* iOS only: appearance:none would strip the calendar icon in desktop Chrome. */
@supports (-webkit-touch-callout: none) {
  input[type="date"],
  input[type="datetime-local"] {
    -webkit-appearance: none;
    appearance: none;
  }
}

/* box-sizing has to be restated: the `*` reset does not match pseudo-elements. */
input[type="date"]::-webkit-date-and-time-value,
input[type="datetime-local"]::-webkit-date-and-time-value {
  box-sizing: border-box;
  min-width: 0;
  width: 100%;
  margin: 0;
  text-align: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

input[type="date"]::-webkit-datetime-edit,
input[type="datetime-local"]::-webkit-datetime-edit,
input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="datetime-local"]::-webkit-datetime-edit-fields-wrapper {
  box-sizing: border-box;
  min-width: 0;
  max-width: 100%;
  padding: 0;
  overflow: hidden;
}

input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  flex: none;
  margin-inline-start: 4px;
}

.field input[type="text"],
.field input[type="date"],
.field input[type="datetime-local"],
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px;
  width: 100%;
  min-width: 0; /* iOS date/time controls otherwise refuse to shrink */
  max-width: 100%;
  font-size: 16px; /* under 16px makes iOS Safari zoom on focus */
  transition: border-color .18s var(--ease), background .18s var(--ease);
}

.field input:focus, .field textarea:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  outline: none;
}

.field textarea { resize: vertical; }

.switch { width: 50px; height: 30px; accent-color: var(--accent); }

.scale { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.scale[data-kind="stress"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.scale-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  min-height: 62px;
  font-size: 17px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 2px;
  transition: transform .16s var(--ease), background .16s var(--ease);
}

.scale-btn:active { transform: scale(.93); }

/* The drawn Bristol type sits above the number in the picker. */
.scale-btn .glyph { width: 36px; height: 18px; opacity: .8; }
.scale-btn.selected .glyph { opacity: 1; }
.scale-num { line-height: 1; }

.scale-btn.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
}

.hint { margin: 0; font-size: 13px; color: var(--muted); min-height: 1.2em; }
.hint strong { color: var(--text); font-weight: 620; }

/* Label plus its help link, so the question sits where the doubt is. */
.field-head { display: flex; align-items: center; gap: 10px; }
.field-head label { flex: 1; min-width: 0; }

#bristol-help-open {
  flex: none;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-radius: 999px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 620;
  padding: 5px 11px;
  min-height: 30px;
}

#bristol-help-open[hidden] { display: none; }

/* ---------- Bristol guide ---------- */

.bristol-guide { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.guide-row {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--band);
  border-radius: var(--r-md);
  padding: 12px;
}

/* The three readings of the scale, so the ordering has a shape you can see. */
.guide-row.band-constipated { --band: var(--stress); }
.guide-row.band-typical     { --band: var(--life); }
.guide-row.band-loose       { --band: var(--food); }

.guide-art { width: 74px; height: 37px; color: var(--poop); display: block; }
.guide-main { display: grid; gap: 3px; min-width: 0; }
.guide-head { display: flex; align-items: center; gap: 8px; }
.guide-head strong { font-size: 15px; font-weight: 620; letter-spacing: -.015em; }

.guide-band {
  margin-left: auto;
  flex: none;
  font-size: 11px;
  font-weight: 620;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--band);
  background: color-mix(in srgb, var(--band) 14%, transparent);
  border-radius: 999px;
  padding: 3px 9px;
}

.guide-look { font-size: 13px; color: var(--muted); }

.danger {
  background: color-mix(in srgb, var(--danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
  border-radius: 14px;
  color: var(--danger);
  font-weight: 600;
  padding: 13px;
  min-height: 50px;
}

.danger[hidden] { display: none; }

.menu-body a,
.menu-body button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  min-height: 50px;
}

.menu-body .menu-danger { color: var(--danger); }
.menu-body .hint { margin: -4px 0 0; }

/* ---------- login ---------- */

.login-body { display: grid; place-items: center; min-height: 100svh; padding: 24px; }
.login-card { width: 100%; max-width: 340px; display: grid; gap: 18px; }

.login-card h1 {
  margin: 0;
  text-align: center;
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -.03em;
}

.login-card form { display: grid; gap: 10px; }
.login-card label { font-size: 12px; color: var(--muted); font-weight: 620; text-transform: uppercase; letter-spacing: .05em; }

.login-card input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 15px;
  font-size: 16px;
}

.login-card button {
  background: var(--accent);
  border: 0;
  border-radius: 14px;
  color: var(--on-accent);
  font-weight: 660;
  padding: 15px;
  min-height: 52px;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 32%, transparent);
}

/* ---------- motion ---------- */

/*
 * Entrance stagger without touching the DOM: the delay comes from nth-child, and
 * only the first rows get one, so a long timeline never waits on an animation.
 */
@media (prefers-reduced-motion: no-preference) {
  .stat, .event, .insight {
    animation: rise .38s var(--ease) both;
  }

  .event:nth-child(2), .insight:nth-child(2)  { animation-delay: .04s; }
  .event:nth-child(3), .insight:nth-child(3)  { animation-delay: .08s; }
  .event:nth-child(4), .insight:nth-child(4)  { animation-delay: .12s; }
  .event:nth-child(5), .insight:nth-child(5)  { animation-delay: .16s; }
  .event:nth-child(6), .insight:nth-child(6)  { animation-delay: .20s; }
  .event:nth-child(n+7), .insight:nth-child(n+7) { animation-delay: .24s; }

  .stat:nth-child(2) { animation-delay: .05s; }
  .stat:nth-child(3) { animation-delay: .10s; }
  .stat:nth-child(4) { animation-delay: .15s; }

  dialog[open] { animation: sheet-up .32s var(--ease); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px) scale(.99); }
  to   { opacity: 1; transform: none; }
}

@keyframes sheet-up {
  from { transform: translateY(18px); opacity: .4; }
  to   { transform: none; opacity: 1; }
}
