:root {
  --pink: #ff7aa2;
  --pink-dark: #ff4f80;
  --blue: #5ec8ff;
  --blue-dark: #2aa8ec;
  --yellow: #ffd75e;
  --green: #6bd06b;
  --green-dark: #45b845;
  --purple: #b98cff;
  --ink: #40324a;
  --paper: #fff7fb;
  --card: #ffffff;
  --shadow: 0 6px 0 rgba(0,0,0,.10), 0 12px 24px rgba(0,0,0,.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 10% -10%, #ffe1ec, transparent),
              radial-gradient(1200px 600px at 110% 0%, #d9f3ff, transparent),
              var(--paper);
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  overflow: hidden;
}
h2, h3 { margin: 0 0 .4em; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 14px 22px; flex-wrap: wrap;
}
.logo { font-size: 30px; font-weight: 800; }
.logo span { color: var(--pink-dark); }
.tabs { display: flex; gap: 10px; background: #ffffffaa; padding: 6px; border-radius: 999px; box-shadow: var(--shadow); }
.tab {
  border: none; font: inherit; font-weight: 800; font-size: 20px;
  padding: 12px 24px; border-radius: 999px; background: transparent; color: var(--ink);
  cursor: pointer; transition: transform .08s;
}
.tab:active { transform: scale(.94); }
.tab.is-active { background: var(--pink); color: #fff; box-shadow: 0 4px 0 var(--pink-dark); }
.scan-hint {
  margin-left: auto; font-weight: 800; font-size: 18px; color: #fff;
  background: var(--blue); padding: 10px 20px; border-radius: 999px;
  box-shadow: 0 4px 0 var(--blue-dark); animation: bob 1.6s ease-in-out infinite;
}
@keyframes bob { 50% { transform: translateY(-4px); } }

.screen { flex: 1; padding: 0 22px 22px; overflow: hidden; }
.hidden { display: none !important; }

/* ---------- Checkout ---------- */
#checkoutScreen { display: flex; gap: 22px; }
.cart-panel {
  flex: 1; background: var(--card); border-radius: 28px; padding: 20px 24px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden;
}
.cart-panel h2 { font-size: 26px; }
.cart-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.cart-row {
  display: flex; align-items: center; gap: 16px; padding: 14px 8px;
  border-bottom: 3px dashed #ffe0ea; animation: pop .25s ease;
}
.cart-row .pic { font-size: 40px; width: 56px; text-align: center; }
.cart-row .pic img { width: 52px; height: 52px; object-fit: contain; border-radius: 12px; }
.cart-row .name { flex: 1; font-weight: 800; font-size: 22px; }
.cart-row .qty { font-weight: 800; font-size: 20px; color: var(--blue-dark); background: #e9f7ff; padding: 4px 14px; border-radius: 999px; }
.cart-row .line { font-weight: 800; font-size: 22px; min-width: 92px; text-align: right; }
.cart-row .rm { border: none; background: #ffe0ea; color: var(--pink-dark); font-size: 22px; font-weight: 800; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; }
.cart-row .rm:active { transform: scale(.9); }
.cart-empty, .inv-empty { margin: auto; text-align: center; color: #b9a9c2; font-size: 22px; font-weight: 700; }
.big-emoji { font-size: 90px; }

.total-panel {
  width: 300px; background: linear-gradient(160deg, var(--yellow), #ffca4d);
  border-radius: 28px; padding: 26px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.total-label { font-size: 26px; font-weight: 800; color: #8a6b12; }
.total-amount { font-size: 72px; font-weight: 900; color: #5b4708; margin: 6px 0 22px; line-height: 1; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 800; border: none; border-radius: 999px;
  padding: 16px 26px; font-size: 22px; cursor: pointer; transition: transform .08s;
  width: 100%; margin-top: 12px;
}
.btn:active:not(:disabled) { transform: translateY(3px); }
.btn:disabled { opacity: .45; }
.btn-pay { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-dark); font-size: 28px; }
.btn-ghost { background: #ffffffcc; color: var(--ink); box-shadow: 0 4px 0 #d9c9e0; }
.btn-add { width: auto; background: var(--blue); color: #fff; box-shadow: 0 4px 0 var(--blue-dark); margin: 0; }
.btn-save { background: var(--green); color: #fff; box-shadow: 0 5px 0 var(--green-dark); width: auto; }
.btn-danger { background: #ff6b6b; color: #fff; box-shadow: 0 5px 0 #e04b4b; width: auto; }

/* ---------- Inventory ---------- */
.inv-toolbar { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 16px; }
.inv-toolbar h2 { font-size: 26px; margin: 0; }
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 18px; overflow-y: auto; max-height: calc(100vh - 150px); padding: 4px 4px 24px; }
.inv-card {
  background: var(--card); border-radius: 24px; padding: 16px; box-shadow: var(--shadow);
  text-align: center; position: relative; animation: pop .25s ease; cursor: pointer;
}
.inv-card.flash { animation: flash .6s ease; }
.inv-card .pic { font-size: 64px; height: 84px; display: flex; align-items: center; justify-content: center; }
.inv-card .pic img { max-width: 84px; max-height: 84px; object-fit: contain; }
.inv-card .name { font-weight: 800; font-size: 20px; margin: 6px 0 2px; }
.inv-card .price { color: var(--green-dark); font-weight: 800; font-size: 20px; }
.inv-card .desc { font-size: 13px; font-weight: 600; color: #a495b0; margin-top: 4px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.inv-card .count { position: absolute; top: -10px; right: -8px; background: var(--pink); color: #fff; font-weight: 900; font-size: 20px; min-width: 40px; height: 40px; border-radius: 999px; display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 0 var(--pink-dark); padding: 0 8px; }
.inv-card .count.zero { background: #c7b9d0; box-shadow: 0 3px 0 #a897b5; }

/* ---------- Modals ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(64,50,74,.45); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; z-index: 50; animation: fade .2s ease; }
.modal { background: var(--paper); border-radius: 30px; padding: 26px 30px; width: min(520px, 92vw); box-shadow: var(--shadow); animation: pop .25s ease; }
.modal h3 { font-size: 28px; text-align: center; }
.modal-pic { font-size: 70px; text-align: center; height: 84px; }
.modal-pic img { max-height: 84px; max-width: 120px; object-fit: contain; }
.modal label { display: block; font-weight: 800; font-size: 18px; margin-top: 14px; }
.modal input[type=text], .modal input[type=number], .modal textarea {
  width: 100%; margin-top: 6px; font: inherit; font-size: 22px; font-weight: 700;
  padding: 12px 16px; border: 3px solid #ffd0de; border-radius: 16px; background: #fff; color: var(--ink);
}
.modal textarea { font-size: 18px; font-weight: 600; resize: none; }
.modal input:focus, .modal textarea:focus { outline: none; border-color: var(--pink); }
.row { display: flex; gap: 14px; }
.row label { flex: 1; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.emoji-pick button { font-size: 28px; width: 48px; height: 48px; border-radius: 14px; border: 3px solid transparent; background: #fff; cursor: pointer; }
.emoji-pick button.sel { border-color: var(--pink); background: #ffe6ee; }
.lookup-note { text-align: center; font-weight: 700; color: var(--blue-dark); min-height: 22px; margin-top: 10px; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; align-items: center; }
.modal-actions .btn-ghost { width: auto; }

.modal-msg { text-align: center; }
.msg-emoji { font-size: 80px; }
.modal-msg p { font-size: 22px; font-weight: 700; white-space: pre-line; }
.modal-msg .btn { width: auto; margin: 10px auto 0; padding: 14px 40px; }

/* ---------- Pay ---------- */
.modal-pay { text-align: center; }
.pay-total { font-size: 60px; font-weight: 900; color: var(--green-dark); }
.pay-sub { font-weight: 700; font-size: 18px; }
.cash-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 12px 0; }
.cash-row button { font: inherit; font-weight: 800; font-size: 22px; padding: 14px 20px; border: none; border-radius: 16px; background: #d6f5d6; color: var(--green-dark); cursor: pointer; box-shadow: 0 4px 0 #b3e6b3; }
.cash-row button:active { transform: translateY(3px); }
.cash-row button.sel { background: var(--green); color: #fff; }
.change-box { font-size: 24px; font-weight: 800; margin: 8px 0; }
.change-box strong { color: var(--pink-dark); font-size: 34px; display: block; }

/* ---------- Toast + confetti ---------- */
.toast { position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; font-weight: 800; font-size: 22px; padding: 14px 28px; border-radius: 999px; z-index: 60; animation: pop .25s ease; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 80; overflow: hidden; }
.confetti-bit { position: absolute; top: -20px; font-size: 26px; animation: fall linear forwards; }

@keyframes pop { from { transform: scale(.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { from { opacity: 0; } }
@keyframes flash { 0%,100% { transform: scale(1); } 40% { transform: scale(1.12); box-shadow: 0 0 0 6px var(--yellow); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: 1; } }

@media (max-width: 820px) {
  #checkoutScreen { flex-direction: column; }
  .total-panel { width: 100%; }
  .scan-hint { margin-left: 0; }
}
