:root {
  --bg: #fbf7f0;
  --card: #ffffff;
  --card-2: #f5efe4;
  --ink: #211c16;
  --ink-soft: #6b6154;
  --line: #e6ddcc;
  --accent: #d2542a;
  --accent-ink: #ffffff;
  --green: #3f7d52;
  --amber: #b7791f;
  --red: #b3392c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(33, 28, 22, .06), 0 6px 18px rgba(33, 28, 22, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16130f;
    --card: #211d18;
    --card-2: #2b251e;
    --ink: #f2ebe0;
    --ink-soft: #a89c8c;
    --line: #3a322a;
    --accent: #e8703f;
    --accent-ink: #1a1410;
    --green: #6dbb85;
    --amber: #e0ac52;
    --red: #e8796b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

header {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
header h1 { font-size: 18px; margin: 0; flex: 1; letter-spacing: -.01em; }
header .logo { font-size: 22px; }

main { padding: 14px 16px 20px; max-width: 720px; margin: 0 auto; }
.view { display: none; animation: in .18s ease-out; }
.view.on { display: block; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); margin: 22px 0 10px; }
h2:first-child { margin-top: 4px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 12px;
  box-shadow: var(--shadow);
}

button, .btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid var(--line); background: var(--card-2); color: var(--ink);
  border-radius: 11px; padding: 11px 14px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
}
button:active { transform: scale(.985); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.wide { width: 100%; }
.ghost { background: transparent; }
.danger { color: var(--red); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 11px;
  padding: 11px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 76px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; font-weight: 600; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--line); background: var(--card-2); color: var(--ink);
  border-radius: 999px; padding: 7px 13px; font-size: 14px; min-height: 0;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* dispensa */
.pantry-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
}
.pantry-item:last-child { border-bottom: 0; }
.pantry-item .nome { flex: 1; min-width: 0; }
.pantry-item .nome b { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pantry-item .nome small { color: var(--ink-soft); }
.x { border: 0; background: none; color: var(--ink-soft); font-size: 20px; padding: 6px 8px; min-height: 0; }
.badge { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green); }
.badge.warn { background: color-mix(in srgb, var(--amber) 20%, transparent); color: var(--amber); }
.badge.bad { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }

.empty { text-align: center; color: var(--ink-soft); padding: 26px 10px; }
.empty .big { font-size: 34px; display: block; margin-bottom: 8px; }

/* ricette / menu */
.recipe summary, .day summary { cursor: pointer; list-style: none; }
.recipe summary::-webkit-details-marker, .day summary::-webkit-details-marker { display: none; }
.recipe h3 { margin: 0 0 4px; font-size: 17px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.meta span { font-size: 12px; color: var(--ink-soft); background: var(--card-2); border-radius: 999px; padding: 3px 9px; }
.recipe ol { padding-left: 20px; margin: 8px 0; }
.recipe ol li { margin-bottom: 7px; }
.recipe ul.ing { list-style: none; padding: 0; margin: 8px 0; }
.recipe ul.ing li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 15px; }
.recipe ul.ing li.miss { color: var(--accent); font-weight: 600; }
.tip { background: var(--card-2); border-radius: 10px; padding: 10px 12px; font-size: 14px; margin-top: 10px; }

.day summary { display: flex; align-items: baseline; gap: 10px; }
.day summary .g { font-weight: 700; text-transform: capitalize; flex: 1; }
.day .pasto { padding: 10px 0; border-top: 1px solid var(--line); }
.day .pasto .et { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-soft); }
.day .pasto .t { font-weight: 600; }

/* spesa */
.shop-item { display: flex; align-items: center; gap: 11px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.shop-item input[type=checkbox] { width: 22px; height: 22px; min-height: 0; flex: none; accent-color: var(--accent); }
.shop-item.done .lbl { text-decoration: line-through; color: var(--ink-soft); }
.shop-item .lbl { flex: 1; }
.shop-item .lbl small { display: block; color: var(--ink-soft); }

nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav button {
  border: 0; background: none; border-radius: 0; min-height: 60px;
  flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600; color: var(--ink-soft);
}
nav button i { font-style: normal; font-size: 21px; line-height: 1; }
nav button.on { color: var(--accent); }

dialog {
  border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--ink);
  padding: 18px; width: min(440px, calc(100vw - 32px)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin-top: 0; }

.overlay {
  position: fixed; inset: 0; z-index: 50; background: #000;
  display: none; flex-direction: column; align-items: center; justify-content: center;
}
.overlay.on { display: flex; }
.overlay video { width: 100%; max-height: 78vh; object-fit: cover; }
.overlay .bar { position: absolute; bottom: 0; left: 0; right: 0; padding: 18px calc(16px + env(safe-area-inset-bottom)); display: flex; gap: 10px; }
.scanline { position: absolute; left: 8%; right: 8%; height: 2px; background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.loading { text-align: center; padding: 30px 10px; color: var(--ink-soft); }
.pot { font-size: 40px; display: inline-block; animation: bob 1.1s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-8px) rotate(-4deg); } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(78px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); max-width: 90vw; text-align: center;
}
.cost { font-size: 12px; color: var(--ink-soft); text-align: right; margin-top: 6px; }

/* comando vocale */
.mic-card { padding: 12px; }
.mic-wrap { display: flex; align-items: center; gap: 12px; }
.mic {
  width: 62px; height: 62px; flex: none; padding: 0;
  border-radius: 50%; border: 0; font-size: 25px;
  background: var(--accent); color: var(--accent-ink);
  transition: transform .12s;
}
.mic.on { animation: pulsa 1.3s ease-out infinite; }
.mic:disabled { background: var(--card-2); color: var(--ink-soft); }
@keyframes pulsa {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70% { box-shadow: 0 0 0 18px color-mix(in srgb, var(--accent) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
}
.mic-text { flex: 1; min-width: 0; }
.mic-text b { display: block; font-size: 15px; }
.mic-text small { color: var(--ink-soft); font-size: 12.5px; line-height: 1.35; display: block; }
.mic-text.udito b { color: var(--accent); }
#btnAudio.muto { opacity: .45; }

.voce-out { border-left: 3px solid var(--accent); }
.voce-out .detto { font-size: 13px; color: var(--ink-soft); font-style: italic; margin: 0 0 8px; }
.voce-out .risposta { font-size: 16px; margin: 0 0 10px; }

/* indicatore di sincronizzazione */
#sync { font-size: 15px; color: var(--ink-soft); min-width: 26px; text-align: center; cursor: pointer; padding: 6px 2px; }
#sync.ok { color: var(--green); }
#sync.errore { color: var(--amber); }
#sync.invio { opacity: .6; }

/* adattamento dei piatti per i bambini */
.tip.bimbi {
  background: color-mix(in srgb, var(--green) 12%, transparent);
  color: var(--ink);
  border-left: 3px solid var(--green);
}

/* invito a mettere la scadenza sulle voci che non ce l'hanno */
.badge.vuoto {
  background: transparent; border: 1px dashed var(--line);
  color: var(--ink-soft); font-weight: 600; font-size: 11.5px;
}

/* bottone per cambiare un singolo pasto del menu */
.modifica {
  min-height: 0; padding: 4px 10px; font-size: 12px; font-weight: 600;
  border-radius: 999px; background: transparent; color: var(--ink-soft);
  border: 1px solid var(--line);
}
.day .pasto .spread { margin-bottom: 4px; }

/* ricetta passo passo dentro il menu */
.day .azioni { display: flex; gap: 6px; }
.ricetta-passo {
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line);
}
.ricetta-passo .attrezzi { font-size: 13px; color: var(--ink-soft); margin: 8px 0 0; }
.ricetta-passo ul.ing { list-style: none; padding: 0; margin: 8px 0; }
.ricetta-passo ul.ing li {
  display: flex; justify-content: space-between; gap: 10px;
  padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 15px;
}
.ricetta-passo ul.ing li.miss { color: var(--accent); font-weight: 600; }
.ricetta-passo ol { padding-left: 22px; margin: 10px 0; }
.ricetta-passo ol li { margin-bottom: 10px; line-height: 1.55; }
.ricetta-passo ol li::marker { color: var(--accent); font-weight: 700; }
