/* Flat, neutral, phone-first. One centred column that also reads fine on a
   desktop. No gradients, no shadows — a hairline border is the only chrome. */

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e3e5e9;
  --hairline: #eceef1;
  --text: #16181d;
  --muted: #6b7280;
  --faint: #9ca3af;
  --track: #eef0f3;

  --kcal: #22a35a;
  --protein: #7c5cd6;
  --carbs: #ef6f5a;
  --fat: #e0a026;

  --heat-0: #eceef1;
  --heat-1: #c6ead4;
  --heat-2: #8ed5ac;
  --heat-3: #4dba81;
  --heat-4: #22a35a;

  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1114;
    --card: #17191e;
    --border: #262a31;
    --hairline: #22262c;
    --text: #edeef0;
    --muted: #9199a5;
    --faint: #6b7280;
    --track: #23262c;

    --kcal: #35c274;
    --protein: #9b7ef0;
    --carbs: #ff8a72;
    --fat: #f0b445;

    --heat-0: #22262c;
    --heat-1: #1c4a32;
    --heat-2: #226b45;
    --heat-3: #2a8f5b;
    --heat-4: #35c274;
  }
}

* {
  box-sizing: border-box;
}

/* The UA rule for [hidden] is `display: none` at the same specificity as a class
   selector, and this stylesheet loads later — so .app{display:flex} and
   .gate{display:grid} would BEAT the hidden attribute and paint anyway.
   Everything that toggles via `hidden` needs this to actually disappear. */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
    'Noto Sans', sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 420px;
  margin: 0 auto;
  padding: 24px 16px calc(32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.header {
  padding: 4px 2px 2px;
}

.greeting {
  margin: 0;
  font-size: 26px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.header-meta {
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--muted);
}

.streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
  font-weight: 550;
}

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.card-head .card-title {
  margin-bottom: 12px;
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
}

.card-footer {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hairline);
  font-size: 13px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hairline {
  border: 0;
  border-top: 1px solid var(--hairline);
  margin: 14px 0 12px;
}

/* ---------------------------------------------------------------- today */

.kcal-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 8px;
}

.kcal-value {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.kcal-unit {
  font-size: 13px;
  color: var(--muted);
}

.bar {
  background: var(--track);
  border-radius: 999px;
  overflow: hidden;
}

.bar-lg {
  height: 8px;
}

.bar-sm {
  height: 4px;
}

.bar-fill {
  height: 100%;
  border-radius: 999px;
  width: 0;
  transition: width 0.5s ease;
}

.bar-kcal {
  background: var(--kcal);
}
.bar-protein {
  background: var(--protein);
}
.bar-carbs {
  background: var(--carbs);
}
.bar-fat {
  background: var(--fat);
}

/* Over target: the bar stays full, the number turns amber. */
.over .kcal-value {
  color: var(--fat);
}

.macros {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.macro-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--faint);
}

.macro-value {
  margin: 2px 0 6px;
  font-size: 14px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.macro-value .target {
  color: var(--muted);
  font-weight: 400;
}

.coach {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- week */

.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  align-items: end;
  height: 92px;
}

.day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  justify-content: flex-end;
}

.day-bar {
  width: 100%;
  min-height: 3px;
  background: var(--track);
  border-radius: 5px;
  transition: height 0.5s ease;
}

.day.has-data .day-bar {
  background: var(--heat-2);
}

.day.today .day-bar {
  background: var(--kcal);
}

.day-label {
  font-size: 11px;
  color: var(--faint);
}

.day.today .day-label {
  color: var(--text);
  font-weight: 600;
}

/* ---------------------------------------------------------------- month */

.heatmap {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}

.cell {
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  background: var(--heat-0);
}

.cell.l1 {
  background: var(--heat-1);
}
.cell.l2 {
  background: var(--heat-2);
}
.cell.l3 {
  background: var(--heat-3);
}
.cell.l4 {
  background: var(--heat-4);
}

/* Days that haven't happened yet read as absent, not as a zero. */
.cell.future {
  background: transparent;
  border: 1px dashed var(--hairline);
}

.cell.today {
  outline: 2px solid var(--kcal);
  outline-offset: 1px;
}

.caption {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--faint);
}

/* ---------------------------------------------------------------- states */

.foot {
  text-align: center;
  font-size: 11px;
  color: var(--faint);
  padding-top: 4px;
}

.gate {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.gate-inner {
  max-width: 320px;
  text-align: center;
}

.gate-title {
  margin: 0 0 8px;
  font-size: 17px;
  font-weight: 600;
}

.gate-body {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
}

.spinner {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-top-color: var(--muted);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

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

@media (prefers-reduced-motion: reduce) {
  .bar-fill,
  .day-bar {
    transition: none;
  }
  .spinner {
    animation: none;
  }
}
