:root {
  --bg: #f3f3ef;
  --card: #ffffff;
  --soft: #f4f4f0;
  --soft-2: #ebebe6;
  --ink: #0d0d0f;
  --ink-2: #3a3a40;
  --muted: #8b8b91;
  --line: rgba(13, 13, 15, 0.07);

  --lime: #d4ff4f;
  --protein: #9b7bff;
  --carbs: #3db2f5;
  --fat: #f5a524;
  --danger: #ff5a4e;

  --r-xl: 28px;
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;

  --shadow-sm: 0 1px 2px rgba(13, 13, 15, 0.04), 0 6px 20px rgba(13, 13, 15, 0.04);
  --shadow-lg: 0 24px 64px rgba(13, 13, 15, 0.22);
  --ease: cubic-bezier(0.22, 0.9, 0.25, 1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter', system-ui, sans-serif;
  --font-num: ui-rounded, 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pan-x pan-y;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body.no-scroll {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

[hidden] {
  display: none !important;
}

.icon {
  width: 22px;
  height: 22px;
  display: block;
  flex-shrink: 0;
}

/* ---------- Layout ---------- */

.app {
  max-width: 520px;
  height: 100%;
  margin: 0 auto;
}

.main {
  display: flex;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}

.main::-webkit-scrollbar,
.view::-webkit-scrollbar {
  display: none;
}

.view {
  flex: 0 0 100%;
  min-width: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  padding: calc(var(--safe-top) + 18px) 18px calc(var(--safe-bottom) + 110px);
}

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

.pager-dots {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 6px);
  z-index: 20;
  display: flex;
  gap: 2px;
  padding: 5px 6px;
  border-radius: 999px;
  background: rgba(243, 243, 239, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transform: translateX(-50%);
}

.pager-dot {
  width: 18px;
  height: 14px;
  display: grid;
  place-items: center;
}

.pager-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(13, 13, 15, 0.22);
  transition: width 0.3s var(--ease), background 0.3s;
}

.pager-dot.is-active::before {
  width: 16px;
  background: var(--ink);
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 4px 18px;
}

.eyebrow {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.large-title {
  margin: 0;
  font-size: 34px;
  line-height: 1.05;
  font-weight: 750;
  letter-spacing: -0.035em;
}

.section-label {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.card {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

/* ---------- Buttons ---------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 56px;
  padding: 0 22px;
  border-radius: 18px;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
  transition: transform 0.15s var(--ease), opacity 0.2s, background 0.2s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn--block {
  width: 100%;
}

.btn--primary {
  background: var(--ink);
  color: #fff;
}

.btn--secondary {
  background: var(--soft);
  color: var(--ink);
}

.btn--lime {
  background: var(--lime);
  color: var(--ink);
}

.btn__label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn__label .icon {
  width: 20px;
  height: 20px;
}

.spinner {
  display: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}

.btn.is-loading .btn__label {
  display: none;
}

.btn.is-loading .spinner {
  display: block;
}

.btn.is-loading::after {
  content: 'Analyzing…';
  font-weight: 600;
}

.btn.is-loading:disabled {
  opacity: 1;
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink);
  transition: background 0.2s, opacity 0.2s, transform 0.15s;
}

.icon-btn:active {
  transform: scale(0.9);
}

.icon-btn:disabled {
  opacity: 0.2;
  cursor: default;
}

.icon-btn .icon {
  width: 20px;
  height: 20px;
}

.icon-btn--soft {
  background: var(--soft);
}

.pill-btn {
  height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.add-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  flex-shrink: 0;
  transition: transform 0.15s var(--ease);
}

.add-btn:active {
  transform: scale(0.88);
}

.add-btn .icon {
  width: 20px;
  height: 20px;
  stroke-width: 2.3;
}

.add-btn--lg {
  width: 44px;
  height: 44px;
  margin-bottom: 2px;
}

/* ---------- Week strip ---------- */

.week {
  display: flex;
  align-items: center;
  gap: 2px;
  margin: 0 -6px 16px;
}

.week__days {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.week__day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 0 7px;
  border-radius: 16px;
  transition: background 0.25s var(--ease), color 0.25s;
}

.week__day:disabled {
  opacity: 0.28;
  cursor: default;
}

.week__dow {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

.week__num {
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* Left half: food logged. Right half: gym plan (A lime, B violet). */
.week__dot {
  --food: transparent;
  --gym: var(--food);
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: linear-gradient(90deg, var(--food) 50%, var(--gym) 50%);
  transition: background 0.25s;
}

.week__day.has-entries .week__dot {
  --food: var(--ink);
}

.week__day[data-gym] .week__dot {
  --food: rgba(13, 13, 15, 0.14);
}

.week__day[data-gym].has-entries .week__dot {
  --food: var(--ink);
}

.week__day[data-gym='A'] .week__dot {
  --gym: #b8e62a;
}

.week__day[data-gym='B'] .week__dot {
  --gym: var(--protein);
}

.week__day.is-selected {
  background: var(--ink);
  color: #fff;
}

.week__day.is-selected .week__dow {
  color: rgba(255, 255, 255, 0.55);
}

.week__day.is-selected[data-gym] .week__dot {
  --food: rgba(255, 255, 255, 0.2);
}

.week__day.is-selected.has-entries .week__dot {
  --food: #fff;
}

.week__day.is-selected[data-gym='A'] .week__dot {
  --gym: var(--lime);
}

/* ---------- Hint ---------- */

.hint {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 14px;
  border-radius: var(--r-lg);
  background: var(--lime);
  text-align: left;
}

.hint__icon {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(13, 13, 15, 0.08);
}

.hint__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: rgba(13, 13, 15, 0.65);
}

.hint__text strong {
  font-size: 15px;
  color: var(--ink);
}

/* ---------- Summary ---------- */

.summary {
  position: relative;
  overflow: hidden;
  padding: 22px 20px 18px;
  margin-bottom: 14px;
  border-radius: var(--r-xl);
  color: #fff;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(212, 255, 79, 0.16), transparent 55%),
    radial-gradient(90% 70% at 0% 100%, rgba(155, 123, 255, 0.14), transparent 60%),
    var(--ink);
  box-shadow: 0 18px 40px rgba(13, 13, 15, 0.18);
}

.summary__top {
  display: flex;
  align-items: center;
  gap: 22px;
}

.gym {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.4);
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 700;
  line-height: 1;
  transition: background 0.25s var(--ease), color 0.25s, box-shadow 0.25s;
}

.gym[data-gym='A'] {
  background: var(--lime);
  color: var(--ink);
  box-shadow: 0 0 16px rgba(212, 255, 79, 0.35);
}

.gym[data-gym='B'] {
  background: var(--protein);
  color: #fff;
  box-shadow: 0 0 16px rgba(155, 123, 255, 0.4);
}

.gym.is-pop {
  animation: gym-pop 0.35s var(--ease);
}

@keyframes gym-pop {
  40% {
    transform: scale(1.18);
  }
}

.ring-wrap {
  position: relative;
  width: 150px;
  height: 150px;
  flex-shrink: 0;
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring__track,
.ring__value {
  fill: none;
  stroke-width: 11;
}

.ring__track {
  stroke: rgba(255, 255, 255, 0.09);
}

.ring__value {
  stroke: var(--lime);
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 1s var(--ease), stroke 0.3s;
  filter: drop-shadow(0 0 10px rgba(212, 255, 79, 0.35));
}

.summary.is-over .ring__value {
  stroke: var(--danger);
  filter: drop-shadow(0 0 10px rgba(255, 90, 78, 0.4));
}

.ring__center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring__num {
  font-family: var(--font-num);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.ring__label {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.55);
}

.summary.is-over .ring__label {
  color: var(--danger);
}

.summary__stats {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat__label {
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.5);
}

.stat__value {
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat__value small,
.macro__val small {
  margin-left: 3px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  color: rgba(255, 255, 255, 0.45);
}

.goal-link {
  align-self: flex-start;
  font-size: 13px;
  font-weight: 600;
  color: var(--lime);
}

.summary__macros {
  display: grid;
  grid-template-columns: 1.3fr 1fr 1fr;
  gap: 14px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.macro {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.macro__label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.55);
}

.macro__val {
  font-family: var(--font-num);
  font-size: 19px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.macro__bar {
  height: 4px;
  margin-top: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
}

.macro__bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--protein);
  transition: width 0.9s var(--ease);
}

.dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}

.macro--p .dot,
.dot--p,
.macro-input--p .dot {
  background: var(--protein);
}

.macro--c .dot,
.dot--c,
.macro-input--c .dot {
  background: var(--carbs);
}

.macro--f .dot,
.dot--f,
.macro-input--f .dot {
  background: var(--fat);
}

/* ---------- Tiles ---------- */

.tile {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  flex-shrink: 0;
}

.tile .icon {
  width: 21px;
  height: 21px;
}

.tile--xs {
  width: 22px;
  height: 22px;
  border-radius: 7px;
}

.tile--xs .icon {
  width: 13px;
  height: 13px;
  stroke-width: 2.2;
}

.tile--lg {
  width: 60px;
  height: 60px;
  border-radius: 20px;
}

.tile--lg .icon {
  width: 28px;
  height: 28px;
}

.tile--amber {
  background: #fff1d4;
  color: #c98500;
}

.tile--green {
  background: #e2f6e7;
  color: #24934f;
}

.tile--violet {
  background: #ebe7ff;
  color: #6a4cff;
}

.tile--pink {
  background: #ffe5ee;
  color: #e0457b;
}

.tile--gray {
  background: var(--soft);
  color: var(--ink-2);
}

.tile--lime {
  background: var(--lime);
  color: var(--ink);
}

/* ---------- Meals ---------- */

.meals {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 10px;
}

.meal {
  overflow: hidden;
}

.meal__head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  text-align: left;
  transition: background 0.2s;
}

.meal__head:not(:disabled):active {
  background: var(--soft);
}

.meal__head:disabled {
  cursor: default;
}

.meal__titles {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.meal__title {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.meal__sub {
  margin-top: 1px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.meal.is-empty .meal__title {
  color: var(--ink-2);
}

.meal__kcal {
  font-family: var(--font-num);
  font-size: 17px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.meal__kcal::after {
  content: ' kcal';
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.meal__chev {
  display: grid;
  place-items: center;
  color: #b4b4b9;
  transition: transform 0.3s var(--ease);
}

.meal__chev .icon {
  width: 18px;
  height: 18px;
}

.meal.is-open .meal__chev {
  transform: rotate(90deg);
}

.meal__body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.35s var(--ease);
}

.meal__body > div {
  min-height: 0;
  overflow: hidden;
}

.meal.is-open .meal__body {
  grid-template-rows: 1fr;
}

.meal__items {
  list-style: none;
  margin: 0;
  padding: 0 14px 2px;
}

.tile--emoji {
  font-size: 22px;
  line-height: 1;
}

.group__emoji {
  font-size: 16px;
  line-height: 1;
}

/* ---------- FAB ---------- */

.fab {
  position: fixed;
  z-index: 21;
  right: max(18px, calc(50% - 260px + 18px));
  bottom: calc(var(--safe-bottom) + 30px);
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 22px;
  background: var(--lime);
  color: var(--ink);
  box-shadow:
    0 12px 30px rgba(13, 13, 15, 0.22),
    0 0 0 1px rgba(13, 13, 15, 0.04);
  transition: transform 0.18s var(--ease);
  animation: fab-in 0.45s var(--ease);
  will-change: opacity, transform;
}

.fab:active {
  transform: scale(0.9);
}

.fab .icon {
  width: 28px;
  height: 28px;
  stroke-width: 2.4;
}

@keyframes fab-in {
  from {
    opacity: 0;
    transform: scale(0.6);
  }
}

.entry {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-top: 1px solid var(--line);
}

.entry__main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.entry__name {
  font-size: 15px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.entry__name::first-letter {
  text-transform: uppercase;
}

.macros-inline {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.macros-inline span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.macros-inline .dot {
  width: 6px;
  height: 6px;
}

.entry__kcal {
  font-family: var(--font-num);
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.entry__kcal::after {
  content: ' kcal';
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.entry__del {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #c2c2c6;
  margin-right: -4px;
  transition: color 0.2s, background 0.2s;
}

.entry__del:active {
  color: var(--danger);
  background: #fff0ef;
}

.entry__del .icon {
  width: 17px;
  height: 17px;
}

/* ---------- Weight ---------- */

.weight {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  cursor: text;
}

.weight__text {
  flex: 1;
  display: flex;
  flex-direction: column;
  font-size: 13px;
  color: var(--muted);
}

.weight__text strong {
  font-size: 16px;
  font-weight: 650;
  color: var(--ink);
}

.weight__input {
  display: flex;
  align-items: baseline;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--soft);
}

.weight__input input {
  width: 58px;
  border: none;
  background: transparent;
  outline: none;
  text-align: right;
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.weight__input em,
.row__input em {
  font-style: normal;
  font-size: 14px;
  color: var(--muted);
}

/* ---------- Grouped rows (Profile, Settings) ---------- */

.group__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 6px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.page-head + form > .group__title:first-child,
.page-head + .group__title,
#template-list > .group__title:first-child {
  margin-top: 4px;
}

.group {
  background: var(--card);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.group + .btn {
  margin-top: 14px;
}

.group--flat {
  background: var(--soft);
  box-shadow: none;
  margin-top: 14px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 8px 16px;
  text-decoration: none;
  color: inherit;
}

.row + .row {
  border-top: 1px solid var(--line);
}

.row__label {
  font-size: 16px;
  font-weight: 500;
}

.row__text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

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

#template-form .group--flat {
  margin-top: 0;
}

.tag {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--lime);
  color: var(--ink);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.list--card .entry {
  cursor: pointer;
}

.row__value {
  font-size: 16px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.row__value .icon {
  width: 18px;
  height: 18px;
}

.row__input {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.row__input input {
  width: 90px;
  border: none;
  background: transparent;
  outline: none;
  text-align: right;
  font-family: var(--font-num);
  font-size: 18px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.row__input input::placeholder,
.weight__input input::placeholder {
  color: #c7c7cb;
}

.row__input--wide input {
  width: 180px;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
}

.row__input--full {
  flex: 1;
}

.row__input--full input {
  width: 100%;
  text-align: left;
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
}

.row--link:active {
  background: var(--soft);
}

.mono {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 13px;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  color: var(--muted);
}

.status i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d0d0d4;
}

.status.is-on {
  color: var(--ink);
}

.status.is-on i {
  background: #34c759;
  box-shadow: 0 0 0 4px rgba(52, 199, 89, 0.15);
}

.footnote {
  margin: 12px 8px 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

/* ---------- Switch ---------- */

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  width: 51px;
  height: 31px;
  margin: 0;
  border-radius: 999px;
  background: #dcdcd8;
  cursor: pointer;
  transition: background 0.25s var(--ease);
  flex-shrink: 0;
}

.switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
  transition: transform 0.25s var(--ease);
}

.switch:checked {
  background: var(--ink);
}

.switch:checked::before {
  transform: translateX(20px);
}

/* ---------- Empty state ---------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 32px 24px 24px;
}

.empty h3 {
  margin: 16px 0 6px;
  font-size: 19px;
  letter-spacing: -0.02em;
}

.empty p {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.5;
  color: var(--muted);
  max-width: 280px;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.list--card {
  padding: 2px 16px;
}

.list--card .entry:first-child {
  border-top: none;
}

/* ---------- Sheets ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.sheet__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 10, 12, 0.42);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  opacity: 0;
  transition: opacity 0.35s var(--ease);
}

.sheet__panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 520px;
  max-height: 92vh;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 20px calc(var(--safe-bottom) + 20px);
  background: var(--card);
  border-radius: 30px 30px 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(100%);
  transition: transform 0.42s var(--ease);
}

.sheet.is-open .sheet__backdrop {
  opacity: 1;
}

.sheet.is-open .sheet__panel {
  transform: translateY(0);
}

.sheet__grabber {
  width: 38px;
  height: 5px;
  margin: 4px auto 12px;
  border-radius: 99px;
  background: #dcdcd8;
}

.sheet__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.sheet__head h2 {
  margin: 0;
  font-size: 26px;
  font-weight: 750;
  letter-spacing: -0.03em;
}

.sheet__actions {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 10px;
  margin-top: 18px;
}

/* ---------- Composer ---------- */

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -20px 18px;
  padding: 0 20px 2px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--soft);
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  transition: transform 0.15s var(--ease), background 0.2s;
}

.chip:active {
  transform: scale(0.95);
  background: var(--lime);
}

.chip__meta {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.composer {
  padding: 14px;
  border-radius: var(--r-lg);
  background: var(--soft);
  transition: box-shadow 0.2s;
}

.composer:focus-within {
  box-shadow: 0 0 0 2px var(--ink);
}

.composer textarea {
  width: 100%;
  min-height: 108px;
  padding: 2px 4px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  font-size: 17px;
  line-height: 1.45;
}

.composer--sm textarea {
  min-height: 56px;
  font-size: 16px;
}

.composer textarea::placeholder,
.input::placeholder {
  color: #a6a6ab;
}

.composer__bar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.photo-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease);
}

.photo-btn:active {
  transform: scale(0.95);
}

.photo-btn .icon {
  width: 18px;
  height: 18px;
}

.photo-btn--dark {
  margin-left: auto;
  background: var(--ink);
  color: #fff;
}

.photo-btn:disabled {
  opacity: 0.6;
}

.mic-btn {
  position: relative;
  width: 38px;
  height: 38px;
  margin-left: auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--card);
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s var(--ease), background 0.2s, color 0.2s;
}

.mic-btn:active {
  transform: scale(0.92);
}

.mic-btn .icon {
  width: 19px;
  height: 19px;
}

.mic-btn + .photo-btn--dark {
  margin-left: 0;
}

.mic-btn.is-recording {
  background: var(--danger);
  color: #fff;
}

.mic-btn.is-recording::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--danger);
  animation: pulse 1.2s ease-out infinite;
}

.mic-btn.is-busy {
  cursor: default;
}

.mic-btn.is-busy .icon {
  opacity: 0;
}

.mic-btn.is-busy::after {
  content: '';
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  border: 2px solid rgba(13, 13, 15, 0.12);
  border-top-color: var(--ink);
  animation: spin 0.7s linear infinite;
}

@keyframes pulse {
  from {
    transform: scale(1);
    opacity: 0.7;
  }
  to {
    transform: scale(1.7);
    opacity: 0;
  }
}

.photos {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.photos:empty {
  display: none;
}

.photos--two {
  grid-template-columns: 1fr 1fr;
}

.photo {
  position: relative;
}

.photo img {
  display: block;
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--r-md);
}

.photos--two .photo img {
  height: 150px;
}

.composer--sm .photo img {
  height: 120px;
}

.photo__remove {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(13, 13, 15, 0.6);
  color: #fff;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.photo__remove .icon {
  width: 16px;
  height: 16px;
}

.error {
  margin: 12px 4px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--danger);
}

.error:empty {
  margin: 0 0 14px;
}

.input {
  width: 100%;
  height: 56px;
  padding: 0 16px;
  border: none;
  outline: none;
  border-radius: var(--r-md);
  background: var(--soft);
  font-size: 17px;
  font-weight: 500;
  transition: box-shadow 0.2s;
}

.input:focus {
  box-shadow: 0 0 0 2px var(--ink);
}

/* ---------- Result ---------- */

.result {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 0 18px;
  animation: view-in 0.4s var(--ease);
}

.result__name {
  width: 100%;
  margin-bottom: 14px;
  padding: 6px 8px;
  border: none;
  border-radius: 12px;
  outline: none;
  background: transparent;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  transition: background 0.2s;
}

.result__name:focus {
  background: var(--soft);
}

.ingredients {
  list-style: none;
  margin: 0;
  padding: 4px 14px;
  border-radius: var(--r-md);
  background: var(--soft);
}

.ingredient {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 9px 0;
  font-size: 15px;
}

.ingredient + .ingredient {
  border-top: 1px solid var(--line);
}

.ingredient__name {
  font-weight: 550;
}

.ingredient__amount {
  flex: 1;
  color: var(--muted);
  font-size: 13px;
}

.ingredient__kcal {
  font-family: var(--font-num);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.ingredient__kcal::after {
  content: ' kcal';
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
}

.entry__ingredients {
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--ink-2);
  opacity: 0.75;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tpl-ingredients {
  margin: 0 4px;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.result__num {
  font-family: var(--font-num);
  font-size: 60px;
  font-weight: 750;
  letter-spacing: -0.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.result__unit {
  margin-top: 4px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
}

.result__macros {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  margin-top: 16px;
}

.mpill {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.mpill--p {
  background: #efeaff;
  color: #6a4cff;
}

.mpill--c {
  background: #e3f4fe;
  color: #1484c4;
}

.mpill--f {
  background: #fff1d9;
  color: #b97400;
}

.note {
  margin: 10px 0 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}

.note:empty {
  display: none;
}

/* ---------- Template sheet ---------- */

#template-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#template-form .error {
  margin: 0 4px;
}

#template-form .error:empty {
  display: none;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 4px;
  border-radius: 16px;
  background: var(--soft);
}

.segmented button {
  height: 38px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.25s var(--ease), color 0.2s, box-shadow 0.25s;
}

.segmented--emoji button {
  height: auto;
  padding: 8px 0 7px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 12px;
}

.segmented--emoji button span {
  font-size: 20px;
  line-height: 1;
  filter: grayscale(0.6);
  opacity: 0.7;
  transition: filter 0.2s, opacity 0.2s, transform 0.25s var(--ease);
}

.segmented--emoji button.is-active span {
  filter: none;
  opacity: 1;
  transform: scale(1.1);
}

#add-seg {
  margin-bottom: 16px;
}

.segmented button.is-active {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(13, 13, 15, 0.08);
}

.macro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.macro-input {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 14px;
  border-radius: var(--r-md);
  background: var(--soft);
  cursor: text;
}

.macro-input span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.macro-input input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-num);
  font-size: 24px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.macro-input input::placeholder {
  color: #c7c7cb;
}

.macro-input--k {
  background: var(--ink);
  color: #fff;
}

.macro-input--k span {
  color: rgba(255, 255, 255, 0.55);
}

.macro-input--k input::placeholder {
  color: rgba(255, 255, 255, 0.3);
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 12px);
  z-index: 100;
  max-width: min(90vw, 400px);
  padding: 12px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 30px rgba(13, 13, 15, 0.25);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -16px) scale(0.96);
  transition: opacity 0.3s var(--ease), transform 0.4s var(--ease);
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}

.toast--error {
  background: var(--danger);
}

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