:root {
  --ink: #231A3B;
  --wall: #0F4C4A;
  --wall-deep: #0A3534;
  --paper: #FBF3D9;
  --paper-warm: #F6E5B4;
  --plum: #B3264F;
  --gold: #F7B32B;
  --pink: #F4A6B8;
  --pink-deep: #E488A0;
  --display: "Rockwell", "Roboto Slab", "Cooper Black", "DejaVu Serif", Georgia, serif;
  --body: "Avenir Next", "Avenir", "Segoe UI", "Trebuchet MS", Roboto, system-ui, sans-serif;
  --awning-height: 62px;
  --hard: 4px 4px 0 var(--ink);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body {
  background: var(--wall);
  color: var(--paper);
  font-family: var(--body);
  font-size: 17px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
p { margin: 0; }
h1, h2, h3 { font-family: var(--display); font-weight: 700; line-height: 1.12; margin: 0; }
svg { display: block; width: 100%; height: 100%; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.noscript { padding: 24px; }

/* A focus ring that reads on teal, paper and pink alike. */
:focus-visible {
  outline: 3px solid var(--paper);
  outline-offset: 3px;
  box-shadow: 0 0 0 3px var(--ink);
}
#stage:focus-visible, h1:focus-visible { outline: none; box-shadow: none; }

#app { position: relative; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- Awning ---------- */
#topbar { position: relative; z-index: 30; flex: none; height: var(--awning-height); }
.awning {
  position: absolute; inset: 0 0 auto; height: 50px;
  background: repeating-linear-gradient(90deg, var(--plum) 0 44px, var(--paper) 44px 88px);
  border-top: 3px solid var(--ink);
}
.awning::after {
  content: ""; position: absolute; left: 0; right: 0; top: 100%; height: 12px;
  background:
    radial-gradient(circle at 22px 0, var(--plum) 21px, var(--ink) 21.5px 23px, transparent 23.5px) 0 0 / 88px 24px repeat-x,
    radial-gradient(circle at 66px 0, var(--paper) 21px, var(--ink) 21.5px 23px, transparent 23.5px) 0 0 / 88px 24px repeat-x;
}
.topbar-row {
  position: absolute; inset: 7px 12px auto; display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.plate {
  display: inline-flex; align-items: center; gap: 10px; min-height: 36px; padding: 3px 12px;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 4px;
  font-size: 15px; font-weight: 700;
}
.plate-button { margin-left: auto; font: inherit; font-size: 15px; font-weight: 700; cursor: pointer; }
.plate-button:hover { background: var(--gold); }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 8px; height: 8px; border: 2px solid var(--ink); border-radius: 50%; }
.pips i.on { background: var(--plum); }

/* ---------- Stage ---------- */
#stage { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.wrap { width: min(1040px, 100%); margin: 0 auto; padding: 10px 16px 0; min-height: 100%; display: flex; flex-direction: column; gap: 14px; }
.screen-title { font-size: clamp(30px, 6vw, 46px); }

.btn {
  appearance: none; min-height: 48px; padding: 9px 18px; font: inherit; font-weight: 700; line-height: 1.2; cursor: pointer;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 6px; box-shadow: var(--hard);
  touch-action: manipulation;
}
.btn:hover:not(:disabled) { background: #fff; }
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn-primary { background: var(--gold); font-size: 18px; }
.btn-primary:hover:not(:disabled) { background: #FFC655; }
.btn:disabled { background: #BFC7BD; color: #3D3A4C; box-shadow: none; cursor: not-allowed; }
.button-row { display: flex; flex-wrap: wrap; gap: 12px; }

.action-bar {
  position: sticky; bottom: 0; z-index: 5; margin: auto -16px 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--wall-deep); border-top: 3px solid var(--ink);
  display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 12px;
}
.action-bar:empty { display: none; }
.action-bar .sure { flex: 1 1 100%; }
.action-bar .btn-primary { flex: 1 1 auto; max-width: 440px; }

/* ---------- Title ---------- */
.title-screen { min-height: 100%; display: flex; flex-direction: column; }
.hero { --peek: 208px; position: relative; flex: 1 1 56%; min-height: 350px; overflow: hidden; border-bottom: 5px solid var(--ink); background: var(--wall-deep); }
.hero-interior { position: absolute; inset: 0; }
.hero-customer { position: absolute; left: 50%; bottom: 18px; width: 200px; aspect-ratio: 1; transform: translateX(-50%); }
.hero-counter { position: absolute; left: 0; right: 0; bottom: 0; height: 26px; background: var(--plum); border-top: 4px solid var(--ink); }
.hero-shutter {
  position: absolute; inset: 0 0 var(--peek);
  display: flex; align-items: flex-end; justify-content: center; padding: 0 16px 14px;
  background: repeating-linear-gradient(180deg, var(--pink) 0 19px, var(--pink-deep) 19px 22px, var(--ink) 22px 24px);
  border-bottom: 9px solid var(--ink);
  animation: hero-lift .9s cubic-bezier(.3, 1.3, .5, 1) .2s backwards;
}
@keyframes hero-lift { from { transform: translateY(var(--peek)); } }
.wordmark {
  color: var(--ink); text-align: center; font-weight: 800; letter-spacing: -.01em; line-height: .96;
  font-size: clamp(46px, min(13vw, 12vh), 100px);
  text-shadow: 3px 3px 0 var(--paper);
}
.title-copy { flex: none; width: min(1040px, 100%); margin: 0 auto; padding: 18px 16px calc(20px + env(safe-area-inset-bottom)); display: grid; gap: 10px; }
.lede { font-family: var(--display); font-size: clamp(21px, 3.2vw, 28px); line-height: 1.2; max-width: 34em; }
.title-meta { color: var(--paper-warm); }
.title-copy .button-row { margin-top: 6px; }
.title-copy .btn-primary { min-width: 180px; }

/* ---------- Setup ---------- */
.setup-screen { max-width: 640px; }
.setup-note { max-width: 56ch; }
.stepper { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.stepper-count { font-family: var(--display); font-size: 21px; font-weight: 700; min-width: 5.2em; text-align: center; }
.stepper .btn { flex: 1 1 110px; min-width: 0; }
.name-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.name-row { display: flex; align-items: center; gap: 10px; }
.name-row input {
  flex: 1; min-width: 0; height: 48px; padding: 8px 12px; font: inherit; font-size: 18px;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 4px;
}
.name-row input::placeholder { color: #5D5670; opacity: 1; }
.seal { display: inline-block; flex: none; width: 34px; height: 34px; }
.name-row .seal { width: 44px; height: 44px; }

/* ---------- Customer ---------- */
.customer { display: grid; grid-template-columns: auto 1fr; gap: 14px; align-items: center; }
.customer-art { width: clamp(108px, 22vw, 190px); aspect-ratio: 1; }
.customer-compact .customer-art { width: 72px; }
.customer-copy { min-width: 0; display: grid; gap: 7px; }
.customer-name { color: var(--paper); font-size: 15px; }
.customer-name strong { font-family: var(--display); font-size: 19px; }
.bubble {
  position: relative; isolation: isolate; margin: 0; padding: 10px 14px; background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); border-radius: 14px; font-family: var(--display); font-size: clamp(17px, 2.3vw, 22px); line-height: 1.22;
}
.bubble::before {
  content: ""; position: absolute; z-index: -1; left: -10px; top: 50%; width: 17px; height: 17px; margin-top: -8.5px;
  background: var(--paper); border-left: 3px solid var(--ink); border-bottom: 3px solid var(--ink); transform: rotate(45deg);
}
.customer-compact .bubble { font-size: 15.5px; padding: 7px 11px; }
.customer-compact .customer-name { font-size: 13.5px; }
.customer-compact .customer-name strong { font-size: 16px; }
.keeper-note { display: flex; align-items: center; gap: 10px; }

/* ---------- Gift hang tags ---------- */
.gift-rail { display: grid; gap: 10px; grid-template-columns: 1fr; }
.tag {
  --cut: 16px;
  position: relative; isolation: isolate; width: 100%; color: var(--ink); text-align: left; font: inherit;
  appearance: none; background: none; border: 0; padding: 10px 12px 10px 28px; min-height: 88px;
  display: grid; grid-template-columns: 74px minmax(0, 1fr) auto; gap: 2px 12px; align-items: center;
}
.tag::before, .tag::after {
  content: ""; position: absolute; z-index: -1;
  clip-path: polygon(var(--cut) 0, 100% 0, 100% 100%, var(--cut) 100%, 0 calc(100% - var(--cut)), 0 var(--cut));
}
.tag::before { inset: 0; background: var(--ink); }
.tag::after { inset: 3px; background: var(--paper); }
.tag-button { cursor: pointer; touch-action: manipulation; }
.tag-button:hover::after { background: #FFFBEC; }
.tag-marked::after { background: var(--paper-warm); }
.tag-art { width: 74px; height: 74px; }
.tag-copy { display: grid; gap: 1px; min-width: 0; }
.tag-name { font-family: var(--display); font-weight: 700; font-size: 18px; line-height: 1.15; }
.tag-note { font-size: 14.5px; line-height: 1.25; }
.tag-key {
  align-self: start; font: 700 13px var(--body); color: var(--ink); min-width: 24px; height: 24px;
  display: grid; place-items: center; border: 2px solid var(--ink); border-radius: 4px; background: #fff;
}
.tag-stamps { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 3px; }
.tag-stamps:empty { display: none; }
.tag-stamp { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; font-weight: 700; }
.tag-stamp .seal { width: 28px; height: 28px; }
.stamp-in .seal { animation: stamp .24s cubic-bezier(.3, 1.6, .6, 1); }
@keyframes stamp { from { transform: scale(2.3) rotate(-14deg); opacity: 0; } }

/* ---------- Private pick ---------- */
.prompt { display: flex; align-items: center; gap: 12px; }
.prompt-seal { width: 52px; height: 52px; }
.prompt-step { font-size: 15px; font-weight: 700; color: var(--paper-warm); }
.prompt-title { font-size: clamp(25px, 4vw, 34px); }
.sure {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 9px 12px; text-align: left; font: inherit; font-size: 15px; line-height: 1.25;
  background: transparent; color: var(--paper); border: 3px dashed var(--paper-warm); border-radius: 8px; cursor: pointer; touch-action: manipulation;
}
.sure-chip {
  flex: none; display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50%;
  font: 800 18px var(--display); background: transparent; color: var(--paper); border: 3px solid var(--paper);
}
.sure-on { background: var(--gold); color: var(--ink); border: 3px solid var(--ink); box-shadow: var(--hard); }
.sure-on .sure-chip { background: var(--plum); color: var(--paper); border-color: var(--ink); }
.sure-detail { font-weight: 400; }
p.sure-spent { display: block; border-style: solid; border-color: transparent; cursor: default; padding: 2px 0; color: var(--paper-warm); }

/* ---------- Reveal ---------- */
.reveal-title { font-size: clamp(23px, 3.6vw, 32px); }
.gift-rail-reveal { gap: 7px; }
.reveal-gift {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 38px; grid-template-rows: auto auto; gap: 4px 8px; align-items: center;
  background: var(--wall-deep); border: 3px solid var(--ink); border-radius: 8px; padding: 7px 9px;
}
.reveal-tag { grid-column: 1; display: flex; align-items: center; gap: 9px; min-width: 0; }
.reveal-tag .tag-art { flex: none; width: 54px; height: 54px; padding: 3px; background: var(--paper); border: 2px solid var(--ink); border-radius: 6px; }
.reveal-tag .tag-name { font-size: 16px; }
.reveal-gift .pile { grid-column: 1; }
.pile-count { grid-column: 2; grid-row: 1 / span 2; font: 800 34px var(--display); text-align: center; }
.pile { display: flex; flex-wrap: wrap; gap: 3px; min-height: 36px; align-items: center; }
.pile .seal { width: 36px; height: 36px; }
.pile-empty { color: var(--paper-warm); font-size: 14px; font-style: italic; }
.seal.drop { animation: drop .46s cubic-bezier(.3, .8, .4, 1.25) .42s backwards; }
@keyframes drop {
  from { transform: translateY(-120px) scale(1.9) rotate(-18deg); opacity: 0; }
  55% { opacity: 1; }
}
.reveal-gift.crowned { background: var(--gold); color: var(--ink); }
.reveal-gift.crowned .crown { position: absolute; z-index: 2; left: -4px; top: -11px; width: 38px; height: 26px; animation: crown .42s cubic-bezier(.3, 1.6, .6, 1); }
@keyframes crown { from { transform: translateY(-20px) scale(1.6); opacity: 0; } }

.ledger { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 8px; font-size: 15px; overflow: hidden; }
.ledger-row { display: grid; grid-template-columns: minmax(0, 1fr) 36px 36px 46px 42px; gap: 6px; align-items: center; padding: 5px 8px; border-top: 2px solid rgba(35, 26, 59, .25); }
.ledger-row:first-child { border-top: 0; }
.ledger-head { font-size: 12.5px; font-weight: 700; padding-block: 3px; }
.ledger-right { background: var(--paper-warm); }
.ledger-player { display: flex; align-items: center; gap: 7px; min-width: 0; }
.ledger-player .seal { width: 30px; height: 30px; }
.ledger-player > span:last-child { min-width: 0; overflow-wrap: anywhere; }
.ledger-detail { display: block; font-size: 12.5px; line-height: 1.2; }
.mini { display: block; width: 34px; height: 34px; }
.ledger-num { text-align: right; font-weight: 700; }
.ledger-points { font: 800 18px var(--display); }

/* ---------- Results ---------- */
.results-screen { gap: 16px; }
.winner-banner { display: grid; justify-items: center; text-align: center; gap: 8px; padding-top: 12px; }
.winner-seals { display: flex; flex-wrap: wrap; justify-content: center; gap: 16px; }
.winner-seal { position: relative; display: block; padding-top: 22px; }
.winner-seal .seal { width: 86px; height: 86px; }
.winner-seal .crown { position: absolute; top: 0; left: 50%; width: 54px; height: 36px; transform: translateX(-50%); }
.receipt {
  width: min(620px, 100%); margin: 0 auto; padding: 16px; background: var(--paper); color: var(--ink);
  border: 3px solid var(--ink); box-shadow: var(--hard);
}
.receipt h2 { font-size: 21px; margin: 16px 0 6px; }
.receipt > h2:first-child { margin-top: 0; }
.standing-list, .award-list, .shop-log { list-style: none; margin: 0; padding: 0; }
.standing-list li { display: grid; grid-template-columns: 22px 34px minmax(0, 1fr) auto 40px; gap: 8px; align-items: center; padding: 6px 0; border-top: 2px dashed rgba(35, 26, 59, .4); }
.standing-list li:first-child { border-top: 0; }
.standing-top { background: var(--paper-warm); margin: 0 -8px; padding-inline: 8px !important; }
.standing-rank { font-weight: 700; }
.standing-name { font-weight: 700; overflow-wrap: anywhere; }
.standing-reads { font-size: 13.5px; }
.standing-score { font: 800 24px var(--display); text-align: right; }
.award-list li { padding: 3px 0; }
.shop-log { display: grid; gap: 8px; }
.shop-log li { display: flex; align-items: center; gap: 10px; line-height: 1.25; font-size: 15px; }
.log-art { flex: none; width: 46px; height: 46px; }
.receipt-note { margin-top: 14px; font-size: 14px; }
.results-screen .action-bar { margin-top: auto; }

/* ---------- Shutter: the one loud thing ---------- */
#shutter {
  position: absolute; z-index: 20; inset: var(--awning-height) 0 0; display: flex; overflow-y: auto; padding: 18px 16px 34px;
  background: repeating-linear-gradient(180deg, var(--pink) 0 25px, var(--pink-deep) 25px 29px, var(--ink) 29px 31px);
  border-bottom: 12px solid var(--ink);
  transition: transform .46s cubic-bezier(.34, 1.18, .5, 1), visibility 0s;
}
#shutter[data-state="up"] {
  transform: translateY(-104%); visibility: hidden;
  transition: transform .42s cubic-bezier(.5, 0, .7, .4), visibility 0s .42s;
}
.sign {
  position: relative; margin: auto; width: min(460px, 100%); padding: 20px; color: var(--ink); background: var(--paper);
  border: 3px solid var(--ink); box-shadow: 6px 6px 0 var(--ink); display: grid; justify-items: center; gap: 11px; text-align: center;
}
.sign-title { font-size: clamp(27px, 5vw, 36px); overflow-wrap: anywhere; }
.sign-seal { width: 76px; height: 76px; }
.sign-seals, .sign-progress { display: flex; flex-wrap: wrap; justify-content: center; gap: 5px; }
.sign-seals .seal { width: 44px; height: 44px; }
.sign-progress .seal { width: 28px; height: 28px; }
.sign-progress .waiting { opacity: .32; filter: grayscale(1); }
.sign-locked { font-weight: 700; }
.sign .btn-primary { width: 100%; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 20px; overflow-y: auto;
  color: var(--ink); background: var(--paper); border: 3px solid var(--ink); box-shadow: 7px 7px 0 var(--ink);
}
dialog::backdrop { background: rgba(10, 53, 52, .9); }
dialog h2 { font-size: 27px; margin-bottom: 8px; }
dialog h3 { font-size: 20px; margin: 15px 0 5px; }
dialog p { margin-bottom: 8px; }
.dialog-note { font-size: 15px; }
.dialog-actions { display: grid; gap: 12px; margin-top: 14px; }
.rules-steps { margin: 0; padding-left: 24px; display: grid; gap: 6px; }
.rules-points { margin: 0; display: grid; gap: 5px; }
.rules-points div { display: grid; grid-template-columns: 40px 1fr; gap: 8px; }
.rules-points dt { font: 800 21px var(--display); }
.rules-points dd { margin: 0; }
kbd { font: 700 13px var(--body); padding: 1px 6px; border: 2px solid var(--ink); border-radius: 4px; background: #fff; }

/* Phones: the choice and the action must share one screen. */
@media (max-width: 719px) {
  .wrap { gap: 10px; }
  .customer-compact { gap: 10px; }
  .customer-compact .customer-art { width: 58px; }
  .customer-compact .customer-who { display: none; }
  .customer-compact .customer-copy { gap: 3px; }
  .customer-compact .bubble { font-size: 15px; line-height: 1.2; padding: 6px 10px; }
  .prompt-seal { width: 42px; height: 42px; }
  .prompt-title { font-size: 23px; }
  .pick-screen .tag { min-height: 72px; padding-block: 6px; grid-template-columns: 62px 1fr auto; }
  .pick-screen .tag-art { width: 62px; height: 62px; }
  .pick-reading .tag-note { display: none; }
  .pick-reading .gift-rail { gap: 7px; }
  .action-bar { gap: 9px; padding-block: 9px; }
  .sure { padding: 6px 10px; font-size: 14px; }
  .sure-chip { width: 36px; height: 36px; font-size: 15px; }
  .beat-2 .pile { display: none; }
  .beat-2 .reveal-gift { grid-template-rows: auto; padding-block: 5px; }
  .beat-2 .pile-count { grid-row: 1; font-size: 28px; }
  .beat-2 .reveal-tag .tag-art { width: 44px; height: 44px; }
}

@media (max-width: 359px) { .pips { display: none; } }

/* Touch screens have no use for key hints. */
@media (hover: none) { .tag-key, .keys-title, .keys { display: none; } }

/* ---------- Wider screens ---------- */
@media (min-width: 720px) {
  .wrap { padding-top: 14px; gap: 18px; }
  .gift-rail { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
  .tag { grid-template-columns: 1fr; justify-items: center; text-align: center; padding: 16px 14px 14px; align-content: start; gap: 6px; --cut: 22px; }
  .tag-art { width: min(100%, 146px); height: auto; aspect-ratio: 1; }
  .tag-copy { justify-items: center; }
  .tag-name { font-size: 20px; }
  .tag-note { font-size: 15px; }
  .tag-key { position: absolute; top: 10px; right: 10px; }
  .tag-stamps { justify-content: center; }
  .customer-compact .customer-art { width: 92px; }
  .customer-compact .bubble { font-size: 17px; }
  .reveal-gift { grid-template-columns: minmax(0, 1fr) 42px; }
  .ledger { font-size: 16px; }
  .ledger-row { grid-template-columns: minmax(0, 1fr) 44px 44px 64px 56px; padding-inline: 12px; }
  .ledger-detail { display: inline; margin-left: 10px; font-size: 14px; }
  .mini { width: 40px; height: 40px; }
  .action-bar { margin-inline: 0; padding-inline: 0; background: var(--wall); border-top: 0; }
  .action-bar .btn-primary { flex: 0 1 auto; min-width: 260px; }
  .title-copy { padding-top: 24px; }
}

/* Short laptop viewports and small embedded iframes keep the actions in reach. */
@media (max-height: 640px) and (min-width: 720px) {
  .tag-art { width: 84px; }
  .customer-compact .customer-art { width: 64px; }
}
@media (max-height: 640px) {
  .hero { --peek: 150px; min-height: 260px; }
  .hero-customer { width: 140px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
