/* ==========================================================================
   Dietz — one accent, one light source, three surface levels.
   Phone layout first; the Mac adaptation begins at 900px.
   ========================================================================== */

:root {
  --canvas: #ede7db;
  --page-top: #fffcf6;
  --page-bot: #f7f1e5;
  --card-top: #ffffff;
  --card-bot: #fffdf8;
  --border: #eae5da;
  --hairline: #e6e1d6;
  --frame: #e1dbce;
  --ink: #3b3630;
  --ink-soft: #4a443c;
  --muted: #6e6a60;
  --accent: #0fa47a;
  --accent-lift: #1bc194;
  --accent-deep: #0b9670;
  --mint: #e4faf2;
  --mint-edge: #cdf2e5;
  --terracotta: #e4602f;

  --radius-card: 16px;
  --radius-pill: 12px;
  --display: -apple-system, 'SF Pro Display', 'Helvetica Neue', system-ui, sans-serif;
  --text: -apple-system, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;

  /* Overhead light, slightly in front: every shadow falls downward. */
  --shadow-card: 0 1px 1px rgba(28, 26, 22, 0.03), 0 12px 26px -14px rgba(28, 26, 22, 0.2);
  --shadow-inset: inset 0 1px 2px rgba(28, 26, 22, 0.08);
  --shadow-accent: 0 1px 1px rgba(28, 26, 22, 0.06), 0 10px 20px -10px rgba(15, 164, 122, 0.55);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--text);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }

/* --------------------------------------------------------------- structure */

.shell { display: flex; min-height: 100dvh; background: linear-gradient(180deg, var(--page-top) 0%, var(--page-bot) 100%); }

.main {
  flex: 1;
  min-width: 0;
  padding: 24px 20px calc(84px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.task {
  min-height: 100dvh;
  background: linear-gradient(180deg, var(--page-top) 0%, var(--page-bot) 100%);
  padding: 24px 20px 40px;
}

.task-main, .stack { display: flex; flex-direction: column; gap: 20px; }

.task-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  margin-left: -6px;
  color: var(--accent);
  font-weight: 400;
  background: none;
  border: 0;
  padding: 0 6px;
  cursor: pointer;
}
.task-back svg { width: 20px; height: 20px; }

/* ------------------------------------------------------------- navigation */

.sidebar { display: none; }

.tabbar {
  position: fixed;
  inset: auto 0 0 0;
  display: flex;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--hairline);
  /* The one shadow that points against the light: chrome over scrolling content. */
  box-shadow: 0 -6px 18px -12px rgba(28, 26, 22, 0.28);
  z-index: 20;
}

.tab {
  flex: 1;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}
.tab svg { width: 22px; height: 22px; }
.tab.is-active { color: var(--accent); }

/* ------------------------------------------------------------- typography */

.screen-title {
  font-family: var(--display);
  font-weight: 300;
  letter-spacing: -0.03em;
  font-size: 30px;
  line-height: 1.1;
  margin: 0;
}

.hero-title {
  font-family: var(--display);
  font-weight: 300;
  letter-spacing: -0.03em;
  font-size: 34px;
  line-height: 1.1;
  margin: 8px 0 0;
}

.section-label {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 4px 0 0;
}
.section-label-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.link-action { color: var(--accent); font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; }

.lede { color: var(--muted); margin: 0; }
.note { color: var(--muted); margin: 0; font-size: 14px; }
.footnote { color: var(--muted); font-size: 13px; margin: 0; }
.empty { color: var(--muted); margin: 0; padding: 20px 0; }

/* ---------------------------------------------------------------- surfaces */

.card {
  background: linear-gradient(180deg, var(--card-top) 0%, var(--card-bot) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

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

.day { display: flex; flex-direction: column; gap: 20px; }

.day-header { display: flex; align-items: center; gap: 8px; }
.day-heading { flex: 1; min-width: 0; }
.day-count { color: var(--muted); font-size: 13px; }

.chev {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 22px;
  color: var(--ink);
}
.chev.is-disabled { color: var(--frame); pointer-events: none; }

.day-card { padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.day-card-top { display: flex; align-items: center; gap: 20px; }
.day-figures { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.figure-label { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.figure { font-family: var(--display); font-weight: 300; letter-spacing: -0.03em; font-size: 34px; line-height: 1.05; }
.figure.is-over { color: var(--terracotta); }
.figure-sm { font-size: 24px; }
.figure-sub { color: var(--muted); font-size: 13px; }

.day-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.day-actions > * { flex: 1; min-width: 140px; }
.day-actions form { display: contents; }

/* ------------------------------------------------------------------- ring */

.ring { position: relative; flex: none; }
.ring-track { stroke: var(--mint-edge); }
.ring-arc { stroke: var(--accent); }
.ring-arc.is-over { stroke: var(--terracotta); }
.ring-centre {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.ring-figure { font-family: var(--display); font-weight: 300; letter-spacing: -0.03em; font-size: 30px; line-height: 1; }
.ring-unit { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* ------------------------------------------------------------------ rows */

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--hairline);
}
.row:last-child, .row-last { border-bottom: 0; }
.row-link { cursor: pointer; }
.row-label { font-weight: 400; display: flex; flex-direction: column; }
.row-sub { font-size: 12px; color: var(--muted); font-weight: 400; }
.row-value { color: var(--muted); text-align: right; }

.row-input {
  font: inherit;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-align: right;
  background: transparent;
  border: 0;
  min-height: 44px;
  max-width: 55%;
}
.row-input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.stones { display: inline-flex; align-items: center; gap: 4px; }
.stones input { font: inherit; font-variant-numeric: tabular-nums; text-align: right; width: 3.2em; border: 0; background: transparent; min-height: 44px; }
.stones em { font-style: normal; color: var(--muted); }

.row-switch { width: 44px; height: 28px; accent-color: var(--accent); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border-radius: var(--radius-pill);
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-align: center;
}
.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, var(--accent-lift) 0%, var(--accent) 100%);
  /* The only place colour is allowed into a shadow. */
  box-shadow: var(--shadow-accent);
}
.btn-primary:active { background: var(--accent-deep); }
.btn-secondary { color: var(--accent); background: transparent; border-color: var(--accent); }

/* ------------------------------------------------------------- segmented */

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  background: var(--page-bot);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-inset);
}
.segment {
  flex: 1;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  white-space: nowrap;
}
.segment.is-active { background: var(--ink); color: var(--page-top); font-weight: 500; }

/* --------------------------------------------------------------- entries */

.entries { display: flex; flex-direction: column; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 16px;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  background: transparent;
  text-align: left;
}
.entry:last-child { border-bottom: 0; }
.entry-pick { cursor: pointer; }
.entry-pick:hover { background: var(--mint); }
.entry-main { flex: 1; min-width: 0; }
.entry-name { font-weight: 400; }
.entry-meta { font-size: 13px; color: var(--muted); }
.entry-cals { font-family: var(--display); font-weight: 300; font-size: 17px; }

.entry-again, .entry-delete {
  min-height: 44px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.entry-again { color: var(--accent); }
.entry-delete { color: var(--muted); }
.entry-delete:hover { color: var(--terracotta); }

/* ----------------------------------------------------------------- chips */

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--mint-edge);
  background: var(--mint);
  color: var(--accent-deep);
  font-weight: 500;
  cursor: pointer;
}

/* ---------------------------------------------------------------- search */

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  min-height: 44px;
  border-radius: var(--radius-pill);
  background: var(--page-bot);
  border: 1px solid var(--border);
  /* Recessed: pressed into the surface rather than raised off it. */
  box-shadow: var(--shadow-inset);
  color: var(--muted);
}
.search input { flex: 1; min-width: 0; font: inherit; border: 0; background: transparent; min-height: 42px; }
.search input:focus { outline: none; }
.search svg { width: 18px; height: 18px; flex: none; }

/* -------------------------------------------------- confirm portion panel */

.split { display: flex; flex-direction: column; gap: 20px; }
.split-list { flex: 1; min-width: 0; }

/* On the phone the panel is the screen; on the Mac it sits beside the list. */
.confirm-panel:empty { display: none; }
.confirm-panel {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow-y: auto;
  padding: 24px 20px 40px;
  background: linear-gradient(180deg, var(--page-top) 0%, var(--page-bot) 100%);
}
.confirm { display: flex; flex-direction: column; gap: 20px; }

.stepper-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.step {
  width: 48px;
  height: 48px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 24px;
  border: 1px solid var(--border);
  background: var(--card-top);
  font-size: 22px;
  color: var(--accent);
  cursor: pointer;
}
.stepper-value { text-align: center; }
.stepper-figure { font-family: var(--display); font-weight: 300; letter-spacing: -0.03em; font-size: 34px; line-height: 1.1; }
.stepper-unit { font-size: 13px; color: var(--muted); }
.stepper-note { font-size: 13px; color: var(--muted); text-align: center; }

.hero-figure { display: flex; align-items: baseline; justify-content: center; gap: 8px; padding: 8px 0; }
.hero-number { font-family: var(--display); font-weight: 300; letter-spacing: -0.03em; font-size: 64px; line-height: 1; }
.hero-unit { color: var(--muted); font-size: 15px; }

/* -------------------------------------------------------------- weigh in */

.weight-hero { display: flex; align-items: baseline; justify-content: center; gap: 16px; padding: 16px 0; }
.weight-part { display: inline-flex; align-items: baseline; gap: 4px; }
.weight-part input {
  font-family: var(--display);
  font-weight: 300;
  letter-spacing: -0.03em;
  font-size: 76px;
  line-height: 1;
  width: 2.2ch;
  border: 0;
  background: transparent;
  text-align: right;
  color: inherit;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}
.weight-part input::-webkit-outer-spin-button,
.weight-part input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.weight-part.is-accent input { color: var(--accent); }
.weight-unit { font-size: 18px; color: var(--muted); }

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

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; background: var(--hairline); }
.stats .stat { background: var(--card-bot); padding: 14px 12px; }
.stats-inline { border: 0; background: transparent; gap: 12px; padding: 16px 16px 0; }
.stats-inline .stat { background: transparent; padding: 0; }
.stat-label { font-size: 12px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.stat-value { font-family: var(--display); font-weight: 300; letter-spacing: -0.03em; font-size: 22px; line-height: 1.2; margin-top: 4px; }
.stat-sub { font-size: 12px; color: var(--muted); }

.card > .section-label-row { padding: 16px 16px 0; }
.card > .footnote { padding: 0 16px 16px; }

/* ---------------------------------------------------------------- charts */

.chart { display: block; width: 100%; height: auto; padding: 8px 16px 16px; }
.chart .grid { stroke: var(--hairline); stroke-width: 1; }
.chart .line { stroke: var(--accent); stroke-width: 2; fill: none; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart .dot { fill: var(--accent); }
.chart-label { font-family: var(--text); font-size: 11px; fill: var(--muted); }

.bars { display: flex; align-items: flex-end; gap: 6px; position: relative; padding: 16px 16px 0; margin-bottom: 24px; }
.bar-col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; height: 100%; }
.bar { background: var(--accent); border-radius: 4px; min-height: 2px; }
.bar.is-over { background: var(--terracotta); }
.bar-label { font-size: 11px; color: var(--muted); text-align: center; margin-top: 6px; white-space: nowrap; }
.bars-target {
  position: absolute;
  left: 16px;
  right: 16px;
  border-top: 1px dashed var(--ink);
  opacity: 0.55;
  margin-bottom: 24px;
}
.bars-target-label { position: absolute; right: 0; top: -16px; font-size: 11px; color: var(--muted); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; padding: 0 16px 16px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; background: var(--accent); display: inline-block; }
.swatch.is-over { background: var(--terracotta); }
.swatch.is-rule { height: 0; border-top: 1px dashed var(--ink); border-radius: 0; width: 14px; }

/* ------------------------------------------------------------------ tips */

.tips { display: flex; flex-direction: column; gap: 12px; }
.tip { display: flex; gap: 14px; padding: 16px; }
.tip-icon {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--mint);
  border: 1px solid var(--mint-edge);
  color: var(--accent-deep);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tip-title { font-size: 15px; font-weight: 500; margin: 0 0 4px; }
.tip-body { margin: 0; color: var(--muted); font-size: 14px; }

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

.panel { display: none; flex-direction: column; gap: 12px; }
.panel.is-active { display: flex; }

/* ---------------------------------------------------------------- banner */

.banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border: 1px solid var(--terracotta);
  border-radius: var(--radius-pill);
  color: var(--terracotta);
  background: var(--card-top);
  font-size: 14px;
}
.banner-retry { margin-left: auto; background: none; border: 0; color: var(--terracotta); font-weight: 500; min-height: 44px; cursor: pointer; }

/* ==========================================================================
   The Mac adaptation: a sidebar, not a stretched phone.
   ========================================================================== */

@media (min-width: 900px) {
  .tabbar { display: none; }

  .sidebar {
    display: flex;
    flex-direction: column;
    gap: 4px;
    width: 220px;
    flex: none;
    padding: 28px 12px;
    border-right: 1px solid var(--hairline);
    background: linear-gradient(180deg, var(--card-top) 0%, var(--card-bot) 100%);
    position: sticky;
    top: 0;
    height: 100dvh;
  }
  .wordmark {
    font-family: var(--display);
    font-weight: 300;
    letter-spacing: -0.03em;
    font-size: 24px;
    padding: 0 12px 20px;
  }
  .side-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 12px;
    border-radius: 10px;
    color: var(--muted);
    font-weight: 400;
  }
  .side-item svg { width: 20px; height: 20px; }
  .side-item:hover { background: var(--page-bot); }
  .side-item.is-active { background: var(--mint); color: var(--accent-deep); font-weight: 500; }

  .main { padding: 32px 40px 40px; max-width: 1220px; gap: 24px; }

  .screen-title { font-size: 36px; }

  /* Five tiles across, and the two comparisons side by side. */
  .stats-week { grid-template-columns: repeat(3, 1fr); }
  .day-card-top { gap: 32px; }
  .day-actions > * { flex: 0 1 200px; }

  /* Log food and Confirm portion in one glance. */
  .split { flex-direction: row; align-items: flex-start; gap: 32px; }
  .split-list { flex: 1 1 420px; }
  .confirm-panel {
    position: static;
    flex: 1 1 380px;
    padding: 0;
    background: transparent;
    overflow: visible;
  }
  .split-confirm-only .split-list { display: none; }

  /* Settings shows all three groups at once; the control stays for parity. */
  .panel { display: flex; }

  .entry { min-height: 46px; }
  .row { min-height: 48px; }
}

/* ==========================================================================
   Motion. Four transitions, each tied to a meaning the interface already has:
   the direction of a day step, the push of a task layer, the consequence of a
   logged entry, and the arrival of the error banner. Nothing else moves, and
   none of it moves for a reader who has asked for less.
   ========================================================================== */

@media (prefers-reduced-motion: no-preference) {
  .htmx-request { opacity: 0.7; transition: opacity 120ms ease; }

  /* --- 1. Stepping a day: the slide says which way through time you went. --- */

  #day { view-transition-name: day; }

  ::view-transition-old(day),
  ::view-transition-new(day) {
    animation-duration: 260ms;
    animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1);
    animation-fill-mode: both;
  }

  /* No direction set — logging, deleting — keeps the browser's plain fade. */
  html[data-dir='forward']::view-transition-old(day) { animation-name: day-exit-left; }
  html[data-dir='forward']::view-transition-new(day) { animation-name: day-enter-right; }
  html[data-dir='back']::view-transition-old(day) { animation-name: day-exit-right; }
  html[data-dir='back']::view-transition-new(day) { animation-name: day-enter-left; }

  @keyframes day-exit-left { to { transform: translateX(-24px); opacity: 0; } }
  @keyframes day-enter-right { from { transform: translateX(24px); opacity: 0; } }
  @keyframes day-exit-right { to { transform: translateX(24px); opacity: 0; } }
  @keyframes day-enter-left { from { transform: translateX(-24px); opacity: 0; } }

  /* --- 3. The ring sweeps to the new total, so the commit has a consequence. */

  .ring-arc { animation: ring-sweep 620ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }

  @keyframes ring-sweep {
    from { stroke-dashoffset: var(--arc-full); }
    to { stroke-dashoffset: var(--arc-offset); }
  }

  /* --- 5. Destination changes. Five flat peers with no hierarchy between them,
     so the content settles in place rather than sliding from a direction the
     navigation does not have. The chrome around it does not move at all. --- */

  .main > *, .task-main > * { animation: screen-enter 240ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }

  /* A short stagger down the screen, so the page assembles top-first. */
  .main > *:nth-child(2), .task-main > *:nth-child(2) { animation-delay: 30ms; }
  .main > *:nth-child(3), .task-main > *:nth-child(3) { animation-delay: 60ms; }
  .main > *:nth-child(4), .task-main > *:nth-child(4) { animation-delay: 90ms; }

  @keyframes screen-enter {
    from { opacity: 0; transform: translateY(6px); }
  }

  /* Home is exempt: the day block is swapped by the chevrons and by every log,
     and its own view transition and ring sweep already carry the screen. */
  .main > #day, #day > *, .confirm > * { animation: none; }

  /* --- 4. The banner shifts the card below it, so it arrives rather than pops. */

  .banner { animation: banner-in 220ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }

  @keyframes banner-in {
    from { opacity: 0; transform: translateY(-6px); }
  }
}

/* --- 2. Confirm portion is a layer on the phone and a column on the Mac, so
   it pushes in on one and does nothing at all on the other. The stepper and
   the Portions/Grams control swap the same panel on a 48px tap and are
   deliberately left out: they carry no transition:true. --- */

@media (max-width: 899px) and (prefers-reduced-motion: no-preference) {
  .confirm { view-transition-name: confirm-panel; }

  ::view-transition-new(confirm-panel) {
    animation: panel-push-in 280ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
  }
  ::view-transition-old(confirm-panel) {
    animation: panel-push-out 240ms cubic-bezier(0.4, 0, 0.6, 1) both;
  }

  @keyframes panel-push-in { from { transform: translateX(100%); } }
  @keyframes panel-push-out { to { transform: translateX(100%); } }
}
