:root {
  color-scheme: dark;
  --night: #141a3f;
  --dusk: #2c2656;
  --amber: #ffb44d;
  --amber-deep: #e58a2e;
  --wood: #9c5e2c;
  --wood-dark: #6b3d1c;
  --cream: #fff3dc;
  --ink: #3a2414;
  --pine: #2f7d62;
  --glass: rgba(20, 24, 58, 0.62);
  --display: "Grandstander", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --body: "Nunito", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--night); }
body { font-family: var(--body); color: var(--cream); user-select: none; -webkit-user-select: none; }

#app { position: fixed; inset: 0; }
#scene { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
button:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- HUD ---------- */
#hud {
  position: absolute; left: 0; right: 0; top: 0;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; gap: 12px;
  pointer-events: none;
}
#hud > * { pointer-events: auto; }

#progress { display: flex; gap: 6px; flex-wrap: wrap; padding-top: 8px; }
.pip {
  width: 22px; height: 22px; display: grid; place-items: center;
  clip-path: polygon(50% 0, 100% 42%, 100% 100%, 0 100%, 0 42%);
  background: rgba(255, 243, 220, 0.16);
  transition: background .4s, transform .4s;
}
.pip.done { background: var(--amber); }
.pip.now { background: var(--cream); transform: scale(1.18); }

#plaque {
  justify-self: center;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 22px 10px;
  border-radius: 12px;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0) 0 9px, rgba(0,0,0,.09) 9px 11px),
    linear-gradient(180deg, #b87238, var(--wood));
  box-shadow: inset 0 0 0 2px rgba(255, 220, 170, .25), 0 6px 0 var(--wood-dark), 0 10px 24px rgba(0,0,0,.35);
  color: var(--cream);
  text-align: center;
  transition: transform .5s cubic-bezier(.3,1.6,.5,1);
}
#plaque.bump { transform: scale(1.12) rotate(-2deg); }
#stageNum { font: 800 12px/1 var(--body); letter-spacing: .12em; text-transform: uppercase; opacity: .8; }
#stageName { font: 800 clamp(18px, 3.4vw, 26px)/1.15 var(--display); text-wrap: balance; text-shadow: 0 2px 0 rgba(60, 30, 10, .45); }

#tools { justify-self: end; display: flex; gap: 8px; }
.round {
  width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--glass); backdrop-filter: blur(6px);
  box-shadow: inset 0 0 0 1.5px rgba(255, 243, 220, .18);
}
.round:active { transform: scale(.92); }
#btnSound .mute { display: none; }
#btnSound[aria-pressed="false"] .wave { display: none; }
#btnSound[aria-pressed="false"] .mute { display: inline; }
#btnGfx[aria-pressed="true"] { background: var(--amber); color: var(--ink); }

/* ---------- hint ---------- */
#hint {
  position: absolute; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 96px);
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 8px 16px; border-radius: 999px;
  background: var(--glass); backdrop-filter: blur(6px);
  font-weight: 800; font-size: 15px; text-align: center;
  opacity: 0; transition: opacity .6s; pointer-events: none;
}
#hint.show { opacity: 1; }

/* ---------- tray ---------- */
#tray {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  display: flex; justify-content: center; gap: 12px;
  overflow-x: auto; scrollbar-width: none;
  background: linear-gradient(180deg, rgba(20,26,63,0) 0%, rgba(20,26,63,.55) 45%, rgba(20,26,63,.8) 100%);
  transition: transform .6s cubic-bezier(.5,0,.3,1);
}
#tray::-webkit-scrollbar { display: none; }
#tray.away { transform: translateY(110%); }

.card {
  position: relative; flex: 0 0 auto;
  width: 96px; height: 96px; border-radius: 22px;
  background:
    radial-gradient(circle at 50% 38%, #fffaf0 0%, #f6e3c2 70%);
  box-shadow: inset 0 -5px 0 rgba(160, 100, 50, .25), 0 6px 14px rgba(0,0,0,.35);
  touch-action: none;
  transition: transform .25s cubic-bezier(.3,1.6,.5,1), opacity .3s;
  animation: cardIn .45s cubic-bezier(.3,1.6,.5,1) both;
}
.card img { width: 100%; height: 100%; object-fit: contain; padding: 6px; pointer-events: none; -webkit-user-drag: none; }
.card .lbl { position: absolute; left: 0; right: 0; bottom: 6px; font: 800 11px/1 var(--body); color: var(--ink); text-align: center; }
.card .lbl.solo { top: 50%; transform: translateY(-50%); font-size: 14px; }
.card .n {
  position: absolute; top: -6px; right: -6px;
  min-width: 28px; height: 28px; padding: 0 7px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--amber); color: var(--ink);
  font: 800 15px/1 var(--display); font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 0 var(--amber-deep);
}
.card.holding { transform: scale(.88); opacity: .55; }
.card.locked { filter: grayscale(.8) brightness(.8); }
.card.wiggle { animation: wiggle .4s; }
.card.gone { transform: scale(0); opacity: 0; }
@keyframes cardIn { from { transform: translateY(40px) scale(.6); opacity: 0; } }
@keyframes wiggle { 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }

/* ---------- buttons ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px;
  background: var(--amber); color: var(--ink);
  font: 800 18px/1 var(--display);
  box-shadow: 0 5px 0 var(--amber-deep), 0 10px 22px rgba(0,0,0,.3);
}
.pill:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--amber-deep); }
.pill.big { padding: 16px 30px; font-size: 22px; }
.pill.big svg { width: 28px; height: 28px; }
.pill.ghost { background: rgba(255, 243, 220, .14); color: var(--cream); box-shadow: inset 0 0 0 2px rgba(255,243,220,.35); }
#btnPlay svg { fill: currentColor; }

#btnDone {
  position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 132px);
  animation: pop .5s cubic-bezier(.3,1.6,.5,1);
}
@keyframes pop { from { transform: scale(0); } }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 60%, rgba(20,26,63,.2), rgba(20,26,63,.75));
}
.overlay.soft { background: radial-gradient(ellipse at 50% 50%, rgba(20,26,63,0) 30%, rgba(20,26,63,.55)); }
.overlay[hidden] { display: none; }
.sign {
  width: min(460px, 100%);
  padding: 26px 24px 28px;
  border-radius: 26px;
  text-align: center;
  background:
    repeating-linear-gradient(0deg, rgba(0,0,0,0) 0 14px, rgba(0,0,0,.08) 14px 16px),
    linear-gradient(180deg, #bd7a3f, var(--wood));
  box-shadow: inset 0 0 0 3px rgba(255, 220, 170, .25), 0 8px 0 var(--wood-dark), 0 24px 60px rgba(0,0,0,.45);
  animation: pop .6s cubic-bezier(.3,1.5,.5,1);
}
.sign h1, .sign h2 {
  margin: 0 0 10px;
  font: 800 clamp(30px, 7vw, 44px)/1.05 var(--display);
  text-wrap: balance;
  text-shadow: 0 3px 0 rgba(60, 30, 10, .5);
}
.sign p { margin: 0 auto 22px; max-width: 34ch; font-size: 17px; line-height: 1.45; opacity: .95; }
.sign .row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- loader ---------- */
#loader {
  position: absolute; inset: 0; z-index: 10;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px;
  background: radial-gradient(ellipse at 50% 40%, var(--dusk), var(--night));
  transition: opacity .6s;
}
#loader img { width: min(180px, 40vw); height: auto; }
#loader .bar { width: min(220px, 60vw); height: 10px; border-radius: 5px; background: rgba(255,243,220,.15); overflow: hidden; }
#loader .bar i { display: block; height: 100%; width: 0; background: var(--amber); border-radius: 5px; transition: width .3s; }
#loader.out { opacity: 0; pointer-events: none; }

@media (max-width: 560px) {
  #hud { grid-template-columns: 1fr auto; }
  #progress { grid-column: 1 / -1; order: 3; justify-content: center; padding-top: 0; }
  #plaque { justify-self: start; }
  .pip { width: 18px; height: 18px; }
  #hint { top: calc(env(safe-area-inset-top, 0px) + 118px); font-size: 14px; }
  .card { width: 78px; height: 78px; border-radius: 18px; }
  #tray { justify-content: flex-start; gap: 10px; }
  #btnDone { bottom: calc(env(safe-area-inset-bottom, 0px) + 112px); }
  .round { width: 42px; height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
