:root {
  --bg: #0f1115;
  --bg-2: #161a21;
  --card: #1b212b;
  --card-2: #202836;
  --line: #2a323f;
  --ink: #f3f5f8;
  --ink-dim: #aab4c2;
  --ink-faint: #7c8696;
  --accent: #ff7a59;     /* calorie / brand */
  --protein: #ff7a59;
  --carbs: #6ea8fe;
  --fat: #f5c451;
  --lime: #a3e635;
  --good: #5dd1a4;
  --radius: 18px;
  --shadow: 0 18px 40px -22px rgba(0,0,0,.7);
  --maxw: 1080px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  background: radial-gradient(1200px 600px at 80% -10%, #1a2230 0%, var(--bg) 55%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
h1, h2 { font-family: "Fraunces", Georgia, serif; letter-spacing: -.01em; }

.visually-hidden, .skip-link:not(:focus) {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link:focus {
  position: fixed; top: 12px; left: 12px; z-index: 100;
  background: var(--accent); color: #1a1207; padding: 10px 16px; border-radius: 10px;
  font-weight: 600; text-decoration: none;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }

button { font-family: inherit; cursor: pointer; }

/* TOPBAR */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 14px clamp(16px, 4vw, 32px);
  background: rgba(15,17,21,.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand__mark { color: var(--accent); display: grid; place-items: center; }
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
.brand__text strong { font-family: "Fraunces", serif; font-size: 1.25rem; }
.brand__sub { font-size: .72rem; color: var(--ink-faint); }

.datenav { display: flex; align-items: center; gap: 4px; margin: 0 auto; position: relative; }
.datenav__arrow {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); font-size: 1.3rem; line-height: 1;
  display: grid; place-items: center; transition: background .15s;
}
.datenav__arrow:hover { background: var(--card-2); }
.datenav__label {
  min-width: 132px; text-align: center; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); padding: 7px 14px; border-radius: 10px; font-weight: 600; font-size: .92rem;
}
.datenav__label:hover { background: var(--card-2); }
.datenav__picker {
  position: absolute; inset: 0; opacity: 0; pointer-events: none;
}

.ghost-btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-dim);
  padding: 8px 13px; border-radius: 10px; font-weight: 600; font-size: .86rem;
  transition: color .15s, border-color .15s;
}
.ghost-btn:hover { color: var(--ink); border-color: #3a4555; }
.ghost-btn--danger { color: #ff9a8b; }
.ghost-btn--danger:hover { color: #ff7a59; border-color: #5a3a36; }

/* MAIN */
main { max-width: var(--maxw); margin: 0 auto; padding: clamp(18px, 3vw, 30px) clamp(16px, 4vw, 32px) 60px; }

/* DASHBOARD */
.dashboard {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 18px; margin-bottom: 26px;
}
.dash-card {
  background: linear-gradient(180deg, var(--card) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px;
}
.dash-card--ring { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.ring-wrap { position: relative; width: 200px; height: 200px; }
.ring { width: 100%; height: 100%; }
.ring__track { fill: none; stroke: #2a323f; stroke-width: 16; }
.ring__fill {
  fill: none; stroke: var(--accent); stroke-width: 16; stroke-linecap: round;
  stroke-dasharray: 540.35; stroke-dashoffset: 540.35;
  transition: stroke-dashoffset .9s cubic-bezier(.22,1,.36,1), stroke .4s;
  filter: drop-shadow(0 0 6px rgba(255,122,89,.35));
}
.ring-center {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.ring-center__num { font-family: "Fraunces", serif; font-size: 2.9rem; font-weight: 600; line-height: 1; }
.ring-center__label { font-size: .8rem; color: var(--ink-faint); margin-top: 4px; letter-spacing: .02em; }
.ring-legend {
  display: flex; align-items: flex-end; gap: 12px; color: var(--ink-dim); font-size: .8rem;
}
.ring-legend > div { display: flex; flex-direction: column; align-items: center; }
.ring-legend span { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.ring-legend small { color: var(--ink-faint); }
.ring-legend__plus, .ring-legend__eq { font-size: 1.1rem; color: var(--ink-faint); padding-bottom: 14px; }

.dash-card--macros { display: flex; flex-direction: column; gap: 16px; }
.dash-card__title { margin: 0; font-size: 1.05rem; color: var(--ink-dim); font-weight: 600; }
.macro__head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.macro__name { font-weight: 600; font-size: .92rem; }
.macro__val { font-size: .85rem; color: var(--ink-dim); font-variant-numeric: tabular-nums; }
.macro__bar { height: 11px; border-radius: 999px; background: #2a323f; overflow: hidden; }
.macro__fill {
  display: block; height: 100%; width: 0%; border-radius: 999px;
  transition: width .8s cubic-bezier(.22,1,.36,1), background .3s;
}
.macro[data-macro="protein"] .macro__fill { background: linear-gradient(90deg,#ff7a59,#ff9b80); }
.macro[data-macro="carbs"] .macro__fill { background: linear-gradient(90deg,#6ea8fe,#9ac1ff); }
.macro[data-macro="fat"] .macro__fill { background: linear-gradient(90deg,#f5c451,#f7d57e); }
.macro__fill.over { background: repeating-linear-gradient(45deg,#ff5470,#ff5470 7px,#d8425c 7px,#d8425c 14px) !important; }
.macro__note { margin: 2px 0 0; font-size: .78rem; color: var(--ink-faint); }

/* LAYOUT */
.layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.section-title { font-size: 1.4rem; margin: 0 0 14px; }

/* DIARY */
.meal {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 14px; overflow: hidden;
}
.meal__head {
  display: flex; align-items: center; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid transparent;
}
.meal__icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; font-size: 1rem; flex: none; }
.meal__name { font-weight: 600; font-size: 1rem; flex: 1; }
.meal__cals { font-variant-numeric: tabular-nums; color: var(--ink-dim); font-size: .9rem; font-weight: 600; }
.meal__add {
  border: none; background: none; color: var(--accent); font-size: 1.5rem; line-height: 1;
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
}
.meal__add:hover { background: rgba(255,122,89,.12); }
.meal__list { list-style: none; margin: 0; padding: 0; }
.entry {
  display: flex; align-items: center; gap: 12px; padding: 11px 18px;
  border-top: 1px solid var(--line);
}
.entry__main { flex: 1; min-width: 0; }
.entry__name { font-size: .92rem; font-weight: 500; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.entry__macros { font-size: .76rem; color: var(--ink-faint); }
.entry__macros b { font-weight: 600; }
.entry__macros .dot { color: var(--protein); }
.entry__cals { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem; }
.entry__del {
  border: none; background: none; color: var(--ink-faint); font-size: 1.1rem; line-height: 1;
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; flex: none;
}
.entry__del:hover { color: #ff7a59; background: rgba(255,122,89,.1); }
.meal__empty { padding: 14px 18px; color: var(--ink-faint); font-size: .85rem; font-style: italic; border-top: 1px solid var(--line); }

/* SIDE PANELS */
.side { display: flex; flex-direction: column; gap: 18px; position: sticky; top: 84px; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.panel .section-title { font-size: 1.15rem; margin-bottom: 4px; }
.panel__hint { margin: 0 0 12px; font-size: .8rem; color: var(--ink-faint); }
.panel__headrow { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.panel__pill { font-size: .72rem; color: var(--ink-dim); background: var(--bg-2); border: 1px solid var(--line); padding: 3px 9px; border-radius: 999px; }

.fav-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fav {
  display: flex; align-items: center; gap: 11px; width: 100%; text-align: left;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px;
  color: var(--ink); transition: border-color .15s, transform .08s;
}
.fav:hover { border-color: var(--accent); }
.fav:active { transform: scale(.985); }
.fav__emoji { font-size: 1.2rem; flex: none; }
.fav__body { flex: 1; min-width: 0; }
.fav__name { font-size: .86rem; font-weight: 600; display: block; }
.fav__meta { font-size: .72rem; color: var(--ink-faint); }
.fav__add { color: var(--accent); font-weight: 700; font-size: 1.25rem; flex: none; }

/* WEEK CHART */
.week { display: flex; align-items: flex-end; gap: 7px; height: 110px; padding: 6px 2px 0; }
.week__day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.week__barwrap { width: 100%; flex: 1; display: flex; align-items: flex-end; }
.week__bar {
  width: 100%; border-radius: 6px 6px 3px 3px; background: linear-gradient(180deg,#3a4555,#2a323f);
  min-height: 4px; transition: height .6s cubic-bezier(.22,1,.36,1);
}
.week__bar.is-today { background: linear-gradient(180deg,#ff9b80,#ff7a59); }
.week__bar.on-target { background: linear-gradient(180deg,#7be0b3,#5dd1a4); }
.week__lab { font-size: .68rem; color: var(--ink-faint); }
.week__day.today .week__lab { color: var(--ink); font-weight: 700; }
.week-stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin: 14px 0 0; padding-top: 14px; border-top: 1px solid var(--line); }
.week-stats div { display: flex; flex-direction: column; }
.week-stats dt { font-size: .68rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .04em; }
.week-stats dd { margin: 2px 0 0; font-weight: 700; font-size: 1.05rem; font-variant-numeric: tabular-nums; }

/* FAB */
.fab {
  position: fixed; right: clamp(16px, 4vw, 34px); bottom: clamp(16px, 4vw, 34px); z-index: 25;
  width: 60px; height: 60px; border-radius: 50%; border: none; color: #1a1207;
  background: linear-gradient(135deg,#ff9b80,#ff7a59); box-shadow: 0 14px 28px -8px rgba(255,122,89,.55);
  display: grid; place-items: center; transition: transform .12s;
}
.fab:hover { transform: translateY(-2px) scale(1.04); }
.fab:active { transform: scale(.95); }

/* DIALOGS */
.sheet {
  border: 1px solid var(--line); background: var(--bg-2); color: var(--ink);
  border-radius: 22px; padding: 0; width: min(480px, calc(100vw - 28px)); box-shadow: 0 30px 80px -20px rgba(0,0,0,.8);
}
.sheet::backdrop { background: rgba(7,9,12,.62); backdrop-filter: blur(3px); }
.sheet[open] { animation: pop .22s cubic-bezier(.22,1,.36,1); }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } to { opacity: 1; transform: none; } }
.sheet__form { padding: 22px; display: flex; flex-direction: column; gap: 15px; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; }
.sheet__head h2 { margin: 0; font-size: 1.3rem; }
.icon-btn { border: none; background: var(--card); color: var(--ink-dim); width: 32px; height: 32px; border-radius: 9px; font-size: .9rem; }
.icon-btn:hover { color: var(--ink); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field__label { font-size: .8rem; color: var(--ink-dim); font-weight: 600; }
.field input[type="text"], .field input[type="number"], .field select {
  background: var(--card); border: 1px solid var(--line); color: var(--ink);
  border-radius: 11px; padding: 11px 13px; font-size: .95rem; width: 100%;
}
.field input::placeholder { color: var(--ink-faint); }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.grid4 .field input { padding: 10px; text-align: center; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--card); padding: 4px; border-radius: 12px; border: 1px solid var(--line); }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 8px 4px; border-radius: 9px; font-size: .78rem; color: var(--ink-dim); font-weight: 600; transition: background .15s, color .15s; }
.seg input:checked + span { background: var(--accent); color: #1a1207; }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.field--serving output { color: var(--accent); font-weight: 700; }
input[type="range"] { accent-color: var(--accent); width: 100%; }

.check { display: flex; align-items: center; gap: 9px; font-size: .85rem; color: var(--ink-dim); cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }

.sheet__foot { margin-top: 4px; }
.sheet__foot--split { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.primary-btn {
  border: none; border-radius: 12px; background: linear-gradient(135deg,#ff9b80,#ff7a59); color: #1a1207;
  font-weight: 700; font-size: .95rem; padding: 13px 22px; width: 100%;
}
.sheet__foot--split .primary-btn { width: auto; }
.primary-btn:hover { filter: brightness(1.05); }
.goals__macrocheck { margin: 0; font-size: .78rem; color: var(--ink-faint); min-height: 1.2em; }
.goals__macrocheck.ok { color: var(--good); }
.goals__macrocheck.warn { color: var(--fat); }

/* TOAST */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 30px);
  background: var(--card-2); color: var(--ink); border: 1px solid var(--line);
  padding: 12px 18px; border-radius: 12px; font-size: .88rem; font-weight: 500;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; z-index: 50;
  transition: opacity .25s, transform .25s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast b { color: var(--lime); }

/* FOOTER */
.sitefoot { max-width: var(--maxw); margin: 0 auto; padding: 26px clamp(16px,4vw,32px) 90px; color: var(--ink-faint); font-size: .8rem; border-top: 1px solid var(--line); }
.sitefoot p { margin: 4px 0; }
.sitefoot__demo strong { color: var(--ink-dim); }

@media (max-width: 860px) {
  .dashboard { grid-template-columns: 1fr; }
  .layout { grid-template-columns: 1fr; }
  .side { position: static; }
}
@media (max-width: 520px) {
  .brand__sub { display: none; }
  .ghost-btn span { display: none; }
  .ghost-btn { padding: 8px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .datenav__label { min-width: 104px; font-size: .85rem; }
  .ring-wrap { width: 168px; height: 168px; }
  .ring-center__num { font-size: 2.4rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; scroll-behavior: auto; }
}
