/* Whack-a-Ghost: Nightmare Edition. Older-Android-friendly CSS: no inset, no gap, no custom properties. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #06020f; color: #fff; font-family: "Chalkboard SE","Comic Sans MS","Marker Felt","Arial Rounded MT Bold","Trebuchet MS",Arial,sans-serif; font-weight: 900;
  overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: default;
}
img, svg { -webkit-user-drag: none; user-drag: none; }
#app { position: fixed; top: 0; right: 0; bottom: 0; left: 0; overflow: hidden; }
#scene { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#ambient, #title, .hud, #big, #celebrate, #fx, #diag, #pops, #lightning { pointer-events: none; }

/* ---------- scene animation ---------- */
#stars circle { animation: twinkle 3s ease-in-out infinite; }
@keyframes twinkle { 0%,100% { opacity: .2; } 50% { opacity: 1; } }
.cloud { animation: drift 80s linear infinite; }
.c2 { animation-duration: 100s; animation-delay: -40s; } .c3 { animation-duration: 130s; animation-delay: -70s; }
@keyframes drift { from { transform: translateX(-700px); } to { transform: translateX(900px); } }
.win { animation: windowGlow 2.6s ease-in-out infinite; }
.w2 { animation-delay: -1.1s; } .w3 { animation-delay: -2.2s; } .w4 { animation-delay: -.6s; }
@keyframes windowGlow { 0%,100% { opacity: 1; } 40% { opacity: .55; } 55% { opacity: .9; } 70% { opacity: .35; } }
.eyes { animation: blink 6s steps(1, end) infinite; }
.e2 { animation-delay: -3s; animation-duration: 8s; }
@keyframes blink { 0%,86% { opacity: 1; } 88% { opacity: 0; } 92% { opacity: 1; } 94% { opacity: 0; } 96%,100% { opacity: 1; } }

#ambient { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; }
.fog { position: absolute; left: -50%; width: 200%; border-radius: 50%; background: radial-gradient(ellipse at center, rgba(150,200,170,.22), rgba(150,200,170,0) 68%); animation: fogMove 50s linear infinite; }
.fog1 { top: 60%; height: 28%; } .fog2 { top: 72%; height: 24%; animation-duration: 70s; animation-direction: reverse; } .fog3 { top: 38%; height: 22%; animation-duration: 90s; opacity: .5; }
@keyframes fogMove { from { transform: translateX(-12%); } to { transform: translateX(12%); } }
.bat { position: absolute; width: 6vw; height: 3vw; left: -10vw; animation: batFly 18s linear infinite; }
.bat .wing { transform-box: fill-box; animation: flap .22s ease-in-out infinite alternate; }
.bat .wl { transform-origin: 100% 50%; } .bat .wr { transform-origin: 0% 50%; }
@keyframes flap { from { transform: scaleY(1); } to { transform: scaleY(.3); } }
@keyframes batFly { 0% { transform: translate(0,0); } 25% { transform: translate(35vw,-5vh); } 50% { transform: translate(70vw,4vh); } 75% { transform: translate(105vw,-4vh); } 100% { transform: translate(125vw,2vh); } }
.b1 { top: 14%; } .b2 { top: 40%; animation-duration: 24s; animation-delay: -8s; width: 4vw; height: 2vw; } .b3 { top: 26%; animation-duration: 16s; animation-delay: -12s; } .b4 { top: 60%; animation-duration: 30s; animation-delay: -18s; width: 3.5vw; height: 1.75vw; }
.dghost { position: absolute; width: 6vh; height: 7.8vh; opacity: .38; left: -12vw; filter: drop-shadow(0 0 1vh rgba(140,255,160,.6)); animation: ghostFloat 44s linear infinite; }
.dg1 { top: 30%; } .dg2 { top: 55%; animation-duration: 58s; animation-delay: -20s; } .dg3 { top: 18%; animation-duration: 50s; animation-delay: -34s; animation-direction: reverse; }
@keyframes ghostFloat { 0% { transform: translate(0,0) rotate(-4deg); } 25% { transform: translate(28vw,-3vh) rotate(4deg); } 50% { transform: translate(60vw,2vh) rotate(-4deg); } 75% { transform: translate(92vw,-3vh) rotate(4deg); } 100% { transform: translate(120vw,0) rotate(-4deg); } }
#lightning { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: #cfe0ff; opacity: 0; animation: flash 11s linear infinite; }
@keyframes flash { 0%,93%,100% { opacity: 0; } 93.4% { opacity: .35; } 93.8% { opacity: .05; } 94.3% { opacity: .5; } 96% { opacity: 0; } }

/* ---------- title + HUD ---------- */
#title { position: absolute; top: 2vh; left: 0; right: 0; text-align: center; animation: bob 4s ease-in-out infinite; transition: opacity .4s; }
#title h1 { margin: 0; font-size: 11vh; line-height: 1.05; letter-spacing: .05em; color: #7dff6b; -webkit-text-stroke: .8vh #0d0320; paint-order: stroke fill; text-shadow: 0 .8vh 0 #3a0f66, 0 0 4vh rgba(125,255,107,.8); }
#title p { margin: .8vh 0 0; font-size: 3.6vh; letter-spacing: .5em; color: #ff7a2b; -webkit-text-stroke: .35vh #0d0320; paint-order: stroke fill; text-shadow: 0 0 2vh rgba(255,122,43,.9); }
body[data-state="PLAYING"] #title { opacity: 0; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(1vh); } }
.hud { position: absolute; opacity: 0; transition: opacity .3s; text-align: center; }
body[data-state="PLAYING"] .hud, body[data-state="VICTORY"] #score { opacity: 1; }
#score { left: 1.5vw; top: 1.5vh; min-width: 14vw; padding: .8vh 1.2vw 1vh; border: .5vh solid #7dff6b; border-radius: 2vh; background: rgba(10,2,24,.7); box-shadow: 0 0 2.4vh rgba(125,255,107,.5); }
#score .lbl { display: block; font-size: 2.4vh; letter-spacing: .25em; color: #7dff6b; }
#scoreNum { display: block; font-size: 8vh; line-height: 1; color: #fff; text-shadow: 0 0 1.6vh #7dff6b; }
#scoreNum.bump { animation: bump .22s ease-out; }
@keyframes bump { 0% { transform: scale(1.3); color: #ffd34d; } 100% { transform: scale(1); } }
#combo { display: block; min-height: 3.4vh; font-size: 3vh; color: #ff7a2b; text-shadow: 0 0 1.4vh #ff3b1c; }
#timer { right: 7vw; top: 1.5vh; min-width: 11vw; padding: .6vh 1vw; border: .5vh solid #ff7a2b; border-radius: 2vh; background: rgba(10,2,24,.7); box-shadow: 0 0 2.4vh rgba(255,122,43,.5); font-size: 9vh; line-height: 1.1; color: #fff; text-shadow: 0 0 1.6vh #ff7a2b; }
#timer.low { color: #ff3b3b; animation: pulse .45s ease-in-out infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
/* Countdown + end screen: one centered, self-spacing stack so lines can never overlap. */
#big { position: absolute; z-index: 10; left: 50%; top: 50%; transform: translate(-50%,-50%); display: none; max-width: 96vw; text-align: center; white-space: nowrap; }
body[data-state="COUNTDOWN"] #big, body[data-state="VICTORY"] #big { display: block; }
body[data-state="VICTORY"] #big { padding: 2.6vh 4vw 3vh; border: .7vh solid #7dff6b; border-radius: 4vh; background: rgba(8,2,20,.92); box-shadow: 0 0 5vh rgba(125,255,107,.55); }
#big div { display: block; line-height: 1.15; }
#big div:empty { display: none; }
#bigMain { font-size: 24vh; color: #7dff6b; -webkit-text-stroke: 1vh #0d0320; paint-order: stroke fill; text-shadow: 0 1.2vh 0 #3a0f66, 0 0 6vh rgba(125,255,107,.9); }
#bigMain.pop { animation: bigPop .7s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes bigPop { 0% { transform: scale(.2) rotate(-8deg); opacity: 0; } 55% { transform: scale(1.18) rotate(3deg); opacity: 1; } 100% { transform: scale(1) rotate(0); opacity: 1; } }
body[data-state="VICTORY"] #bigMain { font-size: 15vh; color: #ff7a2b; text-shadow: 0 1vh 0 #3a0f66, 0 0 5vh rgba(255,122,43,.9); }
#bigSub { margin-top: 1.4vh; font-size: 6vh; letter-spacing: .08em; color: #7dff6b; text-shadow: 0 0 2.4vh rgba(125,255,107,.9); }
#bigScore { margin-top: 2.4vh; font-size: 8vh; color: #fff; text-shadow: 0 0 2vh #b86bff, 0 .4vh 0 #3a0f66; }
#bigTier { margin-top: 1vh; font-size: 4.6vh; letter-spacing: .12em; color: #ffd34d; text-shadow: 0 0 1.6vh #ff7a2b; }
#bigNew { margin-top: 1.6vh; font-size: 5vh; color: #ffd34d; text-shadow: 0 0 2vh #ff3b1c; animation: pulse .5s ease-in-out infinite alternate; }

/* ---------- start screen: two compact boards above the two mode buttons ---------- */
/* The menu is one flex column, so the boards and buttons are spaced by the layout and can never overlap. */
#menu { position: absolute; left: 0; right: 0; top: 20vh; bottom: 3vh; display: none; flex-direction: column; justify-content: space-evenly; align-items: center; pointer-events: none; }
body[data-state="ATTRACT"] #menu { display: flex; }
#boards { display: flex; justify-content: center; align-items: flex-start; width: 100%; min-height: 0; }
.board { width: 38vw; margin: 0 1vw; padding: .8vh 1.6vw 1vh; border: .5vh solid #7dff6b; border-radius: 2.4vh; background: rgba(8,2,20,.8); box-shadow: 0 0 2.6vh rgba(125,255,107,.4); overflow: hidden; }
.board.bd2 { border-color: #ff7a2b; box-shadow: 0 0 2.6vh rgba(255,122,43,.4); }
.board h2 { margin: 0 0 .4vh; text-align: center; font-size: 3.2vh; letter-spacing: .14em; color: #7dff6b; text-shadow: 0 0 1.4vh rgba(125,255,107,.8); }
.board.bd2 h2 { color: #ff7a2b; text-shadow: 0 0 1.4vh rgba(255,122,43,.8); }
.board ol { list-style: none; margin: 0; padding: 0; }
.board li { display: flex; justify-content: space-between; align-items: baseline; font-size: 3.1vh; line-height: 1.25; color: #fff; }
.board .rk { width: 4vh; color: #b8a8e0; }
.board .in { flex: 1; letter-spacing: .25em; text-align: center; }
.board .sc { min-width: 9vh; text-align: right; color: #ffd34d; }
.board li.first .in, .board li.first .sc { color: #ffd34d; text-shadow: 0 0 1.4vh #ff7a2b; }
.board li.me { animation: pulse .45s ease-in-out infinite alternate; text-shadow: 0 0 2vh #7dff6b; }
.board .empty { display: block; text-align: center; color: #b8a8e0; font-size: 2.8vh; line-height: 1.5; }

/* ---------- initials entry ---------- */
#entry { position: absolute; left: 0; right: 0; top: 5vh; text-align: center; display: none; }
body[data-state="ENTRY"] #entry { display: block; }
body[data-state="ENTRY"] #title, body[data-state="ENTRY"] .hud { opacity: 0; }
#entry h2 { margin: 0; font-size: 9vh; line-height: 1.15; color: #ffd34d; -webkit-text-stroke: .6vh #0d0320; paint-order: stroke fill; text-shadow: 0 0 3vh #ff7a2b; }
#entryScore { margin: .6vh 0 0; font-size: 6vh; color: #fff; text-shadow: 0 0 2vh #b86bff; }
#entrySlots { margin-top: 2vh; }
#entrySlots span { display: inline-block; width: 11vh; height: 13vh; margin: 0 1vw; border: .6vh solid #7dff6b; border-radius: 2vh; background: rgba(8,2,20,.8); font-size: 10vh; line-height: 12vh; color: #fff; text-shadow: 0 0 2vh #7dff6b; box-shadow: 0 0 2vh rgba(125,255,107,.5); }
#entrySlots span.cur { border-color: #ffd34d; box-shadow: 0 0 3vh #ffd34d; }
#entryHint { margin: 1.4vh 0 1vh; font-size: 3.6vh; letter-spacing: .15em; color: #7dff6b; }
#kbd .row { margin-bottom: 1.2vh; }
#kbd button { display: inline-block; width: 6.4vw; height: 8.6vh; margin: 0 .35vw; padding: 0; font: inherit; font-size: 5vh; color: #fff; background: #2a0b52; border: .4vh solid #b86bff; border-radius: 1.4vh; cursor: pointer; touch-action: none; }
#kbd button:active { background: #5a1fa0; }
#kbd button.wide { width: 11vw; }
#kbd button.ok { background: #1f7a2e; border-color: #7dff6b; }

/* ---------- play field + ghosts ---------- */
#field { position: absolute; top: 0; left: 0; width: 100%; height: 100%; touch-action: none; }
body:not([data-state="PLAYING"]) #field { pointer-events: none; }
.gh { position: absolute; left: 0; top: 0; width: 8.4vh; height: 10.9vh; opacity: 0; pointer-events: none; will-change: transform, opacity; display: none; }
.gh svg { width: 100%; height: 100%; display: block; overflow: visible; filter: drop-shadow(0 0 1.2vh rgba(150,255,190,.95)); }
.gh.t1 svg { filter: drop-shadow(0 0 1.2vh rgba(80,255,120,.95)) hue-rotate(70deg) saturate(2); }
.gh.t2 svg { filter: drop-shadow(0 0 1.6vh rgba(255,200,60,1)) sepia(1) saturate(4); }
.gh.hit svg { filter: drop-shadow(0 0 2vh #fff) brightness(2); }
.gh .f0, .gh .f1 { display: none; }
.gh[data-face="0"] .f0, .gh[data-face="1"] .f1 { display: inline; }
#pops { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; }
.wpop { position: absolute; font-size: 5.4vh; color: #ffd34d; -webkit-text-stroke: .4vh #1a0630; paint-order: stroke fill; text-shadow: 0 0 1.6vh #ff7a2b; white-space: nowrap; animation: popUp .8s ease-out forwards; }
@keyframes popUp { 0% { transform: translate(-50%,-30%) scale(.5); opacity: 1; } 30% { transform: translate(-50%,-90%) scale(1.2); } 100% { transform: translate(-50%,-220%) scale(1); opacity: 0; } }

/* Mode picker (inside #menu) */
#modes { width: 94vw; text-align: center; white-space: nowrap; pointer-events: none; }
#start, #start2 { display: inline-block; vertical-align: middle; width: 42vw; height: 17vh; margin: 0 1.2vw; padding: 0; border: .9vh solid #7dff6b; border-radius: 4vh; font: inherit; color: #fff; cursor: pointer; touch-action: none; pointer-events: auto;
  background: linear-gradient(#2a0b52, #12042a 70%); box-shadow: 0 0 5vh 1vh rgba(125,255,107,.7), inset 0 0 3vh rgba(125,255,107,.4); text-shadow: 0 0 2.4vh #7dff6b; animation: startPulse 1.1s ease-in-out infinite; }
#start2 { border-color: #ff7a2b; box-shadow: 0 0 5vh 1vh rgba(255,122,43,.7), inset 0 0 3vh rgba(255,122,43,.4); text-shadow: 0 0 2.4vh #ff7a2b; animation-delay: -.55s; }
#start span, #start2 span { display: block; font-size: 8vh; line-height: 1.05; letter-spacing: .05em; -webkit-text-stroke: .5vh #0d0320; paint-order: stroke fill; }
#start small, #start2 small { display: block; margin-top: .4vh; font-size: 3.2vh; letter-spacing: .3em; color: #ffd34d; text-shadow: 0 0 1.4vh #ff7a2b; }
@keyframes startPulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.04); } }
#start:active, #start2:active { filter: brightness(1.3); }

#fx { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
#celebrate { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; }
.cg { position: absolute; bottom: -22vh; width: 12vh; height: 15.6vh; animation: riseUp 3.6s ease-out forwards; filter: drop-shadow(0 0 1.5vh rgba(150,255,190,.9)); }
@keyframes riseUp { 0% { transform: translateY(0) rotate(-8deg); opacity: 1; } 50% { transform: translateY(-60vh) rotate(8deg); } 100% { transform: translateY(-110vh) rotate(-8deg); opacity: .9; } }
#diag { position: absolute; left: 1vw; bottom: 1vh; margin: 0; padding: 1vh 1.2vw; font: 700 2vh/1.4 monospace; background: rgba(0,0,0,.7); color: #7dff9e; border-radius: 1vh; z-index: 20; }
#diag[hidden] { display: none; }

/* Booth-operator full-screen control: unlabeled purple box, top-right corner. Hidden once full screen. */
#fs { position: absolute; top: 1vh; right: 1vw; width: 4.5vh; height: 4.5vh; padding: 0; margin: 0; background: #8a3fe0; border: .3vh solid #c9a0ff; border-radius: .8vh; opacity: .75; cursor: pointer; touch-action: none; z-index: 6; }
body.is-fs #fs, body.no-fs #fs { display: none; }
body[data-state="PLAYING"] .dghost { display: none; }

/* Distraction witches: flying decoration only. They never receive touches (taps pass through to the field). */
#witches { position: absolute; top: 0; left: 0; width: 100%; height: 100%; overflow: hidden; pointer-events: none; z-index: 5; }
.witch { position: absolute; left: 0; top: 0; width: 27vh; height: 16.9vh; display: none; pointer-events: none; will-change: transform; filter: drop-shadow(0 0 1.4vh rgba(184,107,255,.9)); }
.witch svg { width: 100%; height: 100%; display: block; overflow: visible; pointer-events: none; }

/* ---------- two-player head to head ---------- */
#halves { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; display: none; }
body[data-mode="2"][data-state="COUNTDOWN"] #halves, body[data-mode="2"][data-state="PLAYING"] #halves { display: block; }
#halves i { position: absolute; top: 0; height: 100%; display: block; }
#half1 { left: 0; width: 50%; background: linear-gradient(90deg, rgba(125,255,107,.10), rgba(125,255,107,.02)); }
#half2 { left: 50%; width: 50%; background: linear-gradient(270deg, rgba(255,122,43,.10), rgba(255,122,43,.02)); }
#divider { left: 50%; width: .7vh; transform: translateX(-50%); background: linear-gradient(#b86bff, #fff, #b86bff); box-shadow: 0 0 3vh #b86bff; opacity: .85; }
#score2 { display: none; right: 6vw; top: 1.5vh; min-width: 14vw; padding: .8vh 1.2vw 1vh; border: .5vh solid #ff7a2b; border-radius: 2vh; background: rgba(10,2,24,.7); box-shadow: 0 0 2.4vh rgba(255,122,43,.5); }
body[data-mode="2"] #score2 { display: block; }
#score2 .lbl { display: block; font-size: 2.4vh; letter-spacing: .25em; color: #ff7a2b; }
#scoreNum2 { display: block; font-size: 8vh; line-height: 1; color: #fff; text-shadow: 0 0 1.6vh #ff7a2b; }
#scoreNum2.bump { animation: bump .22s ease-out; }
#combo2 { display: block; min-height: 3.4vh; font-size: 3vh; color: #7dff6b; text-shadow: 0 0 1.4vh #3acc2c; }
body[data-mode="2"] #timer { right: auto; left: 50%; margin-left: -5.5vw; }
body[data-state="PLAYING"] #score2, body[data-state="VICTORY"] #score2 { opacity: 1; }
.gh.s1.t0 svg { filter: drop-shadow(0 0 1.2vh rgba(255,150,70,.95)); }
body[data-mode="2"] #bigMain { font-size: 12vh; }
body[data-mode="2"][data-state="COUNTDOWN"] #bigMain { font-size: 24vh; }
body[data-mode="2"] #entry h2 { font-size: 7vh; }

/* ---------- two-player victory: the winner's half lights up, the other half dims ---------- */
#wins { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; display: none; }
body[data-state="VICTORY"][data-winner] #wins { display: block; }
#wins > div { position: absolute; top: 0; width: 50%; height: 100%; overflow: hidden; display: none; text-align: center; }
#w0 { left: 0; } #w1 { right: 0; }
body[data-winner="0"] #w0, body[data-winner="1"] #w1, body[data-winner="tie"] #w0, body[data-winner="tie"] #w1 { display: block; background: radial-gradient(ellipse at 50% 38%, rgba(255,236,150,.62), rgba(255,180,50,.32) 48%, rgba(255,120,0,.08) 80%); box-shadow: inset 0 0 9vh 2.5vh rgba(255,215,90,.85); animation: winPulse .7s ease-in-out infinite alternate; }
@keyframes winPulse { from { filter: brightness(1); } to { filter: brightness(1.35); } }
#wins > div::before { content: ""; position: absolute; left: 50%; top: 38%; width: 190vh; height: 190vh; margin: -95vh 0 0 -95vh; border-radius: 50%;
  background: repeating-conic-gradient(rgba(255,244,190,.55) 0deg 7deg, rgba(255,244,190,0) 7deg 22deg);
  -webkit-mask-image: radial-gradient(circle, #000 12%, transparent 66%); mask-image: radial-gradient(circle, #000 12%, transparent 66%);
  animation: raySpin 7s linear infinite; }
@keyframes raySpin { to { transform: rotate(360deg); } }
#wins b { position: absolute; left: 0; right: 0; bottom: 4vh; font-size: 12vh; line-height: 1; color: #fff7c8; -webkit-text-stroke: .8vh #8a4a00; paint-order: stroke fill; text-shadow: 0 0 4vh #ffd34d, 0 0 9vh #ff9a00; animation: winBounce .5s ease-in-out infinite alternate; }
body[data-winner="tie"] #wins b { display: none; }
@keyframes winBounce { from { transform: scale(1); } to { transform: scale(1.1); } }
/* the half that did not win goes dark */
body[data-winner="0"] #w1, body[data-winner="1"] #w0 { display: block; background: rgba(4,1,12,.6); }
body[data-winner="0"] #w1::before, body[data-winner="1"] #w0::before, body[data-winner="0"] #w1 b, body[data-winner="1"] #w0 b { display: none; }

/* A miss briefly locks that player's taps: flash their area red so it is clear why. */
#field.lock0, #field.lock1 { transition: none; }
#field.lock0 { background: rgba(255,40,40,.14); }
#field.lock1 { background: rgba(255,40,40,.14); }
body[data-mode="2"] #field.lock0 { background: linear-gradient(90deg, rgba(255,40,40,.2) 50%, rgba(255,40,40,0) 50%); }
body[data-mode="2"] #field.lock1 { background: linear-gradient(270deg, rgba(255,40,40,.2) 50%, rgba(255,40,40,0) 50%); }

/* ---------- touching a witch costs points ---------- */
.witch.zap svg { animation: witchZap .5s ease-out; }
@keyframes witchZap { 0% { transform: scale(1.35) rotate(-14deg); filter: brightness(2.4) hue-rotate(80deg); } 40% { transform: scale(1.15) rotate(10deg); } 100% { transform: scale(1) rotate(0); filter: none; } }
.wpop.bad { color: #ff4a4a; text-shadow: 0 0 1.8vh #ff0000; font-size: 7vh; }
#scoreNum.hurt, #scoreNum2.hurt { animation: hurt .45s ease-out; }
@keyframes hurt { 0% { transform: translateX(-.8vh) scale(.88); color: #ff4a4a; } 25% { transform: translateX(.8vh); } 50% { transform: translateX(-.5vh); color: #ff4a4a; } 100% { transform: none; } }
