:root {
  --bg: #fbf6f0;
  --card: #ffffff;
  --ink: #2a211c;
  --muted: #8f8279;
  --line: #f0e7dd;
  --soft: #f6efe7;
  --accent: #ff6b4a;
  --accent-soft: #ffe6de;
  --green: #22b07d;
  --green-soft: #dcf5ea;
  --p: #ff6b4a;
  --c: #ffb020;
  --f: #6d7cff;
  --t-colazione: #fff1c9;
  --t-spuntino: #e3f6dc;
  --t-pranzo: #ffe4d8;
  --t-merenda: #e2edff;
  --t-cena: #ece3ff;
  --shadow: 0 1px 2px rgba(60, 40, 20, .05), 0 8px 24px rgba(60, 40, 20, .07);
  --r: 22px;
  --tab-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14110f; --card: #1f1a17; --ink: #f5ede7; --muted: #a2968d; --line: #2e2723; --soft: #29221e;
    --accent-soft: #3a221b; --green-soft: #14322a;
    --t-colazione: #3a3220; --t-spuntino: #22321f; --t-pranzo: #3a2720; --t-merenda: #1f2a3c; --t-cena: #2c2440;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--bg); }
body {
  margin: 0; color: var(--ink); background: var(--bg);
  font: 16px/1.4 ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.02em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small-pad { margin: 6px 0 14px; font-size: 14px; }

.view {
  max-width: 560px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 18px calc(var(--tab-h) + var(--safe-b) + 28px);
  min-height: 100vh;
}

/* header */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 2px 16px; }
.top h1 { font-size: 30px; font-weight: 800; line-height: 1.1; }
.eyebrow { margin: 0 0 4px; font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.section-title { margin: 26px 4px 10px; font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hint { text-align: center; color: var(--muted); font-size: 13px; margin: 18px 0 0; opacity: .8; }

.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 9px 14px; border-radius: 999px;
  background: var(--soft); font-weight: 700; font-size: 14px; white-space: nowrap; transition: transform .15s;
}
.chip:active { transform: scale(.94); }
.chip.danger { color: #e0483a; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 5px 11px; border-radius: 999px; background: rgba(255,255,255,.75); font-weight: 700; font-size: 13px; color: #2a211c; }
.pill.small { padding: 2px 8px; font-size: 11px; background: var(--accent-soft); color: var(--accent); }

/* day strip */
.daystrip { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -18px 16px; padding: 2px 18px 6px; scroll-snap-type: x mandatory; }
.daystrip::-webkit-scrollbar { display: none; }
.daypill {
  flex: 0 0 auto; width: 54px; padding: 9px 0; border-radius: 18px; background: var(--card); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 2px; scroll-snap-align: center; transition: transform .2s, background .2s;
}
.daypill small { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.daypill b { font-size: 19px; }
.daypill.today small { color: var(--accent); }
.daypill.on { background: var(--ink); color: var(--bg); transform: translateY(-2px); }
.daypill.on small { color: inherit; opacity: .7; }

/* swipe area */
.swipe-area { touch-action: pan-y; transition: transform .25s ease, opacity .25s ease; }
.swipe-area.in-right { animation: inR .32s cubic-bezier(.2,.8,.2,1); }
.swipe-area.in-left { animation: inL .32s cubic-bezier(.2,.8,.2,1); }
@keyframes inR { from { transform: translateX(60px); opacity: 0; } }
@keyframes inL { from { transform: translateX(-60px); opacity: 0; } }

/* kcal */
.kcal-card { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: center; padding: 18px; }
.kcal-ring { position: relative; width: 132px; height: 132px; }
.ring-bg { fill: none; stroke: var(--soft); stroke-width: 13; }
.ring-fg { fill: none; stroke: var(--accent); stroke-width: 13; stroke-linecap: round; transition: stroke-dashoffset .8s cubic-bezier(.2,.8,.2,1); }
.ring-fg.over { stroke: #e0483a; }
.kcal-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.kcal-center b { font-size: 28px; font-weight: 800; letter-spacing: -.03em; }
.kcal-center small { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.kcal-side { display: grid; gap: 11px; }
.mbar-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.mbar-top b small { color: var(--muted); font-weight: 600; }
.mbar-track { height: 8px; border-radius: 8px; background: var(--soft); overflow: hidden; }
.mbar-track i { display: block; height: 100%; border-radius: 8px; transition: width .8s cubic-bezier(.2,.8,.2,1); }
.mbar.p i { background: var(--p); } .mbar.c i { background: var(--c); } .mbar.f i { background: var(--f); }
.kcal-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.water { display: flex; gap: 4px; }
.drop {
  width: 22px; height: 28px; background: var(--soft);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 28'%3E%3Cpath d='M11 1C11 1 2 12 2 18a9 9 0 0 0 18 0C20 12 11 1 11 1z'/%3E%3C/svg%3E") center/contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 22 28'%3E%3Cpath d='M11 1C11 1 2 12 2 18a9 9 0 0 0 18 0C20 12 11 1 11 1z'/%3E%3C/svg%3E") center/contain no-repeat;
  transition: background .2s, transform .2s;
}
.drop.on { background: #4aa8ff; }
.drop:active { transform: scale(.8); }

/* tint */
.tint-colazione { background: var(--t-colazione); } .tint-spuntino { background: var(--t-spuntino); }
.tint-pranzo { background: var(--t-pranzo); } .tint-merenda { background: var(--t-merenda); } .tint-cena { background: var(--t-cena); }

/* hero */
.hero { padding: 16px 18px 18px; position: relative; overflow: hidden; transition: transform .2s; }
.hero:active { transform: scale(.985); }
.hero-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; }
.hero-top .muted { color: rgba(42,33,28,.55); }
@media (prefers-color-scheme: dark) { .hero-top .muted { color: rgba(245,237,231,.6); } }
.hero-art { margin: 4px auto 2px; max-width: 300px; animation: bob 4s ease-in-out infinite; }
.hero-art .art, .meal-art .art, .sheet-art .art, .wm-art .art, .empty-art .art { display: block; width: 100%; height: auto; }
@keyframes bob { 50% { transform: translateY(-5px) rotate(-.6deg); } }
.hero h2 { font-size: 23px; font-weight: 800; line-height: 1.15; }
.hero-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; }
.kcal { font-weight: 800; font-size: 16px; }
.done-btn { padding: 12px 20px; border-radius: 999px; background: var(--ink); color: var(--bg); font-weight: 800; transition: transform .15s, background .2s; }
.done-btn:active { transform: scale(.94); }
.done-btn.on { background: var(--green); color: #fff; }

/* meal rows */
.meals { display: grid; gap: 10px; }
.meal { display: grid; grid-template-columns: 74px 1fr auto; gap: 14px; align-items: center; padding: 10px 12px 10px 10px; transition: transform .15s, opacity .3s; }
.meal:active { transform: scale(.985); }
.meal-art { width: 74px; height: 64px; border-radius: 16px; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.meal-art .art { width: 112%; }
.meal-info { min-width: 0; }
.meal-slot { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.meal h3 { font-size: 16px; font-weight: 700; line-height: 1.2; margin: 2px 0 3px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.meal .muted { font-size: 13px; }
.tag { font-style: normal; font-size: 10px; padding: 2px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-left: 4px; vertical-align: 1px; }
.tag.x2 { background: var(--green-soft); color: var(--green); }
.meal.is-done { opacity: .62; }
.meal.is-done h3 { text-decoration: line-through; text-decoration-thickness: 2px; text-decoration-color: var(--muted); }

.check {
  width: 40px; height: 40px; flex: 0 0 auto; border-radius: 50%; border: 2.5px solid var(--line); display: grid; place-items: center;
  transition: background .2s, border-color .2s, transform .15s;
}
.check svg { width: 22px; height: 22px; fill: none; stroke: #fff; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 24; stroke-dashoffset: 24; transition: stroke-dashoffset .3s .05s; }
.check.on { background: var(--green); border-color: var(--green); animation: pop .35s; }
.check.on svg { stroke-dashoffset: 0; }
.check:active { transform: scale(.85); }
@keyframes pop { 40% { transform: scale(1.18); } }

.tipbox { margin: 14px 0 0; padding: 13px 15px; border-radius: 16px; background: var(--accent-soft); font-size: 14.5px; line-height: 1.45; }
.tipbox a { color: var(--accent); font-weight: 700; }

/* week */
.chart-card { padding: 16px 16px 12px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; margin-bottom: 12px; }
.bars { position: relative; display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; height: 150px; align-items: end; }
.bar { display: flex; flex-direction: column; align-items: center; height: 100%; gap: 4px; }
.bar-v { font-size: 10px; color: var(--muted); font-weight: 700; height: 12px; }
.bar-col { flex: 1; width: 100%; display: flex; align-items: flex-end; background: var(--soft); border-radius: 10px; overflow: hidden; }
.bar-col i { width: 100%; background: #ffc8b8; border-radius: 10px; transition: height .6s; }
.bar-col i.ok { background: var(--green); } .bar-col i.over { background: #e0483a; }
.bar small { font-size: 12px; font-weight: 700; color: var(--muted); }
.bar.today small { color: var(--accent); }
.target-line { position: absolute; left: 0; right: 0; bottom: calc(20px + (100% - 36px) * var(--t)); border-top: 2px dashed var(--muted); opacity: .45; pointer-events: none; }
.target-line span { position: absolute; left: -2px; top: -15px; color: var(--muted); font-size: 10px; font-weight: 700; }
.weekday { margin-top: 10px; padding: 14px; transition: transform .15s; }
.weekday:active { transform: scale(.985); }
.weekday.is-today { outline: 2.5px solid var(--accent); }
.weekday-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.weekday-head .muted { margin-left: auto; font-size: 13px; }
.weekday-meals { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.wm { text-align: center; min-width: 0; }
.wm-art { border-radius: 12px; aspect-ratio: 1.15; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.wm-art .art { width: 120%; }
.wm small { display: block; font-size: 10.5px; line-height: 1.15; margin-top: 4px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wm.done .wm-art { opacity: .45; }

/* segmented */
.seg { display: flex; padding: 4px; border-radius: 16px; background: var(--soft); gap: 4px; }
.seg button { flex: 1; padding: 10px 0; border-radius: 12px; font-weight: 700; font-size: 14.5px; color: var(--muted); transition: background .2s, color .2s; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* spesa */
.total-card { display: grid; grid-template-columns: 1fr 1fr; padding: 16px 18px; margin-bottom: 4px; }
.total-card small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 600; }
.total-card b { font-size: 22px; font-weight: 800; }
.total-card div + div { text-align: right; }
.rep { margin: 18px 6px 8px; font-size: 13px; font-weight: 800; color: var(--muted); }
.slist { display: grid; gap: 8px; }
.srow { position: relative; border-radius: 18px; overflow: hidden; }
.srow.swipe { touch-action: pan-y; }
.srow-in {
  position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow); transition: transform .22s cubic-bezier(.2,.8,.2,1);
}
.swipe-bg { position: absolute; inset: 0; display: flex; align-items: center; padding: 0 22px; font-weight: 800; color: #fff; border-radius: 18px; }
.swipe-bg.ok { background: var(--green); }
.swipe-bg.bad { background: #e0483a; justify-content: flex-end; }
.srow.armed .swipe-bg { filter: brightness(1.08); }
.srow-txt { flex: 1; min-width: 0; }
.srow-txt b { display: block; font-size: 15.5px; }
.srow-txt small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.3; margin-top: 2px; }
.srow-q { text-align: right; flex: 0 0 auto; }
.srow-q b { display: block; font-size: 14px; }
.srow-q small { color: var(--muted); font-size: 12px; }
.srow.done .srow-in { opacity: .6; box-shadow: none; background: var(--soft); }
.srow.done b { text-decoration: line-through; }
.empty { text-align: center; padding: 22px 20px 26px; }
.empty-art { max-width: 220px; margin: 0 auto 6px; }

/* dispensa */
.exp { font-style: normal; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--soft); color: var(--muted); margin-left: 4px; vertical-align: 1px; }
.exp.warn { background: #fff0c2; color: #b07400; }
.exp.bad { background: #ffe0dc; color: #d23c2e; }
.stepper { display: flex; align-items: center; gap: 4px; background: var(--soft); border-radius: 999px; padding: 3px; flex: 0 0 auto; }
.stepper button { width: 32px; height: 32px; border-radius: 50%; background: var(--card); font-weight: 800; font-size: 17px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.stepper button:active { transform: scale(.88); }
.stepper b { min-width: 58px; text-align: center; font-size: 13.5px; }
.basegrid { display: flex; flex-wrap: wrap; gap: 8px; }
.basechip { display: inline-flex; align-items: center; gap: 8px; padding: 9px 14px 9px 9px; border-radius: 999px; background: var(--card); box-shadow: var(--shadow); font-weight: 600; font-size: 14px; transition: transform .15s; }
.basechip span { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 900; background: var(--green-soft); color: var(--green); }
.basechip.off { opacity: .75; }
.basechip.off span { background: #ffe0dc; color: #d23c2e; }
.basechip:active { transform: scale(.94); }
.settings { margin-top: 30px; padding: 16px 18px; }
.settings p { margin: 4px 0 12px; font-size: 14px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* tabbar */
.tabbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--safe-b)); z-index: 20;
  width: min(calc(100% - 24px), 520px); height: var(--tab-h); display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--card) 82%, transparent); backdrop-filter: blur(18px) saturate(1.6); -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border-radius: 26px; box-shadow: 0 10px 34px rgba(40, 25, 10, .16); padding: 6px;
}
.tab { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border-radius: 20px; color: var(--muted); font-size: 11.5px; font-weight: 700; transition: color .2s, background .2s; }
.tab svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--accent); background: var(--accent-soft); }
.tab.on svg { stroke-width: 2.4; }
.badge { position: absolute; top: 6px; right: calc(50% - 22px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font-style: normal; font-size: 11px; font-weight: 800; display: grid; place-items: center; }

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 12, 6, .4); opacity: 0; transition: opacity .25s; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; margin: 0 auto; max-width: 560px; max-height: 92vh;
  background: var(--card); border-radius: 28px 28px 0 0; transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  display: flex; flex-direction: column; box-shadow: 0 -10px 40px rgba(0,0,0,.2);
}
.sheet-wrap.open .sheet { transform: translateY(0); }
.sheet-wrap.open .sheet-backdrop { opacity: 1; }
.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--line); margin: 10px auto 4px; flex: 0 0 auto; }
.sheet-body { overflow-y: auto; padding: 6px 20px calc(24px + var(--safe-b)); overscroll-behavior: contain; }
.sheet-art { border-radius: 22px; margin-bottom: 14px; padding: 6px 30px 0; }
.sheet-title { font-size: 25px; font-weight: 800; line-height: 1.15; margin-bottom: 2px; }
.macros4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 16px; }
.macros4 div { background: var(--soft); border-radius: 14px; padding: 10px 4px; text-align: center; }
.macros4 b { display: block; font-size: 17px; font-weight: 800; }
.macros4 small { color: var(--muted); font-size: 11.5px; font-weight: 600; }
.macros4 .p b { color: var(--p); } .macros4 .c b { color: var(--c); } .macros4 .f b { color: var(--f); }
.ings { list-style: none; padding: 0; margin: 0; display: grid; gap: 2px; }
.ings li { display: flex; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); font-size: 15px; }
.ings li b { margin-left: auto; font-weight: 700; color: var(--muted); font-size: 14px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); flex: 0 0 auto; }
.dot.ok { background: var(--green); } .dot.no { background: #ffb3a6; }
.steps { margin: 0; padding: 0; list-style: none; counter-reset: s; display: grid; gap: 10px; }
.steps li { counter-increment: s; position: relative; padding-left: 40px; font-size: 15px; line-height: 1.45; min-height: 28px; }
.steps li::before { content: counter(s); position: absolute; left: 0; top: -1px; width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 14px; display: grid; place-items: center; }
.big-btn { display: block; width: 100%; margin-top: 22px; padding: 17px; border-radius: 18px; background: var(--ink); color: var(--bg); font-weight: 800; font-size: 17px; transition: transform .15s; }
.big-btn:active { transform: scale(.97); }
.big-btn.ghost { background: var(--soft); color: var(--ink); }
.extragrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.extra { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 12px 6px; border-radius: 16px; background: var(--soft); transition: transform .15s; }
.extra:active { transform: scale(.93); }
.extra span { font-size: 28px; }
.extra b { font-size: 12.5px; line-height: 1.15; text-align: center; }
.extra small { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.custom { display: flex; gap: 8px; }
.custom input { flex: 1; min-width: 0; padding: 11px 14px; border-radius: 14px; border: 0; background: var(--soft); outline: none; }
.custom input[name="kcal"] { flex: 0 0 90px; }

/* toast */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + var(--safe-b) + 24px); transform: translate(-50%, 20px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 999px; font-weight: 700; font-size: 14.5px;
  opacity: 0; transition: opacity .25s, transform .25s; white-space: nowrap; box-shadow: 0 8px 24px rgba(0,0,0,.2);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

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