:root {
  --claret: #7b1e3a;
  --claret-dark: #5a1229;
  --cream: #f7efe4;
  --latte: #ead6bd;
  --coffee: #3b2416;
  --gold: #e8ad3f;
  --ink: #2b1a14;
  --muted: #8b7466;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; overscroll-behavior: none; background: var(--claret-dark); }
body {
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
svg { display: block; }

#app { position: relative; max-width: 480px; height: 100vh; height: 100dvh; margin: 0 auto; overflow: hidden; background: var(--cream); }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; }
.screen[hidden], [hidden] { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  border: 0; border-radius: 16px; padding: 13px 20px; font-weight: 800; font-size: 17px;
  box-shadow: 0 4px 0 rgba(0,0,0,.25); transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.25); }
.btn-cream { background: var(--cream); color: var(--claret); }
.btn-claret { background: var(--claret); color: var(--cream); }
.btn-soft { background: #fff; color: var(--coffee); }
.btn-outline { background: transparent; color: var(--cream); box-shadow: inset 0 0 0 2px rgba(247,239,228,.6); }
.icon-btn { border: 0; background: rgba(255,255,255,.14); color: #fff; width: 34px; height: 34px; border-radius: 50%; font-size: 17px; display: grid; place-items: center; }
.icon-btn.dark { background: var(--latte); color: var(--ink); }

/* ---------- Title ---------- */
.screen-title {
  background: radial-gradient(120% 80% at 50% 20%, #9a2a4b 0%, var(--claret) 45%, var(--claret-dark) 100%);
  color: var(--cream); align-items: center; text-align: center;
  padding: calc(var(--safe-t) + 8px) 20px calc(var(--safe-b) + 20px);
  overflow-y: auto;
}
.bunting { width: 100%; height: 34px; flex: none; }
.bunting svg { width: 100%; height: 100%; }
.title-art { width: min(62vw, 270px); aspect-ratio: 200 / 220; margin-top: 4px; flex: none; filter: drop-shadow(0 10px 18px rgba(0,0,0,.3)); animation: bob 3.2s ease-in-out infinite; }
.logo { font-family: Georgia, "Times New Roman", serif; font-style: italic; font-size: 54px; line-height: .95; letter-spacing: -1px; margin-top: 6px; text-shadow: 0 3px 0 rgba(0,0,0,.2); }
.logo-small { display: block; font-size: 26px; font-weight: 400; letter-spacing: 1px; color: var(--gold); }
.tagline { margin-top: 6px; opacity: .85; font-size: 15px; }
.title-stats { margin-top: 10px; font-size: 14px; opacity: .8; min-height: 1.2em; }
.title-buttons { display: flex; flex-direction: column; gap: 12px; width: min(100%, 300px); margin-top: auto; padding-top: 16px; }
.install-hint { font-size: 13px; opacity: .8; margin-top: 12px; }

/* ---------- HUD ---------- */
.hud { display: flex; align-items: center; gap: 6px; padding: calc(var(--safe-t) + 8px) 10px 8px; background: var(--claret); color: var(--cream); flex: none; }
.pill { background: rgba(255,255,255,.14); border-radius: 999px; padding: 5px 10px; font-weight: 800; font-size: 14px; white-space: nowrap; }
.pill-gold { margin-left: auto; background: var(--gold); color: var(--ink); min-width: 70px; text-align: center; }

/* ---------- Scene ---------- */
.scene {
  position: relative; flex: 1 1 auto; min-height: 180px; overflow: hidden;
  background:
    linear-gradient(180deg, transparent 0 58%, rgba(123,30,58,.12) 58% 60%, transparent 60%),
    repeating-linear-gradient(90deg, #f3e3cf 0 26px, #efdcc5 26px 52px);
}
.scene .bunting { position: absolute; top: 0; left: 0; height: 26px; opacity: .9; }
.lamp { position: absolute; top: 0; width: 2px; height: 34px; background: #5a3a28; }
.lamp::after { content: ""; position: absolute; left: -13px; top: 32px; width: 28px; height: 15px; border-radius: 14px 14px 3px 3px; background: var(--claret); box-shadow: 0 12px 26px 10px rgba(255,210,120,.35); }
.lamp-1 { left: 18%; } .lamp-2 { left: 40%; height: 22px; }
.shelf { position: absolute; left: 8px; top: 40%; width: 44%; border-bottom: 5px solid #b07a52; display: flex; justify-content: space-around; font-size: 18px; opacity: .55; }
.customer { position: absolute; left: 1%; bottom: 17%; width: 50%; max-width: 230px; aspect-ratio: 200 / 220; z-index: 1; }
.customer svg { width: 100%; height: 100%; animation: breathe 3s ease-in-out infinite; transform-origin: 50% 100%; }
.customer.enter { animation: walkIn .55s cubic-bezier(.2,.8,.3,1.1); }
.customer.leave { animation: walkOut .45s ease-in forwards; }
.counter { position: absolute; left: 0; right: 0; bottom: 0; height: 18%; z-index: 2; background: linear-gradient(#d3a57c 0 7px, #a8714a 7px 11px, var(--claret) 11px); box-shadow: 0 -2px 6px rgba(0,0,0,.15); }
.counter::after { content: ""; position: absolute; left: 0; right: 0; top: 11px; bottom: 0; background: repeating-linear-gradient(90deg, transparent 0 46px, rgba(0,0,0,.12) 46px 48px); }

.bubble {
  position: absolute; right: 10px; top: 30px; width: 52%; z-index: 3;
  background: #fff; border-radius: 18px; padding: 10px 12px 11px;
  box-shadow: 0 6px 16px rgba(59,36,22,.18);
}
.bubble::before { content: ""; position: absolute; left: -9px; top: 38px; border: 9px solid transparent; border-right-color: #fff; border-left: 0; }
.bubble.pop { animation: pop .3s ease-out; }
.bubble.complain { background: #fff4e8; }
.bubble.complain::before { border-right-color: #fff4e8; }
.bubble-greet { font-size: 12.5px; color: var(--muted); line-height: 1.25; }
.bubble-greet b { color: var(--coffee); }
.ticket-title { font-weight: 900; font-size: 19px; line-height: 1.1; color: var(--claret); margin-top: 3px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.chips span { background: var(--latte); border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 800; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 5px; font-weight: 700; }
.patience { height: 6px; background: #efe6dc; border-radius: 3px; margin-top: 8px; overflow: hidden; }
#patience-fill { height: 100%; width: 100%; border-radius: 3px; background: #6fbf73; transition: width .25s linear, background-color .4s; }

.floaters { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
.float { position: absolute; left: 30%; top: 30%; transform: translateX(-50%); font-weight: 900; font-size: 22px; color: var(--claret); text-shadow: 0 2px 0 #fff, 0 0 8px #fff; animation: floatUp 1.3s ease-out forwards; white-space: nowrap; }
.float.tip { top: 42%; color: #2e7d32; font-size: 17px; animation-delay: .15s; opacity: 0; }

/* ---------- Bench ---------- */
.bench {
  flex: none; height: clamp(150px, 23dvh, 196px);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: end; gap: 6px;
  padding: 8px 10px 8px;
  background: linear-gradient(#e3c9a8, #d6b892); border-top: 4px solid #c09673;
}
.faith-mini { position: relative; align-self: end; justify-self: start; }
.faith-face { width: 76px; height: 82px; border-radius: 40px 40px 18px 18px; overflow: hidden; background: #f3dcc6; border: 3px solid var(--claret); box-shadow: 0 3px 0 rgba(0,0,0,.18); }
.faith-face svg { width: 100%; height: 100%; }
.quip {
  position: absolute; bottom: 92px; left: 0; width: max-content; max-width: 120px;
  background: var(--claret); color: var(--cream); font-size: 12.5px; font-weight: 800; line-height: 1.2;
  padding: 6px 9px; border-radius: 12px 12px 12px 3px;
}
.quip:empty { display: none; }
.quip.pop { animation: pop .3s ease-out; }

.cup-wrap { position: relative; width: 112px; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.cup-wrap.served { animation: serveUp .6s ease-in forwards; }
.glass { position: relative; width: 90px; height: 116px; --s: 1; transform: scale(var(--s)); transform-origin: 50% 100%; transition: transform .25s cubic-bezier(.3,1.4,.5,1); }
.glass.shake { animation: shake .45s; }
.glass-outline { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.liquid { position: absolute; inset: 1.5% 0 1.5%; clip-path: polygon(3% 0, 97% 0, 86% 100%, 14% 100%); display: flex; flex-direction: column-reverse; }
.layer { flex: none; width: 100%; animation: pour .35s ease-out; }
.layer.shot { background: linear-gradient(#c98a4b 0 22%, #3a1d0e 22%); }
.layer.choc { background: #4f2512; }
.layer.water { background: linear-gradient(rgba(150,95,55,.75), rgba(110,62,32,.85)); }
.layer.foam {
  background: radial-gradient(circle at 20% 30%, #fff 0 18%, transparent 19%) 0 0 / 14px 10px, radial-gradient(circle at 70% 60%, #fff 0 16%, transparent 17%) 0 0 / 11px 9px, #fbf5ea;
  border-radius: 40% 40% 0 0 / 12px 12px 0 0;
}
.glass.empty .liquid, .glass.empty .glass-outline { opacity: 0; }
.glass-placeholder { display: none; position: absolute; inset: 0; border: 3px dashed rgba(123,30,58,.45); border-radius: 6px 6px 18px 18px; place-items: center; font-weight: 800; font-size: 13px; color: var(--claret); text-align: center; }
.glass.empty .glass-placeholder { display: grid; animation: pulse 1.6s ease-in-out infinite; }
.cup-name { margin-top: 4px; font-family: "Marker Felt", "Comic Sans MS", cursive; font-size: 13px; color: var(--coffee); height: 16px; white-space: nowrap; }

.stream { position: absolute; left: 50%; top: -46px; width: 8px; height: 0; margin-left: -4px; border-radius: 4px; opacity: 0; z-index: 2; }
.stream.go { animation: stream .45s ease-out; }
.steam { position: absolute; left: 0; right: 0; top: -30px; height: 30px; display: flex; justify-content: center; gap: 12px; opacity: 0; transition: opacity .4s; pointer-events: none; }
.steam.on { opacity: 1; }
.steam span { width: 6px; height: 26px; border-radius: 6px; background: linear-gradient(transparent, rgba(255,255,255,.85)); animation: steam 2.2s ease-in-out infinite; }
.steam span:nth-child(2) { animation-delay: .6s; } .steam span:nth-child(3) { animation-delay: 1.2s; }

.bench-actions { display: flex; flex-direction: column; gap: 8px; justify-self: end; width: 100%; max-width: 118px; }
.btn-serve { font-size: 19px; padding: 16px 10px; }
.bench-actions .btn-soft { font-size: 14px; padding: 9px 10px; }

/* ---------- Controls ---------- */
.controls { flex: none; display: grid; gap: 7px; padding: 9px 10px calc(var(--safe-b) + 10px); background: var(--coffee); }
.row { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 7px; }
.ctl {
  position: relative; height: 48px; border: 0; border-radius: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  font-weight: 800; font-size: 11.5px; line-height: 1.05; background: var(--cream);
  box-shadow: 0 3px 0 rgba(0,0,0,.35); transition: transform .06s, box-shadow .06s, background-color .15s;
}
.ctl:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.ctl .ic { font-size: 19px; line-height: 1; }
.row-cup .ctl { background: #fff; }
.row-coffee .ctl { background: #ecd5b8; }
.row-milk .ctl { background: #fbf8f2; }
.row-syrup .ctl { background: #f6dfb2; }
.ctl.on { background: var(--gold) !important; box-shadow: 0 3px 0 #a8731a, inset 0 0 0 2px #fff6; }
.ctl.locked { opacity: .5; }
.ctl .badge { position: absolute; top: -6px; right: -4px; min-width: 21px; height: 21px; padding: 0 5px; border-radius: 999px; background: var(--claret); color: #fff; font-size: 12px; display: grid; place-items: center; }
.ctl .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; box-shadow: 0 0 0 1px rgba(0,0,0,.2); }
.row.nudge { animation: nudge .5s; }

/* ---------- End ---------- */
.end-card { background: var(--cream); color: var(--ink); width: 100%; border-radius: 24px; padding: 16px 18px 18px; margin-top: 8px; display: flex; flex-direction: column; gap: 10px; align-items: center; box-shadow: 0 10px 30px rgba(0,0,0,.25); }
.end-faith { width: 120px; aspect-ratio: 100 / 108; border-radius: 50%; overflow: hidden; background: #f3dcc6; border: 4px solid var(--claret); margin-top: -2px; }
.end-faith svg { width: 100%; height: 100%; }
.end-card h2 { font-family: Georgia, serif; font-style: italic; font-size: 28px; color: var(--claret); }
.stars { font-size: 34px; letter-spacing: 4px; }
.stars .off { filter: grayscale(1); opacity: .3; }
.end-stats { width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: 15px; }
.end-stats dt { color: var(--muted); font-weight: 700; }
.end-stats dd { font-weight: 900; text-align: right; }
.bean-club { width: 100%; background: #fff; border-radius: 16px; padding: 10px; border: 2px dashed rgba(123,30,58,.35); }
.bean-title { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; color: var(--claret); text-align: center; margin-bottom: 6px; }
.stamps { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.stamp { aspect-ratio: 1; border-radius: 50%; border: 2px dashed #d9c6b3; display: grid; place-items: center; font-size: 15px; }
.stamp.got { background: var(--claret); border: 0; animation: stampIn .35s backwards; }
.end-unlock { font-weight: 800; color: var(--claret); text-align: center; font-size: 14px; }
.end-unlock:empty { display: none; }
.end-card .btn { width: 100%; }

/* ---------- Jo ---------- */
.brief { align-items: center; padding: 16px; }
.brief-sheet { border-radius: 22px; display: flex; flex-direction: column; gap: 14px; padding: 18px; animation: pop .3s ease-out; }
.brief-row, .jo-says { display: flex; gap: 12px; align-items: center; text-align: left; }
.jo-says { width: 100%; background: #fff; border-radius: 16px; padding: 10px; }
.jo-face { flex: none; width: 64px; height: 64px; border-radius: 50%; overflow: hidden; background: #f3e3cf; border: 3px solid var(--claret); }
.jo-face svg { width: 100%; height: 100%; }
.jo-name { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 1px; color: var(--claret); }
.jo-text { font-size: 15px; line-height: 1.35; margin-top: 2px; }

/* ---------- Recipe book ---------- */
.modal { position: absolute; inset: 0; z-index: 20; background: rgba(43,26,20,.5); display: flex; align-items: flex-end; animation: fade .2s; }
.sheet { width: 100%; max-height: 82%; overflow-y: auto; background: var(--cream); border-radius: 22px 22px 0 0; padding: 14px 16px calc(var(--safe-b) + 18px); animation: slideUp .25s ease-out; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.sheet-head h3 { font-family: Georgia, serif; font-style: italic; color: var(--claret); font-size: 22px; }
.recipe { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 9px 0; border-bottom: 1px dashed #dccab7; }
.recipe b { font-size: 16px; }
.recipe small { display: block; color: var(--muted); font-weight: 700; font-size: 11px; }
.recipe span { font-weight: 800; color: var(--claret); font-size: 13px; text-align: right; }
.book-sub { margin-top: 14px; font-family: Georgia, serif; font-style: italic; color: var(--claret); font-size: 18px; }
.bubble-greet i { color: var(--claret); font-style: normal; font-weight: 700; }
.book-tip { margin-top: 12px; font-size: 13px; color: var(--muted); line-height: 1.4; }

/* ---------- Animations ---------- */
@keyframes bob { 50% { transform: translateY(-6px); } }
@keyframes breathe { 50% { transform: scaleY(1.012) translateY(-1px); } }
@keyframes walkIn { from { transform: translateX(-115%); } }
@keyframes walkOut { to { transform: translateX(-120%); } }
@keyframes pop { from { transform: scale(.7); opacity: 0; } }
@keyframes pour { from { height: 0; } }
@keyframes stream { 0% { opacity: 0; height: 0; } 20% { opacity: 1; height: 70px; } 70% { opacity: 1; height: 70px; } 100% { opacity: 0; height: 70px; transform: translateY(30px); } }
@keyframes steam { 0% { transform: translateY(8px) scaleX(1); opacity: 0; } 40% { opacity: .9; } 100% { transform: translateY(-14px) scaleX(1.6); opacity: 0; } }
@keyframes shake { 20%, 60% { transform: scale(var(--s)) translateX(-7px) rotate(-3deg); } 40%, 80% { transform: scale(var(--s)) translateX(7px) rotate(3deg); } }
@keyframes serveUp { to { transform: translate(-60px, -150px) scale(.4); opacity: 0; } }
@keyframes floatUp { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.8); } 15% { opacity: 1; transform: translate(-50%, 0) scale(1.1); } 100% { opacity: 0; transform: translate(-50%, -60px) scale(1); } }
@keyframes pulse { 50% { opacity: .55; } }
@keyframes nudge { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
@keyframes stampIn { from { transform: scale(2) rotate(-20deg); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes slideUp { from { transform: translateY(100%); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (max-height: 640px) {
  .ctl { height: 42px; } .ctl .ic { font-size: 16px; }
  .bench { height: 138px; }
  .title-art { width: 46vw; }
}
