/* ============ Nibble Nook — cozy theme ============ */
:root {
  --cream: #FFF4E8;
  --paper: #FFFBF5;
  --cocoa: #5B4636;
  --cocoa-soft: #8C7462;
  --peach: #FFB4A2;
  --peach-deep: #F2877A;
  --butter: #FFE3A3;
  --sage: #B8D4A8;
  --sage-deep: #7FAE6E;
  --lav: #D9C8EE;
  --sky: #BFE0F0;
  --line: #F0E2D2;
  --shadow: 0 6px 0 rgba(91, 70, 54, 0.08), 0 10px 24px rgba(91, 70, 54, 0.08);
  --radius: 22px;
  --tabbar-h: 78px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Nunito", system-ui, sans-serif;
  color: var(--cocoa);
  background:
    radial-gradient(circle at 20% 0%, #FFE9D6 0, transparent 40%),
    radial-gradient(circle at 100% 30%, #F3E7FA 0, transparent 35%),
    var(--cream);
  background-attachment: fixed;
}
h2, h3, .day-label, .ring-num, .level-title, .btn, .fab, .chip { font-family: "Fredoka", "Nunito", sans-serif; }
h2 { margin: 0; font-size: 1.7rem; }
h3 { margin: 0 0 10px; font-size: 1.1rem; }
.muted { color: var(--cocoa-soft); }
.tiny { font-size: 0.78rem; }
.spacer { height: calc(var(--tabbar-h) + 40px); }

#app { max-width: 520px; margin: 0 auto; padding: env(safe-area-inset-top) 16px 0; }
.view { display: none; animation: pop-in .25s ease; }
.view.active { display: block; }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- headers ---------- */
.day-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 0 8px; }
.day-title { text-align: center; }
.day-label { font-size: 1.45rem; font-weight: 600; }
.streak-pill { display: inline-block; margin-top: 4px; padding: 3px 10px; border-radius: 99px; background: var(--butter); font-weight: 800; font-size: .8rem; }
.page-header { padding: 18px 0 10px; }
.icon-btn { width: 42px; height: 42px; border-radius: 50%; border: none; background: var(--paper); color: var(--cocoa); font-size: 1.6rem; box-shadow: var(--shadow); cursor: pointer; }

/* ---------- cards ---------- */
.card { background: var(--paper); border-radius: var(--radius); padding: 16px; margin: 12px 0; box-shadow: var(--shadow); border: 2px solid var(--line); }

.hero { display: flex; align-items: center; gap: 10px; background: linear-gradient(135deg, #FFF8EF, #FFEFE6); }
.mascot-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; }
#mascot { width: 110px; height: 100px; }
#mascot svg { width: 100%; height: 100%; overflow: visible; }
.mascot-bounce { animation: bounce .6s ease; }
@keyframes bounce { 0%,100% { transform: translateY(0) } 30% { transform: translateY(-14px) scale(1.04, .96) } 60% { transform: translateY(0) scale(.96, 1.04) } }
.mascot-idle { animation: breathe 3.2s ease-in-out infinite; transform-origin: 50% 100%; }
@keyframes breathe { 0%,100% { transform: scale(1, 1) } 50% { transform: scale(1.02, .98) } }
.bubble { position: relative; margin-top: 8px; background: white; border: 2px solid var(--line); border-radius: 14px; padding: 6px 10px; font-weight: 700; font-size: .82rem; text-align: center; max-width: 170px; }
.bubble::before { content: ""; position: absolute; top: -8px; left: 50%; transform: translateX(-50%); border: 7px solid transparent; border-bottom-color: var(--line); border-top: 0; }

.ring-wrap { position: relative; width: 140px; height: 140px; }
.ring { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #F6E6D6; stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--peach-deep); stroke-width: 12; stroke-linecap: round; stroke-dasharray: 314.16; stroke-dashoffset: 314.16; transition: stroke-dashoffset .8s cubic-bezier(.3,1.4,.5,1), stroke .3s; }
.ring-text { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.ring-num { font-size: 1.9rem; font-weight: 700; line-height: 1; }
.ring-sub { font-size: .75rem; font-weight: 700; color: var(--cocoa-soft); margin-top: 4px; }

/* ---------- duel ---------- */
.duel-head { display: flex; justify-content: space-between; align-items: center; }
.duel-head h3 { margin: 0; }
.duel-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.duel-label { width: 84px; font-weight: 800; font-size: .9rem; }
.duel-val { width: 52px; text-align: right; font-weight: 800; }
.bar { flex: 1; height: 16px; background: #F6EDE3; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 99px; transition: width .8s cubic-bezier(.3,1.3,.5,1); }
.bar-fill.burn { background: repeating-linear-gradient(45deg, #FFB37A, #FFB37A 8px, #FFC593 8px, #FFC593 16px); }
.bar-fill.eat { background: repeating-linear-gradient(45deg, var(--peach), var(--peach) 8px, #FFC6B8 8px, #FFC6B8 16px); }
.zone { margin-top: 6px; padding: 10px 12px; border-radius: 14px; background: var(--cream); font-weight: 700; font-size: .9rem; }
.zone.good { background: #E7F3DF; }
.zone.over { background: #FFE6E0; }
.zone.under { background: #FFF1CC; }

/* ---------- quests ---------- */
.quests { list-style: none; margin: 0; padding: 0; }
.quests li { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-weight: 700; border-bottom: 1px dashed var(--line); }
.quests li:last-child { border-bottom: none; }
.qbox { width: 26px; height: 26px; border-radius: 9px; border: 2px solid var(--line); display: grid; place-items: center; font-size: .9rem; background: white; flex: none; }
.quests li.done .qbox { background: var(--sage); border-color: var(--sage-deep); animation: pop .4s ease; }
.quests li.done .qtext { text-decoration: line-through; text-decoration-color: var(--sage-deep); color: var(--cocoa-soft); }
.qxp { margin-left: auto; font-size: .75rem; background: var(--lav); padding: 2px 8px; border-radius: 99px; }
@keyframes pop { 50% { transform: scale(1.25) rotate(-6deg); } }

/* ---------- meals ---------- */
.meal-card .meal-head { display: flex; align-items: center; justify-content: space-between; }
.meal-card .meal-head h3 { margin: 0; }
.meal-kcal { font-weight: 800; color: var(--cocoa-soft); }
.entry { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px dashed var(--line); cursor: pointer; }
.entry:last-child { border-bottom: none; }
.entry .emoji { font-size: 1.4rem; width: 34px; height: 34px; display: grid; place-items: center; background: var(--cream); border-radius: 12px; flex: none; }
.entry .name { font-weight: 700; }
.entry .sub { font-size: .78rem; color: var(--cocoa-soft); }
.entry .kcal { margin-left: auto; font-weight: 800; }
.meal-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.empty { color: var(--cocoa-soft); font-size: .9rem; padding: 6px 0; }

/* ---------- buttons & chips ---------- */
.btn { border: none; border-radius: 16px; padding: 14px 18px; font-size: 1.05rem; font-weight: 600; cursor: pointer; background: var(--peach-deep); color: white; box-shadow: 0 4px 0 #D06D60; transition: transform .1s; display: inline-block; text-align: center; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #D06D60; }
.btn.secondary { background: white; color: var(--cocoa); border: 2px solid var(--line); box-shadow: 0 4px 0 var(--line); }
.btn.green { background: var(--sage-deep); box-shadow: 0 4px 0 #618F52; }
.btn.danger { background: #fff; color: #C2473A; border: 2px solid #F3CFC9; box-shadow: 0 4px 0 #F3CFC9; }
.btn.wide { width: 100%; margin-top: 10px; }
.chip { border: 2px solid var(--line); background: white; color: var(--cocoa); border-radius: 99px; padding: 7px 13px; font-size: .92rem; font-weight: 600; cursor: pointer; }
.chip.active { background: var(--butter); border-color: #F2CF7A; }
.chip.small { padding: 5px 11px; font-size: .82rem; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }

/* ---------- tab bar ---------- */
.tabbar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(12px + env(safe-area-inset-bottom)); width: calc(100% - 24px); max-width: 496px; height: 66px; background: var(--paper); border: 2px solid var(--line); border-radius: 26px; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: space-around; z-index: 20; }
.tab { background: none; border: none; color: var(--cocoa-soft); font-family: "Nunito"; font-weight: 800; font-size: .72rem; display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer; padding: 6px; border-radius: 14px; }
.tab span { font-size: 1.35rem; filter: grayscale(.6); transition: transform .2s; }
.tab.active { color: var(--cocoa); }
.tab.active span { filter: none; transform: translateY(-2px) scale(1.12); }
.fab { width: 64px; height: 64px; margin-top: -34px; border-radius: 22px; border: 4px solid var(--cream); background: var(--peach-deep); color: white; font-size: 2.2rem; line-height: 1; box-shadow: 0 6px 0 #D06D60; cursor: pointer; transform: rotate(-4deg); transition: transform .15s; }
.fab:active { transform: rotate(4deg) scale(.94); }

/* ---------- sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(91, 70, 54, .35); opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 30; }
.scrim.open { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 50%; bottom: 0; transform: translate(-50%, 105%); width: 100%; max-width: 520px; max-height: 88vh; overflow-y: auto; background: var(--paper); border-radius: 28px 28px 0 0; padding: 10px 18px calc(24px + env(safe-area-inset-bottom)); transition: transform .32s cubic-bezier(.3,1.2,.5,1); z-index: 31; }
.sheet.open { transform: translate(-50%, 0); }
.sheet-close { position: absolute; right: 14px; top: 12px; width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--line); background: white; color: var(--cocoa-soft); font-size: 1rem; font-weight: 800; cursor: pointer; }
.grabber { width: 44px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font-size: 1.4rem; margin-bottom: 6px; }

.search, .sheet input[type=text], .sheet input[type=number], .form input[type=number] {
  width: 100%; padding: 13px 15px; border-radius: 16px; border: 2px solid var(--line); background: white; font: inherit; font-weight: 700; color: var(--cocoa); outline: none;
}
.search:focus, .sheet input:focus, .form input:focus { border-color: var(--peach); }
.search { margin: 8px 0; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

.action-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.action-tile { background: white; border: 2px solid var(--line); border-radius: 18px; padding: 12px 6px; text-align: center; font-weight: 800; font-size: .82rem; cursor: pointer; box-shadow: 0 4px 0 var(--line); }
.action-tile span { display: block; font-size: 1.6rem; margin-bottom: 2px; }
.action-tile:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); }

.list-label { font-family: "Fredoka"; font-weight: 600; margin: 14px 0 4px; color: var(--cocoa-soft); font-size: .9rem; }
.row { display: flex; align-items: center; gap: 10px; padding: 10px 6px; border-bottom: 1px dashed var(--line); cursor: pointer; border-radius: 12px; }
.row:active { background: var(--cream); }
.row .emoji { font-size: 1.4rem; width: 38px; height: 38px; display: grid; place-items: center; background: var(--cream); border-radius: 13px; flex: none; }
.row .name { font-weight: 800; }
.row .sub { font-size: .78rem; color: var(--cocoa-soft); }
.row .right { margin-left: auto; text-align: right; font-weight: 800; font-size: .85rem; }
.row .quick { background: var(--butter); border: none; border-radius: 12px; padding: 6px 10px; font-weight: 800; font-family: "Nunito"; color: var(--cocoa); cursor: pointer; }

/* portion sheet */
.portion-big { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 10px 0; }
.portion-big input { width: 150px !important; font-size: 2.4rem !important; text-align: center; font-family: "Fredoka" !important; }
.portion-big .unit { font-family: "Fredoka"; font-size: 1.5rem; font-weight: 600; }
.kcal-preview { text-align: center; font-family: "Fredoka"; font-size: 1.3rem; font-weight: 600; margin-bottom: 8px; }
.kcal-preview b { color: var(--peach-deep); font-size: 2rem; }
.form label, .sheet label { display: block; font-weight: 800; margin: 10px 0 4px; font-size: .9rem; }
.form label input[type=number] { margin-top: 6px; }
.toggle { display: flex !important; gap: 10px; align-items: center; }
.toggle input { width: 22px; height: 22px; accent-color: var(--peach-deep); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.emoji-pick { display: flex; gap: 6px; flex-wrap: wrap; }
.emoji-pick button { font-size: 1.3rem; width: 42px; height: 42px; border-radius: 12px; border: 2px solid var(--line); background: white; cursor: pointer; }
.emoji-pick button.active { background: var(--butter); border-color: #F2CF7A; }
.file-btn { display: block; }

/* scanner */
#reader { width: 100%; border-radius: 20px; overflow: hidden; background: #2b211a; min-height: 240px; position: relative; }
#reader video { width: 100% !important; object-fit: cover; }
.scan-frame { position: relative; }
.scan-frame::after { content: ""; position: absolute; left: 12%; right: 12%; top: 50%; height: 3px; background: var(--peach); box-shadow: 0 0 12px var(--peach); animation: scanline 1.6s ease-in-out infinite; border-radius: 3px; pointer-events: none; }
@keyframes scanline { 0%,100% { transform: translateY(-50px) } 50% { transform: translateY(50px) } }

/* ---------- pantry ---------- */
.seg { display: flex; background: #F6EADC; border-radius: 16px; padding: 4px; }
.seg-btn { flex: 1; border: none; background: none; padding: 10px; border-radius: 12px; font-family: "Fredoka"; font-weight: 600; font-size: .95rem; color: var(--cocoa-soft); cursor: pointer; }
.seg-btn.active { background: white; color: var(--cocoa); box-shadow: 0 2px 0 var(--line); }

/* ---------- progress ---------- */
.level-top { display: flex; align-items: center; gap: 14px; }
.level-badge { width: 64px; height: 64px; border-radius: 22px; background: var(--lav); display: grid; place-items: center; font-family: "Fredoka"; font-size: 1.8rem; font-weight: 700; transform: rotate(-5deg); box-shadow: 0 4px 0 #BCA6D8; }
.level-info { flex: 1; }
.level-title { font-size: 1.2rem; font-weight: 600; }
.xpbar { height: 14px; background: #F1E7F8; border-radius: 99px; margin: 6px 0 4px; overflow: hidden; }
.xpfill { height: 100%; background: linear-gradient(90deg, #C9A9EC, #A98BDA); border-radius: 99px; width: 0; transition: width .8s cubic-bezier(.3,1.3,.5,1); }

.week { display: flex; justify-content: space-between; align-items: flex-end; height: 150px; gap: 6px; padding-top: 10px; }
.wday { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.wbars { display: flex; gap: 3px; align-items: flex-end; height: 110px; }
.wbar { width: 11px; border-radius: 6px 6px 3px 3px; min-height: 3px; }
.wbar.burn, .dot.burn { background: #FFB37A; }
.wbar.eat, .dot.eat { background: var(--peach-deep); }
.wlabel { font-size: .72rem; font-weight: 800; color: var(--cocoa-soft); }
.wstar { height: 16px; font-size: .8rem; }
.legend { display: flex; gap: 14px; justify-content: center; font-size: .75rem; font-weight: 700; color: var(--cocoa-soft); margin-top: 8px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 4px; }

.stickers { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.sticker { text-align: center; padding: 12px 4px; border-radius: 18px; background: var(--cream); border: 2px dashed var(--line); }
.sticker .s-emoji { font-size: 2rem; display: block; }
.sticker .s-name { font-size: .74rem; font-weight: 800; margin-top: 4px; }
.sticker.locked .s-emoji { filter: grayscale(1) brightness(1.5) opacity(.45); }
.sticker.locked .s-name { color: var(--cocoa-soft); }
.sticker.got { background: white; border: 2px solid var(--butter); transform: rotate(-2deg); box-shadow: 0 4px 0 var(--butter); }
.sticker.got:nth-child(even) { transform: rotate(2deg); }

/* ---------- toast & confetti ---------- */
.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, -140%); background: var(--cocoa); color: white; padding: 11px 18px; border-radius: 16px; font-weight: 800; z-index: 50; transition: transform .35s cubic-bezier(.3,1.4,.5,1); max-width: 90%; text-align: center; }
.toast.show { transform: translate(-50%, 0); }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 60; width: 100%; height: 100%; }
