/* ===========================================================================
   CalTrack — design system
   Four colours only: cream #EAF9E7 · sage #C0E6BA · green #4CA771 · teal #013237
   Light is the default theme; the choice is explicit and persisted, so themes
   are driven by [data-theme] rather than prefers-color-scheme.
   =========================================================================== */

@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/fonts/poppins-400.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('/fonts/poppins-500.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/fonts/poppins-600.woff2') format('woff2');
}
@font-face {
  font-family: 'Poppins';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('/fonts/poppins-700.woff2') format('woff2');
}

:root,
:root[data-theme='light'] {
  --bg: #eaf9e7;
  --soft: #eaf9e7;
  --card: #eaf9e7;
  --card2: #c0e6ba;
  --line: #c0e6ba;
  --text: #013237;
  --muted: rgba(1, 50, 55, 0.62);
  --accent: #4ca771;
  --on-accent: #eaf9e7;
  --over: #013237;
  --scrim: rgba(1, 50, 55, 0.32);
}

:root[data-theme='dark'] {
  --bg: #013237;
  --soft: #013237;
  --card: #0a3d3f;
  --card2: #0f4a48;
  --line: #1c5750;
  --text: #eaf9e7;
  --muted: #9dc4b2;
  --accent: #4ca771;
  --on-accent: #013237;
  --over: #eaf9e7; /* deep teal is the page in dark, so invert the over-goal arc */
  --scrim: rgba(1, 50, 55, 0.62);
}

:root {
  --gutter: 18px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --dock-pad: 154px; /* must cover the dock's full height, incl. its fade */
}

* { box-sizing: border-box; }

/* Class-level `display` beats the UA sheet's [hidden] rule, so restate it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: Poppins, -apple-system, 'Segoe UI', Roboto, system-ui, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

svg {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  padding-top: env(safe-area-inset-top);
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: env(safe-area-inset-top) 0 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

/* The only scrolling regions. Scrolling is touch/inertial — no visible bars. */
.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.scroll::-webkit-scrollbar { display: none; }

.home-scroll { padding: 0 0 var(--dock-pad); }
.sub-scroll { padding: 6px var(--gutter) 30px; }

/* ---------- header ---------- */

/* Lives inside .home-scroll, so it scrolls away with the content.
   Sub-screen headers stay pinned — they hold the back/close control. */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px 2px 20px;
}

.date-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  margin-left: -6px;
  border-radius: 14px;
  text-align: left;
  color: var(--text);
}
.date-btn .stack { display: flex; flex-direction: column; gap: 1px; }
.date-btn .title { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.date-btn .full { font-size: 11.5px; color: var(--muted); }
.date-btn svg { width: 16px; height: 16px; flex: none; stroke: var(--muted); stroke-width: 2.2; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  color: var(--muted);
  flex: none;
}
.icon-btn svg { width: 21px; height: 21px; stroke-width: 1.7; }

.sub-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 8px 20px;
  flex: none;
}
.sub-head h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 0; }
.sub-head .close { font-size: 20px; color: var(--muted); }

.back-head {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 12px 8px;
  flex: none;
}
.back-head h1 { font-size: 17px; font-weight: 600; margin: 0; }
.back-head .icon-btn { color: var(--text); }
.back-head .icon-btn svg { width: 22px; height: 22px; stroke-width: 2; }

.eyebrow {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  padding: 0 2px 10px;
}
.eyebrow.spaced { padding-top: 24px; }

/* ---------- hero ---------- */

.hero {
  position: relative;
  margin: 8px var(--gutter) 0;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--card);
  overflow: hidden;
}

/* Diagonal hairline texture — the only decorative flourish in the system. */
.hero::before {
  content: '';
  position: absolute;
  inset: 0;
  opacity: 0.5;
  background: repeating-linear-gradient(118deg, transparent 0 13px, var(--card2) 13px 14px);
}

.hero-inner { position: relative; padding: 16px 18px 14px; }

.arc-wrap { position: relative; height: 118px; }
.arc-wrap svg { width: 100%; height: 100%; overflow: visible; }
.arc-track { stroke: var(--card2); stroke-width: 14; }
.arc-fill {
  stroke: var(--accent);
  stroke-width: 14;
  stroke-dasharray: 270.2;
  transition: stroke-dashoffset 0.6s var(--ease), stroke 0.25s ease;
}
.hero.over .arc-fill { stroke: var(--over); }

.arc-center {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.arc-center .big {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1;
}
.arc-center .label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.hero-summary {
  display: flex;
  justify-content: space-between;
  padding: 12px 6px 0;
  border-top: 1px solid var(--line);
  margin-top: 10px;
}
.hero-summary > div { display: flex; flex-direction: column; gap: 2px; }
.hero-summary > div:nth-child(2) { align-items: center; }
.hero-summary > div:nth-child(3) { align-items: flex-end; }
.hero-summary .k {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.hero-summary .v { font-size: 14.5px; font-weight: 600; }

/* ---------- macro dials ---------- */

.macros {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 12px var(--gutter) 0;
}

.macro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 14px 6px;
}

.donut { position: relative; width: 62px; height: 62px; }
.donut svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-track { stroke: var(--card2); stroke-width: 6; }
.donut-fill {
  stroke: var(--accent);
  stroke-width: 6;
  stroke-dasharray: 125.66;
  transition: stroke-dashoffset 0.6s var(--ease);
}
.donut .pct {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 600;
}

.macro .name {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.macro .val { font-size: 12.5px; font-weight: 500; }
.macro .meta { display: flex; flex-direction: column; align-items: center; gap: 2px; }

/* ---------- meal cards ---------- */

.meal {
  margin: 12px var(--gutter) 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 14px 16px 6px;
}

.meal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.meal-head .label { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.meal-head .kcal { font-size: 12.5px; font-weight: 500; color: var(--muted); }

.share {
  height: 4px;
  border-radius: 99px;
  background: var(--card2);
  overflow: hidden;
  margin: 9px 0 2px;
}
.share i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.5s var(--ease);
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 0;
}
.row + .row { border-top: 1px solid var(--line); }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .title { font-size: 14px; font-weight: 500; }
.row .macros-line { font-size: 11.5px; color: var(--muted); }
.row .kcal { font-size: 14px; font-weight: 600; }

.del {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  margin: -11px -14px -11px 0;
  color: var(--muted);
  opacity: 0.75;
  border-radius: 12px;
}
.del svg { width: 16px; height: 16px; stroke-width: 1.7; }
.del:active { opacity: 1; }

.meal-empty { font-size: 12.5px; color: var(--muted); padding: 10px 0 12px; }

/* ---------- dock ---------- */

.dock {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 30px var(--gutter) calc(12px + env(safe-area-inset-bottom));
  /* No backdrop blur — it read as smear over scrolling content. Instead the
     fade lives entirely in the top padding, so the status line always sits on
     solid background and never collides with a food row. */
  background: linear-gradient(to top, var(--bg) 76%, transparent);
}

.status {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted);
  padding-bottom: 10px;
  min-height: 18px;
}

.dock-row {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 74px;
}

/* Mic: hollow at rest, fills and widens into a waveform pill while listening. */
.mic {
  position: relative;
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  border-radius: 36px;
  border: 3px solid var(--accent);
  background: transparent;
  color: var(--accent);
  transition: width 0.35s var(--ease), background 0.25s ease, color 0.25s ease;
}
.mic .mic-glyph { width: 28px; height: 28px; stroke-width: 1.9; }
.mic .wave { display: none; align-items: center; gap: 3px; height: 16px; }
.mic .wave span {
  width: 3px;
  border-radius: 99px;
  background: currentColor;
  animation: wave 0.8s ease-in-out infinite;
}
.mic .wave span:nth-child(1) { height: 6px; animation-delay: 0s; }
.mic .wave span:nth-child(2) { height: 12px; animation-delay: 0.18s; }
.mic .wave span:nth-child(3) { height: 16px; animation-delay: 0.36s; }
.mic .wave span:nth-child(4) { height: 9px; animation-delay: 0.18s; }
.mic .wave span:nth-child(5) { height: 13px; animation-delay: 0s; }

.mic .pulse {
  position: absolute;
  inset: -8px;
  border-radius: 44px;
  border: 2px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}

body.listening .mic {
  width: 104px;
  background: var(--accent);
  color: var(--on-accent);
}
body.listening .mic .mic-glyph { display: none; }
body.listening .mic .wave { display: flex; }
body.listening .mic .pulse { animation: pulse 1.4s var(--ease) infinite; }
body.connecting .mic { opacity: 0.6; }

@keyframes wave {
  0%, 100% { transform: scaleY(0.45); }
  50% { transform: scaleY(1.5); }
}
@keyframes pulse {
  0% { transform: scale(0.96); opacity: 0.75; }
  100% { transform: scale(1.55); opacity: 0; }
}

.kbd-btn {
  position: absolute;
  right: 0;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--muted);
  border-radius: 15px;
}
.kbd-btn svg { width: 20px; height: 20px; stroke-width: 1.7; }

/* ---------- calendar popover ---------- */

.scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  z-index: 20;
}

.cal {
  position: absolute;
  top: 96px;
  left: 16px;
  width: 292px;
  z-index: 21;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 22px 54px rgba(1, 50, 55, 0.32);
  padding: 16px 16px 14px;
}

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 12px;
}
.cal-head .month { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.cal-nav {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  background: var(--card2);
  color: var(--text);
  border-radius: 11px;
}
.cal-nav svg { width: 15px; height: 15px; stroke-width: 2.2; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-week { padding-bottom: 4px; }
.cal-week div {
  text-align: center;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 4px 0;
}

.cal-cell {
  height: 36px;
  border-radius: 11px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  background: transparent;
}
.cal-cell.today { background: var(--card2); font-weight: 600; }
.cal-cell.selected { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.cal-cell.future { color: var(--muted); opacity: 0.4; pointer-events: none; }
.cal-cell.blank { pointer-events: none; }

.cal-today {
  width: 100%;
  margin-top: 12px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

/* ---------- settings ---------- */

.theme-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.theme-tile {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-radius: 20px;
  background: var(--card);
  border: 2px solid var(--line);
  text-align: left;
}
.theme-tile[aria-pressed='true'] { border-color: var(--accent); }
.theme-tile .label { font-size: 13.5px; font-weight: 600; color: var(--text); }

.theme-mock {
  height: 74px;
  border-radius: 12px;
  padding: 9px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.theme-mock .ring {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 5px solid var(--accent);
}
.theme-mock .bar { height: 6px; border-radius: 99px; }
.theme-mock .bar.short { width: 60%; }

.theme-mock.light { background: #eaf9e7; border: 1px solid #c0e6ba; }
.theme-mock.light .ring { border-right-color: #c0e6ba; }
.theme-mock.light .bar { background: #c0e6ba; }

.theme-mock.dark { background: #013237; border: 1px solid #1c5750; }
.theme-mock.dark .ring { border-right-color: #0f4a48; }
.theme-mock.dark .bar { background: #0f4a48; }

.row-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  width: 100%;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--card);
  color: var(--text);
  text-align: left;
}
.row-btn .stack { display: flex; flex-direction: column; gap: 4px; }
.row-btn .t { font-size: 15px; font-weight: 500; }
.row-btn .s { font-size: 12px; color: var(--muted); }
.row-btn svg { width: 18px; height: 18px; flex: none; stroke: var(--muted); stroke-width: 2; }

.note {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
  padding: 20px 4px 0;
}

/* ---------- targets ---------- */

.presets { display: flex; gap: 8px; padding-bottom: 16px; }
.presets button {
  flex: 1;
  padding: 10px 4px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
}

.target-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.target-row .k {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
}
.target-row .stack { display: flex; flex-direction: column; gap: 4px; }
.target-row .v { display: flex; align-items: baseline; gap: 5px; }
.target-row .v b { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
.target-row .v span { font-size: 13px; color: var(--muted); }
.target-row .steppers { display: flex; align-items: center; gap: 6px; }
.target-row .steppers button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 14px;
  font-size: 19px;
  line-height: 1;
}

.reconcile { font-size: 12px; color: var(--muted); line-height: 1.6; padding: 16px 4px 0; }

.primary {
  width: 100%;
  margin-top: 20px;
  padding: 17px;
  border-radius: 18px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 16px;
  font-weight: 600;
}
.primary:active { filter: brightness(0.95); }

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

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
