:root {
  color-scheme: light dark;

  --colour-temperature: oklch(0.73 0.138 35);
  --colour-nappy: oklch(0.85 0.145 88);
  --colour-milestone: oklch(0.73 0.138 120);
  --colour-food: oklch(0.73 0.138 60);
  --colour-weight: oklch(0.73 0.138 175);
  --colour-feed: oklch(0.73 0.138 230);
  --colour-feed-breast: oklch(0.73 0.138 265);
  --colour-sleep: oklch(0.73 0.138 300);
  --colour-medicine: oklch(0.73 0.138 350);

  --colour-feed-countdown: oklch(0.73 0.138 195);

  --colour-wake: oklch(0.83 0.138 300);

  --colour-on-event: oklch(0.243 0.012 67);

  --colour-banner-text: oklch(0.96 0.008 75);

  --colour-scrim: oklch(0.15 0.008 67 / 0.62);

  --colour-pending: oklch(0.62 0.13 75);

  --colour-bg: oklch(0.98 0.006 75);
  --colour-surface: oklch(0.995 0.005 78);
  --colour-text: oklch(0.243 0.012 67);
  --colour-muted: oklch(0.502 0.018 67);
  --colour-danger: oklch(0.503 0.12 46);
  --colour-success: oklch(0.454 0.062 160);
  --colour-border: oklch(0.904 0.018 78);
  --colour-primary: oklch(0.454 0.062 160);
  --colour-primary-inverse: oklch(0.773 0.074 159);
  --colour-on-primary: oklch(1 0 0);

  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
  --space-2xl: 64px;

  --text-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.8rem);
  --text-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.9rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.05rem);
  --text-lg: clamp(1rem, 0.9rem + 0.5vw, 1.2rem);
  --text-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.6rem);
  --text-2xl: clamp(1.6rem, 1.3rem + 1.5vw, 2.2rem);

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px oklch(0.3 0.02 55 / 0.06);
  --shadow-md: 0 2px 8px oklch(0.3 0.02 55 / 0.08), 0 1px 2px oklch(0.3 0.02 55 / 0.04);
  --shadow-lg: 0 4px 16px oklch(0.3 0.02 55 / 0.1), 0 2px 4px oklch(0.3 0.02 55 / 0.06);

  --font-sans: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  @media (prefers-color-scheme: dark) {
    --colour-bg: oklch(0.207 0.008 67);
    --colour-surface: oklch(0.238 0.011 73);
    --colour-text: oklch(0.946 0.013 75);
    --colour-muted: oklch(0.707 0.02 75);
    --colour-border: oklch(0.301 0.015 71);
    --colour-primary: oklch(0.773 0.074 159);
    --colour-primary-inverse: oklch(0.454 0.062 160);
    --colour-on-primary: oklch(0.243 0.012 67);
    --colour-danger: oklch(0.70 0.13 46);
    --colour-success: oklch(0.773 0.074 159);
    --colour-pending: oklch(0.68 0.11 75);
    --shadow-sm: 0 1px 2px oklch(0.05 0.008 67 / 0.3);
    --shadow-md: 0 2px 8px oklch(0.05 0.008 67 / 0.35);
    --shadow-lg: 0 4px 16px oklch(0.05 0.008 67 / 0.4);
  }
}

@media (prefers-color-scheme: dark) {
  .auth-form input {
    background: var(--colour-surface);
    color: var(--colour-text);
  }

  .modal { background: var(--colour-surface); }
  .modal-btn { background: var(--colour-surface); color: var(--colour-text); }
  .modal-btn:active, .modal-btn.active { background: var(--colour-border); border-color: var(--colour-feed); }

  .amount-input-group button { background: var(--colour-surface); color: var(--colour-text); }
  .amount-input-group button:active { background: var(--colour-border); }
  .amount-input-group input { background: var(--colour-surface); color: var(--colour-text); }

  .timeline-item.type-nappy .icon { background: color-mix(in oklab, var(--colour-nappy) 18%, transparent); }
  .timeline-item.type-feed .icon { background: color-mix(in oklab, var(--colour-feed) 18%, transparent); }
  .timeline-item.type-sleep .icon { background: color-mix(in oklab, var(--colour-sleep) 18%, transparent); }
  .timeline-item.type-medicine .icon { background: color-mix(in oklab, var(--colour-medicine) 18%, transparent); }
  .timeline-item.type-weight .icon { background: color-mix(in oklab, var(--colour-weight) 18%, transparent); }
  .timeline-item.type-temperature .icon { background: color-mix(in oklab, var(--colour-temperature) 18%, transparent); }
  .timeline-item.type-milestone .icon { background: color-mix(in oklab, var(--colour-milestone) 18%, transparent); }
  .timeline-item.type-food .icon { background: color-mix(in oklab, var(--colour-food) 18%, transparent); }

  .timeline-day-count { background: var(--colour-border); }

  .timeline-item.active-event {
    background: color-mix(in oklch, var(--colour-primary) 8%, var(--colour-surface));
  }
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overscroll-behavior-y: contain;
  overflow-x: hidden;
}

input, select, textarea { font-size: 16px; }

body {
  font-family: var(--font-sans);
  background: var(--colour-bg);
  color: var(--colour-text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;

  @supports (padding-top: env(safe-area-inset-top)) {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

.header {
  background: var(--colour-surface);
  padding: 14px var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--colour-border);
  position: sticky;
  top: var(--banner-offset, 0px);
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: color-mix(in oklch, var(--colour-surface) 85%, transparent);

  @supports (padding-top: env(safe-area-inset-top)) {
    padding-top: calc(14px + env(safe-area-inset-top));
  }

  & h1 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: none;
}

.header-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 600;
  padding: var(--space-sm) var(--space-sm);
  min-height: 44px;
  border-radius: var(--radius-sm);
  opacity: 0.6;
  transition: all 0.2s var(--ease-out);
  color: var(--colour-text);

  &:active { opacity: 1; background: var(--colour-bg); }
  &.active { opacity: 1; color: var(--colour-primary); }
}

.brand-btn {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;

  &:active { opacity: 0.6; }
}

.sync-indicator {
  width: 44px;
  height: 44px;
  margin: -17px;
  padding: 0;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--colour-muted);
  -webkit-appearance: none;
  appearance: none;

  &::before {
    content: '';
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: currentColor;
    transition: background-color 0.3s var(--ease-out);
  }

  &.synced { color: var(--colour-success); }
  &.pending { color: var(--colour-pending); animation: pulse 2s var(--ease-in-out) infinite; }
  &.offline { color: var(--colour-danger); }
  &.blocked { color: var(--colour-danger); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.auth-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--space-lg);

  & h1 {
    font-family: var(--font-display);
    font-size: var(--text-2xl);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: var(--space-sm);
  }

  & p {
    color: var(--colour-muted);
    margin-bottom: var(--space-xl);
    text-align: center;
    font-size: var(--text-base);
  }
}

.auth-form {
  width: 100%;
  max-width: 320px;

  & input {
    width: 100%;
    padding: 14px var(--space-md);
    border: 2px solid var(--colour-border);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-family: inherit;
    margin-bottom: var(--space-sm);
    outline: none;
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);

    &:focus {
      border-color: var(--colour-primary);
      box-shadow: 0 0 0 3px color-mix(in oklab, var(--colour-primary) 14%, transparent);
    }
  }

  & .error {
    color: var(--colour-danger);
    font-size: var(--text-sm);
    margin-bottom: var(--space-sm);
    min-height: 1.25rem;
    font-weight: 500;
    line-height: 1.5;
    text-align: left;

    &:not(:empty) {
      margin-bottom: var(--space-md, 16px);
    }
  }
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--colour-primary);
  color: var(--colour-on-primary);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.15s var(--ease-out), box-shadow 0.15s var(--ease-out);

  &:active { transform: scale(0.97); }
  &:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
}

.summary {
  padding: var(--space-md) var(--space-md) var(--space-md);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  border-bottom: 1px solid var(--colour-border);
}

.summary-card {
  background: transparent;
  border-radius: 0;
  padding: var(--space-sm) var(--space-xs);
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;

  & .icon { font-size: 1.1rem; opacity: 0.7; }
  & .label { color: var(--colour-muted); font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.01em; }
  & .value { font-weight: 600; font-size: var(--text-sm); color: var(--colour-muted); }
}

.quick-log {
  padding: var(--space-sm) var(--space-md) var(--space-md);
  margin-top: var(--space-sm);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.log-btn {
  --btn-accent: var(--colour-nappy);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-md) var(--space-sm);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: transform 0.12s var(--ease-out), box-shadow 0.12s var(--ease-out);
  min-height: 68px;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  color: var(--colour-on-event);
  box-shadow: var(--shadow-sm);
  background-color: var(--btn-accent);
  background-image:
    radial-gradient(120% 90% at 50% -25%, oklch(1 0 0 / 0.25), oklch(1 0 0 / 0) 55%),
    linear-gradient(to bottom, transparent 55%, oklch(0 0 0 / 0.08));

  &:active { transform: scale(0.94); box-shadow: none; }
  & .emoji { font-size: 1.4rem; }

  &.nappy { --btn-accent: var(--colour-nappy); }
  &.feed { --btn-accent: var(--colour-feed); }
  &.feed-breast { --btn-accent: var(--colour-feed-breast); }
  &.sleep { --btn-accent: var(--colour-sleep); }
  &.wake { --btn-accent: var(--colour-wake); }
  &.medicine { --btn-accent: var(--colour-medicine); }
  &.weight { --btn-accent: var(--colour-weight); }
  &.temperature { --btn-accent: var(--colour-temperature); }
  &.milestone { --btn-accent: var(--colour-milestone); }
  &.food { --btn-accent: var(--colour-food); }
}

/*
 * Press and hold to reorder.
 *
 * The held button lifts and loses its transition so it tracks the finger with
 * no lag; the rest slide to the place it is about to take. Transforms only, so
 * nothing here costs a layout. The lift itself is an inline transform, which is
 * what keeps `.log-btn:active`'s tap-scale from fighting it.
 */
.quick-log.reorderable {
  /* Nothing to draw. The class is what says a hold means something here. */
  touch-action: pan-y;
}

.quick-log.reordering {
  cursor: grabbing;

  & .log-btn { touch-action: none; }

  & .log-btn.dragging {
    z-index: 2;
    box-shadow: var(--shadow-lg);
    opacity: 0.95;
  }
}

.more-toggle {
  text-align: center;
  padding: 0 var(--space-md) var(--space-md);

  & button {
    background: none;
    border: none;
    color: var(--colour-primary);
    font-size: var(--text-sm);
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-full);
    transition: background 0.15s var(--ease-out);

    &:active { background: color-mix(in oklab, var(--colour-primary) 10%, transparent); }
  }
}

.filter-bar {
  padding: var(--space-md) var(--space-md) var(--space-md);
  display: flex;
  gap: var(--space-sm);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;

  &::-webkit-scrollbar { display: none; }
}

.filter-chip {
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1.5px solid var(--colour-border);
  border-radius: var(--radius-full);
  background: var(--colour-surface);
  font-size: var(--text-xs);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  color: var(--colour-muted);
  transition: all 0.15s var(--ease-out);
  letter-spacing: 0.01em;

  &.active {
    background: var(--colour-primary);
    border-color: var(--colour-primary);
    color: var(--colour-on-primary);
  }
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--colour-scrim);
  z-index: 260;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fadeIn 0.15s var(--ease-out);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--colour-surface);
  width: 100%;
  min-width: 0;
  max-width: 480px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-lg) var(--space-md) var(--space-xl);
  animation: slideUp 0.25s var(--ease-out);
  max-height: 90vh;
  max-height: 90dvh;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  will-change: transform;

  /* The grab handle. sheet.js does the dragging; this says it can be dragged. */
  &::before {
    content: '';
    display: block;
    width: 36px;
    height: 5px;
    margin: calc(var(--space-sm) - var(--space-lg)) auto var(--space-md);
    border-radius: 999px;
    background: var(--colour-border);
  }

  & h2 {
    font-family: var(--font-display);
    font-size: var(--text-lg);
    font-weight: 600;
    letter-spacing: -0.01em;
    margin-bottom: var(--space-md);
    text-align: center;
  }
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: var(--space-md);
}

.modal-btn {
  padding: var(--space-md);
  border: 2px solid var(--colour-border);
  border-radius: var(--radius-md);
  background: var(--colour-surface);
  font-size: var(--text-base);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s var(--ease-out), background 0.15s var(--ease-out), transform 0.1s var(--ease-out);
  color: var(--colour-text);

  &:active { transform: scale(0.96); }

  &:active, &.active {
    border-color: var(--colour-feed);
    background: color-mix(in oklab, var(--colour-feed) 8%, transparent);
  }

  & .emoji { display: block; font-size: 1.5rem; margin-bottom: var(--space-xs); }
}

.modal-close {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  background: none;
  font-size: var(--text-base);
  font-weight: 700;
  font-family: inherit;
  color: var(--colour-muted);
  cursor: pointer;
  transition: background 0.15s var(--ease-out);

  &:active { background: var(--colour-border); }
}

.modal-actions {
  display: flex;
  gap: var(--space-sm);
  margin-top: var(--space-md);

  > * {
    flex: 1 1 0;
    min-width: 0;
  }
}

.ingredient-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin-bottom: var(--space-sm);
}

.ingredient-row {
  display: flex;
  gap: var(--space-sm);
  align-items: stretch;

  & .food-ingredient {
    flex: 1 1 0;
  }

  & .ingredient-remove {
    flex: 0 0 48px;
    min-height: 48px;
    border: 2px solid var(--colour-border);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--colour-muted);
    font-size: var(--text-base);
    font-family: inherit;
    cursor: pointer;
  }
}

.modal-field.ingredient-field {
  overflow: visible;
}

.ingredient-add {
  padding: 12px;
}

.btn-secondary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--colour-bg);
  color: var(--colour-muted);
  font-size: var(--text-base);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s var(--ease-out), transform 0.15s var(--ease-out);

  &:active {
    background: var(--colour-border);
    transform: scale(0.97);
  }
}

.modal-field {
  margin-bottom: var(--space-md);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  & label {
    display: block;
    font-size: var(--text-xs);
    font-weight: 700;
    color: var(--colour-muted);
    margin-bottom: 6px;
    letter-spacing: 0.01em;
  }

  & input,
  & textarea,
  & select {
    box-sizing: border-box;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 1;
    padding: 12px;
    border: 2px solid var(--colour-border);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    font-family: inherit;
    outline: none;
    background: var(--colour-surface);
    color: var(--colour-text);
    transition: border-color 0.2s var(--ease-out), box-shadow 0.2s var(--ease-out);
  }

  & input:focus,
  & textarea:focus,
  & select:focus {
    border-color: var(--colour-primary);
    box-shadow: 0 0 0 3px color-mix(in oklab, var(--colour-primary) 14%, transparent);
  }

  & textarea {
    resize: vertical;
    min-height: 60px;
  }
}

.datetime-row {
  display: flex;
  gap: var(--space-sm);

  & input {
    flex: 1;
    min-width: 0;
  }
}

.amount-input-group {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-bottom: var(--space-md);
  justify-content: center;

  & button {
    width: 48px;
    height: 48px;
    border: 2px solid var(--colour-border);
    border-radius: 50%;
    background: var(--colour-surface);
    font-size: 1.5rem;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--colour-text);
    transition: transform 0.1s var(--ease-out), background 0.15s var(--ease-out);

    &:active { transform: scale(0.92); background: var(--colour-bg); }
  }

  & input {
    width: 100px;
    text-align: center;
    font-size: 1.5rem;
    font-weight: 800;
    font-family: inherit;
    border: 2px solid var(--colour-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    outline: none;
    background: var(--colour-surface);
    color: var(--colour-text);
    font-variant-numeric: tabular-nums;
    -moz-appearance: textfield;
    appearance: textfield;

    &::-webkit-outer-spin-button,
    &::-webkit-inner-spin-button {
      -webkit-appearance: none;
      margin: 0;
    }

    &:focus { border-color: var(--colour-feed); box-shadow: 0 0 0 3px color-mix(in oklab, var(--colour-feed) 12%, transparent); }
  }
}

.amount-label {
  text-align: center;
  color: var(--colour-muted);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-md);
}

.btn-save {
  width: 100%;
  padding: var(--space-md);
  background: var(--colour-feed);
  color: var(--colour-on-event);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: var(--space-sm);
  transition: transform 0.12s var(--ease-out);

  &:active { transform: scale(0.97); }
}

.btn-danger {
  width: 100%;
  padding: 14px;
  background: none;
  color: var(--colour-danger);
  border: 2px solid var(--colour-danger);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  margin-top: var(--space-sm);
  transition: all 0.15s var(--ease-out);

  &:active { background: var(--colour-danger); color: white; transform: scale(0.97); }
}

.timeline { padding: 0 var(--space-md) var(--space-lg); margin-top: var(--space-sm); }

.timeline-day { margin-bottom: var(--space-lg); }

.timeline-day-header {
  font-size: var(--text-xs);
  font-weight: 800;
  color: var(--colour-muted);
  letter-spacing: 0.01em;
  margin-bottom: var(--space-sm);
  padding-bottom: var(--space-xs);
  display: flex;
  align-items: center;
  gap: var(--space-sm);

  &::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--colour-border);
  }
}

.timeline-day-count {
  font-size: 0.65rem;
  font-weight: 800;
  background: var(--colour-border);
  color: var(--colour-muted);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  letter-spacing: 0;
  flex-shrink: 0;
}

.timeline-item {
  background: var(--colour-surface);
  border-radius: var(--radius-md);
  padding: 10px 14px 10px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--colour-border);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform 0.1s var(--ease-out), box-shadow 0.1s var(--ease-out);
  contain: layout style;
  overflow: hidden;
  position: relative;

  &:active { transform: scale(0.98); box-shadow: var(--shadow-md); }

  &.type-nappy .timeline-item-accent { background: var(--colour-nappy); }
  &.type-feed .timeline-item-accent { background: var(--colour-feed); }
  &.type-sleep .timeline-item-accent { background: var(--colour-sleep); }
  &.type-medicine .timeline-item-accent { background: var(--colour-medicine); }
  &.type-weight .timeline-item-accent { background: var(--colour-weight); }
  &.type-temperature .timeline-item-accent { background: var(--colour-temperature); }
  &.type-milestone .timeline-item-accent { background: var(--colour-milestone); }
  &.type-food .timeline-item-accent { background: var(--colour-food); }

  & .icon {
    font-size: 1.2rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    line-height: 1;
  }

  & .icon.icon-dual {
    font-size: 0.85rem;
    gap: 1px;
    letter-spacing: -1px;
  }

  &.type-nappy .icon { background: color-mix(in oklab, var(--colour-nappy) 12%, transparent); }
  &.type-feed .icon { background: color-mix(in oklab, var(--colour-feed) 12%, transparent); }
  &.type-sleep .icon { background: color-mix(in oklab, var(--colour-sleep) 12%, transparent); }
  &.type-medicine .icon { background: color-mix(in oklab, var(--colour-medicine) 12%, transparent); }
  &.type-weight .icon { background: color-mix(in oklab, var(--colour-weight) 12%, transparent); }
  &.type-temperature .icon { background: color-mix(in oklab, var(--colour-temperature) 12%, transparent); }
  &.type-milestone .icon { background: color-mix(in oklab, var(--colour-milestone) 12%, transparent); }
  &.type-food .icon { background: color-mix(in oklab, var(--colour-food) 12%, transparent); }

  & .details { flex: 1; min-width: 0; }
  & .details .title { font-weight: 700; font-size: var(--text-sm); line-height: 1.3; }
  & .details .subtitle {
    color: var(--colour-muted);
    font-size: var(--text-xs);
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  & .note-indicator {
    display: inline;
    color: var(--colour-muted);
    font-size: 0.65rem;
    opacity: 0.6;
    margin-left: 4px;
    vertical-align: middle;
  }

  & .time-col {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    gap: 1px;
  }

  & .time {
    color: var(--colour-text);
    font-size: var(--text-sm);
    font-weight: 700;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
  }

  & .time-ago {
    color: var(--colour-muted);
    font-size: 0.65rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
  }

  & .edit-chevron {
    color: var(--colour-muted);
    opacity: 0.3;
    font-size: 0.75rem;
    flex-shrink: 0;
    margin-left: 4px;
  }

  &.active-event {
    border-color: var(--colour-primary);
    border-width: 1.5px;
    background: color-mix(in oklch, var(--colour-primary) 4%, var(--colour-surface));
  }

  &.active-event .details .subtitle {
    color: var(--colour-primary);
    font-weight: 600;
  }
}

.timeline-item-accent {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: 0 2px 2px 0;
}

@keyframes active-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.active-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--colour-primary);
  animation: active-pulse 2s var(--ease-in-out) infinite;
  flex-shrink: 0;
}

.timeline-empty {
  text-align: center;
  color: var(--colour-muted);
  padding: var(--space-2xl) 0;
  font-size: var(--text-base);
}

.timeline-capped {
  text-align: center;
  color: var(--colour-muted);
  padding: var(--space-md) 0;
  font-size: var(--text-xs);
  font-weight: 600;
}

.active-timer-banner {
  --banner-accent: var(--colour-sleep);
  background: var(--banner-accent);
  color: var(--colour-on-event);
  padding: 12px var(--space-md) 16px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  cursor: pointer;
  position: sticky;
  top: 0;
  z-index: 101;
  overflow: hidden;

  & + .active-timer-banner {
    top: var(--banner-height, 96px);
  }

  &.feed-bottle {
    --banner-accent: var(--colour-feed);
  }

  &.feed-breast {
    --banner-accent: var(--colour-feed-breast);
  }

  &.feed-countdown {
    --banner-accent: var(--colour-feed-countdown);
  }

  & .timer-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    font-weight: 600;
    font-size: var(--text-sm);
  }

  & .timer-value {
    display: block;
    width: 100%;
    text-align: center;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    font-size: clamp(3.5rem, 22vw, 8rem);
    line-height: 1;
    letter-spacing: -0.04em;
  }

  & .banner-finish-btn,
  & .banner-hint {
    display: none;
  }

  &.expanded {
    position: fixed;
    inset: 0;
    top: 0;
    z-index: 250;
    padding: var(--space-lg) var(--space-md);
    justify-content: center;
    align-items: center;
    gap: var(--space-md);
    animation: slideUp 0.25s var(--ease-out);

    & .timer-info {
      font-size: var(--text-base);
    }

    & .timer-value {
      font-size: clamp(5rem, 35vw, 14rem);
    }

    & .banner-finish-btn {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      gap: var(--space-xs);
      width: min(80%, 360px);
      padding: 18px var(--space-md);
      margin-top: var(--space-md);
      border: none;
      border-radius: 999px;
      background: var(--colour-on-event);
      color: var(--colour-banner-text);
      font-size: var(--text-lg);
      font-weight: 700;
      font-family: inherit;
      cursor: pointer;
      box-shadow: 0 6px 24px oklch(0 0 0 / 0.18);
      transition: transform 0.1s var(--ease-out);

      &:active {
        transform: scale(0.97);
      }
    }

    & .banner-hint {
      display: block;
      position: absolute;
      bottom: calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
      left: 0;
      right: 0;
      text-align: center;
      font-size: var(--text-xs);
      font-weight: 600;
      color: color-mix(in oklab, var(--colour-on-event) 70%, transparent);
      letter-spacing: 0.01em;
    }
  }
}

@keyframes banner-spinner {
  to { transform: rotate(360deg); }
}

.banner-spin {
  width: 18px;
  height: 18px;
  border: 2.5px solid oklch(0 0 0 / 0.25);
  border-top-color: var(--colour-on-event);
  border-radius: 50%;
  animation: banner-spinner 0.8s linear infinite;
  flex-shrink: 0;
}

.banner-clock {
  font-size: 18px;
  flex-shrink: 0;
  line-height: 1;
}

body.banner-expanded { overflow: hidden; }

.confetti-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 300;
  overflow: hidden;

  @media (prefers-reduced-motion: reduce) { display: none; }
}

.confetti-piece {
  position: absolute;
  left: 50%;
  top: 60%;
  width: 10px;
  height: 14px;
  border-radius: 2px;
  transform: translate(-50%, -50%);
  animation: confetti-burst 1.4s var(--ease-out) forwards;
  animation-delay: var(--delay, 0ms);
  opacity: 0;
}

@keyframes confetti-burst {
  0% {
    transform: translate(-50%, -50%) rotate(0);
    opacity: 1;
  }
  100% {
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot));
    opacity: 0;
  }
}

.stats-view {
  padding: var(--space-md);

  & h2 { font-size: var(--text-lg); font-weight: 800; letter-spacing: -0.02em; margin-bottom: var(--space-md); }
}

.stats-heading {
  margin-top: var(--space-lg);
}

.stats-note {
  font-size: var(--text-xs);
  color: var(--colour-muted);
  margin-top: calc(-1 * var(--space-sm));
  margin-bottom: var(--space-sm);
}

.stats-period-toggle {
  display: flex;
  gap: 0;
  margin-bottom: var(--space-lg);
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--colour-border);
  background: var(--colour-surface);

  & button {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    font-size: var(--text-sm);
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    color: var(--colour-muted);
    transition: all 0.2s var(--ease-out);

    &.active {
      background: var(--colour-primary);
      color: var(--colour-on-primary);
    }
  }
}

.stat-card {
  background: var(--colour-surface);
  border-radius: var(--radius-md);
  padding: var(--space-md);
  margin-bottom: var(--space-sm);
  border: 1px solid var(--colour-border);

  & h3 {
    font-size: var(--text-xs);
    font-weight: 800;
    color: var(--colour-muted);
    letter-spacing: 0.01em;
    margin-bottom: var(--space-sm);
  }
}

.stat-subheading {
  font-size: var(--text-xs);
  font-weight: 800;
  color: var(--colour-muted);
  letter-spacing: 0.01em;
  margin: var(--space-sm) 0 0;
  padding-top: var(--space-sm);
  border-top: 1px solid var(--colour-border);
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 0;

  & .stat-label { font-size: var(--text-sm); color: var(--colour-muted); }
  & .stat-value { font-size: var(--text-base); font-weight: 800; font-variant-numeric: tabular-nums; }
  & .stat-value.big { font-size: var(--text-xl); }
}

.stat-day-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 6px 0;
  border-bottom: 1px solid var(--colour-border);

  &:last-child { border-bottom: none; }
}

.stat-day-label {
  width: 60px;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--colour-muted);
  flex-shrink: 0;
}

.stat-bar {
  flex: 1;
  height: 18px;
  background: var(--colour-bg);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.stat-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.4s var(--ease-out);

  &.nappy { background: var(--colour-nappy); }
  &.feed { background: var(--colour-feed); }
  &.sleep { background: var(--colour-sleep); }
}

.stat-bar-value {
  font-size: var(--text-xs);
  font-weight: 700;
  width: 36px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.trends-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: var(--space-sm);
}
.trends-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--text-xs);
  color: var(--colour-muted);
  font-weight: 600;
}
.trend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;

  &.trend-sleep,
  &.trend-feed { border-radius: 2px; }
}

.trends-grid {
  --trends-label-h: 30px;
  --trends-body-h: 360px;
  display: flex;
  gap: 4px;
}

.trends-hours {
  position: relative;
  width: 28px;
  flex-shrink: 0;
  margin-top: var(--trends-label-h);
  height: var(--trends-body-h);
}
.trends-hour-mark {
  position: absolute;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  font-size: 10px;
  color: var(--colour-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
  padding-right: 4px;
}

.trends-days {
  flex: 1;
  display: grid;
  gap: 2px;
}

.trends-day {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.trends-day-label {
  height: var(--trends-label-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: var(--colour-muted);
  line-height: 1.1;
  gap: 1px;

  & .trends-day-name { letter-spacing: 0.01em; }
  & .trends-day-num { font-size: 11px; color: var(--colour-text); }
}
.trends-day.today .trends-day-label .trends-day-num {
  color: var(--colour-on-primary);
  background: var(--colour-primary);
  border-radius: var(--radius-full);
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  padding: 0 4px;
  text-align: center;
}

.trends-day-body {
  position: relative;
  height: var(--trends-body-h);
  background: var(--colour-bg);
  border-radius: var(--radius-sm);
  background-image: linear-gradient(to bottom, var(--colour-border) 1px, transparent 1px);
  background-size: 100% 12.5%;
  background-repeat: repeat;
  overflow: hidden;
}

.trend-dot {
  position: absolute;
  left: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 0 1px var(--colour-surface);
}

.trend-block {
  position: absolute;
  left: 10%;
  right: 10%;
  border-radius: 3px;
  min-height: 2px;
  opacity: 0.75;
}

.trend-nappy, .trend-swatch.trend-nappy { background: var(--colour-nappy); }
.trend-feed, .trend-swatch.trend-feed { background: var(--colour-feed); }
.trend-sleep, .trend-swatch.trend-sleep { background: var(--colour-sleep); }
.trend-medicine, .trend-swatch.trend-medicine { background: var(--colour-medicine); }
.trend-weight, .trend-swatch.trend-weight { background: var(--colour-weight); }
.trend-temperature, .trend-swatch.trend-temperature { background: var(--colour-temperature); }
.trend-milestone, .trend-swatch.trend-milestone { background: var(--colour-milestone); }
.trend-food, .trend-swatch.trend-food { background: var(--colour-food); }

.settings-view {
  padding: var(--space-md);

  & h2 { font-size: var(--text-lg); font-weight: 800; letter-spacing: -0.02em; margin-bottom: var(--space-md); }
}

.settings-heading {
  color: var(--colour-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin: var(--space-lg) 0 var(--space-sm);

  &:first-of-type { margin-top: 0; }
}

.settings-group {
  background: var(--colour-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--colour-border);
  overflow: hidden;
  margin-bottom: var(--space-md);
}

.settings-item {
  padding: 14px var(--space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--colour-border);
  cursor: pointer;
  transition: background 0.15s var(--ease-out);
  color: inherit;
  text-decoration: none;

  &:last-child { border-bottom: none; }
  &:active { background: var(--colour-bg); }
  & .settings-label { font-size: var(--text-sm); font-weight: 600; }
  & .settings-arrow { color: var(--colour-muted); font-size: var(--text-sm); }
  & .settings-external { color: var(--colour-muted); font-size: var(--text-sm); }
  &.danger .settings-label { color: var(--colour-danger); }
}

.settings-version {
  text-align: center;
  color: var(--colour-muted);
  font-size: var(--text-xs);
  padding: var(--space-md) 0;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--colour-muted);
  font-size: var(--text-lg);
  font-weight: 600;
}

.toast {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - (var(--space-md) * 2));
  background: var(--colour-text);
  color: var(--colour-bg);
  padding: 12px var(--space-md);
  border-radius: var(--radius-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  line-height: 1.4;
  text-wrap: pretty;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.25s var(--ease-out);

  & button {
    background: none;
    border: none;
    color: var(--colour-primary-inverse);
    font-weight: 700;
    font-size: var(--text-sm);
    font-family: inherit;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
  }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.hidden { display: none !important; }

.pull-to-refresh {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 0;
  overflow: hidden;
  z-index: 1000;
  pointer-events: none;
  transition: none;

  &.releasing {
    transition: height 0.3s var(--ease-out), opacity 0.3s var(--ease-out);
  }

  &.refreshing .pull-to-refresh-spinner {
    animation: ptr-spin 0.8s linear infinite;
  }

  &.threshold .pull-to-refresh-spinner {
    border-top-color: var(--colour-success);
  }
}

.pull-to-refresh-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--colour-border);
  border-top-color: var(--colour-feed);
  border-radius: 50%;
  transition: transform 0.15s ease;
}

@keyframes ptr-spin {
  to { transform: rotate(360deg); }
}

.pair-hint {
  margin-top: var(--space-lg, 1.5rem);
  max-width: 22rem;
  font-size: 0.9rem;
  line-height: 1.5;
  opacity: 0.75;
  text-align: center;
}

.code-field {
  position: relative;
  display: flex;
  align-items: center;

  & input {
    flex: 1;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.85rem;
    padding-right: 3.25rem;
  }
}

.code-toggle {
  position: absolute;
  right: var(--space-md, 16px);
  font-size: 0.9rem;
}

.sync-code {
  margin: var(--space-md, 16px) 0;
  padding: var(--space-md, 16px);
  border-radius: 8px;
  background: var(--colour-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem;
  letter-spacing: 0.02em;
  text-align: center;
  overflow-wrap: break-word;
  user-select: all;
}

.sync-qr-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 0 0 var(--space-md, 16px);
}

.sync-qr {
  width: 160px;
  height: 160px;
  border-radius: 8px;
  shape-rendering: crispEdges;
}

.sync-qr-caption {
  margin: 6px 0 0;
  font-size: 0.85rem;
  opacity: 0.7;
}

.demo-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-md);
  padding: 10px var(--space-md);
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: var(--colour-text);
  color: var(--colour-bg);
  font-size: var(--text-sm);
  font-weight: 600;

  & .demo-bar-quiet {
    background: none;
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    padding: 6px 0;
    font-weight: 600;
    white-space: nowrap;
  }

  & button {
    flex-shrink: 0;
    min-height: 36px;
    padding: 6px var(--space-md);
    border: none;
    border-radius: var(--radius-full);
    background: var(--colour-bg);
    color: var(--colour-text);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
  }
}

.demo-bar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  margin-left: auto;
}

body.has-demo-bar main,
body.has-demo-bar #app-root {
  padding-bottom: calc(var(--demo-bar-h, 56px) + var(--space-md));
}

body.has-demo-bar .toast {
  bottom: calc(var(--demo-bar-h, 56px) + var(--space-md));
}

body.has-demo-bar .modal-overlay {
  padding-bottom: var(--demo-bar-h, 56px);
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--colour-primary);
  text-decoration: underline;
  cursor: pointer;

  &:hover,
  &:focus-visible {
    text-decoration-thickness: 2px;
  }
}

.modal-note {
  font-size: 0.9rem;
  line-height: 1.5;
  opacity: 0.8;
  margin-bottom: 1rem;
}

.modal-steps {
  font-size: 0.9rem;
  line-height: 1.6;
  opacity: 0.8;
  margin: 0 0 1rem;
  padding-left: 1.25rem;

  & li + li {
    margin-top: var(--space-xs);
  }
}
