@font-face {
  font-family: "Young Serif";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/young-serif-latin.woff2") format("woff2");
}

:root {
  --bg: #faf5ee;
  --surface: #ffffff;
  --surface-2: #f4ece1;
  --cell: #f7f0e6;
  --text: #2a1f1a;
  --muted: #76675c;
  --border: #eadfd2;
  --accent: #c8472b;
  --accent-ink: #ffffff;
  --danger: #b3261e;
  --pranzo: #e0a02e;
  --cena: #6b4ea0;
  --altro: #3f8f5f;
  --shadow: 0 8px 24px rgba(120, 50, 20, .22);
  --shadow-sm: 0 1px 2px rgba(80, 40, 10, .06), 0 6px 16px rgba(80, 40, 10, .06);
  --radius: 18px;
  --serif: "Young Serif", Georgia, "Times New Roman", serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17110e;
    --surface: #231a16;
    --surface-2: #2d221c;
    --cell: #1d1512;
    --text: #f3e9e0;
    --muted: #ab9a8d;
    --border: #3a2d26;
    --accent: #ef7455;
    --accent-ink: #2a120a;
    --danger: #ff8a80;
    --pranzo: #f0b44a;
    --cena: #a78bda;
    --altro: #6fc08a;
    --shadow: 0 8px 24px rgba(0, 0, 0, .55);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html {
  -webkit-text-size-adjust: 100%;
  background:
    radial-gradient(120% 50% at 50% -8%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 70%),
    var(--bg);
  background-repeat: no-repeat;
  background-color: var(--bg);
}

body {
  margin: 0;
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

h1, h2, p { margin: 0; }

svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

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

/* ---------- Layout ---------- */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(12px + env(safe-area-inset-top)) 16px calc(124px + env(safe-area-inset-bottom));
}

.brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 14px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 1.35rem;
  letter-spacing: .005em;
}
.wordmark img { border-radius: 10px; box-shadow: 0 2px 8px rgba(120, 50, 20, .25); }

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.icon-btn:active { background: var(--surface-2); }

.pill-btn {
  height: 38px;
  padding: 0 16px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 650;
  font-size: .9rem;
  box-shadow: var(--shadow-sm);
}
.pill-btn:active { background: var(--surface-2); }

/* ---------- Riepilogo (tovaglia a quadretti) ---------- */
.hero {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: end;
  gap: 8px 16px;
  margin-bottom: 14px;
  padding: 18px 18px 16px;
  border-radius: 24px;
  color: #fff;
  background: linear-gradient(135deg, #c8472b 0%, #a33520 100%);
  box-shadow: var(--shadow);
  overflow: hidden;
  isolation: isolate;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(255,255,255,.55) 50%, transparent 50%) 0 0 / 26px 26px,
    linear-gradient(rgba(255,255,255,.55) 50%, transparent 50%) 0 0 / 26px 26px;
  opacity: .16;
  -webkit-mask-image: linear-gradient(105deg, transparent 38%, #000 95%);
  mask-image: linear-gradient(105deg, transparent 38%, #000 95%);
}

.hero-main { display: flex; flex-direction: column; min-width: 0; }
.hero-main strong { font-family: var(--serif); font-weight: 400; font-size: 3.6rem; line-height: .95; font-variant-numeric: lining-nums; }
.hero-main span { margin-top: 4px; font-size: .9rem; font-weight: 600; opacity: .95; }

.hero-side { display: flex; gap: 8px; }
.hero-stat {
  min-width: 64px;
  padding: 8px 10px;
  border-radius: 14px;
  background: rgba(255, 255, 255, .16);
  backdrop-filter: blur(2px);
  text-align: center;
  display: flex;
  flex-direction: column;
}
.hero-stat strong { font-family: var(--serif); font-weight: 400; font-size: 1.5rem; line-height: 1.1; }
.hero-stat span { font-size: .72rem; font-weight: 600; opacity: .92; }

.hero-fav {
  grid-column: 1 / -1;
  margin-top: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, .16);
  font-size: .84rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

/* ---------- Calendario ---------- */
.calendar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 10px 12px;
  box-shadow: var(--shadow-sm);
  touch-action: pan-y;
}

.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.month-title { font-family: var(--serif); font-weight: 400; font-size: 1.4rem; text-transform: capitalize; text-align: center; }

.weekdays, .grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.weekdays { margin-bottom: 5px; text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); letter-spacing: .06em; }

.cell {
  position: relative;
  aspect-ratio: 1 / 1.1;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: var(--cell);
  overflow: hidden;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  isolation: isolate;
  transition: transform .12s ease;
}
.cell:active { transform: scale(.94); }
.cell.out { opacity: .42; }
.cell .num {
  align-self: flex-start;
  min-width: 22px;
  height: 22px;
  margin: 4px 0 0 4px;
  padding: 0 5px;
  border-radius: 11px;
  font-size: .8rem;
  font-weight: 650;
  line-height: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.cell.today .num { background: var(--accent); color: var(--accent-ink); }
.cell.today:not(.has-photo) { box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 55%, transparent); }
.cell.selected { box-shadow: inset 0 0 0 2.5px var(--accent); }

.cell .dots { display: flex; gap: 3px; justify-content: center; padding: 0 0 6px; min-height: 14px; }
.cell .dot { width: 7px; height: 7px; }

.cell.has-photo { background-size: cover; background-position: center; }
.cell.has-photo::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, rgba(0,0,0,.5) 0%, rgba(0,0,0,0) 48%, rgba(0,0,0,.4) 100%);
}
.cell.has-photo .num { color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.cell.has-photo.today .num { color: var(--accent-ink); text-shadow: none; }
.cell.has-photo .dot { box-shadow: 0 0 0 1.5px rgba(255,255,255,.95); }

.cell.pop { animation: pop .55s cubic-bezier(.2, .9, .3, 1.35); }
@keyframes pop { 0% { transform: scale(.6); } 55% { transform: scale(1.14); } 100% { transform: scale(1); } }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.pranzo { background: var(--pranzo); }
.dot.cena { background: var(--cena); }
.dot.altro { background: var(--altro); }

.pranzo { --m: var(--pranzo); }
.cena { --m: var(--cena); }
.altro { --m: var(--altro); }

.legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  font-size: .76rem;
  color: var(--muted);
}
.legend li { display: flex; align-items: center; gap: 5px; }

/* ---------- Giorno selezionato ---------- */
.day { margin-top: 26px; }
.day h2 { margin-bottom: 12px; font-family: var(--serif); font-weight: 400; font-size: 1.3rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.day h2 .tag { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: .7rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent); color: var(--accent-ink); letter-spacing: .02em; }

.entries { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }

.entry {
  display: flex;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  box-shadow: var(--shadow-sm);
}

.entry-thumb {
  flex: none;
  width: 84px;
  height: 84px;
  border: 0;
  border-radius: 14px;
  padding: 0;
  background: var(--surface-2) center / cover no-repeat;
  display: grid;
  place-items: center;
  color: var(--muted);
}
.entry-thumb.no-photo { background: color-mix(in srgb, var(--m) 20%, var(--surface)); color: var(--m); }
.entry-thumb svg { width: 32px; height: 32px; }

.entry-body {
  flex: 1;
  min-width: 0;
  border: 0;
  background: none;
  padding: 2px 0;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 3px;
  justify-content: center;
  align-items: flex-start;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px 2px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--m) 18%, transparent);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.entry-title { font-family: var(--serif); font-size: 1.12rem; line-height: 1.2; overflow-wrap: anywhere; }
.entry-dish { font-size: .93rem; overflow-wrap: anywhere; }
.entry-note { font-size: .83rem; color: var(--muted); font-style: italic; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- Giorno vuoto ---------- */
.empty { padding: 8px 12px 4px; text-align: center; display: grid; justify-items: center; gap: 4px; }
.empty-art { width: 150px; height: auto; margin-bottom: 4px; stroke-width: 3; }
.art-shadow { fill: color-mix(in srgb, var(--text) 10%, transparent); stroke: none; }
.art-plate { fill: var(--surface); stroke: var(--border); }
.art-rim { fill: none; stroke: var(--border); stroke-width: 2.5; }
.art-cutlery { stroke: var(--accent); }
.empty-title { font-family: var(--serif); font-size: 1.1rem; }
.empty-sub { color: var(--muted); font-size: .92rem; max-width: 26ch; }

/* ---------- Pulsante Aggiungi ---------- */
.fab-wrap {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 18px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  justify-content: flex-end;
  pointer-events: none;
}
.fab {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 58px;
  padding: 0 24px 0 18px;
  border: 0;
  border-radius: 29px;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 82%, #000));
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 1.04rem;
  box-shadow: var(--shadow);
  transition: transform .12s ease;
}
.fab:active { transform: scale(.95); }

/* ---------- Scheda (bottom sheet) ---------- */
dialog { color: var(--text); }
dialog::backdrop { background: rgba(20, 10, 4, .55); backdrop-filter: blur(2px); }

.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 94dvh;
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 28px 28px 0 0;
  background: var(--bg);
  overflow: hidden;
}
.sheet[open] { display: flex; animation: slide-up .24s ease-out; }
.sheet form { display: flex; flex-direction: column; width: 100%; min-height: 0; max-height: 94dvh; }

@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .sheet[open], .cell.pop { animation: none; }
  .cell, .fab { transition: none; }
}

.grabber { width: 40px; height: 5px; margin: 8px auto 0; border-radius: 3px; background: var(--border); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 8px 0 20px; }
.sheet-head h2 { font-family: var(--serif); font-weight: 400; font-size: 1.3rem; }

.sheet-body { overflow-y: auto; padding: 8px 20px 12px; display: flex; flex-direction: column; gap: 14px; overscroll-behavior: contain; }
.sheet-body > * { flex: none; }

.photo-box {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: 20px;
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 6%, var(--surface-2));
  border: 2px dashed color-mix(in srgb, var(--accent) 35%, var(--border));
  display: grid;
  place-items: center;
}
.photo-box.filled { border: 0; }
.photo-box img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.photo-empty { display: grid; justify-items: center; gap: 2px; color: var(--muted); font-size: .88rem; text-align: center; }
.photo-empty svg { width: 40px; height: 40px; margin-bottom: 6px; color: var(--accent); }
.photo-empty strong { color: var(--text); font-family: var(--serif); font-weight: 400; font-size: 1.1rem; }
.photo-busy { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.45); color: #fff; font-weight: 600; }

.photo-actions { display: flex; gap: 8px; margin-top: -4px; }
.photo-actions .btn { flex: 1 1 0; min-width: 0; padding: 0 8px; }

.field { display: grid; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > label, .field > legend { font-size: .85rem; font-weight: 700; padding: 0; }
.field small { font-weight: 500; color: var(--muted); }

.field input[type="text"], .field input[type="date"], .field textarea {
  width: 100%;
  min-height: 50px;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-size: 1rem; /* 16px: evita lo zoom automatico su iPhone */
}
.field textarea { resize: vertical; min-height: 76px; }
.field input:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.seg-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg-row label { display: block; }
.seg-row input { position: absolute; opacity: 0; pointer-events: none; }
.seg-row span {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 50px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  font-weight: 600;
}
.seg-row input:checked + span { border-color: var(--m); background: color-mix(in srgb, var(--m) 16%, var(--surface)); }
.seg-row input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.m-pranzo { --m: var(--pranzo); }
.m-cena { --m: var(--cena); }
.m-altro { --m: var(--altro); }

.sheet-foot {
  display: grid;
  gap: 8px;
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
}

.form-error { padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--danger) 14%, var(--surface)); color: var(--danger); font-size: .9rem; font-weight: 600; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 14px;
  font-weight: 700;
}
.btn svg { width: 20px; height: 20px; }
.btn-primary { background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 82%, #000)); color: var(--accent-ink); font-size: 1.05rem; box-shadow: var(--shadow-sm); }
.btn-primary:disabled { opacity: .6; }
.btn-soft { background: var(--surface); border: 1.5px solid var(--border); }
.btn-soft:active { background: var(--surface-2); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger.armed { background: var(--danger); color: #fff; }

/* ---------- Foto a tutto schermo ---------- */
.viewer {
  width: 100%;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #000;
  color: #fff;
}
.viewer[open] { display: grid; grid-template-rows: 1fr auto; }
.viewer img { width: 100%; height: 100%; min-height: 0; object-fit: contain; }
.viewer .icon-btn { position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 8px; z-index: 1; background: rgba(0,0,0,.5); color: #fff; }
.viewer p { padding: 12px 20px calc(18px + env(safe-area-inset-bottom)); text-align: center; font-family: var(--serif); font-size: 1.1rem; }

/* ---------- Avviso ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 100;
  max-width: calc(100% - 32px);
  padding: 11px 20px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: .92rem;
  box-shadow: var(--shadow);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
