:root {
  --cream: #fffaf0;
  --paper: #fff4e2;
  --ink: #5a3a22;
  --stitch: #e2c49a;
  --coral: #ff6b6b;
  --coral-d: #d9474f;
  --sun: #ffd23f;
  --font: "Baloo 2", "Fredoka", "Nunito", "Varela Round", ui-rounded, "Arial Rounded MT Bold", "Ubuntu", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f3e6d2; font-family: var(--font); color: var(--ink); }
body { touch-action: none; -webkit-user-select: none; user-select: none; }
#gl, #fx { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(70, 40, 10, 0.22) 100%); }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
[hidden] { display: none !important; }

button { font-family: var(--font); cursor: pointer; color: var(--ink); }

/* steps */
#steps {
  position: absolute; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px 10px; border-radius: 40px;
  background: rgba(255, 250, 240, 0.92); box-shadow: 0 4px 14px rgba(90, 50, 20, 0.18);
  outline: 2px dashed var(--stitch); outline-offset: -6px; pointer-events: none;
}
.step { display: flex; flex-direction: column; align-items: center; width: 62px; opacity: 0.4; transition: opacity 0.3s, transform 0.3s; }
.step svg { width: 30px; height: 30px; }
.step span { font-size: 13px; font-weight: 800; }
.step.done { opacity: 0.75; }
.step.now { opacity: 1; transform: scale(1.18); }

/* trays */
.tray {
  position: absolute; top: 100px; max-height: calc(100% - 210px); overflow-y: auto;
  background: var(--cream); border-radius: 26px; padding: 12px 14px 16px;
  box-shadow: 0 8px 26px rgba(90, 50, 20, 0.22);
  outline: 2.5px dashed var(--stitch); outline-offset: -7px;
  animation: slidein 0.45s cubic-bezier(.2,1.4,.4,1);
  scrollbar-width: thin;
}
#left { left: 18px; width: 236px; }
#right { right: 18px; width: 330px; }
@keyframes slidein { from { transform: translateY(24px) scale(0.94); opacity: 0; } to { transform: none; opacity: 1; } }
.tray h3 { margin: 6px 4px 6px; font-size: 16px; font-weight: 900; letter-spacing: 0.02em; }
.swatches { display: grid; grid-template-columns: repeat(3, 62px); gap: 8px; }
.swatch {
  width: 62px; height: 62px; border: none; padding: 0; background-size: cover; background-position: center;
  clip-path: polygon(0% 6%, 6% 0%, 12% 6%, 18% 0%, 24% 6%, 30% 0%, 36% 6%, 42% 0%, 48% 6%, 54% 0%, 60% 6%, 66% 0%, 72% 6%, 78% 0%, 84% 6%, 90% 0%, 96% 6%, 100% 0%, 100% 100%, 94% 94%, 88% 100%, 82% 94%, 76% 100%, 70% 94%, 64% 100%, 58% 94%, 52% 100%, 46% 94%, 40% 100%, 34% 94%, 28% 100%, 22% 94%, 16% 100%, 10% 94%, 4% 100%, 0% 94%);
  transition: transform 0.18s cubic-bezier(.2,1.6,.4,1), filter 0.2s;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.2));
}
.swatch:hover { transform: translateY(-3px) rotate(-2deg); }
.swatch.on { transform: scale(1.12) rotate(2deg); filter: drop-shadow(0 0 0 #fff) drop-shadow(0 4px 6px rgba(0,0,0,0.35)); }
.swatch.on::after { content: ""; }
.spools { display: grid; grid-template-columns: repeat(4, 46px); gap: 8px; }
.spool { width: 46px; height: 52px; border: none; background: none; padding: 0; transition: transform 0.18s cubic-bezier(.2,1.6,.4,1); }
.spool svg { width: 100%; height: 100%; }
.spool:hover { transform: translateY(-3px); }
.spool.on { transform: scale(1.18); }
.toggle {
  width: 62px; height: 52px; border-radius: 16px; border: 2px solid transparent; background: #fff;
  box-shadow: 0 2px 0 #ead6b8; padding: 4px; display: grid; place-items: center; margin: 0 4px;
  transition: transform 0.15s cubic-bezier(.2,1.6,.4,1), border-color 0.15s;
}
.toggle svg { width: 40px; height: 40px; }
.toggle:hover { transform: translateY(-2px) scale(1.05); }
.toggle.on { border-color: var(--coral); background: #fff3f0; transform: scale(1.08); }
.items { display: grid; grid-template-columns: repeat(6, 46px); gap: 5px; }
.item {
  width: 46px; height: 46px; border-radius: 14px; border: 2px solid transparent; background: #fff;
  box-shadow: 0 2px 0 #ead6b8; padding: 3px; display: grid; place-items: center;
  transition: transform 0.15s cubic-bezier(.2,1.6,.4,1), border-color 0.15s;
  touch-action: none;
}
.item img { width: 37px; height: 37px; pointer-events: none; }
.item:hover { transform: translateY(-2px) scale(1.05); }
.item.on { border-color: var(--coral); transform: scale(1.1); background: #fff3f0; }

/* bottom bar */
#bar {
  position: absolute; bottom: 20px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px; align-items: center; flex-wrap: nowrap;
}
#bar:empty { display: none; }
.big {
  font-size: 22px; font-weight: 900; padding: 12px 26px 13px; border-radius: 40px; border: none;
  background: var(--cream); box-shadow: 0 5px 0 #e2c49a, 0 10px 22px rgba(90, 50, 20, 0.22);
  transition: transform 0.12s, box-shadow 0.12s; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px;
}
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #e2c49a, 0 4px 10px rgba(90, 50, 20, 0.2); }
.big.primary, button.primary { background: var(--coral); color: #fff; box-shadow: 0 5px 0 var(--coral-d), 0 10px 22px rgba(160, 40, 40, 0.3); }
.big.primary:active { box-shadow: 0 1px 0 var(--coral-d); }
.big:disabled { opacity: 0.45; cursor: default; transform: none; }
.big.pulse:not(:disabled) { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.07); } }
.big svg { width: 26px; height: 26px; }
.mid { font-size: 17px; padding: 9px 18px 10px; }
.round {
  width: 52px; height: 52px; border-radius: 50%; border: none; background: var(--cream); padding: 9px;
  box-shadow: 0 4px 0 #e2c49a, 0 8px 18px rgba(90, 50, 20, 0.2); position: relative;
}
.round svg { width: 100%; height: 100%; }
#corner { position: absolute; top: 18px; right: 18px; display: flex; gap: 10px; }
#toybox b { position: absolute; right: -4px; top: -4px; background: var(--coral); color: #fff; font-size: 13px; border-radius: 12px; padding: 1px 7px; }
#sound .cross { display: none; }
#sound.off .cross { display: inline; }
#sound.off .waves { display: none; }

.namechip {
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; font-size: 20px; font-weight: 900;
  background: #fff; padding: 8px 10px 8px 18px; border-radius: 30px; box-shadow: 0 5px 0 #e2c49a, 0 10px 22px rgba(90,50,20,0.18);
  position: relative;
}
.namechip::before { content: ""; position: absolute; left: -9px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; background: #f3e6d2; box-shadow: inset 0 0 0 3px #e2c49a; }
.namechip button { border: none; background: #fff3d6; border-radius: 50%; width: 36px; height: 36px; padding: 6px; }
.namechip button svg { width: 100%; height: 100%; }

/* hint and bubble */
#hint {
  position: absolute; top: 108px; left: 50%; transform: translateX(-50%);
  background: #fff7c7; padding: 10px 20px; border-radius: 18px; font-size: 20px; font-weight: 800;
  box-shadow: 0 6px 16px rgba(90, 60, 10, 0.18); animation: bob 2.2s ease-in-out infinite; pointer-events: none; white-space: nowrap;
}
@keyframes bob { 0%, 100% { transform: translate(-50%, 0) rotate(-1deg); } 50% { transform: translate(-50%, -5px) rotate(1deg); } }
#bubble {
  position: absolute; left: 0; top: 0; background: #fff; padding: 10px 18px; border-radius: 22px; font-size: 22px; font-weight: 900;
  box-shadow: 0 8px 20px rgba(60, 30, 10, 0.22); pointer-events: none; white-space: nowrap; transform-origin: 50% 100%;
  animation: popin 0.35s cubic-bezier(.2,1.8,.4,1);
}
#bubble::after { content: ""; position: absolute; left: 50%; bottom: -12px; margin-left: -10px; border: 10px solid transparent; border-top-color: #fff; border-bottom: 0; }
@keyframes popin { from { transform: translate(-50%, -100%) scale(0.3); } to { transform: translate(-50%, -100%) scale(1); } }

/* title */
#title { position: absolute; inset: 0; display: grid; place-items: start center; padding-top: 4vh; background: radial-gradient(ellipse at 50% 50%, rgba(255, 244, 226, 0.25), rgba(80, 45, 15, 0.25)); pointer-events: none; }
#title .card { pointer-events: auto; }
.card {
  background: var(--cream); border-radius: 34px; padding: 26px 40px 30px; text-align: center;
  box-shadow: 0 18px 50px rgba(80, 40, 10, 0.3); outline: 3px dashed var(--stitch); outline-offset: -10px;
  animation: slidein 0.6s cubic-bezier(.2,1.4,.4,1);
  max-width: min(92vw, 560px);
}
#title .card { margin-top: 0; padding: 18px 34px 22px; }
#title h1 { font-size: clamp(44px, 6.4vw, 74px); }
#title .card p { margin: 4px 0 14px; }
h1 { font-size: clamp(48px, 8vw, 86px); margin: 0 0 4px; font-weight: 900; letter-spacing: 0.01em; line-height: 1.05; }
h1 span { display: inline-block; animation: jiggle 2.4s ease-in-out infinite; text-shadow: 0 4px 0 rgba(90, 50, 20, 0.18); }
h1 span:nth-child(1) { color: #ff6b6b; animation-delay: 0s; }
h1 span:nth-child(2) { color: #ff9f43; animation-delay: 0.08s; }
h1 span:nth-child(3) { color: #f5b700; animation-delay: 0.16s; }
h1 span:nth-child(4) { color: #3dbb6b; animation-delay: 0.24s; }
h1 span:nth-child(5) { color: #2f9fd6; animation-delay: 0.32s; }
h1 span:nth-child(6) { color: #7b5cf0; animation-delay: 0.4s; }
h1 span:nth-child(7) { color: #ff6fae; animation-delay: 0.48s; }
h1 span:nth-child(8) { color: #ff6b6b; animation-delay: 0.56s; }
h1 span:nth-child(9) { color: #ff9f43; animation-delay: 0.64s; }
h1 span:nth-child(10) { color: #3dbb6b; animation-delay: 0.72s; }
h1 span:nth-child(11) { color: #2f9fd6; animation-delay: 0.8s; }
@keyframes jiggle { 0%, 70%, 100% { transform: translateY(0) scale(1); } 80% { transform: translateY(-8px) scale(1.06, 0.94); } 90% { transform: translateY(0) scale(0.95, 1.05); } }
.card p { font-size: 21px; font-weight: 700; margin: 8px 0 20px; line-height: 1.35; }
.card em { font-style: normal; color: var(--coral); }
#title .big { margin: 4px 6px; }
h2 { margin: 2px 0 6px; font-size: 30px; font-weight: 900; }
.linkrow { display: flex; gap: 8px; margin: 10px 0; }
.linkrow input { flex: 1; font: 600 15px/1 ui-monospace, monospace; padding: 10px 12px; border-radius: 14px; border: 2px solid var(--stitch); background: #fff; color: var(--ink); min-width: 0; }
.linkrow button { border: none; border-radius: 14px; padding: 0 18px; font-size: 18px; font-weight: 900; }
.small { font-size: 16px !important; opacity: 0.85; }
#giftcard, #forgetcard { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(80, 45, 15, 0.3); }
#forgetcard .big { margin: 4px 6px; }
#forgetgo { color: #b0353d; }

/* zoom: + and - (pinch and the wheel do the same) */
#zoomctl { position: absolute; left: 18px; bottom: 22px; display: flex; gap: 8px; }
#zoomctl .round { width: 46px; height: 46px; padding: 8px; }

#ghost { position: fixed; left: 0; top: 0; width: 56px; height: 56px; pointer-events: none; transform: translate(-50%, -50%) scale(1.25); filter: drop-shadow(0 6px 6px rgba(0,0,0,0.3)); z-index: 10; }
#ghost img { width: 100%; height: 100%; }
.nogl { position: absolute; inset: 0; display: grid; place-items: center; font-size: 24px; font-weight: 800; padding: 40px; text-align: center; background: var(--paper); }

@media (max-width: 900px) {
  #left { width: 176px; }
  .swatches { grid-template-columns: repeat(2, 62px); }
  .spools { grid-template-columns: repeat(3, 46px); }
  #right { width: 232px; }
  .items { grid-template-columns: repeat(4, 46px); }
  .step { width: 48px; }
  .big { font-size: 18px; padding: 10px 18px; }
}
/* Phones and small windows: html.compact (with .portrait or .landscape), set by main.js. */
html.compact #steps { top: 8px; padding: 3px 6px; gap: 0; outline-offset: -4px; }
html.compact .step { width: 31px; }
html.compact .step span { display: none; }
html.compact .step svg { width: 23px; height: 23px; }
html.compact .step.now { transform: scale(1.12); }
html.compact.portrait #steps { left: 8px; transform: none; }
html.compact #corner { top: 8px; right: 8px; gap: 6px; }
html.compact .round { width: 40px; height: 40px; padding: 7px; box-shadow: 0 3px 0 #e2c49a, 0 6px 12px rgba(90, 50, 20, 0.18); }
html.compact #toybox b { font-size: 11px; padding: 0 5px; }
html.compact #hint { top: 56px; font-size: 15px; padding: 6px 12px; white-space: normal; width: max-content; max-width: 70vw; text-align: center; }
html.compact #bubble { font-size: 16px; padding: 7px 12px; }
html.compact #bar { bottom: calc(8px + env(safe-area-inset-bottom)); gap: 6px; flex-wrap: wrap; justify-content: center; width: max-content; max-width: 96vw; }
html.compact .big { font-size: 16px; padding: 8px 14px 9px; gap: 6px; box-shadow: 0 3px 0 #e2c49a, 0 6px 14px rgba(90, 50, 20, 0.2); }
html.compact .big.primary { box-shadow: 0 3px 0 var(--coral-d), 0 6px 14px rgba(160, 40, 40, 0.25); }
html.compact .big svg { width: 22px; height: 22px; }
html.compact .big.mid { padding: 8px 10px; }
html.compact .big.mid span, html.compact.portrait .big:not(.primary) span { display: none; }
html.compact.portrait .big:not(.primary) { padding: 8px 10px; }
html.compact .namechip { font-size: 15px; padding: 4px 5px 4px 14px; }
html.compact .namechip button { width: 30px; height: 30px; padding: 5px; }
html.compact #title { padding-top: 2vh; }
html.compact.portrait #title { padding-top: 56px; }
html.compact.landscape.playing #steps { display: none; }
html.compact #title .card { padding: 12px 20px 14px; }
html.compact #title h1 { font-size: clamp(34px, 9vw, 56px); }
html.compact .card p { font-size: 15px; margin: 4px 0 10px; }
html.compact h2 { font-size: 22px; }
html.compact #zoomctl { left: auto; right: 8px; bottom: auto; top: 104px; flex-direction: column; gap: 6px; }
html.compact #zoomctl .round { width: 38px; height: 38px; padding: 6px; }
html.compact.landscape #zoomctl { top: 8px; right: 100px; flex-direction: row; }
/* portrait: the trays become a sheet along the bottom, one sliding row per kind */
html.compact.portrait #left, html.compact.portrait #right { left: 8px; right: 8px; width: auto; }
html.compact.portrait .tray { top: auto; bottom: calc(64px + env(safe-area-inset-bottom)); max-height: 36vh; padding: 4px 8px 6px; border-radius: 20px; outline-offset: -5px; }
html.compact.portrait .tray h3 { font-size: 12px; margin: 5px 6px 1px; }
html.compact.portrait .swatches, html.compact.portrait .spools, html.compact.portrait .items { display: flex; overflow-x: auto; gap: 6px; padding: 4px 4px 6px; scrollbar-width: none; }
html.compact.portrait .swatch { flex: 0 0 auto; width: 46px; height: 46px; }
html.compact.portrait .spool { flex: 0 0 auto; width: 32px; height: 38px; }
html.compact.portrait .item { flex: 0 0 auto; width: 44px; height: 44px; }
html.compact.portrait .toggle { width: 50px; height: 42px; }
html.compact.portrait .toggle svg { width: 32px; height: 32px; }
/* landscape: narrow columns down the sides, between the top and bottom bars */
html.compact.landscape .tray { top: 52px; bottom: calc(60px + env(safe-area-inset-bottom)); max-height: none; padding: 4px 8px 6px; border-radius: 18px; outline-offset: -5px; }
html.compact.landscape #left { left: 8px; width: 132px; }
html.compact.landscape #right { right: 8px; width: 166px; }
html.compact.landscape .tray h3 { font-size: 12px; margin: 5px 2px 3px; }
html.compact.landscape .swatches { grid-template-columns: repeat(2, 50px); gap: 6px; }
html.compact.landscape .swatch { width: 50px; height: 50px; }
html.compact.landscape .spools { grid-template-columns: repeat(3, 32px); gap: 5px; }
html.compact.landscape .spool { width: 32px; height: 38px; }
html.compact.landscape .items { grid-template-columns: repeat(3, 44px); gap: 5px; }
html.compact.landscape .item { width: 44px; height: 44px; }
html.compact.landscape .toggle { width: 50px; height: 42px; }
html.compact.landscape .toggle svg { width: 32px; height: 32px; }

@media (prefers-reduced-motion: reduce) {
  h1 span, #hint, .big.pulse { animation: none !important; }
}
