@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 140ms; }

:root {
  color-scheme: light dark;
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1d1a17;
  --muted: #7b7268;
  --line: rgba(29, 26, 23, 0.08);
  --fill: rgba(29, 26, 23, 0.05);
  --accent: #d8532b;
  --accent-2: #f0813f;
  --accent-soft: rgba(216, 83, 43, 0.12);
  --on-accent: #ffffff;
  --ok: #2f9e6b;
  --lcd-bg: #15181a;
  --lcd-fg: #7cf0bd;
  --lcd-dim: rgba(124, 240, 189, 0.55);
  --shadow: 0 1px 2px rgba(29, 26, 23, 0.04), 0 10px 28px -14px rgba(29, 26, 23, 0.18);
  --glass: rgba(255, 255, 255, 0.78);
  --r: 22px;
  font-size: 17px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1f1c19;
    --ink: #f4efe8;
    --muted: #a3988b;
    --line: rgba(255, 255, 255, 0.09);
    --fill: rgba(255, 255, 255, 0.07);
    --accent: #ff7a47;
    --accent-2: #ffa25a;
    --accent-soft: rgba(255, 122, 71, 0.16);
    --on-accent: #1a1410;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 28px -14px rgba(0, 0, 0, 0.6);
    --glass: rgba(31, 28, 25, 0.72);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  padding: 20px 18px 120px;
  padding: max(20px, env(safe-area-inset-top)) 18px 120px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

main { max-width: 640px; margin: 0 auto; }
main > :not(.banner):not(script) { animation: rise 260ms ease-out both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h1 { font-size: 2.1rem; line-height: 1.1; letter-spacing: -0.03em; font-weight: 800; margin: 6px 0 4px; }
h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.09em; font-weight: 700; color: var(--muted); margin: 28px 0 10px; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }

button, input, select, textarea { font: inherit; color: inherit; touch-action: manipulation; }

button {
  border: 0;
  border-radius: 14px;
  padding: 11px 16px;
  background: var(--fill);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 90ms ease, background 150ms ease, opacity 150ms ease;
}
button:active { transform: scale(0.96); }
button:disabled { opacity: 0.35; pointer-events: none; }

.primary-btn {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: var(--on-accent);
  box-shadow: 0 8px 20px -10px var(--accent);
}

input[type="search"], input[type="text"], input[type="number"], input[type="password"], select, textarea {
  width: 100%;
  border: 1.5px solid transparent;
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--fill);
  outline: none;
  transition: border-color 150ms ease, background 150ms ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); background: var(--surface); }
textarea { min-height: 6em; resize: vertical; }

.edit-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 50%;
  background: transparent; color: var(--muted); font-size: 1rem; flex-shrink: 0;
}
.edit-btn:hover { background: var(--fill); }

/* ---------- Header / back ---------- */
.back {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow); margin-bottom: 10px;
}
.back svg { width: 20px; height: 20px; }

.eyebrow { color: var(--muted); font-size: 0.9rem; font-weight: 500; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: 0.85rem; font-weight: 700;
}
.chip svg { width: 14px; height: 14px; }

/* ---------- Recipe list ---------- */
.search {
  position: relative; margin: 18px 0 8px;
}
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.search input { padding-left: 42px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow); }

.recipe-list { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.recipe-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: var(--r); padding: 12px 16px 12px 12px;
  box-shadow: var(--shadow); transition: transform 120ms ease;
}
.recipe-card:active { transform: scale(0.98); }
.recipe-tile {
  width: 60px; height: 60px; border-radius: 18px; flex-shrink: 0; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 1.5rem;
  background: hsl(var(--h), 78%, 55%);
  background: linear-gradient(135deg, hsl(var(--h), 78%, 60%), hsl(calc(var(--h) + 38), 82%, 50%));
}
.recipe-card-body { flex: 1; min-width: 0; }
.recipe-card-title { font-weight: 700; font-size: 1.05rem; line-height: 1.25; }
.recipe-card-time { color: var(--muted); font-size: 0.85rem; margin-top: 3px; }
.recipe-card > svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.empty { color: var(--muted); padding: 24px 0; text-align: center; }

/* ---------- Recipe detail ---------- */
.servings-selector {
  display: inline-flex; align-items: center; gap: 6px; margin: 16px 0 4px;
  background: var(--surface); box-shadow: var(--shadow); border-radius: 999px; padding: 6px;
}
.servings-selector button { width: 42px; height: 42px; padding: 0; border-radius: 50%; font-size: 1.3rem; line-height: 1; }
.servings-selector .label { padding: 0 12px; font-weight: 600; }
#servings-value { font-weight: 800; font-size: 1.2rem; }

.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); }

.ingredients-list, .steps-list { list-style: none; padding: 0; margin: 0; }
.ingredients-list { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 4px 16px; }
.ingredients-list li { display: flex; align-items: center; gap: 8px; padding: 12px 0; }
.ingredients-list li + li { border-top: 1px solid var(--line); }
.ing-name { flex: 1; }
.ing-qty { font-weight: 800; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.ing-qty-edit { width: 96px; padding: 8px 10px; }
.ing-qty button { padding: 6px 10px; }

.steps-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 28px 0 10px; }
.steps-header h2 { margin: 0; }
.toggle-btn { font-size: 0.85rem; padding: 9px 14px; background: var(--accent-soft); color: var(--accent); }

.step-nav {
  position: sticky; top: 10px; top: max(10px, env(safe-area-inset-top)); z-index: 5; margin: 0 0 12px;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px;
  background: var(--glass); backdrop-filter: blur(18px) saturate(1.6); -webkit-backdrop-filter: blur(18px) saturate(1.6);
  border-radius: 20px; padding: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.step-nav button { padding: 12px; }
#step-next { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); }
#step-counter { font-weight: 700; color: var(--muted); font-size: 0.85rem; text-align: center; }
.step-progress { position: absolute; left: 0; bottom: 0; height: 3px; width: 100%; background: transparent; }
.step-progress i { display: block; height: 100%; width: var(--p, 0%); background: var(--accent); transition: width 240ms ease; }

.steps-list { display: flex; flex-direction: column; gap: 12px; }
.steps-list > li { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.steps-list.cooking-mode > li:not([hidden]) { padding: 22px 18px; scroll-margin-top: 90px; animation: rise 200ms ease-out both; }
.steps-list.cooking-mode .step-text { font-size: 1.2rem; line-height: 1.5; }

.step-header { display: flex; align-items: center; gap: 12px; }
.step-num {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 0.9rem;
}
.step-title { flex: 1; font-weight: 700; font-size: 1.05rem; }
.step-text { margin: 10px 0 12px; color: var(--ink); color: color-mix(in srgb, var(--ink) 88%, var(--muted)); }

/* TM6 display */
.tm6-bar { display: flex; gap: 2px; background: var(--lcd-bg); border-radius: 16px; padding: 4px; overflow: hidden; }
.tm6-cell { flex: 1; min-width: 0; text-align: center; padding: 10px 6px 8px; border-radius: 12px; }
.tm6-cell + .tm6-cell { box-shadow: -1px 0 0 rgba(255, 255, 255, 0.08); border-radius: 0; }
.tm6-cell b { display: block; color: var(--lcd-fg); font-size: 1.35rem; font-weight: 700; letter-spacing: 0.02em; text-shadow: 0 0 14px rgba(124, 240, 189, 0.45); white-space: nowrap; }
.tm6-cell small { display: block; color: var(--lcd-dim); font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; margin-top: 2px; }
.cooking-mode .tm6-cell b { font-size: 1.7rem; }

.edit-form { margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--line); display: flex; flex-direction: column; gap: 10px; }
.edit-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.checkbox-label { flex-direction: row !important; align-items: center; gap: 10px !important; }
.checkbox-label input { width: 22px; height: 22px; accent-color: var(--accent); }
.edit-actions { display: flex; gap: 8px; }
.edit-actions button { flex: 1; }

.box { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 4px 18px 18px; position: relative; margin-top: 14px; }
.box h2 { margin-top: 18px; }
.box .edit-btn { position: absolute; top: 10px; right: 10px; }
.tip-box { background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface); }

body.cooking .box, body.cooking .cucina-btn, body.cooking .servings-selector, body.cooking #ingredients-section { display: none; }
.cucina-btn { width: 100%; margin-top: 24px; padding: 17px; font-size: 1.05rem; border-radius: 18px; }

/* ---------- Bottom sheet ---------- */
.banner { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(10, 8, 6, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade 160ms ease-out both; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.banner-content {
  position: relative; background: var(--surface); width: 100%; max-width: 640px; max-height: 85vh; overflow-y: auto;
  border-radius: 28px 28px 0 0; padding: 26px 20px 24px; padding-bottom: max(24px, env(safe-area-inset-bottom));
  animation: sheet 260ms cubic-bezier(0.2, 0.9, 0.3, 1) both;
}
.banner-content::before { content: ""; position: absolute; top: 9px; left: 50%; width: 40px; height: 5px; margin-left: -20px; border-radius: 3px; background: var(--line); }
@keyframes sheet { from { transform: translateY(100%); } to { transform: none; } }
.banner-content h2 { margin-top: 6px; }
.banner-list { list-style: none; padding: 0; margin: 4px 0 14px; }
.banner-list li { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.banner-list li + li { border-top: 1px solid var(--line); }
.banner-list input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--accent); flex-shrink: 0; }
.banner-actions { display: flex; gap: 10px; position: sticky; bottom: calc(-1 * max(24px, env(safe-area-inset-bottom))); margin: 0 -20px calc(-1 * max(24px, env(safe-area-inset-bottom))); padding: 12px 20px max(24px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--surface) 78%, transparent); }
.banner-actions button { flex: 1; padding: 15px; border-radius: 16px; }
.banner-actions .primary-btn { flex: 2; }

/* ---------- Shopping ---------- */
.shopping-group h2 { color: var(--accent); }
.shopping-items { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.shopping-items li {
  display: flex; align-items: center; gap: 14px; background: var(--surface); border-radius: 18px;
  padding: 12px 16px 12px 12px; box-shadow: var(--shadow); transition: opacity 220ms ease, transform 220ms ease;
}
.shopping-items li.done { opacity: 0; transform: translateX(24px); }
.item-check {
  width: 30px; height: 30px; padding: 0; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--accent); background: transparent; display: grid; place-items: center;
}
.item-check:active { background: var(--accent-soft); }
.item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.item-name { flex: 1; font-weight: 600; }
.item-qty { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.item-category { color: var(--muted); font-size: 0.75rem; }

.presi-list { list-style: none; padding: 0; margin: 0; }
.presi-list li { display: flex; align-items: center; gap: 12px; padding: 10px 0; opacity: 0.6; }
.presi-list li + li { border-top: 1px solid var(--line); }
.presi-list .item-name { text-decoration: line-through; font-weight: 500; flex: none; }
.presi-list .item-check { background: var(--ok); border-color: var(--ok); }
.presi-list .item-check::after { content: "✓"; color: #fff; font-size: 0.85rem; font-weight: 800; }
.undo-btn { font-size: 0.8rem; color: var(--accent); background: none; padding: 6px 8px; }

.skeleton { height: 56px; border-radius: 18px; margin-bottom: 8px; background: linear-gradient(90deg, var(--fill), var(--line), var(--fill)); background-size: 200% 100%; animation: shimmer 1.1s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.food-search { position: relative; }
.food-suggestions {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 8; margin-top: 6px; max-height: 240px; overflow-y: auto;
  background: var(--surface); border-radius: 16px; box-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.3);
}
.food-suggestions button { display: block; width: 100%; text-align: left; border-radius: 0; background: transparent; padding: 13px 16px; }
.food-suggestions button + button { border-top: 1px solid var(--line); }
.food-suggestions small { color: var(--muted); font-weight: 500; }
.new-food-form { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
#new-food-name { font-weight: 700; }

/* ---------- Floating tab bar ---------- */
.tabbar {
  position: fixed; left: 50%; bottom: 14px; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 10;
  width: 92vw; width: min(92vw, 340px); display: flex; gap: 4px; padding: 6px;
  background: var(--glass); backdrop-filter: blur(20px) saturate(1.7); -webkit-backdrop-filter: blur(20px) saturate(1.7);
  border-radius: 999px; box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.35), inset 0 0 0 1px var(--line);
  view-transition-name: tabbar;
}
.tabbar a {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 8px;
  border-radius: 999px; color: var(--muted); font-size: 0.9rem; font-weight: 700; transition: background 160ms ease, color 160ms ease;
}
.tabbar svg { width: 20px; height: 20px; }
.tabbar a.active { background: var(--accent-soft); color: var(--accent); }

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

/* ---------- Login ---------- */
.eyebrow-row { display: flex; align-items: center; justify-content: space-between; }
.logout { color: var(--muted); font-size: 0.85rem; font-weight: 600; padding: 6px 4px; }
.login { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 4px; }
.login-mark {
  width: 76px; height: 76px; border-radius: 24px; display: grid; place-items: center; margin-bottom: 14px;
  color: #fff; font-size: 2.2rem; font-weight: 800; background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 16px 32px -14px var(--accent);
}
.login-form { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.login-form input[type="password"] { text-align: center; padding: 15px; font-size: 1.05rem; }
.login-form button { padding: 15px; border-radius: 16px; }
.login-error { color: var(--accent); font-weight: 700; font-size: 0.9rem; }
.header-actions { display: flex; align-items: center; gap: 10px; }
button.logout { background: transparent; padding: 6px 4px; }
.login-alt { margin-top: 18px; display: flex; flex-direction: column; align-items: center; gap: 8px; min-height: 60px; }
.passkey-btn { background: var(--accent-soft); color: var(--accent); padding: 14px 22px; border-radius: 16px; }
.sync-note { background: var(--accent-soft); color: var(--accent); border-radius: 14px; padding: 10px 14px; font-size: 0.85rem; font-weight: 600; margin-bottom: 8px; }
.consent-list { list-style: none; padding: 0; margin: 18px 0 4px; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.consent-list li { background: var(--surface); box-shadow: var(--shadow); border-radius: 14px; padding: 12px 16px; font-weight: 600; }
.consent-list li.muted { color: var(--muted); font-weight: 500; box-shadow: none; background: transparent; }
.conn-list .conn { opacity: 1; background: var(--surface); box-shadow: var(--shadow); border-radius: 18px; padding: 12px 16px; margin-bottom: 8px; border-top: 0; }
.conn-list .conn form { margin: 0; }
