:root {
  --orange: #ff8a1f;
  --orange-2: #ffb347;
  --green: #7dff3a;
  --red: #ff3b3b;
  --purple: #2a1748;
  --purple-2: #3d2266;
  --ink: #fff7e8;
  --muted: #c9b8e8;
  --wood: #3b2414;
  --wood-2: #5a3720;
  --panel: rgba(22, 12, 38, 0.92);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #120a22; color: var(--ink); font-family: 'Nunito', system-ui, sans-serif; }
body { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; overscroll-behavior: none; position: fixed; inset: 0; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- background sky ---------- */
#sky { position: fixed; inset: 0; background: radial-gradient(ellipse at 80% 8%, #6b3fa8 0%, #3a1f63 30%, #1d1035 65%, #120a22 100%); overflow: hidden; }
#sky .moon { position: absolute; right: 6%; top: 3%; width: min(26vw, 180px); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 40% 40%, #ffe9b8, #f7b65a 60%, #d9822b); box-shadow: 0 0 60px 20px rgba(255, 170, 70, .35), 0 0 160px 60px rgba(160, 90, 255, .25); opacity: .9; }
#sky .castle { position: absolute; right: 0; bottom: 30%; width: min(60vw, 420px); fill: #120a22; opacity: .9; }
#sky .bats span { position: absolute; font-size: 22px; filter: brightness(0) drop-shadow(0 0 2px #000); animation: bat 14s linear infinite; }
#sky .bats span:nth-child(1) { top: 10%; animation-delay: 0s; }
#sky .bats span:nth-child(2) { top: 18%; animation-delay: -5s; font-size: 16px; }
#sky .bats span:nth-child(3) { top: 6%; animation-delay: -9s; font-size: 18px; }
@keyframes bat { from { left: -10%; transform: translateY(0) } 25% { transform: translateY(14px) } 50% { transform: translateY(-6px) } 75% { transform: translateY(10px) } to { left: 110%; transform: translateY(0) } }

#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#flash { position: fixed; inset: 0; pointer-events: none; opacity: 0; transition: opacity .35s; }
#flash.hurt { background: radial-gradient(ellipse at center, rgba(255,0,0,0) 40%, rgba(255,0,40,.55)); opacity: 1; transition: none; }

/* ---------- header / HUD ---------- */
#top { position: fixed; left: 0; right: 0; top: 0; padding: calc(8px + var(--safe-top)) 12px 6px; display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 5; }
.logo { margin: 0; font-family: 'Creepster', 'Luckiest Guy', cursive; font-weight: 400; letter-spacing: 2px; line-height: .95; text-align: center; font-size: clamp(26px, 7vw, 46px);
  filter: drop-shadow(0 3px 0 #2b0d00) drop-shadow(0 0 12px rgba(255, 120, 0, .45)); }
.logo .o { background: linear-gradient(#ffd27a, #ff8a1f 55%, #c94a00); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo .g { background: linear-gradient(#d6ff8a, #7dff3a 55%, #2f9e00); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo.big { font-size: clamp(40px, 12vw, 72px); margin-bottom: 10px; }
#hud { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: nowrap; pointer-events: auto; }
.pill { display: flex; align-items: center; gap: 6px; padding: 5px 12px 5px 8px; border-radius: 12px; min-width: 0;
  background: linear-gradient(#2a1a10, #170d07); border: 2px solid #8a5a2b; box-shadow: inset 0 0 0 2px #1a0d05, 0 4px 12px rgba(0,0,0,.5); }
.pill .ic { font-size: 22px; }
.pill small { display: block; font-size: 10px; font-weight: 800; color: #f3d7b0; letter-spacing: 1px; }
.pill b { display: block; font-family: 'Luckiest Guy', sans-serif; font-weight: 400; font-size: clamp(18px, 5vw, 26px); color: var(--orange-2); line-height: 1; min-width: 2ch; }
.pill.warn b { color: #ff5a4a; animation: pulse .5s infinite alternate; }
@keyframes pulse { to { transform: scale(1.12); } }
.hearts { white-space: nowrap; letter-spacing: 2px; color: #ff2d4a !important; text-shadow: 0 0 8px rgba(255, 0, 60, .6); }
.hearts i { font-style: normal; display: inline-block; transition: transform .3s, opacity .3s; }
.hearts i.lost { opacity: .2; transform: scale(.7); filter: grayscale(1); }
.round { width: 42px; height: 42px; border-radius: 50%; border: 2px solid var(--orange); background: radial-gradient(#3a1f0b, #160b04); color: var(--orange); font-weight: 800; font-size: 15px; box-shadow: 0 0 10px rgba(255,138,31,.4); flex: none; }
#flavours { display: flex; gap: 6px; pointer-events: none; }
#flavours i { width: 16px; height: 22px; border-radius: 4px 4px 3px 3px; opacity: .25; border: 1px solid rgba(255,255,255,.4); transition: opacity .3s, transform .3s; }
#flavours i.got { opacity: 1; transform: scale(1.15); box-shadow: 0 0 10px currentColor; }

/* ---------- toast & popups ---------- */
#toast { position: fixed; left: 50%; top: 42%; transform: translate(-50%, -50%); pointer-events: none; z-index: 6; font-family: 'Luckiest Guy', sans-serif; font-size: clamp(28px, 9vw, 64px); text-align: center; white-space: nowrap; opacity: 0; }
#toast.show { animation: toast 1.1s ease-out forwards; }
#toast.count { color: #fff; font-size: clamp(60px, 22vw, 140px); text-shadow: 0 0 30px #a56bff, 0 6px 0 #3b1a6b; }
#toast.go { color: var(--green); font-size: clamp(60px, 22vw, 140px); text-shadow: 0 0 30px #3aff7a, 0 6px 0 #0d4a12; }
#toast.bonus { color: #ffe066; text-shadow: 0 0 24px #ff9a00, 0 4px 0 #6b2a00; }
#toast.hint { color: #fff; font-size: clamp(20px, 6vw, 30px); text-shadow: 0 0 18px #a56bff, 0 3px 0 #2b0d4a; animation-duration: 2.4s; }
#toast.hurt { color: #ff5a6a; text-shadow: 0 0 24px #ff0030, 0 4px 0 #4a0010; font-size: clamp(22px, 6vw, 40px); }
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -50%) scale(.5) } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1) } 30% { transform: translate(-50%, -50%) scale(1) } 75% { opacity: 1 } 100% { opacity: 0; transform: translate(-50%, -70%) scale(1) } }
#popups { position: fixed; inset: 0; pointer-events: none; z-index: 4; }
#popups span { position: absolute; font-family: 'Luckiest Guy', sans-serif; font-size: 26px; transform: translate(-50%, -50%); text-shadow: 0 2px 0 #000, 0 0 10px currentColor; animation: pop .9s ease-out forwards; }
@keyframes pop { from { opacity: 1; margin-top: 0 } to { opacity: 0; margin-top: -60px } }


/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; padding-top: max(16px, var(--safe-top)) !important; padding-bottom: max(16px, var(--safe-bottom)) !important; z-index: 10; display: none; align-items: center; justify-content: center; padding: 16px; background: rgba(10, 4, 20, .45); backdrop-filter: blur(2px); }
.screen.show { display: flex; animation: fade .25s ease-out; }
@keyframes fade { from { opacity: 0 } }
.panel { width: min(520px, 100%); max-height: calc(100% - 8px); overflow: auto; padding: 22px 20px; border-radius: 18px; text-align: center; position: relative;
  background: linear-gradient(rgba(58, 35, 18, .97), rgba(33, 19, 9, .97)); border: 3px solid #8a5a2b;
  box-shadow: inset 0 0 0 3px #1a0d05, inset 0 0 40px rgba(0,0,0,.6), 0 20px 60px rgba(0,0,0,.6), 0 0 40px rgba(255, 120, 0, .15); }
.panel::before, .panel::after { content: '🕸️'; position: absolute; top: 4px; font-size: 26px; opacity: .55; }
.panel::before { left: 6px; } .panel::after { right: 6px; transform: scaleX(-1); }
.panel.center { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.title { margin: 6px 0 12px; font-family: 'Luckiest Guy', sans-serif; font-weight: 400; font-size: clamp(26px, 7vw, 36px); color: var(--orange); letter-spacing: 1px; text-shadow: 0 3px 0 #2b0d00, 0 0 14px rgba(255,120,0,.5); }
.steps { text-align: left; margin: 0 auto 16px; padding-left: 26px; max-width: 380px; line-height: 1.55; font-size: 16px; }
.steps b { color: var(--orange-2); }
.btn { display: inline-block; margin: 6px 4px; padding: 10px 20px; border-radius: 12px; border: 2px solid #ffcf7a; background: linear-gradient(#ffa33a, #e0600a); color: #2b0d00; font-family: 'Luckiest Guy', sans-serif; font-size: 18px; letter-spacing: .5px; box-shadow: 0 4px 0 #7a2e00, 0 0 18px rgba(255,138,31,.35); }
.btn:active { transform: translateY(2px); box-shadow: 0 2px 0 #7a2e00; }
.btn.big { font-size: 24px; padding: 14px 28px; }
.btn.ghost { background: rgba(0,0,0,.35); color: var(--orange-2); border-color: #8a5a2b; box-shadow: none; }
.btn:disabled { opacity: .5; }
.row { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.controls { font-size: 13px; margin: 4px 0 8px; }
.tagline { margin: 14px 0 0; font-family: 'Luckiest Guy', sans-serif; font-size: clamp(24px, 7vw, 34px); letter-spacing: 1px; }
.tagline .o { color: var(--orange); } .tagline .g { color: var(--green); } .tagline .r { color: var(--red); }
.tagline span { text-shadow: 0 3px 0 #000; }
.rules { text-align: left; line-height: 1.6; padding-left: 22px; margin: 0 0 8px; }
.rules b { color: var(--orange-2); }
.score-table { display: grid; gap: 6px; margin: 8px 0 12px; }
.score-table div { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-radius: 10px; background: rgba(0,0,0,.35); text-align: left; }
.score-table b { color: var(--orange-2); font-family: 'Luckiest Guy', sans-serif; font-weight: 400; font-size: 18px; white-space: nowrap; }
.score-table .total { border: 1px solid var(--orange); }
.flavour-row { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 4px 0 10px; }
.flavour-row span { padding: 4px 10px; border-radius: 20px; font-size: 13px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; }
.bar { width: 240px; height: 14px; border-radius: 8px; background: rgba(0,0,0,.5); border: 2px solid #8a5a2b; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ff8a1f, #7dff3a); transition: width .2s; }

/* leaderboard */
.tabs { display: flex; justify-content: center; gap: 6px; margin-bottom: 10px; }
.tabs button { padding: 6px 12px; border-radius: 20px; border: 2px solid #8a5a2b; background: rgba(0,0,0,.35); color: var(--muted); font-weight: 800; }
.tabs button.on { background: var(--orange); color: #2b0d00; border-color: #ffcf7a; }
.lb { list-style: none; margin: 0 0 8px; padding: 0; display: grid; gap: 6px; min-height: 120px; align-content: start; }
.lb li { display: grid; grid-template-columns: 40px 1fr auto; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 10px; background: rgba(0,0,0,.45); text-align: left; }
.lb li .rk { font-family: 'Luckiest Guy', sans-serif; font-size: 18px; text-align: center; }
.lb li:nth-child(1) .rk { color: #ffd23f; } .lb li:nth-child(2) .rk { color: #d8d8e8; } .lb li:nth-child(3) .rk { color: #e08a4a; }
.lb li .nm { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb li .tag { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: 1px; }
.lb li .sc { font-family: 'Luckiest Guy', sans-serif; color: #ffd23f; font-size: 18px; }
.lb li.me { outline: 2px solid var(--green); }
.lb .empty { display: block; text-align: center; color: var(--muted); }

/* game over */
.final small { display: block; font-weight: 800; letter-spacing: 2px; color: var(--muted); }
.final b { display: block; font-family: 'Luckiest Guy', sans-serif; font-weight: 400; font-size: clamp(56px, 16vw, 84px); color: #ffd23f; line-height: 1; text-shadow: 0 4px 0 #6b2a00, 0 0 30px rgba(255, 160, 0, .6); }
form { display: grid; gap: 8px; margin: 10px 0; text-align: left; }
label { font-weight: 800; font-size: 14px; color: #f3d7b0; display: grid; gap: 4px; }
label em { font-weight: 600; font-style: normal; color: var(--muted); font-size: 12px; }
input { font: inherit; font-size: 17px; padding: 10px 12px; border-radius: 10px; border: 2px solid #8a5a2b; background: rgba(0,0,0,.45); color: #fff; user-select: text; -webkit-user-select: text; }
input:focus { outline: none; border-color: var(--orange); }
form .btn { justify-self: center; }
.msg { min-height: 1.2em; margin: 0; text-align: center; font-weight: 800; }
.msg.ok { color: var(--green); } .msg.err { color: #ff7a7a; }

.hidden { display: none !important; }

@media (min-width: 900px) and (min-aspect-ratio: 11/10) {
  #top { flex-direction: row; justify-content: space-between; padding-left: 24px; padding-right: 24px; }
  .logo { font-size: 40px; }
  #flavours { position: absolute; top: calc(70px + var(--safe-top)); left: 50%; transform: translateX(-50%); }
}
@media (max-width: 440px) {
  #hud { gap: 5px; }
  .pill { padding: 4px 9px; gap: 4px; border-radius: 10px; }
  .pill .ic { display: none; }
  .pill b { font-size: 20px; }
  .hearts { font-size: 17px !important; letter-spacing: 0; }
  .round { width: 36px; height: 36px; font-size: 13px; }
}

/* ---------- watermark ---------- */
#watermark { position: fixed; right: 10px; bottom: calc(6px + var(--safe-bottom)); z-index: 20; pointer-events: none;
  font-size: 11px; font-weight: 800; letter-spacing: .5px; color: rgba(255, 255, 255, .45); text-shadow: 0 1px 2px rgba(0, 0, 0, .8); }

/* Landscape phones: compact HUD, pad on the right, maze fills the rest. */
@media (orientation: landscape) and (max-height: 520px) {
  #top { flex-direction: row; justify-content: center; gap: 10px; padding-top: calc(4px + var(--safe-top)); }
  #top .logo { display: none; }
  #flavours { flex-direction: column; position: fixed; left: calc(10px + env(safe-area-inset-left, 0px)); top: 50%; transform: translateY(-50%); }
  .pill { padding: 3px 9px; }
  .pill .ic { display: none; }
  .pill b { font-size: 18px; }
  .round { width: 34px; height: 34px; }
  #watermark { right: auto; left: 10px; }
  .panel { max-height: 100%; padding: 14px; }
  .logo.big { font-size: 36px; margin-bottom: 4px; }
  .steps { font-size: 14px; line-height: 1.35; margin-bottom: 8px; }
  .tagline { display: none; }
}

/* ---------- tutorial ---------- */
.tut-cards { position: relative; }
.tut-card { display: none; animation: fade .3s ease-out; }
.tut-card.on { display: block; }
.tut-card p { margin: 0 auto 10px; max-width: 360px; line-height: 1.5; font-size: 16px; }
.tut-card b { color: var(--orange-2); }
.tut-try { color: var(--green) !important; font-weight: 800; animation: pulse .7s infinite alternate; }
body:not(.touch) .tut-touch { display: none; }
body.touch .tut-keys { display: none; }
.tut-art { height: 120px; display: flex; align-items: center; justify-content: center; gap: 10px; position: relative; }
.big-emoji { font-size: 72px; filter: drop-shadow(0 0 16px rgba(255, 140, 30, .5)); }
.wobble { animation: wobble 1s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: rotate(-12deg) } to { transform: rotate(12deg) } }
.swipe-art { width: 220px; margin: 0 auto; }
.swipe-art .finger { font-size: 56px; position: absolute; left: 30px; top: 30px; animation: swipe 1.6s ease-in-out infinite; }
.swipe-art .trail { position: absolute; left: 50px; top: 58px; height: 6px; width: 0; border-radius: 3px; background: linear-gradient(90deg, rgba(125,255,58,0), var(--green)); animation: trail 1.6s ease-in-out infinite; }
@keyframes swipe { 0%, 15% { transform: translateX(0); opacity: 0 } 25% { opacity: 1 } 70% { transform: translateX(120px); opacity: 1 } 100% { transform: translateX(120px); opacity: 0 } }
@keyframes trail { 0%, 25% { width: 0; opacity: 1 } 70% { width: 120px; opacity: 1 } 100% { width: 120px; opacity: 0 } }
.packs-art i { width: 34px; height: 48px; border-radius: 6px 6px 4px 4px; border: 2px solid rgba(255,255,255,.5); box-shadow: 0 0 14px currentColor; animation: bob 1s ease-in-out infinite alternate; }
.packs-art i:nth-child(2) { animation-delay: .2s } .packs-art i:nth-child(3) { animation-delay: .4s } .packs-art i:nth-child(4) { animation-delay: .6s } .packs-art i:nth-child(5) { animation-delay: .8s }
@keyframes bob { to { transform: translateY(-10px) } }
.tut-dots { display: flex; justify-content: center; gap: 8px; margin: 6px 0 4px; }
.tut-dots i { width: 9px; height: 9px; border-radius: 50%; background: rgba(255,255,255,.25); transition: background .2s, transform .2s; }
.tut-dots i.on { background: var(--orange); transform: scale(1.3); }
#screen-tutorial { touch-action: none; }
