:root {
  --red: #e81c2d;
  --red-dark: #c00d1e;
  --yellow: #ffc600;
  --ink: #2a2a2a;
  --paper: #fffaf2;
  --card: #ffffff;
  --line: #f0e6d6;
  --fat: #f2994a;
  --carb: #ffc600;
  --pro: #ffffff;
  --shadow: 0 6px 22px rgba(0, 0, 0, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Arial", "Helvetica Neue", Helvetica, sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

/* ---------- header ---------- */
.topbar {
  background: var(--red);
  color: #fff;
  padding: 22px 20px 26px;
  text-align: center;
  border-bottom: 6px solid var(--yellow);
}
.wordmark { display: inline-flex; flex-direction: column; align-items: center; gap: 6px; }
.brand {
  font-weight: 900; letter-spacing: 3px; font-size: 2.2rem;
  font-style: italic; line-height: 1;
}
.sub {
  font-weight: 800; letter-spacing: 4px; font-size: .8rem;
  color: var(--yellow); text-transform: uppercase;
  border-top: 2px solid rgba(255,255,255,.4); padding-top: 6px;
}
.tagline { margin-top: 6px; font-size: .9rem; opacity: .9; }

/* ---------- layout ---------- */
.layout {
  max-width: 1080px;
  margin: 22px auto;
  padding: 0 16px;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 20px;
  align-items: start;
}
/* ---------- add-item pulse ---------- */
@keyframes pulse {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.06); background: var(--yellow); border-color: var(--yellow); }
  100% { transform: scale(1); }
}
.pulse { animation: pulse .28s ease; }
@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; }
}

/* ---------- mobile cart bar (hidden on desktop) ---------- */
.cart-bar { display: none; }
.sheet-close { display: none; }
.cart-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 55;
}
.cart-backdrop[hidden] { display: none; }

.panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.nutrition-panel { position: sticky; top: 16px; }

.panel-title {
  font-size: .8rem; text-transform: uppercase; letter-spacing: 1px;
  color: var(--red); font-weight: 800;
  margin: 18px 0 10px;
}
.panel-title:first-child { margin-top: 0; }

/* ---------- presets ---------- */
.presets { display: flex; flex-wrap: wrap; gap: 8px; }
.preset {
  border: 2px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: .85rem; font-weight: 700;
  cursor: pointer;
  transition: all .12s ease;
}
.preset:hover { border-color: var(--yellow); }
.preset.active {
  background: var(--red); color: #fff; border-color: var(--red);
}

/* ---------- quick toggles ---------- */
.quick-toggles { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.chip-toggle {
  border: 2px solid var(--line);
  background: #fff; border-radius: 999px;
  padding: 8px 14px; font-size: .85rem; font-weight: 700;
  cursor: pointer; transition: all .12s ease;
}
.chip-toggle.on { background: var(--yellow); border-color: var(--yellow); }

/* ---------- builder rows ---------- */
.builder { display: flex; flex-direction: column; gap: 6px; }
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-radius: 12px; background: #fcfaf6;
  border: 1px solid var(--line);
}
.row .info { display: flex; flex-direction: column; }
.row .name { font-weight: 700; font-size: .92rem; }
.row .meta { font-size: .72rem; color: #8a8378; }

.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button {
  width: 30px; height: 30px; border-radius: 8px; border: none;
  background: var(--red); color: #fff; font-size: 1.1rem; font-weight: 800;
  cursor: pointer; line-height: 1;
}
.stepper button:hover { background: var(--red-dark); }
.stepper button.minus { background: #e7ddd0; color: var(--ink); }
.stepper .count { min-width: 18px; text-align: center; font-weight: 800; }

.toggle {
  position: relative; width: 46px; height: 26px; border-radius: 999px;
  background: #ddd2c2; border: none; cursor: pointer; transition: background .15s;
}
.toggle.on { background: var(--red); }
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 20px; height: 20px; border-radius: 50%; background: #fff;
  transition: transform .15s;
}
.toggle.on::after { transform: translateX(20px); }

/* ---------- extras ---------- */
.extras { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.extra {
  display: flex; align-items: center; justify-content: space-between;
  border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px;
  background: #fcfaf6; color: var(--ink); font-size: .85rem; font-weight: 700; cursor: pointer;
}
.extra.on { background: var(--yellow); border-color: var(--yellow); }
.extra .ecal { font-size: .72rem; color: #8a8378; font-weight: 600; }
.extra.on .ecal { color: var(--ink); }

/* ---------- nutrition card ---------- */
.nutri-card {
  background: var(--red);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}
.cal-number { font-size: 2.6rem; font-weight: 900; line-height: 1; }
.cal-label { text-transform: uppercase; letter-spacing: 2px; font-size: .65rem; color: var(--yellow); }

.ring-wrap { display: flex; flex-direction: column; align-items: center; gap: 14px; margin: 4px 0 12px; }
.macro-ring {
  width: 150px; height: 150px; border-radius: 50%;
  background: conic-gradient(var(--fat) 0 33%, var(--carb) 0 66%, var(--pro) 0 100%);
  position: relative; flex-shrink: 0;
}
/* empty state: flat muted ring (A) */
.macro-ring.empty { background: rgba(255, 255, 255, 0.22); }
.ring-center {
  position: absolute; inset: 16px; border-radius: 50%; background: var(--red);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.macro-legend { list-style: none; display: flex; gap: 16px; font-size: .82rem; }
.macro-legend li { display: flex; align-items: center; gap: 6px; }
.macro-legend b { margin-left: 4px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-fat { background: var(--fat); }
.dot-carb { background: var(--carb); }
.dot-pro { background: #fff; border: 2px solid #fff; }

.sodium-row {
  display: flex; justify-content: space-between;
  border-top: 1px solid rgba(255,255,255,.3);
  margin-top: 12px; padding-top: 10px; font-size: .9rem;
}

/* ---------- order list ---------- */
.break-title {
  font-size: .8rem; text-transform: uppercase; letter-spacing: 1px;
  color: var(--red); margin: 18px 0 8px;
}
.order-list { list-style: none; }
.order-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 0; border-bottom: 1px dashed var(--line);
  font-size: .88rem;
}
.oi-name { flex: 1; font-weight: 700; }
.oi-cal { color: #8a8378; font-weight: 600; }
.oi-edit {
  border: 2px solid var(--line); background: #fff; color: var(--red);
  border-radius: 8px; padding: 4px 10px; font-size: .78rem; font-weight: 800;
  cursor: pointer;
}
.oi-edit:hover { border-color: var(--red); }
.oi-x {
  width: 24px; height: 24px; border-radius: 6px; border: none;
  background: #f0e6d6; color: var(--red); font-size: 1.1rem; font-weight: 800;
  cursor: pointer; line-height: 1;
}
.oi-x:hover { background: var(--red); color: #fff; }
.order-list .empty { color: #b3a892; font-style: italic; border: none; }

/* ---------- modal ---------- */
.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-card {
  position: relative; background: var(--card); border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0,0,0,.3);
  width: 100%; max-width: 460px; max-height: 88vh; overflow: auto;
  padding: 18px 18px 0;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { color: var(--red); font-size: 1.1rem; }
.modal-x {
  width: 30px; height: 30px; border-radius: 8px; border: none;
  background: #f0e6d6; color: var(--red); font-size: 1.3rem; font-weight: 800; cursor: pointer; line-height: 1;
}
.modal-x:hover { background: var(--red); color: #fff; }
.seg-group { margin-bottom: 12px; }
.seg-group:empty { display: none; }
.seg-label {
  display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: 1px;
  color: #8a8378; font-weight: 800; margin-bottom: 6px;
}
.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.seg {
  border: 2px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: .8rem; font-weight: 700; cursor: pointer;
}
.seg:hover { border-color: var(--yellow); }
.seg.on { background: var(--red); color: #fff; border-color: var(--red); }

.modal-foot {
  position: sticky; bottom: 0; background: var(--card);
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; margin-top: 6px; border-top: 1px solid var(--line);
}
.modal-cal { font-weight: 800; color: var(--ink); }
.done-btn {
  border: none; border-radius: 12px; background: var(--red); color: #fff;
  padding: 10px 24px; font-weight: 800; cursor: pointer;
}
.done-btn:hover { background: var(--red-dark); }
.reset-btn {
  margin-top: 14px; width: 100%; padding: 10px;
  border: 2px solid var(--red); background: #fff; color: var(--red);
  border-radius: 12px; font-weight: 800; cursor: pointer;
}
.reset-btn:hover { background: var(--red); color: #fff; }

.foot {
  text-align: center; font-size: .72rem; color: #9a9182;
  padding: 24px 16px 40px;
}

/* ============ MOBILE ============ */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; padding-bottom: 84px; }
  .foot { padding-bottom: 96px; }

  /* nutrition panel becomes a slide-up sheet */
  .nutrition-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    max-height: 85vh; overflow-y: auto;
    border-radius: 20px 20px 0 0;
    transform: translateY(110%);
    transition: transform .25s ease;
    z-index: 60;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .nutrition-panel.open { transform: translateY(0); }

  /* fixed summary bar */
  .cart-bar {
    display: flex; align-items: center; gap: 8px;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: var(--red); color: #fff;
    padding: 14px 18px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
    font-weight: 800; font-size: 1rem; cursor: pointer;
    border-top: 3px solid var(--yellow);
    box-shadow: 0 -4px 18px rgba(0,0,0,.15);
  }
  .cart-bar .bar-emoji { font-size: 1.2rem; }
  .cart-bar #barCal { color: var(--yellow); }
  .cart-bar .bar-caret { margin-left: auto; transition: transform .2s; }
  .cart-bar.open .bar-caret { transform: rotate(180deg); }

  /* sheet close row */
  .sheet-close {
    display: flex; width: 100%; justify-content: flex-end; margin-bottom: 4px;
  }
  .sheet-close button {
    border: none; background: #f0e6d6; color: var(--red);
    width: 34px; height: 34px; border-radius: 10px;
    font-size: 1.3rem; font-weight: 800; cursor: pointer; line-height: 1;
  }

  /* bigger tap targets */
  .stepper button { width: 40px; height: 40px; font-size: 1.25rem; }
  .seg { min-height: 40px; }
  .preset, .extra { min-height: 44px; }

  /* edit modal as bottom sheet */
  .modal { align-items: flex-end; padding: 0; }
  .modal-card {
    max-width: none; max-height: 90vh;
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
    animation: sheetUp .25s ease;
  }
  @keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
}

@media (max-width: 820px) and (prefers-reduced-motion: reduce) {
  .nutrition-panel { transition: none; }
  .modal-card { animation: none; }
}

@media (max-width: 480px) {
  .topbar { padding: 16px 16px 18px; }
  .brand { font-size: 1.6rem; }
  .extras { grid-template-columns: 1fr; }
  .cal-number { font-size: 2.3rem; }
}
