:root {
  --ink: #1b1024;
  --night: #120c22;
  --panel: #2a1d44;
  --panel-2: #3a2860;
  --edge: #ff8a1f;
  --orange: #ff8a1f;
  --orange-2: #ffb347;
  --purple: #a45cff;
  --cream: #fff4dc;
  --muted: #b9a9d9;
  --font: 'Fredoka', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--night);
  font-family: var(--font);
  color: var(--cream);
  user-select: none; -webkit-user-select: none;
}
#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui button { pointer-events: auto; font-family: var(--font); }
.hidden { display: none !important; }

kbd {
  display: inline-block; font-family: var(--font); font-weight: 700; font-size: 0.72em;
  padding: 1px 6px 2px; border-radius: 6px; line-height: 1.3;
  background: var(--cream); color: var(--ink); border: 2px solid var(--ink);
  box-shadow: 0 2px 0 var(--ink); vertical-align: 1px;
}

/* ---------------- HUD */
#hud { position: absolute; inset: 0; }
.panel {
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 0 0 2px rgba(255, 138, 31, 0.55) inset, 0 4px 0 var(--ink), 0 8px 18px rgba(0,0,0,0.45);
}
#hud-costume {
  position: absolute; top: 14px; left: 14px;
  display: flex; align-items: center; gap: 10px; padding: 7px 14px 7px 7px;
  --c: var(--purple);
  box-shadow: 0 0 0 2px var(--c) inset, 0 4px 0 var(--ink), 0 8px 18px rgba(0,0,0,0.45);
  transition: box-shadow 0.3s;
}
#costume-icon {
  width: 58px; height: 58px; border-radius: 12px;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c) 70%, white), var(--c));
  border: 3px solid var(--ink);
  display: grid; place-items: center;
}
#costume-icon svg { width: 50px; height: 50px; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.35)); }
#costume-icon.pop { animation: pop 0.45s ease-out; }
#costume-name { font-weight: 700; font-size: 20px; letter-spacing: 0.3px; color: var(--c); text-shadow: 0 2px 0 var(--ink); }
#costume-power { font-size: 13px; color: var(--muted); margin-top: 2px; }

#hud-center { position: absolute; top: 14px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; align-items: center; }
.panel.small { padding: 6px 14px; font-weight: 600; font-size: 15px; white-space: nowrap; }
#pause-btn { cursor: pointer; padding: 8px 12px; display: flex; gap: 4px; align-items: center; height: 34px; }
#pause-btn i { display: block; width: 5px; height: 14px; border-radius: 2px; background: var(--cream); }
#pause-btn:hover { filter: brightness(1.2); }

#hud-counters { position: absolute; top: 14px; right: 14px; display: flex; gap: 16px; padding: 9px 16px; align-items: center; }
.counter { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: 20px; text-shadow: 0 2px 0 var(--ink); }
.counter .ico { display: grid; place-items: center; }
.counter.pulse { animation: pop 0.35s ease-out; }
#candy-count.done { color: #9dff5f; }

@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---------------- floaters, prompts, toasts */
#floaters { position: absolute; inset: 0; overflow: hidden; }
.floater {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font-weight: 700; font-size: 18px; color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 6px rgba(0,0,0,0.6);
  will-change: transform, opacity;
}
.floater.candy { color: #ff9ad0; }
.floater.coin { color: #ffd84a; }
.floater.small { font-size: 15px; color: #c9ffb0; }
.floater.boo { font-family: 'Creepster', var(--font); font-size: 40px; color: #e6ecff; letter-spacing: 2px; text-shadow: 0 3px 0 #2b2a5a, 0 0 18px #9fb4ff; }
.floater.bell { font-size: 20px; color: #ffe38a; }
.floater.speech {
  font-size: 15px; font-weight: 600; color: var(--ink); text-shadow: none;
  background: var(--cream); border: 3px solid var(--ink); border-radius: 14px; padding: 4px 12px;
}

#prompt {
  position: absolute; left: 0; top: 0; transform: translate(-50%, -100%);
  display: flex; align-items: center; gap: 6px;
  background: rgba(27, 16, 36, 0.85); border: 2px solid var(--c, #fff); border-radius: 12px;
  padding: 3px 10px 3px 5px; font-weight: 700; font-size: 15px; color: var(--c, #fff);
  animation: bob 0.9s ease-in-out infinite alternate;
}
@keyframes bob { from { margin-top: 0; } to { margin-top: -5px; } }

#toast {
  position: absolute; top: 96px; left: 50%; transform: translateX(-50%);
  max-width: min(560px, 90vw); text-align: center;
  background: rgba(27, 16, 36, 0.9); border: 3px solid var(--c, var(--orange)); border-radius: 14px;
  padding: 9px 18px; font-size: 16px; font-weight: 500; line-height: 1.35;
  box-shadow: 0 6px 18px rgba(0,0,0,0.4);
  animation: toastIn 0.25s ease-out;
}
#toast b { font-weight: 700; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

#banner {
  position: absolute; top: 30%; left: 50%; transform: translate(-50%, -50%);
  text-align: center; pointer-events: none;
  animation: bannerIn 0.6s cubic-bezier(.2,1.4,.4,1);
}
#banner.out { transition: opacity 0.6s, transform 0.6s; opacity: 0; transform: translate(-50%, -70%); }
.b-level { font-weight: 700; font-size: 20px; color: var(--orange-2); letter-spacing: 3px; text-transform: uppercase; text-shadow: 0 2px 0 var(--ink); }
.b-name { font-family: 'Creepster', var(--font); font-size: clamp(44px, 7vw, 78px); color: var(--orange); letter-spacing: 3px;
  text-shadow: 0 4px 0 var(--ink), 0 0 30px rgba(255, 138, 31, 0.6); line-height: 1.05; }
.b-sub { margin-top: 10px; font-size: 18px; font-weight: 500; color: var(--cream); text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(0,0,0,0.8); max-width: 80vw; }
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -30%) scale(0.8); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* ---------------- dialog */
#dialog {
  position: absolute; bottom: 22px; left: 50%; transform: translateX(-50%);
  width: min(720px, 94vw); display: flex; gap: 14px; align-items: flex-start;
  background: var(--cream); color: var(--ink);
  border: 4px solid var(--ink); border-radius: 18px; padding: 14px 18px 12px 14px;
  box-shadow: 0 6px 0 var(--ink), 0 12px 30px rgba(0,0,0,0.5);
  animation: toastIn 0.2s ease-out;
}
#dialog-portrait {
  flex: 0 0 76px; height: 76px; border-radius: 14px; border: 3px solid var(--ink);
  background: radial-gradient(circle at 50% 40%, #ffd9a0, #ff9a3a); display: grid; place-items: center;
}
#dialog-portrait svg { width: 66px; height: 66px; }
#dialog-body { flex: 1; min-height: 76px; display: flex; flex-direction: column; }
#dialog-name { font-weight: 700; font-size: 18px; color: #b24a00; }
#dialog-text { font-size: 18px; line-height: 1.4; margin-top: 3px; flex: 1; }
#dialog-more { align-self: flex-end; font-size: 13px; font-weight: 600; color: #7a6a8a; animation: bob 0.7s ease-in-out infinite alternate; }

/* ---------------- screens */
.screen {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  pointer-events: auto; padding: 16px;
}
.screen.dim { background: rgba(10, 6, 20, 0.6); backdrop-filter: blur(3px); }
.menu-card {
  width: min(460px, 100%);
  background: linear-gradient(180deg, rgba(58, 40, 96, 0.92), rgba(33, 22, 56, 0.94));
  border: 4px solid var(--ink); border-radius: 22px; padding: 24px 26px;
  box-shadow: 0 0 0 3px rgba(255, 138, 31, 0.6) inset, 0 8px 0 var(--ink), 0 20px 50px rgba(0,0,0,0.55);
  text-align: center; max-height: calc(100vh - 32px); overflow-y: auto;
}
.menu-card.wide { width: min(860px, 100%); }
.menu-card h2 {
  margin: 0 0 16px; font-family: 'Creepster', var(--font); font-weight: 400; font-size: 44px; letter-spacing: 2px;
  color: var(--orange); text-shadow: 0 3px 0 var(--ink);
}
#screen-menu { align-items: flex-start; padding-left: max(24px, 6vw); }
#screen-menu .menu-foot { align-self: center; position: absolute; bottom: 12px; }
@media (max-aspect-ratio: 1/1) { #screen-menu { align-items: center; justify-content: flex-end; padding: 16px 16px 48px; } }
#screen-menu .menu-card { background: linear-gradient(180deg, rgba(42, 29, 68, 0.78), rgba(24, 16, 42, 0.88)); }
.title { line-height: 0.95; margin-top: -4px; position: relative; display: inline-block; }
.title span { font-family: 'Creepster', var(--font); display: inline-block; letter-spacing: 3px; }
.title .t1 { font-size: 54px; color: var(--cream); text-shadow: 0 4px 0 var(--ink); }
.title .t2 { font-size: 64px; color: var(--orange); text-shadow: 0 4px 0 var(--ink), 0 0 28px rgba(255, 138, 31, 0.7); animation: flicker 3s infinite; }
@keyframes flicker { 0%, 100% { opacity: 1; } 46% { opacity: 1; } 48% { opacity: 0.75; } 50% { opacity: 1; } 72% { opacity: 0.9; } }
.stage-badge:not(:empty) {
  position: absolute; right: -14px; top: -10px; padding: 2px 8px; border-radius: 8px;
  font-family: var(--font); font-weight: 700; font-size: 13px; letter-spacing: 1.5px; text-transform: uppercase;
  color: var(--ink); background: #ffd84a; border: 2px solid var(--ink); transform: rotate(8deg);
  box-shadow: 0 2px 0 var(--ink); text-shadow: none; animation: none;
}
.menu-version { position: absolute; right: 12px; bottom: 10px; font-size: 12px; color: var(--muted); opacity: 0.7; text-shadow: 0 1px 0 var(--ink); }
.tagline { color: var(--muted); font-size: 15px; margin: 6px 0 18px; }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; margin: 8px 0 4px; }
.btn {
  font-size: 19px; font-weight: 700; padding: 11px 18px; border-radius: 14px; cursor: pointer;
  color: var(--cream); background: linear-gradient(180deg, #5a3f8e, #432c70);
  border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.08s, filter 0.15s;
}
.btn:hover, .btn:focus-visible { filter: brightness(1.18); outline: none; transform: translateY(-1px); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn.primary { background: linear-gradient(180deg, #ffa74a, #f27a12); color: var(--ink); }
.btn.danger { background: linear-gradient(180deg, #8a2b3a, #6a1a28); }
.btn.small { font-size: 14px; padding: 8px 14px; }
.btn:disabled { opacity: 0.45; cursor: default; filter: none; transform: none; }
.sound-row { display: flex; gap: 8px; justify-content: center; margin-top: 14px; }
.toggle {
  font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 10px; cursor: pointer;
  background: rgba(0,0,0,0.25); color: var(--muted); border: 2px solid rgba(185, 169, 217, 0.4);
}
.toggle.off { opacity: 0.55; text-decoration: line-through; }
.menu-foot { margin-top: 14px; color: var(--muted); font-size: 13px; text-shadow: 0 2px 0 var(--ink); text-align: center; }
.row-buttons { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin-top: 18px; }

/* level select: one themed page per neighborhood */
#levels-card {
  --hood-a: #4b3478; --hood-b: #35245a; --hood-accent: #ff8a1f; --hood-edge: rgba(255, 138, 31, 0.6); --hood-done: #3f6a3a;
  box-shadow: 0 0 0 3px var(--hood-edge) inset, 0 8px 0 var(--ink), 0 20px 50px rgba(0,0,0,0.55);
  background: linear-gradient(180deg, color-mix(in srgb, var(--hood-a) 80%, #1a1030), color-mix(in srgb, var(--hood-b) 70%, #0e0818));
  transition: background 0.3s, box-shadow 0.3s;
}
.hood-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.hood-title { flex: 1; min-width: 0; }
.hood-num { font-weight: 700; font-size: 13px; letter-spacing: 3px; text-transform: uppercase; color: var(--cream); opacity: 0.75; }
#levels-card h2 { color: var(--hood-accent); margin: 2px 0 4px; line-height: 1.05; }
.hood-tag { color: var(--muted); font-size: 14px; }
.hood-arrow {
  flex: none; width: 48px; height: 48px; border-radius: 50%; cursor: pointer; font-size: 18px;
  color: var(--ink); background: var(--hood-accent); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink);
}
.hood-arrow:hover { filter: brightness(1.15); }
.hood-arrow:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.hood-arrow:disabled { visibility: hidden; }
#hood-dots { display: flex; justify-content: center; gap: 8px; margin-top: 14px; }
#hood-dots button { width: 12px; height: 12px; padding: 0; border-radius: 50%; border: 2px solid var(--ink); background: rgba(255,255,255,0.25); cursor: pointer; }
#hood-dots button.on { background: var(--hood-accent); transform: scale(1.2); }
#level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.level-card {
  position: relative; text-align: left; cursor: pointer; padding: 12px 12px 10px; min-height: 104px;
  border-radius: 14px; border: 3px solid var(--ink); color: var(--cream);
  background: linear-gradient(180deg, var(--hood-a), var(--hood-b)); box-shadow: 0 4px 0 var(--ink);
  display: flex; flex-direction: column; gap: 3px; font-family: var(--font);
}
.level-card:hover { filter: brightness(1.15); }
.level-card .num { font-family: 'Creepster', var(--font); font-size: 30px; color: var(--hood-accent); line-height: 1; text-shadow: 0 2px 0 var(--ink); }
.level-card .name { font-weight: 700; font-size: 15px; line-height: 1.15; }
.level-card .meta { margin-top: auto; font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.level-card .meta svg { width: 16px; height: 16px; flex: none; }
.level-card .meta svg[viewBox="0 0 64 32"] { width: 26px; height: 13px; }
.level-card .meta .gap { width: 6px; }
.level-card.done { background: linear-gradient(180deg, var(--hood-done), color-mix(in srgb, var(--hood-done) 70%, #000)); }
.level-card.done .check { position: absolute; top: 8px; right: 10px; color: #9dff5f; font-size: 20px; font-weight: 700; }
.level-card.locked { cursor: default; filter: grayscale(0.7) brightness(0.65); }
.level-card.locked .num::after { content: ' \1F512'; font-size: 18px; }

.howto { text-align: left; font-size: 16px; line-height: 1.45; }
.howto p { margin: 0 0 10px; }
.howto .keys { text-align: center; margin-top: 12px; color: var(--muted); }
#howto-costumes { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin: 12px 0; }
.costume-row { display: flex; gap: 10px; align-items: center; background: rgba(0,0,0,0.2); border-radius: 12px; padding: 8px; border: 2px solid var(--c); }
.costume-row .ic { flex: 0 0 48px; height: 48px; border-radius: 10px; background: var(--c); border: 2px solid var(--ink); display: grid; place-items: center; }
.costume-row .ic svg { width: 42px; height: 42px; }
.costume-row b { color: var(--c); }
.costume-row div { font-size: 14px; line-height: 1.3; }

.confirm-text { font-size: 16px; line-height: 1.45; margin: -4px 0 16px; color: var(--cream); }
.confirm-text b { color: #ff9a8a; }
#complete-coins { color: #ffd84a; font-weight: 600; margin: -6px 0 14px; min-height: 1em; }

/* ---------------- Costume Closet */
.coin-chip:not(:empty) { display: inline-flex; align-items: center; gap: 4px; margin-left: 8px; padding: 1px 8px 1px 4px; border-radius: 999px;
  background: rgba(0,0,0,0.3); font-size: 15px; color: #ffd84a; vertical-align: 2px; }
.coin-chip svg, .purse svg, .price svg { width: 18px; height: 18px; }
#closet-card { width: min(880px, 100%); text-align: left; }
.closet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.closet-head h2 { margin: 0; }
.purse { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 24px; color: #ffd84a;
  background: rgba(0,0,0,0.3); border: 2px solid rgba(255, 216, 74, 0.4); border-radius: 999px; padding: 4px 14px 4px 8px; }
.purse svg { width: 26px; height: 26px; }
.keeper { display: flex; gap: 12px; align-items: center; margin: 12px 0; background: rgba(0,0,0,0.22); border-radius: 14px; padding: 8px 12px; }
.keeper-face { flex: none; width: 52px; height: 52px; border-radius: 12px; border: 3px solid var(--ink); background: radial-gradient(circle at 50% 40%, #ffe3b0, #e0a060); display: grid; place-items: center; }
.keeper-face svg { width: 46px; height: 46px; }
.keeper-says { display: flex; flex-direction: column; font-size: 15px; line-height: 1.35; }
.keeper-says b { color: var(--orange-2); font-size: 14px; }
#closet-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.closet-tab { display: flex; align-items: center; gap: 6px; padding: 5px 12px 5px 5px; border-radius: 12px; cursor: pointer; font-family: var(--font);
  font-weight: 700; font-size: 14px; color: var(--cream); background: rgba(0,0,0,0.25); border: 3px solid transparent; }
.closet-tab svg { width: 30px; height: 30px; }
.closet-tab.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 30%, rgba(0,0,0,0.3)); }
.closet-body { display: flex; gap: 16px; align-items: stretch; flex-wrap: wrap; }
.closet-preview { flex: 0 0 280px; max-width: 100%; border-radius: 16px; background: radial-gradient(circle at 50% 60%, #3a2860, #150e26); border: 3px solid var(--ink);
  display: flex; flex-direction: column; align-items: center; padding-bottom: 8px; }
#closet-canvas { width: 100%; max-width: 280px; aspect-ratio: 1; display: block; }
#closet-preview-name { font-weight: 700; color: var(--cream); }
#closet-looks { flex: 1; min-width: 260px; display: flex; flex-direction: column; gap: 10px; }
.look-card { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; cursor: pointer;
  background: rgba(0,0,0,0.22); border: 3px solid transparent; }
.look-card.previewing { border-color: var(--orange-2); }
.look-card .swatch { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--ink); }
.look-card .info { flex: 1; min-width: 0; }
.look-card .info b { display: block; font-size: 16px; }
.look-card .info span { font-size: 13px; color: var(--muted); }
.look-card .btn { font-size: 14px; padding: 7px 12px; white-space: nowrap; }
.look-card .btn.wearing { background: linear-gradient(180deg, #3f6a3a, #2c4a2a); cursor: default; }
.price { display: inline-flex; align-items: center; gap: 4px; }
.closet-foot { margin-top: 12px; font-size: 13px; color: var(--muted); }

#complete-sub { color: var(--muted); margin: -6px 0 12px; }
#complete-stats { display: flex; gap: 14px; justify-content: center; margin-bottom: 16px; }
.stat { background: rgba(0,0,0,0.25); border: 2px solid rgba(255,255,255,0.1); border-radius: 14px; padding: 10px 16px; display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 22px; }

#loading {
  position: absolute; inset: 0; display: grid; place-items: center; background: var(--night);
  font-family: 'Creepster', var(--font); font-size: 40px; color: var(--orange); letter-spacing: 2px;
}

/* ---------------- touch */
#touch { position: absolute; inset: auto 0 0 0; height: 200px; pointer-events: none; }
#dpad { position: absolute; left: 18px; bottom: 18px; width: 156px; height: 156px; }
#dpad button, #touch-action {
  position: absolute; width: 52px; height: 52px; border-radius: 14px; font-size: 20px;
  background: rgba(42, 29, 68, 0.75); color: var(--cream); border: 3px solid var(--ink); touch-action: none;
}
#dpad [data-dir=up] { left: 52px; top: 0; }
#dpad [data-dir=down] { left: 52px; bottom: 0; }
#dpad [data-dir=left] { left: 0; top: 52px; }
#dpad [data-dir=right] { right: 0; top: 52px; }
#touch-action { right: 22px; bottom: 40px; width: 92px; height: 92px; border-radius: 50%; font-weight: 700; font-size: 16px; background: rgba(255, 138, 31, 0.8); color: var(--ink); }

@media (max-width: 640px) {
  #hud-costume { padding: 5px 10px 5px 5px; gap: 7px; top: 8px; left: 8px; }
  #costume-icon { width: 44px; height: 44px; }
  #costume-icon svg { width: 38px; height: 38px; }
  #costume-name { font-size: 15px; }
  #costume-power { font-size: 11px; }
  #hud-counters { top: 8px; right: 8px; flex-direction: column; gap: 2px; padding: 6px 10px; align-items: flex-end; }
  .counter { font-size: 15px; }
  #hud-center { top: auto; bottom: 8px; }
  #hud-level { display: none; }
  #toast { top: 76px; font-size: 14px; }
  .title .t1 { font-size: 40px; } .title .t2 { font-size: 48px; }
}
