:root {
  --plum: #2a1240; --plum2: #3d1d5c; --ink: #2a1240; --cream: #fff8ec; --tang: #ff8a1f; --tang2: #ffb54d;
  --teal: #19c3b4; --red: #ff4f6a; --green: #2fc46b; --sky: #7fd8ff;
  --emo: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", "Twemoji Mozilla", "EmojiOne Color", sans-serif;
  font-size: clamp(11px, min(2.1vh, 1.55vw) + 4px, 20px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #6fd8e0; }
body {
  font-family: "Trebuchet MS", "Segoe UI", "Helvetica Neue", Arial, system-ui, sans-serif; color: var(--ink);
  touch-action: manipulation; user-select: none; -webkit-user-select: none;
  background: #74dbe2 url(img/bg.jpg) center / cover no-repeat;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
kbd { display: inline-block; min-width: 1.5em; padding: .05em .35em; border-radius: .35em; background: #fff; color: var(--plum);
  border: 2px solid var(--plum); border-bottom-width: 3px; font-weight: 800; font-size: .78em; line-height: 1.3; font-family: inherit; text-align: center; }
.hide { display: none !important; }
body.atStart #play, body.atStart #party { visibility: hidden; }
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }

/* top bar */
#top { flex: 0 0 auto; height: 3rem; display: flex; align-items: center; gap: .5rem; padding: 0 .6rem; background: var(--plum);
  color: #fff; box-shadow: 0 .25rem 0 rgba(42,18,64,.25); position: relative; z-index: 5; }
.ib { width: 2.3rem; height: 2.3rem; border-radius: .8rem; display: grid; place-items: center; background: rgba(255,255,255,.12); color: #fff; flex: 0 0 auto; }
.ib:hover { background: rgba(255,255,255,.22); }
.ib svg { width: 1.35rem; height: 1.35rem; }
.ib.dark { background: var(--plum); color: #fff; font-weight: 900; }
.ib .slash { display: none; }
.ib.off .slash { display: inline; } .ib.off .wave { display: none; } .ib.off { opacity: .75; }
#where { flex: 1 1 auto; min-width: 0; display: flex; align-items: baseline; gap: .55rem; white-space: nowrap; overflow: hidden; }
#where b { font-size: 1.15rem; font-weight: 900; overflow: hidden; text-overflow: ellipsis; }
#where span { font-size: .9rem; opacity: .8; font-weight: 700; }
#bulbs { display: flex; align-items: center; gap: .25rem; background: var(--tang); color: var(--plum); border-radius: 2rem; padding: .2rem .7rem .2rem .45rem;
  font-weight: 900; font-size: 1.05rem; border: 2px solid #fff; }
#bulbs .bulb { font-family: var(--emo); font-size: 1.05rem; }
#bulbs.pop { animation: pop .45s; }
.tb { display: flex; gap: .35rem; }

/* play area */
#play, #party { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; align-items: center; padding: .5rem .75rem .6rem; gap: .45rem; }
#clue { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
#bubble, #pBubble { position: relative; background: #fff; border: .22rem solid var(--plum); border-radius: 1.6rem; padding: .35rem 1.6rem .45rem;
  box-shadow: .35rem .35rem 0 var(--plum); display: flex; flex-direction: column; align-items: center; max-width: 100%; max-height: 100%; }
#bubble::after, #pBubble::after { content: ""; position: absolute; left: 18%; bottom: -1.05rem; width: 1.4rem; height: 1.4rem; background: #fff;
  border-right: .22rem solid var(--plum); border-bottom: .22rem solid var(--plum); transform: skewX(30deg) rotate(45deg); }
#emo, #pEmo { font-family: var(--emo); line-height: 1.15; white-space: nowrap; letter-spacing: .06em; }
#emo.in { animation: drop .45s cubic-bezier(.3,1.6,.5,1); }
#chip, #pChip { font-size: .85rem; font-weight: 900; letter-spacing: .04em; text-transform: uppercase; color: #fff; background: var(--tang); border-radius: 1rem; padding: .1rem .7rem; }
#tip { margin: 0; font-size: .85rem; font-weight: 700; color: var(--plum); background: rgba(255,255,255,.7); border-radius: 1rem; padding: .1rem .7rem; text-align: center; }
#slots { display: flex; flex-direction: column; align-items: center; gap: var(--g, 6px); flex: 0 0 auto; }
.line { display: flex; gap: calc(var(--t) * .6); }
.word { display: flex; gap: var(--g, 5px); }
.slot { width: var(--t); height: var(--t); border-radius: calc(var(--t) * .2); background: rgba(255,255,255,.88); border: 3px dashed rgba(42,18,64,.45);
  display: grid; place-items: center; font-weight: 900; font-size: calc(var(--t) * .58); color: var(--plum); }
.slot.f { background: var(--cream); border: 3px solid var(--plum); box-shadow: 0 3px 0 var(--plum); cursor: pointer; }
.slot.lock { background: #c9f5e9; border-color: #148a6c; color: #0f6b54; cursor: default; }
.slot.bad { background: #ffd5db; border-color: var(--red); color: #b3132f; }
.slot.good { background: #d4f8c9; border-color: #239b4f; color: #17683a; animation: pop .4s; }
#slots.shake { animation: shake .4s; }
#bank { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--g, 6px); flex: 0 0 auto; }
.tile { width: var(--t); height: var(--t); border-radius: calc(var(--t) * .22); background: linear-gradient(#ffc463, var(--tang)); border: 3px solid var(--plum);
  box-shadow: 0 calc(var(--t) * .08) 0 var(--plum); font-weight: 900; font-size: calc(var(--t) * .56); color: var(--plum); display: grid; place-items: center;
  transition: transform .1s; }
.tile:active { transform: translateY(2px); }
.tile.used { visibility: hidden; }
.tile.gone { visibility: hidden; }
#acts { display: flex; gap: .5rem; flex: 0 0 auto; flex-wrap: nowrap; }
.act { display: flex; align-items: center; gap: .3rem; padding: .35rem .7rem; border-radius: 1rem; background: #fff; border: 3px solid var(--plum); box-shadow: 0 3px 0 var(--plum);
  font-weight: 900; font-size: .95rem; white-space: nowrap; }
.act .ai { font-family: var(--emo); }
.act .cost { font-size: .75rem; background: var(--plum); color: #fff; border-radius: .7rem; padding: 0 .4rem; font-family: inherit; }
.act:disabled { opacity: .45; cursor: default; }
.act:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--plum); }

/* overlays */
.ov { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; padding: .8rem; background: rgba(42,18,64,.55); }
#start { background: rgba(42,18,64,.25); }
body.atStart #top { position: relative; z-index: 21; } /* QA: top-bar buttons (help, music, sound) must stay clickable above the start overlay */
.panel { background: var(--cream); border: .25rem solid var(--plum); border-radius: 1.6rem; box-shadow: .45rem .45rem 0 var(--plum); padding: 1.1rem 1.3rem;
  max-height: 94vh; max-width: 96vw; display: flex; flex-direction: column; gap: .6rem; }
h1 { margin: 0; font-size: 2.6rem; line-height: 1; font-weight: 900; color: var(--plum); letter-spacing: -.01em; }
h1 span { color: var(--tang); -webkit-text-stroke: 2px var(--plum); paint-order: stroke fill; }
h2 { margin: 0; font-size: 1.6rem; font-weight: 900; }
.startp { flex-direction: row; align-items: center; gap: 1.4rem; width: 52rem; }
.sl { flex: 1 1 50%; display: flex; flex-direction: column; align-items: center; gap: .6rem; text-align: center; }
.sl .mascot { height: 11rem; width: auto; animation: bob 2.4s ease-in-out infinite; }
.intro { margin: .4rem 0 0; font-size: 1rem; line-height: 1.35; font-weight: 600; }
.sr { flex: 1 1 50%; display: flex; flex-direction: column; gap: .55rem; align-items: stretch; }
.btn { border-radius: 1.1rem; padding: .55rem 1rem; font-weight: 900; font-size: 1.05rem; border: 3px solid var(--plum); box-shadow: 0 4px 0 var(--plum); background: #fff; }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--plum); }
.btn.go { background: linear-gradient(#3fe0c9, var(--teal)); color: var(--plum); }
.btn.big { font-size: 1.7rem; padding: .7rem 1rem; }
.btn kbd { font-size: .7em; margin-left: .3em; }
.row3 { display: flex; gap: .45rem; } .row3 .btn { flex: 1 1 0; padding: .5rem .3rem; font-size: .95rem; }
.sub { font-size: .85rem; font-weight: 700; opacity: .8; text-align: center; margin: 0; }
.keys { display: flex; flex-wrap: wrap; gap: .3rem .8rem; justify-content: center; font-size: .8rem; font-weight: 700; }
.streak { text-align: center; font-weight: 900; font-size: .9rem; color: #c4561a; min-height: 1em; }
.packsp { width: 50rem; }
.ph { display: flex; justify-content: space-between; align-items: center; }
.scroll { overflow-y: auto; min-height: 0; flex: 1 1 auto; -webkit-overflow-scrolling: touch; }
#packGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10.5rem, 1fr)); gap: .55rem; padding: .2rem .3rem .5rem .1rem; }
.pk { position: relative; display: flex; align-items: center; gap: .5rem; padding: .5rem .6rem; border-radius: 1rem; border: 3px solid var(--plum); box-shadow: 0 3px 0 var(--plum);
  background: #fff; text-align: left; }
.pk .pi { font-family: var(--emo); font-size: 1.7rem; width: 2.4rem; height: 2.4rem; border-radius: .8rem; display: grid; place-items: center; flex: 0 0 auto; }
.pk b { display: block; font-size: .95rem; line-height: 1.1; }
.pk small { display: block; font-weight: 700; font-size: .75rem; opacity: .75; }
.pk .pb { height: .35rem; border-radius: .2rem; background: #eadff3; margin-top: .2rem; overflow: hidden; }
.pk .pb i { display: block; height: 100%; background: var(--green); }
.pk .badge { position: absolute; top: -.6rem; right: .4rem; background: var(--red); color: #fff; font-size: .65rem; font-weight: 900; border-radius: .6rem; padding: .05rem .45rem; border: 2px solid var(--plum); }
.pk.done { background: #eafbe9; }
.solp { flex-direction: row; align-items: center; gap: 1rem; width: 30rem; }
.solp .mascot.sm { height: 8rem; animation: wiggle .6s ease-in-out 2; }
.sc { flex: 1; display: flex; flex-direction: column; gap: .35rem; align-items: center; text-align: center; }
#solEmo { font-family: var(--emo); font-size: 2.2rem; }
.ans { margin: 0; font-size: 1.5rem; font-weight: 900; color: var(--tang); -webkit-text-stroke: 1px var(--plum); letter-spacing: .03em; }
.donep { width: 32rem; align-items: center; text-align: center; }
.donep p { margin: 0; font-weight: 700; }
#grid { font-family: var(--emo); font-size: 2rem; letter-spacing: .15em; }
#shareBox textarea { width: 100%; font-weight: 700; font-size: .9rem; line-height: 1.3; font-family: inherit; border: 2px solid var(--plum); border-radius: .6rem; padding: .3rem; resize: none; }
#shareBox { width: 100%; }
.foot { width: 100%; }
.helpp { width: 40rem; }
.helpp ul { margin: 0; padding-left: 1.2rem; line-height: 1.45; font-size: .95rem; }
.helpp li { margin-bottom: .35rem; }
#toast { position: fixed; left: 50%; top: 3.6rem; transform: translateX(-50%) translateY(-1rem); background: var(--plum); color: #fff; font-weight: 900; padding: .4rem 1rem; border-radius: 1rem;
  opacity: 0; pointer-events: none; transition: .25s; z-index: 30; white-space: nowrap; font-size: .95rem; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 25; overflow: hidden; }
.cf { position: absolute; width: .6rem; height: .9rem; border-radius: .15rem; animation: fall 1.3s ease-in forwards; }

/* party */
#pScores { width: 100%; display: flex; align-items: center; gap: .6rem; flex: 0 0 auto; }
.team { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; padding: .3rem .9rem; border-radius: 1rem; border: 3px solid var(--plum); box-shadow: 0 3px 0 var(--plum); font-weight: 900; }
.team b { font-size: 1.6rem; line-height: 1; } .team i { font-style: normal; font-size: .7rem; opacity: .8; } .team span { font-size: .85rem; }
.team.t1 { background: #ffd28c; } .team.t2 { background: #a7ecff; }
.team.pop { animation: pop .4s; }
#pTimer { flex: 1; height: 1.5rem; background: #fff; border: 3px solid var(--plum); border-radius: 1rem; position: relative; overflow: hidden; }
#pBar { position: absolute; inset: 0; background: linear-gradient(90deg, var(--teal), #8ff0d8); transform-origin: left; }
#pBar.low { background: var(--red); }
#pSec { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 900; font-size: .9rem; }
#pClue { flex: 1 1 auto; min-height: 0; width: 100%; display: flex; align-items: center; justify-content: center; }
#pPat { font-weight: 900; letter-spacing: .25em; font-size: 1.2rem; margin-top: .3rem; }
#pAns { font-weight: 900; font-size: 2rem; color: var(--tang); -webkit-text-stroke: 1px var(--plum); margin-top: .2rem; text-align: center; }
#pBtns { display: flex; gap: .7rem; flex: 0 0 auto; }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0); } 20% { transform: translateX(-10px); } 40% { transform: translateX(9px); } 60% { transform: translateX(-6px); } 80% { transform: translateX(4px); } }
@keyframes drop { 0% { transform: scale(.4) translateY(-30px); opacity: 0; } 100% { transform: none; opacity: 1; } }
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-8px) rotate(2deg); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-8deg); } 75% { transform: rotate(8deg); } }
@keyframes fall { 0% { transform: translateY(0) rotate(0); opacity: 1; } 100% { transform: translateY(var(--dy)) translateX(var(--dx)) rotate(540deg); opacity: 0; } }

/* small frames */
@media (max-height: 560px) {
  #top { height: 2.6rem; }
  .startp { width: 46rem; padding: .8rem 1rem; }
  .sl .mascot { height: 7.5rem; }
  h1 { font-size: 2.1rem; }
  .btn.big { font-size: 1.4rem; padding: .5rem; }
  .solp .mascot.sm { height: 5.5rem; }
  #play { padding-top: .35rem; gap: .3rem; }
}
@media (max-height: 420px) {
  .sl .mascot { height: 5.5rem; }
  .intro { font-size: .85rem; }
  h1 { font-size: 1.8rem; }
  .startp { gap: .9rem; }
  #tip { display: none; }
  .panel { padding: .7rem .9rem; gap: .45rem; }
  .solp .mascot.sm { height: 4.5rem; }
}
@media (max-width: 640px) and (orientation: portrait) {
  .startp { flex-direction: column; width: 100%; gap: .8rem; }
  .sl .mascot { height: 9rem; }
  h1 { font-size: 2.3rem; }
  .solp { width: 100%; }
  #where span { display: none; }
  .act { padding: .35rem .45rem; font-size: .85rem; }
  .act .cost { display: none; }
  #pScores .team { padding: .3rem .5rem; }
  .row3 { flex-wrap: wrap; } .row3 .btn { flex: 1 1 40%; }
}
@media (max-width: 380px) { .act .at { display: none; } }
.btn:disabled { opacity: .5; cursor: default; }
