:root {
  --bg: #F4F7F1;          /* foglia chiara */
  --paper: #FFFFFF;
  --ink: #17251E;         /* verde quasi nero */
  --muted: #5E6E65;
  --line: #DCE4DA;
  --basil: #2D6A4C;       /* basilico */
  --basil-soft: #E2EEE6;
  --lemon: #F6D33C;       /* evidenziatore limone */
  --danger: #B3372B;
  --radius-lg: 22px;
  --radius-sm: 12px;
  --font: "Bricolage Grotesque", system-ui, -apple-system, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14201A; --paper: #1C2B23; --ink: #EAF1EC; --muted: #9DB0A5; --line: #2D3F35;
    --basil: #7CC39C; --basil-soft: #23382D; --lemon: #E9C534; --danger: #F08A7E;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 400 17px/1.45 var(--font); font-variation-settings: "wdth" 100;
  -webkit-font-smoothing: antialiased; min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--basil); }
:focus-visible { outline: 3px solid var(--basil); outline-offset: 2px; border-radius: 6px; }

#app { max-width: 620px; margin: 0 auto; padding: calc(var(--safe-t) + 20px) 18px calc(var(--safe-b) + 110px); }

/* ---------- tipografia ---------- */
h1, h2, h3 { margin: 0; font-weight: 750; letter-spacing: -0.02em; line-height: 1.05; }
h1 { font-size: clamp(38px, 11vw, 54px); font-variation-settings: "wdth" 78, "opsz" 96; }
h2 { font-size: 26px; font-variation-settings: "wdth" 85, "opsz" 48; }
h3 { font-size: 19px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* ---------- barra in basso ---------- */
#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 8px 8px calc(var(--safe-b) + 8px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
#tabs[hidden] { display: none; }
#tabs a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 0; font-size: 12px; font-weight: 600; color: var(--muted); text-decoration: none;
}
#tabs svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#tabs a.on { color: var(--ink); }
#tabs a.on svg { stroke-width: 2.3; }

/* ---------- testata del giorno ---------- */
.dayhead { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.dayhead .when { font-size: 15px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.daynav { display: flex; gap: 6px; }
.round {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--paper); display: grid; place-items: center; cursor: pointer;
}
.round svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.progress { display: flex; align-items: center; gap: 10px; margin: 14px 0 22px; font-size: 15px; font-weight: 600; }
.bar { flex: 1; height: 8px; border-radius: 8px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--basil); border-radius: 8px; transition: width .4s ease; }

/* ---------- pasti: la timeline ---------- */
.meals { list-style: none; margin: 0; padding: 0; position: relative; }
.meals::before {
  content: ""; position: absolute; left: 75px; top: 12px; bottom: 12px; width: 2px; background: var(--line);
}
.meal { display: grid; grid-template-columns: 62px 1fr 48px; gap: 0 26px; padding: 6px 0 18px; position: relative; }
.meal .t {
  font-size: 21px; font-weight: 700; font-variation-settings: "wdth" 75, "opsz" 36;
  letter-spacing: -0.01em; text-align: right; padding-top: 2px; font-variant-numeric: tabular-nums;
}
.meal .t::after {
  content: ""; position: absolute; left: 69px; top: 15px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--bg); border: 2px solid var(--muted);
}
.meal.next .t::after { background: var(--basil); border-color: var(--basil); box-shadow: 0 0 0 5px var(--basil-soft); }
.meal.done .t::after { background: var(--lemon); border-color: var(--lemon); }
.meal .name { position: relative; display: inline-block; font-size: 21px; font-weight: 700; margin: 0 0 6px; z-index: 0; }
/* l'evidenziatore: il momento memorabile dell'app */
.meal .name::before {
  content: ""; position: absolute; z-index: -1; left: -4px; right: -6px; bottom: 1px; height: .55em;
  background: var(--lemon); border-radius: 3px 8px 4px 6px; transform: scaleX(0); transform-origin: left;
  transition: transform .35s cubic-bezier(.6,.1,.3,1);
}
.meal.done .name::before { transform: scaleX(1); }
@media (prefers-color-scheme: dark) { .meal.done .name { color: #17251E; } }
.meal ul { margin: 0; padding: 0; list-style: none; }
.meal li { padding: 2px 0; }
.meal.done li { color: var(--muted); }
.meal .note { font-size: 14px; color: var(--muted); margin-top: 6px; font-style: italic; }
.meal .chk {
  width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--line); background: var(--paper);
  display: grid; place-items: center; cursor: pointer; transition: background .2s, border-color .2s;
}
.meal .chk svg { width: 22px; height: 22px; fill: none; stroke: var(--paper); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.meal.done .chk { background: var(--basil); border-color: var(--basil); }
.meal .bell { font-size: 12px; color: var(--muted); display: block; text-align: right; margin-top: 2px; }

.notes {
  margin-top: 10px; padding: 16px 18px; border-radius: var(--radius-sm);
  background: var(--basil-soft); font-size: 15px; white-space: pre-line;
}
.notes h3 { font-size: 16px; margin-bottom: 6px; }

/* ---------- settimana ---------- */
.week { list-style: none; padding: 0; margin: 18px 0 0; }
.week li a {
  display: grid; grid-template-columns: 74px 1fr auto; gap: 14px; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none;
}
.week .d { font-size: 30px; font-weight: 750; font-variation-settings: "wdth" 75; line-height: 1; }
.week .d small { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 3px; font-variation-settings: "wdth" 100; }
.week .sum { font-size: 14px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.week .today .d { color: var(--basil); }
.dots { display: flex; gap: 4px; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.dots i.on { background: var(--lemon); }

/* ---------- moduli ---------- */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 20px; margin: 16px 0; }
.panel > h3 { margin-bottom: 10px; }
label { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; }
input[type=text], input[type=email], input[type=password], input[type=time], input[type=date], select, textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--bg); font-size: 17px; -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 96px; line-height: 1.4; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--basil); outline-offset: 0; border-color: transparent; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 22px; border-radius: 50px; border: 0; cursor: pointer;
  font-weight: 700; font-size: 17px; background: var(--ink); color: var(--bg); text-decoration: none;
}
.btn.full { width: 100%; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.lemon { background: var(--lemon); color: #17251E; }
.btn.danger { background: transparent; color: var(--danger); border: 1.5px solid currentColor; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1 1 170px; }
.err { color: var(--danger); font-weight: 600; font-size: 15px; margin-top: 12px; }
.link { background: none; border: 0; padding: 0; color: var(--basil); font-weight: 650; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- accesso ---------- */
.auth h1 { margin: 8vh 0 12px; }
.auth .lead { font-size: 19px; color: var(--muted); max-width: 30ch; }
.brandmark { width: 64px; height: 64px; border-radius: 18px; }

/* ---------- caricamento dieta ---------- */
.drop {
  display: block; border: 2px dashed var(--line); border-radius: var(--radius-lg); padding: 34px 20px;
  text-align: center; cursor: pointer; background: var(--paper); margin: 20px 0 12px;
}
.drop:hover, .drop.over { border-color: var(--basil); }
.drop strong { display: block; font-size: 20px; margin-bottom: 4px; }
.drop input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.reading { text-align: center; padding: 50px 10px; }
.spinner { width: 44px; height: 44px; margin: 0 auto 20px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--basil); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- editor ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; margin: 0 -2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 9px 16px; border-radius: 40px; border: 1.5px solid var(--line); background: var(--paper);
  font-weight: 650; font-size: 15px; cursor: pointer;
}
.chip.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.emeal { border-top: 1px solid var(--line); padding: 16px 0 6px; }
.emeal:first-of-type { border-top: 0; }
.emeal .top { display: grid; grid-template-columns: 1fr 112px; gap: 10px; }
.emeal .top label { margin-top: 0; }
.switch { display: flex; align-items: center; gap: 10px; margin: 12px 0 0; font-weight: 600; font-size: 15px; cursor: pointer; }
.switch input { width: 46px; height: 28px; -webkit-appearance: none; appearance: none; background: var(--line); border-radius: 28px; position: relative; cursor: pointer; transition: background .2s; flex: none; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked { background: var(--basil); }
.switch input:checked::after { transform: translateX(18px); }
.emeal .actions { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.savebar {
  position: sticky; bottom: calc(var(--safe-b) + 14px); z-index: 5; margin-top: 20px;
  display: flex; gap: 10px; padding: 10px; border-radius: 60px; background: var(--paper); border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(23,37,30,.12);
}
.savebar .btn { flex: 1; }
.banner { padding: 14px 16px; border-radius: var(--radius-sm); background: var(--lemon); color: #17251E; font-size: 15px; font-weight: 550; margin: 14px 0; }

.ios-steps { margin: 8px 0 0; padding-left: 20px; }
.ios-steps li { margin: 6px 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 12px 20px; border-radius: 40px; font-weight: 650; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.empty { text-align: center; padding: 40px 10px; }

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

details.panel summary { cursor: pointer; list-style: none; font-size: 17px; }
details.panel summary::-webkit-details-marker { display: none; }
details.panel summary::after { content: "+"; float: right; font-weight: 700; font-size: 22px; line-height: 1; color: var(--muted); }
details.panel[open] summary::after { content: "–"; }

.meal li { padding: 3px 0; }
.meal li + li:not(.or) { border-top: 1px dashed var(--line); padding-top: 6px; margin-top: 3px; }
.meal li.or { font-style: italic; color: var(--muted); font-size: 14px; padding: 4px 0 2px; }
.meal li.or + li { border-top: 0; margin-top: 0; }
