:root {
  --green: #3B6D11; --green-soft: #EAF3DE; --green-line: #639922;
  --ink: #1d1d1b; --muted: #6b6b66; --bg: #f7f7f2; --card: #ffffff; --line: #e3e3da;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* l'attributo hidden vince sempre (es. #pin-screen{display:flex}) */
body {
  margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
.screen { min-height: 100dvh; padding: env(safe-area-inset-top) 16px 16px; }

/* PIN */
#pin-screen { display: flex; align-items: center; justify-content: center; }
.pin-card { width: 100%; max-width: 320px; background: var(--card);
  border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; text-align: center; }
.brand { color: var(--green); font-size: 26px; margin: 0 0 6px; }
.pin-sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }
.pin-input { width: 100%; font-size: 24px; text-align: center; letter-spacing: 6px;
  padding: 12px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; }
.btn-primary { width: 100%; background: var(--green); color: #fff; border: 0;
  font-size: 16px; font-weight: 600; padding: 12px; border-radius: 12px; cursor: pointer; }
.btn-primary:active { transform: scale(0.98); }
.pin-error { color: #b3261e; font-size: 13px; margin: 12px 0 0; }

/* Today */
.topbar { display: flex; align-items: center; padding: 6px 2px 12px; }
.brand-sm { color: var(--green); font-weight: 600; font-size: 16px; }
.today-title { font-size: 18px; margin: 4px 2px 14px; text-transform: capitalize; }
.meal { background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 12px; }
.meal h3 { margin: 0 0 8px; font-size: 14px; color: var(--green); text-transform: uppercase; letter-spacing: .5px; }
.meal ul { margin: 0; padding-left: 18px; }
.meal li { font-size: 14px; line-height: 1.7; }
.meal li .qty { color: var(--muted); }
.meal-note { font-size: 12px; color: var(--muted); font-style: italic; margin: 0 0 8px; }

/* ---------- M3: Oggi gamificata ---------- */
#app-screen { padding-bottom: 80px; }
.topbar { justify-content: space-between; }
.stats { display: flex; gap: 8px; }
.stat { font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); }
.stat.flame { color: #854F0B; }
.stat.xp { color: #534AB7; }
.grade { font-size: 12px; color: var(--muted); margin: 0 2px 12px; }
.day-progress { display: flex; align-items: center; gap: 8px; margin: 0 2px 14px; }
.day-progress .bar { flex: 1; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.day-progress .fill { height: 100%; background: var(--green-line); border-radius: 4px; transition: width .35s ease; }
.day-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.meal.done { background: var(--green-soft); border-color: var(--green-line); }
.meal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.meal-head h3 { margin: 0; }
.meal-count { font-size: 11px; color: var(--muted); font-weight: 600; }
.meal.done .meal-count { color: #27500A; }
.meal ul { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; }
.item .tick { width: 24px; height: 24px; flex: 0 0 24px; border-radius: 50%; border: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 14px; transition: background .15s, border-color .15s; }
.item.checked .tick { background: var(--green-line); border-color: var(--green-line); }
.item .lbl { font-size: 14px; line-height: 1.4; }
.item.checked .lbl { color: var(--muted); text-decoration: line-through; }
.item .qty { color: var(--muted); }
.segna-tutto { margin-top: 8px; background: transparent; color: var(--green); border: 1px solid var(--green-line);
  font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 10px; cursor: pointer; }
.segna-tutto:active { transform: scale(.98); }
.placeholder { text-align: center; color: var(--muted); padding: 64px 20px; }
.ph-emoji { font-size: 40px; margin-bottom: 10px; }
.bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding: 6px 0 calc(6px + env(safe-area-inset-bottom)); }
.nav-btn { flex: 1; background: none; border: 0; color: var(--muted); font-size: 11px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 4px 0; }
.nav-btn .nav-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .4; }
.nav-btn.active { color: var(--green); font-weight: 600; }
.nav-btn.active .nav-dot { opacity: 1; }
.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(10px);
  background: #27500A; color: #fff; font-size: 14px; font-weight: 600; padding: 10px 16px; border-radius: 12px;
  opacity: 0; transition: opacity .3s, transform .3s; z-index: 50; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 88%; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.confetti i { position: absolute; top: -12px; width: 9px; height: 9px; border-radius: 2px; animation: cq-fall 2s linear forwards; }
@keyframes cq-fall { to { transform: translateY(105vh) rotate(420deg); opacity: .9; } }

/* ---------- M4: Percorso ---------- */
.path-intro { font-size: 13px; color: var(--muted); margin: 0 2px 14px; }
.path-intro b { color: var(--ink); }
.level-map { display: flex; flex-direction: column; gap: 12px; }
.level { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.level.current { border-color: var(--green-line); box-shadow: 0 0 0 2px var(--green-soft); }
.level.locked { opacity: .62; }
.level-head { display: flex; align-items: center; gap: 10px; }
.level-badge { width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 14px; background: var(--bg); border: 1px solid var(--line); }
.level.done .level-badge { background: var(--green-line); border-color: var(--green-line); color: #fff; }
.level.current .level-badge { background: var(--green); border-color: var(--green); color: #fff; }
.level-headtext { flex: 1; min-width: 0; }
.level-no { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.level-title { margin: 1px 0 0; font-size: 15px; }
.level-state { font-size: 11px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.level.current .level-state { color: var(--green); }
.level.done .level-state { color: #27500A; }
.level-desc { font-size: 13px; color: var(--ink); margin: 10px 0 0; line-height: 1.45; }
.level-desc.locked-hint { color: var(--muted); font-style: italic; }
.level-skills { margin: 8px 0 0; padding-left: 18px; }
.level-skills li { font-size: 12.5px; color: var(--muted); line-height: 1.6; }

.sub-h { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--green);
  margin: 14px 0 8px; }
.challenge { margin-bottom: 10px; }
.challenge-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.challenge-label { font-size: 13px; }
.challenge.done .challenge-label { color: #27500A; font-weight: 600; }
.challenge-num { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.cbar { height: 7px; background: var(--line); border-radius: 4px; overflow: hidden; }
.cfill { height: 100%; background: var(--green-line); border-radius: 4px; transition: width .35s ease; }
.challenge.done .cfill { background: var(--green); }

.declare-count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px;
  background: var(--green-soft); color: var(--green); font-size: 12px; text-align: center; }
.declare-hint { font-size: 12px; color: var(--muted); margin: 0 0 8px; }
.declare-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.declare-chip { background: var(--green-soft); color: var(--green); border: 1px solid var(--green-line);
  font-size: 12.5px; padding: 7px 11px; border-radius: 999px; cursor: pointer; }
.declare-chip:active { transform: scale(.97); }
.declare-undo { margin-top: 10px; background: transparent; color: var(--muted); border: 1px solid var(--line);
  font-size: 12.5px; padding: 6px 11px; border-radius: 10px; cursor: pointer; }

/* Festa di level-up */
.levelup-overlay { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: rgba(20,20,16,.5); opacity: 0; transition: opacity .25s; }
.levelup-overlay.show { opacity: 1; }
.levelup-card { width: 100%; max-width: 320px; background: var(--card); border-radius: 20px; padding: 26px 22px;
  text-align: center; transform: scale(.9); transition: transform .25s; }
.levelup-overlay.show .levelup-card { transform: scale(1); }
.levelup-emoji { font-size: 46px; }
.levelup-h { color: var(--green); margin: 6px 0 2px; font-size: 24px; }
.levelup-title { font-size: 16px; font-weight: 600; margin: 0 0 10px; }
.levelup-xp { display: inline-block; background: var(--green-soft); color: var(--green); font-weight: 700;
  padding: 4px 12px; border-radius: 999px; margin: 0 0 12px; }
.levelup-hint { font-size: 13px; color: var(--muted); line-height: 1.5; margin: 0 0 18px; }

/* ---------- M5: Combo ---------- */
.combo-cat { margin-bottom: 18px; }
.combo-cathead { display: flex; justify-content: space-between; align-items: baseline; margin: 0 2px 8px; }
.combo-cathead h3 { font-size: 14px; color: var(--green); margin: 0; }
.cat-badge { font-size: 14px; }
.combo-count { font-size: 12px; color: var(--muted); font-weight: 600; }
.combo-cards { display: flex; flex-direction: column; gap: 8px; }
.combo-card { display: flex; justify-content: space-between; align-items: center; gap: 10px; text-align: left; width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; cursor: pointer; }
.combo-card:active { transform: scale(.99); }
.combo-card.got { background: var(--green-soft); border-color: var(--green-line); }
.combo-text { font-size: 13.5px; line-height: 1.35; }
.combo-tick { flex: 0 0 auto; font-size: 12px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.combo-card.got .combo-tick { color: #27500A; }

/* ---------- M5: Spesa ---------- */
.shop-cat { margin-bottom: 14px; }
.shop-cat ul { list-style: none; margin: 0; padding: 0; }
.shop-item { display: flex; align-items: center; gap: 10px; padding: 7px 2px; cursor: pointer; }
.shop-item .tick { width: 22px; height: 22px; flex: 0 0 22px; border-radius: 6px; border: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; }
.shop-item.checked .tick { background: var(--green-line); border-color: var(--green-line); }
.shop-item .lbl { font-size: 14px; }
.shop-item.checked .lbl { color: var(--muted); text-decoration: line-through; }
.shop-item .qty { color: var(--muted); font-size: 13px; }

/* ---------- M6: Profilo ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: flex; flex-direction: column; gap: 2px; }
.stat-val { font-size: 18px; font-weight: 700; color: var(--ink); }
.stat-key { font-size: 11.5px; color: var(--muted); }

.grade-prog { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 6px; }
.grade-prog-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--green); font-weight: 600; margin-bottom: 6px; }
.grade-prog-num { font-size: 11.5px; color: var(--muted); display: block; margin-top: 5px; }

.badge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  display: flex; flex-direction: column; gap: 3px; }
.badge.locked { opacity: .5; }
.badge.got { background: var(--green-soft); border-color: var(--green-line); }
.badge-ico { font-size: 20px; }
.badge-name { font-size: 12.5px; font-weight: 600; }
.badge-desc { font-size: 11px; color: var(--muted); line-height: 1.35; }

.profile-actions { display: flex; gap: 8px; }
.btn-secondary { flex: 1; background: var(--green-soft); color: var(--green); border: 1px solid var(--green-line);
  font-size: 13px; font-weight: 600; padding: 10px; border-radius: 12px; cursor: pointer; }
.btn-secondary:active { transform: scale(.98); }

/* ---------- M7: feel ---------- */
.motivation { font-size: 13px; color: var(--green); background: var(--green-soft);
  border-radius: 10px; padding: 8px 12px; margin: 0 0 14px; }
#app-screen { animation: cq-fade .22s ease; }
@keyframes cq-fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.item .tick, .shop-item .tick { transition: background .15s, border-color .15s, transform .12s; }
.item.checked .tick, .shop-item.checked .tick { animation: cq-pop .2s ease; }
@keyframes cq-pop { 0% { transform: scale(.6); } 60% { transform: scale(1.15); } 100% { transform: scale(1); } }

.cq-banner { position: fixed; left: 50%; bottom: calc(74px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: calc(100% - 24px); max-width: 420px; display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--green-line); border-radius: 14px; padding: 10px 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18); z-index: 55; animation: cq-fade .25s ease; }
.cq-banner span { flex: 1; font-size: 13px; }
.cq-banner .btn-secondary { flex: 0 0 auto; width: auto; padding: 8px 12px; }
.banner-x { flex: 0 0 auto; background: none; border: 0; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px; }
