:root {
  --bg: #070a11;
  --surface: rgba(255, 255, 255, 0.055);
  --surface-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f2f5fb;
  --muted: rgba(232, 238, 250, 0.56);
  --accent: #4ade9b;
  --accent-2: #38bdf8;
  --danger: #fb7185;
  --radius: 28px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', system-ui, sans-serif;
  font-size: 17px;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
}

/* ---------- ambient background ---------- */

.aurora {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  opacity: 0.5;
}

.blob-a {
  width: 60vw;
  height: 60vw;
  top: -18vw;
  left: -12vw;
  background: #10b981;
  animation: drift 26s var(--ease) infinite alternate;
}

.blob-b {
  width: 52vw;
  height: 52vw;
  bottom: -20vw;
  right: -14vw;
  background: #2563eb;
  animation: drift 32s var(--ease) infinite alternate-reverse;
}

.blob-c {
  width: 34vw;
  height: 34vw;
  top: 40%;
  left: 55%;
  background: #7c3aed;
  opacity: 0.32;
  animation: drift 38s var(--ease) infinite alternate;
}

@keyframes drift {
  from {
    transform: translate3d(0, 0, 0) scale(1);
  }
  to {
    transform: translate3d(6vw, 8vh, 0) scale(1.18);
  }
}

/* ---------- layout ---------- */

.app {
  position: relative;
  z-index: 1;
  min-height: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 28px) 32px max(env(safe-area-inset-bottom), 36px);
  padding-bottom: 124px;
  padding-bottom: calc(100px + env(safe-area-inset-bottom));
}

.boot {
  padding: 30vh 0;
  text-align: center;
  color: var(--muted);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 26px;
  min-height: 60px;
}

/* Keeps a form page's heading in the same column as its card. */
.app-narrow .topbar {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 30px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.topbar .sub {
  display: block;
  font-size: 15px;
  font-weight: 450;
  color: var(--muted);
  letter-spacing: 0;
  margin-top: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(24px) saturate(150%);
  -webkit-backdrop-filter: blur(24px) saturate(150%);
  box-shadow: var(--shadow);
}

/* ---------- buttons ---------- */

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
  touch-action: manipulation;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  padding: 0 30px;
  border-radius: 20px;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  font-size: 19px;
  font-weight: 600;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  transition: transform 0.16s var(--ease), background 0.16s var(--ease), opacity 0.16s;
}

.btn:active {
  transform: scale(0.965);
  background: rgba(255, 255, 255, 0.16);
}

.btn[hidden] {
  display: none;
}

.btn-icon {
  min-height: 60px;
  width: 60px;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
  flex: none;
}

.btn-icon svg {
  width: 26px;
  height: 26px;
  display: block;
  color: rgba(242, 245, 251, 0.82);
}

.btn-icon:active svg {
  color: var(--text);
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #22c58a);
  border-color: transparent;
  color: #04150d;
}

.btn-primary:active {
  background: linear-gradient(135deg, #3ccb8b, #1eb37c);
}

.btn-danger {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.32);
}

.btn-ghost {
  background: transparent;
}

.btn-block {
  width: 100%;
}

/* ---------- home ---------- */

.hero {
  display: grid;
  gap: 28px;
  max-width: 620px;
  margin: 0 auto;
}

.datebar {
  text-align: center;
}

.date-big {
  font-size: clamp(28px, 4.4vw, 46px);
  font-weight: 680;
  letter-spacing: -0.03em;
  line-height: 1.08;
}

.dial-card {
  padding: 34px;
  display: grid;
  justify-items: center;
  gap: 22px;
}

.dial {
  position: relative;
  width: min(430px, 74vw);
  aspect-ratio: 1;
  padding: 0;
  border-radius: 50%;
  transition: transform 0.18s var(--ease);
}

.dial:active {
  transform: scale(0.97);
}

.dial:focus-visible {
  outline: 3px solid rgba(74, 222, 155, 0.8);
  outline-offset: 6px;
}

.dial svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.dial .track {
  fill: none;
  stroke: rgba(255, 255, 255, 0.08);
  stroke-width: 14;
}

.dial .fill {
  fill: none;
  stroke: url(#dialGradient);
  stroke-width: 14;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.8s var(--ease);
}

.dial.over .fill {
  stroke: var(--danger);
}

.dial-centre {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 4px;
}

.dial-number {
  font-size: clamp(64px, 12vw, 122px);
  font-weight: 700;
  line-height: 0.94;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}

.dial.over .dial-number {
  color: var(--danger);
}

/* ---------- fixed bottom navigation ---------- */

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 50%;
  bottom: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(430px, calc(100% - 32px));
  min-height: 76px;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 28px;
  background: rgba(15, 21, 32, 0.88);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(26px) saturate(160%);
  -webkit-backdrop-filter: blur(26px) saturate(160%);
}

.bottom-nav button {
  min-height: 60px;
  display: grid;
  place-items: center;
  border-radius: 21px;
  color: var(--muted);
  transition: color 0.16s var(--ease), background 0.16s var(--ease), transform 0.16s var(--ease);
}

.bottom-nav button:active {
  transform: scale(0.94);
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}

.bottom-nav button.active {
  color: var(--accent);
  background: rgba(74, 222, 155, 0.12);
}

.bottom-nav button:focus-visible {
  outline: 2px solid rgba(74, 222, 155, 0.8);
  outline-offset: -2px;
}

.bottom-nav svg {
  width: 35px;
  height: 35px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bottom-nav .nav-emoji {
  font-size: 34px;
  line-height: 1;
  filter: saturate(0.9);
}

/* ---------- meal picker ---------- */

.meal-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}

.meal-tile {
  position: relative;
  padding: 0;
  aspect-ratio: 4 / 3;
  border-radius: 30px;
  overflow: hidden;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform 0.2s var(--ease), border-color 0.2s var(--ease);
}

.meal-tile:active {
  transform: scale(0.972);
  border-color: rgba(74, 222, 155, 0.65);
}

.meal-glyph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(72px, 12vw, 132px);
  filter: drop-shadow(0 18px 30px rgba(0, 0, 0, 0.42));
  transition: transform 0.3s var(--ease);
}

.meal-tile:active .meal-glyph {
  transform: scale(1.08);
}

.meal-tile[data-meal='breakfast'] {
  background: linear-gradient(145deg, rgba(251, 191, 36, 0.34), rgba(249, 115, 22, 0.1));
}

.meal-tile[data-meal='lunch'] {
  background: linear-gradient(145deg, rgba(56, 189, 248, 0.32), rgba(37, 99, 235, 0.1));
}

.meal-tile[data-meal='dinner'] {
  background: linear-gradient(145deg, rgba(167, 139, 250, 0.34), rgba(109, 40, 217, 0.1));
}

.meal-tile[data-meal='snack'] {
  background: linear-gradient(145deg, rgba(74, 222, 155, 0.32), rgba(5, 150, 105, 0.1));
}

/* ---------- food grid ---------- */

.adhoc-entry {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  align-items: center;
  gap: 16px;
  padding: 16px 18px;
  margin-bottom: 18px;
}

.adhoc-entry input {
  width: 100%;
  min-width: 0;
  height: 58px;
  padding: 0 18px;
  border-radius: 17px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font: inherit;
  font-size: 21px;
  font-variant-numeric: tabular-nums;
}

.adhoc-entry input:focus {
  outline: 2px solid rgba(74, 222, 155, 0.7);
  outline-offset: 1px;
}

.adhoc-submit {
  min-height: 58px;
  padding: 0 26px;
}

.search {
  width: 100%;
  min-height: 60px;
  margin-bottom: 22px;
  padding: 0 24px;
  border-radius: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 19px;
}

.search::placeholder {
  color: var(--muted);
}

.food-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(178px, 1fr));
  gap: 20px;
}

.food-tile {
  position: relative;
  padding: 0;
  border-radius: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  overflow: hidden;
  text-align: center;
  transition: transform 0.16s var(--ease), border-color 0.16s;
}

.food-tile:active {
  transform: scale(0.955);
  border-color: rgba(74, 222, 155, 0.6);
}

.food-tile.flash {
  animation: flash 0.55s var(--ease);
}

@keyframes flash {
  0% {
    box-shadow: 0 0 0 0 rgba(74, 222, 155, 0.55);
  }
  100% {
    box-shadow: 0 0 0 22px rgba(74, 222, 155, 0);
  }
}

.tile-body {
  display: block;
  padding-bottom: 16px;
}

.thumb {
  display: block;
  height: 150px;
  background: rgba(255, 255, 255, 0.05);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb.placeholder,
.photo-preview.placeholder {
  display: grid;
  place-items: center;
  font-size: 52px;
  font-weight: 300;
  color: rgba(242, 245, 251, 0.28);
  background: linear-gradient(150deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.03));
}

.food-tile .name {
  display: block;
  margin: 14px 12px 4px;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.2;
}

.food-tile .kj {
  display: block;
  font-size: 15px;
  color: var(--accent);
  font-weight: 620;
  font-variant-numeric: tabular-nums;
}

.food-tile .portion {
  display: block;
  margin-top: 3px;
  font-size: 13px;
  color: var(--muted);
}

.food-tile .edit {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  font-size: 16px;
}

/* ---------- forms ---------- */

.form {
  padding: 30px;
  display: grid;
  gap: 24px;
  max-width: 760px;
  margin: 0 auto;
}

.field {
  display: grid;
  gap: 12px;
}

.field > label {
  font-size: 14px;
  font-weight: 640;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-help {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  color: var(--muted);
}

.field input[type='text'],
.field input[type='number'],
.field input[type='date'] {
  width: 100%;
  min-height: 62px;
  padding: 0 22px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  font-family: inherit;
}

/*
 * Safari gives date inputs an intrinsic width and refuses to stretch them in a
 * grid track, so they shrink and hug the left. Resetting the appearance lets
 * the width above apply and keeps the value vertically centred.
 */
.field input[type='date'] {
  -webkit-appearance: none;
  appearance: none;
  display: block;
  text-align: center;
}

.field input[type='date']::-webkit-date-and-time-value {
  text-align: center;
  margin: 0;
}

.field input[type='date']::-webkit-calendar-picker-indicator {
  filter: invert(1);
  opacity: 0.55;
  cursor: pointer;
}

.field input:focus {
  outline: 2px solid rgba(74, 222, 155, 0.7);
  outline-offset: 1px;
}

.field-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 22px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.chip {
  min-height: 54px;
  padding: 0 24px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  font-size: 17px;
  font-weight: 560;
  transition: all 0.14s var(--ease);
}

.chip[aria-pressed='true'] {
  background: rgba(74, 222, 155, 0.2);
  border-color: rgba(74, 222, 155, 0.7);
  color: var(--accent);
}

/* ---------- photo picker ---------- */

.photo-drop {
  height: 260px;
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px dashed rgba(255, 255, 255, 0.24);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.photo-drop img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  display: block;
}

.photo-hint {
  color: var(--muted);
  font-size: 17px;
}

.photo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
}

.photo-action-icon svg {
  width: 29px;
  height: 29px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.photo-preview {
  width: 110px;
  height: 110px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  overflow: hidden;
  flex: none;
  margin: 0 auto;
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* ---------- danger zone ---------- */

.danger-zone {
  display: grid;
  gap: 14px;
  margin-top: 10px;
  padding: 24px;
  border-radius: 22px;
  border: 1px solid rgba(251, 113, 133, 0.28);
  background: rgba(251, 113, 133, 0.06);
}

.danger-zone .section-title {
  color: var(--danger);
}

.section-title {
  margin: 0;
  font-size: 14px;
  font-weight: 680;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.btn-danger-solid {
  background: linear-gradient(135deg, #fb7185, #e11d48);
  border-color: transparent;
  color: #fff;
}

.btn-danger-solid:active {
  background: linear-gradient(135deg, #f4677c, #c81a41);
}

.btn-danger-solid:disabled {
  opacity: 0.6;
}

.sheet-danger {
  border-color: rgba(251, 113, 133, 0.42);
}

.warn-mark {
  width: 72px;
  height: 72px;
  margin: 0 auto;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 40px;
  font-weight: 700;
  color: var(--danger);
  background: rgba(251, 113, 133, 0.14);
  border: 1px solid rgba(251, 113, 133, 0.4);
}

.sheet .warn-lead {
  font-size: 18px;
  line-height: 1.55;
  color: rgba(242, 245, 251, 0.86);
}

.warn-lead strong {
  color: var(--danger);
  font-weight: 700;
}

.warn-note {
  font-size: 15px;
}

.form-actions {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.form-actions .btn {
  flex: 1;
  min-width: 180px;
}

/* ---------- sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(3, 6, 12, 0.6);
  backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 24px;
  animation: fade 0.2s var(--ease);
}

.sheet {
  width: min(520px, 100%);
  padding: 32px;
  display: grid;
  gap: 22px;
  text-align: center;
  animation: rise 0.28s var(--ease);
}

.sheet h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.sheet p {
  margin: 0;
  color: var(--muted);
}

.pin-sheet {
  max-width: 440px;
}

.pin-input {
  width: 100%;
  min-height: 68px;
  padding: 0 22px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  font: inherit;
  font-size: 26px;
  text-align: center;
  letter-spacing: 0.18em;
}

.pin-input:focus {
  outline: 2px solid rgba(74, 222, 155, 0.7);
  outline-offset: 2px;
}

.sheet .pin-error {
  min-height: 24px;
  color: var(--danger);
}

.stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
}

.stepper b {
  min-width: 120px;
  font-size: 40px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(28px) scale(0.97);
  }
}

/* ---------- empty + toast ---------- */

.empty {
  padding: 44px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 17px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(env(safe-area-inset-bottom), 28px);
  transform: translate(-50%, 140%);
  z-index: 60;
  padding: 18px 30px;
  border-radius: 20px;
  background: rgba(20, 26, 38, 0.92);
  border: 1px solid var(--border);
  backdrop-filter: blur(20px);
  font-size: 18px;
  font-weight: 580;
  box-shadow: var(--shadow);
  transition: transform 0.34s var(--ease);
  pointer-events: none;
}

.toast.show {
  transform: translate(-50%, 0);
}

.toast.good {
  border-color: rgba(74, 222, 155, 0.5);
}

.toast.bad {
  border-color: rgba(251, 113, 133, 0.6);
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .app {
    padding-left: 20px;
    padding-right: 20px;
  }
  .meal-grid {
    gap: 14px;
  }

}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
