/* Tiltstack: every UI piece is a "sticker" with the same thick ink outline as the blocks. */
:root {
  --ink: #211d45;
  --paper: #ffffff;
  --mist: #eef1fb;
  --sun: #ffc83d;
  --coral: #ff6b5b;
  --mint: #33cf9a;
  --sky: #4aa8ff;
  --violet: #9b7bff;
  --orange: #ff9640;
  --pink: #ff76b3;
  --line: 3px;
  --lift: 0 4px 0 var(--ink);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  color: var(--ink);
  font-family: var(--font);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9ed9ff; overscroll-behavior: none; }
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
a { color: inherit; -webkit-tap-highlight-color: transparent; }
svg { width: 1.25em; height: 1.25em; flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--coral); outline-offset: 3px; }

#stage { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
body.holding #stage { cursor: grabbing; }

/* Sticker: white card, ink outline, hard drop shadow. */
.sticker {
  display: inline-flex; align-items: center; gap: .5em;
  background: var(--paper); border: var(--line) solid var(--ink); border-radius: 14px;
  box-shadow: var(--lift); padding: .55em .95em; font-weight: 800; text-decoration: none;
}
button.sticker { cursor: pointer; transition: transform .08s, box-shadow .08s, background .15s; }
button.sticker:hover { background: var(--mist); }
button.sticker:active, button.sticker.held { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
button.sticker:disabled { cursor: default; opacity: .55; transform: none; box-shadow: var(--lift); }
.sticker.primary { background: var(--sun); }
.sticker.primary:hover { background: #ffd666; }
.sticker.round { border-radius: 50%; width: 54px; height: 54px; padding: 0; justify-content: center; }
.coins { background: #fff6cf; font-variant-numeric: tabular-nums; }
.coins svg { width: 1.4em; height: 1.4em; }

#loading {
  position: fixed; inset: 0; z-index: 50; display: flex; flex-direction: column; gap: 14px;
  align-items: center; justify-content: center; background: #9ed9ff; font-weight: 800; text-align: center; padding: 24px;
}
#loading p { margin: 0; }
#loading button { margin-top: 8px; }
.spinner { width: 34px; height: 34px; border-radius: 8px; background: var(--sun); border: var(--line) solid var(--ink); animation: turn 1.1s cubic-bezier(.6,0,.3,1) infinite; }
@keyframes turn { to { transform: rotate(360deg); } }

/* ---------- Menu ---------- */
.screen {
  position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column;
  padding: calc(18px + var(--safe-t)) calc(22px + var(--safe-r)) calc(18px + var(--safe-b)) calc(22px + var(--safe-l));
  pointer-events: none;
}
.screen > * { pointer-events: auto; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.club { font-size: 15px; padding: .5em .9em .5em .6em; }
.hero { margin: auto 0; max-width: min(520px, 46vw); display: flex; flex-direction: column; align-items: flex-start; gap: 18px; pointer-events: none; }
.hero > * { pointer-events: auto; }
.logo { margin: 0 0 4px; font-size: clamp(42px, 7.4vw, 86px); line-height: 1; font-weight: 900; display: flex; flex-direction: column; gap: .1em; }
.logo .row { display: flex; gap: .06em; }
.logo .lean { transform-origin: 0% 100%; transform: rotate(-5deg) translateX(.3em); animation: teeter 4.5s ease-in-out infinite; }
.logo i {
  font-style: normal; display: grid; place-items: center; width: .86em; height: .92em; border-radius: .16em;
  border: calc(var(--line) + 1px) solid var(--ink); box-shadow: inset 0 .07em 0 rgba(255,255,255,.55), inset 0 -.08em 0 rgba(33,29,69,.18), 0 .07em 0 var(--ink);
  color: var(--ink); text-transform: uppercase; font-size: 1em; padding-bottom: .04em;
}
.logo i:nth-child(5n+1) { background: var(--coral); }
.logo i:nth-child(5n+2) { background: var(--sun); transform: rotate(3deg) translateY(-.03em); }
.logo i:nth-child(5n+3) { background: var(--mint); }
.logo i:nth-child(5n+4) { background: var(--sky); transform: rotate(-2deg); }
.logo i:nth-child(5n+5) { background: var(--violet); }
.logo .lean i:nth-child(1) { background: var(--pink); }
@keyframes teeter { 0%, 100% { transform: rotate(-5deg) translateX(.3em); } 50% { transform: rotate(-2.5deg) translateX(.24em); } }
.tagline { margin: 0; font-size: clamp(16px, 1.7vw, 20px); line-height: 1.45; font-weight: 700; max-width: 30ch; background: rgba(255,255,255,.72); border-radius: 12px; padding: .5em .75em; }
.huge { font-size: clamp(22px, 2.6vw, 30px); padding: .55em 1.5em .55em 1.15em; border-radius: 18px; }
.menu-links { display: flex; flex-wrap: wrap; gap: 10px; }
.menu-links .sticker { font-size: 15px; position: relative; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--coral); border: 2px solid var(--ink); position: absolute; top: -6px; right: -6px; }
.records { display: flex; gap: 10px; flex-wrap: wrap; }
.records p { margin: 0; display: flex; flex-direction: column; background: rgba(255,255,255,.72); border-radius: 12px; padding: .45em .8em; }
.records b { font-size: 22px; font-variant-numeric: tabular-nums; }
.records span { font-size: 13px; font-weight: 700; opacity: .75; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; z-index: 4; pointer-events: none; }
#hud button { pointer-events: auto; }
.hud-top {
  position: absolute; left: 0; right: 0; top: 0; display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 10px;
  padding: calc(14px + var(--safe-t)) calc(16px + var(--safe-r)) 0 calc(16px + var(--safe-l));
}
.meter { flex-direction: column; gap: 0; padding: .3em 1.1em .45em; border-radius: 18px; min-width: 128px; }
.meter p { margin: 0; }
.meter .now { display: flex; align-items: baseline; gap: 4px; }
.meter strong { font-size: clamp(34px, 4.6vw, 48px); line-height: 1.05; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.meter .now span { font-size: 20px; font-weight: 900; }
.meter .sub { font-size: 13px; font-weight: 800; opacity: .7; font-variant-numeric: tabular-nums; }
.meter.bump { animation: bump .35s; }
@keyframes bump { 30% { transform: scale(1.12) rotate(-2deg); } }
.hud-right { justify-self: end; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.hud-right .coins { font-size: 19px; }
.coins.bump { animation: bump .3s; }
.next { flex-direction: column; gap: 0; padding: 6px 8px 4px; font-size: 12px; }
.next canvas { width: 80px; height: 60px; }
.banner {
  position: absolute; left: 79%; top: 40%; transform: translate(-50%, -50%) scale(.6); opacity: 0;
  text-align: center; font-weight: 900; pointer-events: none; white-space: nowrap;
}
.banner.show { animation: banner 2.3s ease-out forwards; }
.banner b { display: block; font-size: clamp(44px, 8vw, 84px); color: #fff; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; text-shadow: 0 5px 0 var(--ink); letter-spacing: -.02em; }
.banner span { display: inline-block; margin-top: 6px; font-size: 19px; background: var(--sun); border: var(--line) solid var(--ink); border-radius: 12px; padding: .25em .7em; box-shadow: var(--lift); }
@keyframes banner {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(.6) rotate(-6deg); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.08) rotate(2deg); }
  22% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -62%) scale(.96); }
}
.hint {
  position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%);
  font-size: clamp(15px, 1.8vw, 19px); text-align: center; max-width: min(92vw, 520px); justify-content: center; line-height: 1.35;
}
body.pad-on .hint { bottom: calc(132px + var(--safe-b)); }
.pad {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: flex-end; gap: 12px;
  padding: 0 calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
.pad button { width: 96px; height: 96px; border-radius: 22px; justify-content: center; font-size: 22px; touch-action: none; }
.pad button svg { width: 42px; height: 42px; }
.pad .flip svg { transform: scaleX(-1); }
.pad [data-hold=drop] { width: min(260px, 40vw); flex-direction: column; gap: 2px; font-size: 24px; }
.pad [data-hold=drop] small { font-size: 13px; opacity: .75; }
.pad [data-hold=drop].go { background: var(--mint); }

/* ---------- Dialogs ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; overflow: auto;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: rgba(33,29,69,.42);
}
body.fx .overlay { -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px); }
.panel {
  display: block; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow: auto;
  border-radius: 24px; padding: 26px 26px 22px; box-shadow: 0 7px 0 var(--ink); cursor: default;
}
.overlay.show .panel { animation: pop .22s ease-out; }
@keyframes pop { from { transform: translateY(14px) scale(.96); opacity: .4; } }
.panel h2 { margin: 0 0 14px; font-size: 32px; line-height: 1.1; font-weight: 900; letter-spacing: -.01em; }
.panel p { line-height: 1.5; font-weight: 600; margin: 0 0 12px; }
/* Actions stay pinned to the bottom of a long panel, so Done/Back is always reachable. */
#dialog-actions {
  display: flex; flex-wrap: wrap; gap: 10px; margin: 20px -26px -22px; padding: 14px 26px 20px;
  position: sticky; bottom: -22px; background: linear-gradient(rgba(255,255,255,.92), #fff 30%); z-index: 1;
}
.panel.wide { width: min(940px, 100%); }
.panel.wide .shop { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
#dialog-actions .sticker { flex: 1 1 auto; justify-content: center; font-size: 17px; padding: .7em 1em; }
.lede { font-size: 17px; }

/* Results */
.result { display: grid; grid-template-columns: auto 1fr; gap: 22px; align-items: center; }
.polaroid { background: #fff; padding: 10px 10px 34px; border: 2px solid #d9dceb; box-shadow: 0 10px 24px rgba(33,29,69,.25); transform: rotate(-4deg); position: relative; margin: 6px 4px 10px; }
.polaroid canvas { display: block; width: 190px; height: 228px; background: #cdeefe; }
.polaroid figcaption { position: absolute; left: 0; right: 0; bottom: 6px; text-align: center; font-family: "Marker Felt", "Chalkboard SE", "Comic Sans MS", "Segoe Print", cursive; font-size: 19px; color: #3a3570; }
.stamp { position: absolute; right: -18px; top: -14px; background: var(--coral); color: #fff; border: var(--line) solid var(--ink); border-radius: 10px; padding: 4px 9px; font-weight: 900; font-size: 15px; transform: rotate(10deg); box-shadow: 0 3px 0 var(--ink); }
.big-height { font-size: 56px; font-weight: 900; line-height: 1; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.big-height small { font-size: 24px; margin-left: 4px; }
.stats { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 6px; }
.stats li { display: flex; justify-content: space-between; gap: 14px; font-weight: 700; border-bottom: 2px dashed #dcdff0; padding-bottom: 6px; }
.stats b { font-variant-numeric: tabular-nums; }

/* Shop */
.wallet { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }
.wallet p { margin: 0; font-size: 15px; opacity: .8; }
.shop { display: grid; gap: 10px; }
.item { display: grid; grid-template-columns: 46px 1fr auto; gap: 12px; align-items: center; border: 2px solid #dcdff0; border-radius: 16px; padding: 10px 10px 10px 12px; }
.item > svg { width: 46px; height: 46px; }
.item h3 { margin: 0; font-size: 17px; }
.item p { margin: 2px 0 6px; font-size: 14px; line-height: 1.35; font-weight: 600; opacity: .8; }
.pips { display: flex; gap: 4px; }
.pips i { width: 16px; height: 8px; border-radius: 4px; border: 2px solid var(--ink); background: #fff; }
.pips i.on { background: var(--mint); }
.item .sticker { font-size: 15px; padding: .5em .8em; white-space: nowrap; }
.item .sticker svg { width: 1.2em; height: 1.2em; }

/* Settings */
.setting { margin: 0 0 18px; }
.setting > span { display: block; font-weight: 800; margin-bottom: 8px; }
.segmented { display: flex; gap: 8px; flex-wrap: wrap; }
.segmented button { flex: 1 1 0; justify-content: center; font-size: 15px; flex-direction: column; gap: 1px; }
.segmented button small { font-weight: 700; opacity: .7; font-size: 12px; }
.segmented button[aria-pressed=true] { background: var(--sky); }
input[type=range] { width: 100%; accent-color: var(--coral); height: 30px; }
.fine { font-size: 13px !important; opacity: .7; }
.danger { background: #ffe1dc !important; }

/* How to play */
.steps { list-style: none; padding: 0; margin: 0 0 6px; display: grid; gap: 10px; counter-reset: step; }
.steps li { display: grid; grid-template-columns: 36px 1fr; gap: 12px; align-items: start; font-weight: 600; line-height: 1.45; }
.steps li::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--sun); border: var(--line) solid var(--ink); font-weight: 900; }
.keys { background: var(--mist); border-radius: 14px; padding: 12px 14px; font-size: 15px; }
kbd { display: inline-block; min-width: 1.7em; text-align: center; border: 2px solid var(--ink); border-bottom-width: 4px; border-radius: 7px; padding: 0 .35em; background: #fff; font: 800 13px/1.6 var(--font); }

#toast {
  position: fixed; left: 50%; top: calc(16px + var(--safe-t)); transform: translateX(-50%) translateY(-20px); z-index: 40;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700; opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%); }

/* Portrait and small screens: the title sits above the demo tower. */
@media (max-aspect-ratio: 1/1) {
  .banner { left: 50%; top: 74%; }
  .banner b { font-size: clamp(40px, 10vw, 72px); }
  .hero { max-width: none; margin: 4vh 0 auto; align-items: center; text-align: center; gap: 14px; }
  .logo { align-items: center; font-size: clamp(46px, 11vw, 92px); }
  .tagline { max-width: 34ch; }
  .menu-links, .records { justify-content: center; }
  .records p { background: rgba(255,255,255,.8); }
}
@media (max-width: 560px) {
  .result { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .panel { padding: 20px 18px 18px; }
  #dialog-actions { margin: 16px -18px -18px; padding: 12px 18px 16px; bottom: -18px; }
  .panel h2 { font-size: 27px; }
  .item { grid-template-columns: 36px 1fr; }
  .item > svg { width: 36px; height: 36px; }
  .item .sticker { grid-column: 1 / -1; justify-content: center; }
  .pad button { width: 76px; height: 80px; }
  .meter { min-width: 104px; }
  .club { font-size: 13px; }
}
@media (max-height: 520px) and (min-aspect-ratio: 1/1) {
  .hero { gap: 10px; }
  .logo { font-size: clamp(34px, 6vw, 56px); }
  .tagline { display: none; }
  .records { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .logo .lean { animation: none; }
  .banner.show { animation-duration: 3s; }
  .spinner { animation-duration: 3s; }
}
