*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

    :root {
      --white:   #ffffff;
      --off:     #f0f0ee;
      --off2:    #f7f7f5;
      --border:  #e8e7e4;
      --border2: #dddcda;
      --green:   #22c55e;
      --green-l: #dcfce7;
      --green-m: #16a34a;
      --text:    #0a0a0a;
      --sub:     #0a0a0a;
      --hint:    #0a0a0a;
      --red:     #dc2626;
      --nav-h:   72px;
      --radius:  20px;
    }

    @media (min-width: 500px) {
      body { box-shadow: 0 0 0 1px var(--border); }
      html { background: #e8e8e6; }
    }
    html { height: 100%; }
    body {
      height: 100%;
      height: 100dvh;
      overflow: hidden;
    }

    body {
      font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
      background: linear-gradient(180deg, #eaf0e8 0%, #f5f7f4 40%, #ffffff 100%);
      color: var(--text);
      display: flex;
      flex-direction: column;
      max-width: 430px;
      margin: 0 auto;
    }

    /* ── TOPBAR ── */
    .topbar {
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 14px 20px 10px;
      background: transparent;
      border-bottom: 1px solid var(--border);
    }

    .logo {
      font-family: 'Inter', sans-serif;
      font-size: 1.3rem;
      font-weight: 800;
      color: var(--text);
      letter-spacing: -0.04em;
    }

    .logo span { color: var(--green); }

    .topbar-date {
      font-size: 0.72rem;
      color: var(--text);
      font-weight: 500;
      opacity: 0.5;
    }

    /* ── SCREENS ── */
    .screens { flex: 1; overflow: hidden; position: relative; }

    .screen {
      position: absolute;
      inset: 0;
      overflow-y: auto;
      overflow-x: hidden;
      padding: 20px 16px calc(var(--nav-h) + 16px);
      opacity: 0;
      pointer-events: none;
      transform: translateY(10px);
      transition: opacity 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94), transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
      -webkit-overflow-scrolling: touch;
      touch-action: pan-y;
      background: transparent;
    }

    .screen.active { opacity: 1; pointer-events: all; transform: translateY(0); }
    .screen::-webkit-scrollbar { display: none; }

    /* ── BOTTOM NAV ── */
    .bnav {
      flex-shrink: 0;
      height: var(--nav-h);
      background: transparent;
      border-top: none;
      display: flex;
      align-items: center;
      padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    .nav-item {
      flex: 1;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 3px;
      cursor: pointer;
      padding: 6px 4px;
      border-radius: 14px;
      transition: color 0.2s;
    }

    .nav-icon {
      width: 36px; height: 36px;
      border-radius: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: background 0.2s, height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    }
    .cam-box.expanded { height: 340px; }
    .nav-item.active .nav-icon { background: var(--green-l); }
    .nav-item.active { background: transparent; }

    .nav-svg {
      width: 20px; height: 20px;
      fill: none;
      stroke-width: 1.8;
      stroke-linecap: round;
      stroke-linejoin: round;
      stroke: var(--text);
      transition: stroke 0.2s;
    }

    .nav-item.active .nav-svg { stroke: var(--green); }
    .nav-svg { fill: none; stroke: var(--text); }
    .nav-item[data-screen="meal"] .nav-svg { fill: var(--text); stroke: none; }
    .nav-item[data-screen="meal"].active .nav-svg { fill: var(--green); stroke: none; }

    .nav-fa {
      font-size: 1.1rem;
      color: var(--text);
      transition: color 0.2s;
    }
    .nav-item.active .nav-fa { color: var(--green); }

    .nav-lbl {
      font-size: 0.6rem;
      font-weight: 700;
      color: var(--text);
      letter-spacing: 0.02em;
      transition: color 0.2s;
      opacity: 0.45;
    }

    .nav-item.active .nav-lbl { color: var(--green); opacity: 1; }
    .nav-item.active .nav-fa { color: var(--green); opacity: 1; }

    /* ── SHARED COMPONENTS ── */
    .screen-title {
      font-family: 'Inter', sans-serif;
      font-size: 1.75rem;
      font-weight: 800;
      color: var(--text);
      letter-spacing: -0.04em;
      margin-bottom: 4px;
    }

    .screen-sub {
      font-size: 0.78rem;
      color: var(--text);
      margin-bottom: 20px;
      font-weight: 400;
      opacity: 0.45;
    }

    .section-bg {
      background: var(--white);
      border-radius: var(--radius);
      padding: 18px;
      box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    }

    .section-bg-soft {
      background: var(--off2);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 14px;
    }

    .btn-primary {
      width: 100%;
      background: var(--green);
      box-shadow: 0 4px 20px rgba(34,197,94,0.35);
      color: #fff;
      border: none;
      border-radius: 16px;
      padding: 16px;
      font-family: 'Inter', sans-serif;
      font-size: 0.9rem;
      font-weight: 700;
      cursor: pointer;
      transition: opacity 0.15s, transform 0.15s;
      letter-spacing: -0.01em;
      
    }

    .btn-primary:active { transform: scale(0.98); opacity: 0.9; }
    .btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

    .btn-outline {
      width: 100%;
      background: var(--off);
      color: var(--text);
      border: 1.5px solid var(--border2);
      border-radius: 14px;
      padding: 13px;
      font-family: 'Inter', sans-serif;
      font-size: 0.85rem;
      font-weight: 600;
      cursor: pointer;
      transition: border-color 0.15s;
      text-align: center;
    }

    .btn-outline:active { border-color: var(--green); color: var(--green); }

    /* ══════════════
       SCAN SCREEN
    ══════════════ */

    .cam-box {
      background: #dff0d2;
      border: 1.5px solid #b8dba0;
      
      box-shadow: 0 4px 24px rgba(34,197,94,0.15);
      border-radius: 22px;
      height: 260px;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      position: relative;
      overflow: hidden;
      margin-bottom: 14px;
      cursor: pointer;
      transition: background 0.2s;
    }
    body.dark .cam-box { background: #162810; border-color: #2a4a1c; }
    .cam-box:active { background: #111111; }

    .cam-preview {
      position: absolute;
      inset: 0;
      object-fit: cover;
      width: 100%; height: 100%;
      display: none;
      border-radius: 22px;
    }

    .cam-preview.show { display: block; }

    .cam-overlay {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 10px;
      transition: opacity 0.3s;
    }

    .cam-overlay.hidden { opacity: 0; pointer-events: none; }

    .scan-line {
      position: absolute;
      left: 20px; right: 20px;
      height: 2px;
      background: linear-gradient(90deg, transparent, var(--green), transparent);
      border-radius: 2px;
      top: 20%;
      display: none;
      animation: scanMove 1.8s ease-in-out infinite;
      will-change: top;
    }

    .scan-line.show { display: block; }

    @keyframes scanMove {
      0%   { top: 15%; opacity: 0; }
      10%  { opacity: 1; }
      90%  { opacity: 1; }
      100% { top: 85%; opacity: 0; }
    }

    .corner { position: absolute; width: 22px; height: 22px; }
    .corner.tl { top: 14px; left: 14px; border-top: 2.5px solid var(--green); border-left: 2.5px solid var(--green); border-radius: 5px 0 0 0; }
    .corner.tr { top: 14px; right: 14px; border-top: 2.5px solid var(--green); border-right: 2.5px solid var(--green); border-radius: 0 5px 0 0; }
    .corner.bl { bottom: 14px; left: 14px; border-bottom: 2.5px solid var(--green); border-left: 2.5px solid var(--green); border-radius: 0 0 0 5px; }
    .corner.br { bottom: 14px; right: 14px; border-bottom: 2.5px solid var(--green); border-right: 2.5px solid var(--green); border-radius: 0 0 5px 0; }

    .cam-icon-circle {
      width: 62px; height: 62px;
      
      background: var(--white);
      border-radius: 50%;
      box-shadow: 0 4px 16px rgba(34,197,94,0.2);
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .cam-icon-circle svg { width: 22px; height: 22px; stroke: #0a0a0a; fill: none; stroke-width: 2; stroke-linecap: round; }

    .cam-hint-txt { font-size: 0.78rem; color: var(--green-m); font-weight: 700; letter-spacing: 0.02em; margin-top: 4px; }

    .or-row { display: flex; align-items: center; gap: 10px; margin: 12px 0; }
    .or-line { flex: 1; height: 1px; background: var(--border); }
    .or-txt { font-size: 0.72rem; color: var(--text); opacity: 0.4; }

    .status-bar {
      background: var(--off);
      border-radius: 12px;
      padding: 12px 14px;
      align-items: center;
      gap: 10px;
      display: none;
    }

    .status-bar.show { display: flex; }

    .spinner {
      width: 18px; height: 18px;
      border: 2px solid var(--border2);
      border-top-color: var(--green);
      border-radius: 50%;
      animation: spin 0.7s linear infinite;
      flex-shrink: 0;
    }

    @keyframes spin { to { transform: rotate(360deg); } }

    .status-txt { font-size: 0.8rem; color: var(--text); font-weight: 500; }

    #file-input { display: none; }

    /* ══════════════
       RESULT SCREEN
    ══════════════ */

    .empty-result {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      min-height: 55vh;
      gap: 10px;
      text-align: center;
    }

    .empty-icon {
      width: 64px; height: 64px;
      background: var(--off);
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .empty-icon svg { width: 28px; height: 28px; stroke: var(--text); fill: none; stroke-width: 1.5; stroke-linecap: round; opacity: 0.3; }
    .empty-title { font-size: 0.95rem; font-weight: 700; color: var(--text); }
    .empty-sub { font-size: 0.78rem; color: var(--text); opacity: 0.45; }

    .result-card {
      display: flex;
      flex-direction: column;
      gap: 14px;
      animation: fadeUp 0.4s ease both;
    }

    @keyframes fadeUp {
      from { opacity: 0; transform: translateY(14px); }
      to   { opacity: 1; transform: translateY(0); }
    }

    .food-header {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .food-img-wrap {
      width: 56px; height: 56px;
      background: var(--off);
      border-radius: 16px;
      overflow: hidden;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 2rem;
    }

    .food-img-wrap img { width: 100%; height: 100%; object-fit: cover; }

    .food-name {
      font-family: 'Inter', sans-serif;
      font-size: 1.2rem;
      font-weight: 800;
      color: var(--text);
      letter-spacing: -0.03em;
      text-transform: capitalize;
    }

    .food-kcal {
      font-size: 0.8rem;
      color: var(--green);
      font-weight: 700;
      margin-top: 2px;
    }

    .macro-grid {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 8px;
    }

    .macro-card {
      background: var(--white);
      border-radius: 14px;
      padding: 12px 8px;
      text-align: center;
      border: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    }

    .macro-val {
      font-size: 1.1rem;
      font-weight: 800;
      color: var(--text);
      line-height: 1;
      letter-spacing: -0.02em;
    }

    .macro-lbl {
      font-size: 0.65rem;
      color: var(--text);
      margin-top: 3px;
      font-weight: 600;
      opacity: 0.45;
    }

    .bars-section { display: flex; flex-direction: column; gap: 10px; }
    .bar-item { display: flex; flex-direction: column; gap: 5px; }
    .bar-meta { display: flex; justify-content: space-between; align-items: center; }
    .bar-name { font-size: 0.75rem; color: var(--text); font-weight: 600; }
    .bar-pct  { font-size: 0.75rem; color: var(--green); font-weight: 700; }

    .bar-track {
      height: 8px;
      background: var(--border);
      border-radius: 99px;
      overflow: hidden;
    }

    .bar-fill {
      height: 100%;
      border-radius: 99px;
      background: var(--green);
      width: 0%;
      transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
      will-change: width;
    }

    /* ══════════════
       DIARY SCREEN
    ══════════════ */

    .calorie-ring-card {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 16px;
      padding: 20px 16px;
    }

    .ring-wrap { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
    .ring-wrap svg { position: absolute; top: 0; left: 0; }

    .ring-center {
      position: absolute;
      inset: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
    }

    .ring-pct { font-size: 1rem; font-weight: 800; color: var(--green); line-height: 1; }
    .ring-lbl { font-size: 0.6rem; color: var(--text); margin-top: 1px; font-weight: 600; opacity: 0.45; }

    .ring-info { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 0; margin-top: -10px; }

    .ring-big {
      font-family: 'Inter', sans-serif;
      font-size: 3rem;
      font-weight: 900;
      color: #0a0a0a;
      line-height: 1;
      letter-spacing: -0.04em;
    }

    .ring-big span { font-size: 1.5rem; font-family: 'Inter', sans-serif; font-weight: 700; color: #0a0a0a; opacity: 1; }
    .ring-remaining { font-size: 1rem; color: #0a0a0a; opacity: 0.55; font-weight: 600; }
    .ring-side { display:flex; flex-direction:column; align-items:center; justify-content:center; padding-left:12px; border-left:2px solid var(--border); }
    .ring-side-val { font-size:1.8rem; font-weight:900; color:var(--green); line-height:1; letter-spacing:-0.03em; }
    .ring-side-lbl { font-size:0.65rem; font-weight:600; color:var(--text); opacity:0.45; margin-top:4px; text-transform:uppercase; letter-spacing:0.06em; }
    .meal-section { margin-bottom: 6px; }

    .meal-section-lbl {
      font-size: 0.65rem;
      font-weight: 700;
      color: var(--text);
      text-transform: uppercase;
      letter-spacing: 0.1em;
      margin-bottom: 6px;
      padding-left: 2px;
      opacity: 0.45;
    }

    .meal-item {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: var(--white);
      border: 1px solid var(--border);
      border-radius: 16px;
      padding: 13px 14px;
      margin-bottom: 8px;
      animation: fadeUp 0.3s ease both;
    }

    .meal-left { display: flex; align-items: center; gap: 10px; }
    .meal-dot { width: 8px; height: 8px; background: var(--green-l); border: 2px solid var(--green); border-radius: 50%; flex-shrink: 0; }
    .meal-name { font-size: 0.82rem; font-weight: 600; color: var(--text); text-transform: capitalize; }
    .meal-time { font-size: 0.68rem; color: var(--text); margin-top: 1px; opacity: 0.45; }
    .meal-kcal { font-size: 0.82rem; font-weight: 800; color: var(--text); }

    .meal-delete {
      background: none;
      border: none;
      cursor: pointer;
      color: var(--text);
      font-size: 1rem;
      padding: 0 0 0 8px;
      transition: color 0.15s;
      opacity: 0.3;
    }

    .meal-delete:hover { color: var(--red); opacity: 1; }

    .empty-diary {
      text-align: center;
      padding: 2rem 0;
      color: var(--text);
      font-size: 0.8rem;
      opacity: 0.45;
    }

    .macro-summary {
      display: grid;
      grid-template-columns: 1fr 1fr 1fr;
      gap: 8px;
      margin-bottom: 20px;
    }

    .summary-pill {
      background: var(--white);
      border: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.06);
      border-radius: 14px;
      padding: 12px 8px;
      text-align: center;
    }

    .summary-v { font-size: 1rem; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
    .summary-l { font-size: 0.62rem; color: var(--text); margin-top: 2px; opacity: 0.45; font-weight: 500; }
    .pill-carbs { background: #fef9e7; }
    .pill-carbs .summary-v { color: #e39c28; }
    .pill-protein { background: #eef4ff; }
    .pill-protein .summary-v { color: #2a9bfc; }
    .pill-fat { background: #fff0f0; }
    .pill-fat .summary-v { color: #ef4444; }

    /* ══════════════
       AI SCREEN
    ══════════════ */

    .ai-badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      background: var(--green-l);
      border-radius: 20px;
      padding: 5px 12px;
      margin-bottom: 10px;
    }

    .ai-dot { width: 6px; height: 6px; background: var(--green); border-radius: 50%; }
    .ai-badge-txt { font-size: 0.7rem; color: var(--green-m); font-weight: 700; letter-spacing: 0.04em; }

    .ai-text { font-size: 0.82rem; color: var(--text); line-height: 1.7; }

    .ai-loading { display: flex; align-items: center; gap: 10px; }
    .ai-loading .spinner { width: 14px; height: 14px; }
    .ai-loading span { font-size: 0.78rem; color: var(--text); opacity: 0.45; }

    .device-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      padding: 8px 0;
      border-bottom: 1px solid var(--border);
    }

    .device-row:last-child { border-bottom: none; }
    .device-k { font-size: 0.78rem; color: var(--text); opacity: 0.45; }
    .device-v { font-size: 0.78rem; color: var(--text); font-weight: 700; }

    .sec-lbl {
      font-size: 0.82rem;
      font-weight: 700;
      color: var(--text);
      letter-spacing: -0.01em;
      margin-bottom: 10px;
    }

    .toast {
      position: fixed;
      bottom: calc(var(--nav-h) + 20px);
      left: 50%;
      transform: translateX(-50%) translateY(20px);
      background: #1a1a1a;
      color: #fff;
      font-size: 0.78rem;
      font-weight: 500;
      padding: 11px 20px;
      border-radius: 99px;
      opacity: 0;
      transition: opacity 0.3s, transform 0.3s;
      pointer-events: none;
      white-space: nowrap;
      z-index: 999;
      max-width: 90vw;
    }

    .toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

    .unit-btn {
      padding: 5px 11px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
      border: 1.5px solid var(--border2); background: var(--white); color: var(--text);
      cursor: pointer; transition: background 0.15s, border-color 0.15s, color 0.15s;
    }
    .unit-btn.active { background: var(--green); border-color: var(--green); color: #fff; }
    .unit-btn:active { opacity: 0.8; }

    .health-badge {
      display: inline-flex; align-items: center; gap: 6px;
      border-radius: 20px; padding: 5px 12px; font-size: 0.72rem; font-weight: 700;
      margin-bottom: 6px;
    }
    .health-badge.great  { background: #dcfce7; color: #15803d; }
    .health-badge.good   { background: #fef9e7; color: #b7770d; }
    .health-badge.ok     { background: #fdf2e9; color: #b94a00; }

    .portion-row {
      display: flex; align-items: center; gap: 10px;
      background: var(--off); border-radius: 12px; padding: 10px 14px;
    }
    .portion-lbl { font-size: 0.75rem; color: var(--text); flex: 1; font-weight: 600; }
    .portion-btns { display: flex; align-items: center; gap: 8px; }
    .portion-btn {
      width: 28px; height: 28px; border-radius: 50%;
      border: 1.5px solid var(--border2); background: var(--white);
      font-size: 1rem; cursor: pointer; display: flex; align-items: center; justify-content: center;
      color: var(--text); font-weight: 700; transition: border-color 0.15s;
    }
    .portion-btn:active { border-color: var(--green); color: var(--green); }
    .portion-val { font-size: 0.9rem; font-weight: 700; color: var(--text); min-width: 20px; text-align: center; }

    .extra-macros { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    .extra-pill {
      background: var(--off2); border: 1px solid var(--border);
      border-radius: 12px; padding: 8px 10px;
      display: flex; justify-content: space-between; align-items: center;
    }
    .extra-k { font-size: 0.72rem; color: var(--text); opacity: 0.45; }
    .extra-v { font-size: 0.82rem; font-weight: 700; color: var(--text); }

    .manual-wrap { position: relative; margin-bottom: 10px; }
    .manual-input {
      width: 100%; background: var(--off); border: 1.5px solid var(--border2);
      border-radius: 12px; padding: 11px 14px; color: var(--text);
      font-family: 'Inter', sans-serif; font-size: 0.85rem; outline: none;
      transition: border-color 0.2s; font-weight: 500;
    }
    .manual-input:focus { border-color: var(--green); }
    .manual-input::placeholder { color: #aaa; }

    .week-grid { display: flex; gap: 6px; align-items: stretch; margin-bottom: 14px; }
    .week-day { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
    .week-bar-wrap { width: 100%; height: 56px; display: flex; align-items: flex-end; }
    .week-bar {
      width: 100%; border-radius: 6px 6px 0 0; background: var(--off);
      border: 1px solid var(--border); transition: height 0.6s ease;
      min-height: 4px;
    }
    .week-bar.has-data { background: var(--green-l); border-color: var(--green); }
    .week-bar.today { background: var(--green); border-color: var(--green); }
    .week-lbl { font-size: 0.6rem; color: var(--text); font-weight: 600; opacity: 0.45; }
    .week-kcal { font-size: 0.58rem; color: var(--text); opacity: 0.35; }

    .scan-counter {
      font-size: 0.68rem; color: var(--text); text-align: center;
      margin-top: 8px; opacity: 0.45;
    }
    .scan-counter span { color: var(--green); font-weight: 700; opacity: 1; }

    .compare-goal-wrap { display: flex; flex-direction: column; gap: 7px; }
    .cg-row { display: flex; flex-direction: column; gap: 4px; }
    .cg-meta { display: flex; justify-content: space-between; align-items: center; }
    .cg-name { font-size: 0.72rem; color: var(--text); font-weight: 600; }
    .cg-vals { font-size: 0.7rem; color: var(--text); opacity: 0.45; }
    .cg-vals span { color: var(--green); font-weight: 700; opacity: 1; }
    .cg-track { height: 7px; background: var(--border); border-radius: 99px; overflow: hidden; position: relative; }
    .cg-fill { height: 100%; border-radius: 99px; background: var(--green); transition: width 0.8s cubic-bezier(0.4,0,0.2,1); position: relative; }
    .cg-fill.over { background: var(--red); }
    .cg-fill.warn { background: #e6a817; }
    .cg-remaining { font-size: 0.65rem; color: var(--text); text-align: right; margin-top: 2px; opacity: 0.35; }

    .vit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
    .vit-pill {
      background: var(--off); border: 1px solid var(--border);
      border-radius: 14px; padding: 10px 12px;
      display: flex; flex-direction: column; gap: 4px;
    }
    .vit-name { font-size: 0.65rem; color: var(--text); opacity: 0.45; font-weight: 500; }
    .vit-val { font-size: 0.82rem; font-weight: 700; color: var(--text); }
    .vit-bar-track { height: 5px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 4px; }
    .vit-bar-fill { height: 100%; border-radius: 99px; background: var(--green); transition: width 0.8s ease; }

    .confetti-wrap {
      position: fixed; inset: 0; pointer-events: none; z-index: 9999; overflow: hidden;
    }
    .confetti-piece {
      position: absolute; width: 8px; height: 8px; border-radius: 2px;
      animation: confettiFall linear forwards;
      will-change: transform, opacity;
    }
    @keyframes confettiFall {
      0%   { transform: translateY(-20px) rotate(0deg); opacity: 1; }
      100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
    }

    @keyframes countUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
    .count-anim { animation: countUp 0.4s ease both; }

    .meal-cat-row {
      display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px;
    }
    .cat-btn {
      padding: 5px 12px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
      border: 1.5px solid var(--border2); background: var(--white); color: var(--text);
      cursor: pointer; transition: all 0.15s;
    }
    .cat-btn.active { background: var(--green); border-color: var(--green); color: #fff; }
    .cat-tag {
      font-size: 0.6rem; font-weight: 700; padding: 2px 7px; border-radius: 20px;
      background: var(--green-l); color: var(--green-m); margin-left: 4px;
    }
    .cat-tag.lunch   { background: #fef9e7; color: #b7770d; }
    .cat-tag.dinner  { background: #fdf2e9; color: #b94a00; }
    .cat-tag.snack   { background: #f0eeff; color: #6b52cc; }

    .diary-actions {
      display: flex; gap: 8px; margin-bottom: 10px; align-items: center;
    }
    .diary-search {
      flex: 1; background: var(--off); border: 1px solid var(--border2);
      border-radius: 10px; padding: 8px 12px; font-family: 'Inter', sans-serif;
      font-size: 0.8rem; color: var(--text); outline: none; font-weight: 500;
    }
    .diary-search::placeholder { color: #aaa; }
    .diary-search:focus { border-color: var(--green); }
    .clear-all-btn {
      padding: 8px 12px; border-radius: 10px; border: 1px solid #fcd8d8;
      background: #fff5f5; color: var(--red); font-size: 0.72rem; font-weight: 700;
      cursor: pointer; white-space: nowrap; transition: background 0.15s;
    }
    .clear-all-btn:active { background: #ffe0e0; }

    .modal-backdrop {
      position: fixed; inset: 0; background: rgba(0,0,0,0.4);
      display: flex; align-items: center; justify-content: center;
      z-index: 500; opacity: 0; pointer-events: none; transition: opacity 0.2s;
    }
    .modal-backdrop.show { opacity: 1; pointer-events: all; }
    .modal-box {
      background: var(--white); border-radius: 20px; padding: 24px 20px;
      width: calc(100% - 48px); max-width: 340px;
      transform: scale(0.95); transition: transform 0.2s;
    }
    .modal-backdrop.show .modal-box { transform: scale(1); }
    .modal-title { font-family: 'Inter', sans-serif; font-size: 1.1rem; font-weight: 800; margin-bottom: 8px; letter-spacing: -0.02em; color: var(--text); }
    .modal-sub { font-size: 0.82rem; color: var(--text); opacity: 0.55; margin-bottom: 20px; line-height: 1.5; }
    .modal-btns { display: flex; gap: 10px; }
    .modal-cancel { flex: 1; padding: 11px; border-radius: 12px; border: 1px solid var(--border2); background: var(--off); font-size: 0.85rem; font-weight: 600; cursor: pointer; color: var(--text); }
    .modal-confirm { flex: 1; padding: 11px; border-radius: 12px; border: none; background: var(--red); color: #fff; font-size: 0.85rem; font-weight: 700; cursor: pointer; }

    .diary-section-hdr {
      font-size: 0.65rem; font-weight: 700; color: var(--text);
      text-transform: uppercase; letter-spacing: 0.1em;
      margin: 10px 0 6px; padding-left: 2px; opacity: 0.45;
    }

/* ══════════════════════════════
   DARK MODE
══════════════════════════════ */
body.dark {
  --white:   #0e1012;
  --off:     #181b21;
  --off2:    #141619;
  --border:  #252830;
  --border2: #2e3139;
  --green:   #5fb832;
  --green-l: #162810;
  --green-m: #72cc40;
  --text:    #f0f0f8;
  --sub:     #f0f0f8;
  --hint:    #f0f0f8;
  --red:     #ff5555;
}
body.dark .nav-fa { color: var(--text); }
body.dark { background: linear-gradient(180deg, #111a10 0%, #161b15 40%, #0e1012 100%); }
body.dark .nav-item.active .nav-icon { background: var(--green-l); }
body.dark .cam-box { background: #1a2e14; border-color: #2d4a1e; }
body.dark .cam-icon-circle { background: #242830; border: 1px solid #2e3139; }
body.dark .cam-icon-circle svg { stroke: #f0f0f8; }
body.dark .manual-input::placeholder { color: #444; }
body.dark .diary-search::placeholder { color: #444; }

/* dark mode toggle button */
.dark-toggle {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--off);
  border: 1px solid var(--border2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  transition: background 0.2s;
  color: var(--green);
}
.dark-toggle:active { background: var(--border); }

/* ══════════════════════════════
   FAVORITES
══════════════════════════════ */
.fav-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--off);
  border: 1px solid var(--border2);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  transition: background 0.2s, border-color 0.2s;
  flex-shrink: 0;
  color: var(--text);
}
.fav-btn.saved { background: #fff0f0; border-color: #ffb3b3; color: #e05555; }
.fav-btn:active { transform: scale(0.9); }

.fav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px 14px;
  margin-bottom: 8px;
  animation: fadeUp 0.2s ease both;
}
.fav-info { flex: 1; min-width: 0; }
.fav-name { font-size: 0.82rem; font-weight: 700; color: var(--text); text-transform: capitalize; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fav-meta { font-size: 0.68rem; color: var(--text); margin-top: 2px; opacity: 0.45; }
.fav-kcal { font-size: 0.82rem; font-weight: 800; color: var(--green); flex-shrink: 0; }
.fav-log-btn {
  padding: 5px 10px; border-radius: 8px;
  background: var(--green-l); border: 1px solid var(--green);
  color: var(--green-m); font-size: 0.7rem; font-weight: 700;
  cursor: pointer; transition: background 0.15s; white-space: nowrap;
}
.fav-log-btn:active { background: var(--green); color: #fff; }
.fav-delete {
  background: none; border: none; cursor: pointer;
  color: var(--text); font-size: 0.9rem; padding: 4px;
  transition: color 0.15s; opacity: 0.3;
}
.fav-delete:hover { color: var(--red); opacity: 1; }