/* style.css — neon UI theme for Maze Paint */

:root {
  --bg: #05060d;
  --neon: #ff35e0;
  --neon2: #36e0ff;
  --gold: #ffd23f;
  --panel: rgba(20, 18, 48, 0.82);
  --panel-border: rgba(120, 130, 255, 0.35);
  --text: #eef0ff;
  --muted: #9aa3d4;
  --ink: #302750;
  --cream: #fff8dc;
  --font: "Arial Rounded MT Bold", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

#game-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* ---- Overlay container ---- */
#ui {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}
#ui .ui-interactive,
#ui button { pointer-events: auto; }

/* Hidden overlays (menu when in-game, closed shop/settings) are opacity:0 but
   still in the DOM. Their inner panels/buttons carry .ui-interactive, which the
   rule above re-enables to pointer-events:auto — so an *invisible* panel would
   sit on top of whatever's behind it and silently swallow clicks. Force the
   whole subtree inert while not .visible. The double-id + :not() specificity
   beats the rule above, so it wins without !important; when the overlay opens
   (.visible) this no longer matches and buttons work normally. */
#ui #menu:not(.visible),
#ui #menu:not(.visible) *,
#ui #shop:not(.visible),
#ui #shop:not(.visible) *,
#ui #settings:not(.visible),
#ui #settings:not(.visible) * { pointer-events: none; }

/* ---- HUD ---- */
#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  /* Respect notches / rounded corners (viewport-fit=cover). On devices without
     safe areas env() is 0, so this is identical to the old 14px/16px padding. */
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 14px max(16px, env(safe-area-inset-left));
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity .35s ease, transform .35s ease;
}
#hud.visible { opacity: 1; transform: none; }

.hud-chip {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}

#stars-hud {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
}
.star-ico { color: var(--gold); text-shadow: 0 0 10px rgba(255, 210, 63, .8); }

#progress-hud {
  min-width: 160px;
  text-align: center;
}
#hud-difficulty {
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.progress-bar {
  height: 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, .1);
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--neon2), var(--neon));
  box-shadow: 0 0 12px var(--neon);
  transition: width .07s ease-out;
}
.hud-chip.count-pop {
  animation: countPop .16s ease-out;
}
@keyframes countPop {
  50% { transform: scale(1.045) rotate(-.5deg); }
}
#progress-text {
  margin-top: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

#hud-actions { display: flex; gap: 10px; }
/* The HUD collapse toggle is only useful on landscape phones, where the top bar
   overlaps the maze. Hidden everywhere else (portrait has the vertical room). */
#btn-hud-toggle { display: none; }
.icon-btn {
  width: 46px; height: 46px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: transform .12s ease, background .2s ease, box-shadow .2s ease;
}
.icon-btn:hover { background: rgba(40, 44, 90, .85); box-shadow: 0 0 16px rgba(120,130,255,.4); }
.icon-btn:active { transform: scale(.92); }

/* ---- Start menu ---- */
#menu {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .4s ease;
  background:
    radial-gradient(circle at 12% 18%, rgba(255, 245, 98, .95) 0 4%, transparent 4.3%),
    radial-gradient(circle at 87% 22%, rgba(255, 120, 186, .9) 0 6%, transparent 6.3%),
    radial-gradient(circle at 82% 83%, rgba(81, 225, 255, .9) 0 7%, transparent 7.3%),
    linear-gradient(145deg, #65d7ff 0%, #8d86ff 46%, #ff89c8 100%);
  overflow: hidden;
}
#menu.visible { opacity: 1; pointer-events: auto; }
/* Drifting polka dots */
#menu::before {
  content: "";
  position: absolute;
  inset: -12%;
  opacity: .22;
  background-image: radial-gradient(#ffffff 2px, transparent 2px);
  background-size: 26px 26px;
  transform: rotate(-4deg) scale(1.1);
  animation: dotDrift 7s linear infinite;
}
@keyframes dotDrift { to { background-position: 26px 52px; } }
/* Slowly spinning chunky ring */
#menu::after {
  content: "";
  position: absolute;
  width: 36vw;
  height: 36vw;
  min-width: 260px;
  min-height: 260px;
  right: -12vw;
  bottom: -18vw;
  border: clamp(34px, 6vw, 88px) solid rgba(255, 238, 79, .55);
  border-radius: 50%;
  animation: ringSpin 30s linear infinite;
}
@keyframes ringSpin { to { transform: rotate(360deg); } }

/* ---- Alive menu background: floating shapes ---- */
.menu-bg {
  position: absolute;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
}
.float-shape {
  position: absolute;
  border-radius: 42% 58% 55% 45% / 55% 45% 58% 42%;
  opacity: .5;
  filter: blur(.5px);
  animation: floaty var(--dur, 9s) ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  will-change: transform;
}
@keyframes floaty {
  0%, 100% { transform: translate(0, 0) rotate(0deg) scale(1); }
  50% { transform: translate(var(--fx, 14px), var(--fy, -26px)) rotate(var(--fr, 18deg)) scale(1.08); }
}
.fs1 { width: 86px;  height: 86px;  left: 8%;  top: 18%; background: #fff05e; --fx: 18px; --fy: -30px; --fr: 22deg; --dur: 8s; }
.fs2 { width: 64px;  height: 64px;  left: 78%; top: 12%; background: #ff7eb6; --fx: -16px; --fy: 24px; --fr: -18deg; --dur: 10s; --delay: -2s; }
.fs3 { width: 120px; height: 120px; left: 84%; top: 60%; background: #51e1ff; --fx: -22px; --fy: -20px; --fr: 14deg; --dur: 12s; --delay: -4s; }
.fs4 { width: 52px;  height: 52px;  left: 16%; top: 72%; background: #a6ed75; --fx: 20px; --fy: -22px; --fr: -24deg; --dur: 9s; --delay: -1s; }
.fs5 { width: 74px;  height: 74px;  left: 46%; top: 8%;  background: #b48cff; --fx: 12px; --fy: 26px; --fr: 20deg; --dur: 11s; --delay: -3s; }
.fs6 { width: 44px;  height: 44px;  left: 30%; top: 40%; background: #ffd23f; --fx: -18px; --fy: -18px; --fr: -16deg; --dur: 7.5s; --delay: -2.5s; }
.fs7 { width: 96px;  height: 96px;  left: 60%; top: 78%; background: #ff89c8; --fx: 16px; --fy: -28px; --fr: 18deg; --dur: 13s; --delay: -5s; }

/* ---- Custom logo (falls back to .title text if image is missing) ---- */
.logo {
  display: block;
  width: min(100%, 440px);
  height: auto;
  /* PNGs are cropped tight to the wordmark, so it centers on its own. */
  margin: 4px auto 12px;
  filter: drop-shadow(0 4px 0 rgba(48, 39, 80, .22)) drop-shadow(0 10px 16px rgba(46, 36, 92, .4));
  animation: logoBob 3.8s ease-in-out infinite;
}
@keyframes logoBob {
  0%, 100% { transform: rotate(-1.5deg) translateY(0); }
  50% { transform: rotate(1.5deg) translateY(-6px); }
}

.menu-panel {
  position: relative;
  z-index: 1;
  width: min(92vw, 480px);
  padding: 30px 28px 26px;
  border-radius: 34px 28px 38px 26px;
  background: var(--cream);
  border: 5px solid var(--ink);
  box-shadow: 0 12px 0 #302750, 0 22px 45px rgba(46, 36, 92, .35);
  text-align: center;
  transform: translateY(18px) rotate(-1deg) scale(.96);
  transition: transform .4s cubic-bezier(.2, .9, .3, 1.2);
}
#menu.visible .menu-panel { transform: rotate(-1deg); }
.menu-panel::before,
.menu-panel::after {
  content: "";
  position: absolute;
  z-index: -1;
  border: 4px solid var(--ink);
  border-radius: 50%;
  background: #ffdb4d;
}
.menu-panel::before {
  width: 62px;
  height: 62px;
  left: -28px;
  top: 56px;
}
.menu-panel::after {
  width: 44px;
  height: 44px;
  right: -20px;
  top: 110px;
  background: #ff68ad;
}

.title {
  margin: 0;
  font-size: clamp(38px, 9vw, 58px);
  font-weight: 900;
  letter-spacing: -.02em;
  background: linear-gradient(180deg, #ffef59 0 48%, #ff8f2f 50% 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(0 5px 0 #ff4f9a);
  transform: rotate(1deg);
}
.subtitle {
  margin: 10px 0 22px;
  color: #665c82;
  font-size: 15px;
  font-weight: 800;
}

#difficulty-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 14px 16px;
  border-radius: 18px 14px 20px 15px;
  border: 3px solid var(--ink);
  background: #75dcff;
  color: var(--ink);
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  text-align: left;
  transition: transform .12s ease, box-shadow .25s ease, background .25s ease, border-color .25s ease;
}
.diff-btn:hover {
  background: #9be8ff;
  border-color: var(--ink);
  box-shadow: 0 8px 0 var(--ink);
  transform: translateY(-3px) rotate(-1deg);
}
.diff-btn:nth-child(2) { background: #a6ed75; transform: rotate(1deg); }
.diff-btn:nth-child(3) { background: #ffb75e; transform: rotate(.8deg); }
.diff-btn:nth-child(4) { background: #ff79b7; transform: rotate(-1deg); }
.diff-btn:nth-child(2):hover { background: #c4ff9b; transform: translateY(-3px) rotate(0deg); }
.diff-btn:nth-child(3):hover { background: #ffc982; transform: translateY(-3px) rotate(-.3deg); }
.diff-btn:nth-child(4):hover { background: #ff9bca; transform: translateY(-3px) rotate(0deg); }
.diff-btn:active { transform: translateY(4px) scale(.97); box-shadow: 0 1px 0 var(--ink); }
.diff-name { font-size: 18px; font-weight: 900; }
.diff-meta { font-size: 12px; color: #635978; font-weight: 800; }
.diff-reward { font-size: 13px; font-weight: 900; color: #7a4c00; margin-top: 4px; }

.menu-foot {
  display: inline-block;
  margin-top: 21px;
  padding: 7px 14px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff0a8;
  color: var(--ink);
  font-size: 14px;
  font-weight: 800;
  transform: rotate(1deg);
}
.menu-foot b { color: #c36b00; }
.menu-bottom-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}
.shop-open-btn {
  margin-top: 21px;
  padding: 8px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #ff70b7;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transform: rotate(-1deg);
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
}
.shop-open-btn:hover {
  background: #ff98ca;
  transform: translateY(-2px) rotate(1deg);
  box-shadow: 0 6px 0 var(--ink);
}
.shop-open-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}
.sound-btn {
  margin-top: 21px;
  width: 42px;
  height: 42px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #ffe06a;
  font-size: 18px;
  line-height: 1;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  transform: rotate(1deg);
  transition: transform .12s ease, box-shadow .12s ease, background .2s ease;
}
.sound-btn:hover { background: #ffec99; transform: translateY(-2px) rotate(-1deg); box-shadow: 0 6px 0 var(--ink); }
.sound-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.how-to {
  margin: 14px 2px 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: #695f80;
  font-weight: 700;
}

/* ---- Terms & Privacy note (menu) ---- */
.legal-note {
  margin: 9px 4px 0;
  font-size: 10.5px;
  line-height: 1.45;
  color: #8a7fa6;
  font-weight: 700;
}
.legal-note a {
  color: #7a4cc0;
  text-decoration: underline;
  font-weight: 800;
}
.legal-note a:hover { color: #9a5ce0; }

/* ---- Cosmetics shop ---- */
#shop {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(26, 18, 57, .62);
  backdrop-filter: blur(8px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity .22s ease, visibility .22s ease;
}
#shop.visible {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}
.shop-panel {
  position: relative;
  width: min(850px, 96vw);
  max-height: min(740px, 94vh);
  overflow: hidden;
  padding: 22px;
  border: 5px solid var(--ink);
  border-radius: 32px 24px 34px 26px;
  background: #fff8dc;
  color: var(--ink);
  box-shadow: 0 12px 0 var(--ink), 0 25px 70px rgba(18, 10, 50, .48);
  transform: translateY(25px) scale(.94) rotate(.5deg);
  transition: transform .28s cubic-bezier(.2, .9, .25, 1.2);
}
#shop.visible .shop-panel { transform: none; }
.shop-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-right: 48px;
}
.shop-header h2 {
  margin: 0;
  font-size: clamp(28px, 5vw, 46px);
  line-height: .95;
  color: #ff4f9a;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
  filter: drop-shadow(0 4px 0 #ffd64d);
}
.shop-kicker {
  margin-bottom: 3px;
  color: #746789;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .16em;
}
.shop-wallet {
  margin-left: auto;
  padding: 8px 13px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #fff0a8;
  font-size: 18px;
  font-weight: 900;
  white-space: nowrap;
}
.shop-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 40px;
  height: 40px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: #ff886e;
  color: var(--ink);
  font: inherit;
  font-size: 25px;
  font-weight: 900;
  line-height: 30px;
  box-shadow: 0 3px 0 var(--ink);
  cursor: pointer;
}
.shop-close-btn:active { transform: translateY(3px); box-shadow: none; }
.shop-tabs {
  display: flex;
  gap: 8px;
  margin: 20px 0 15px;
}
.shop-tab {
  flex: 1;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 14px 14px 8px 8px;
  background: #a9dcff;
  color: var(--ink);
  font: inherit;
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
}
.shop-tab:nth-child(2) { background: #b5f47e; }
.shop-tab:nth-child(3) { background: #ffacdc; }
.shop-tab.active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
  outline: 3px solid #ffffff;
  outline-offset: -6px;
}
.shop-items {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  max-height: min(490px, 60vh);
  overflow-y: auto;
  padding: 3px 5px 12px;
  scrollbar-color: #8d7bd1 transparent;
}
.shop-card {
  min-width: 0;
  padding: 10px;
  border: 3px solid var(--ink);
  border-radius: 18px 14px 20px 15px;
  background: #ffffff;
  color: var(--ink);
  font: inherit;
  box-shadow: 0 5px 0 var(--ink);
  cursor: pointer;
  transition: transform .14s ease, box-shadow .14s ease, background .2s ease;
}
.shop-card:hover {
  transform: translateY(-3px) rotate(-.5deg);
  box-shadow: 0 8px 0 var(--ink);
  background: #fffdf2;
}
.shop-card:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.shop-card.equipped {
  background: #d7ffad;
  outline: 4px solid #70dd4b;
  outline-offset: -7px;
}
.shop-preview {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1.65;
  margin-bottom: 8px;
  overflow: hidden;
  border: 3px solid var(--ink);
  border-radius: 14px 10px 16px 11px;
  background:
    radial-gradient(circle at 35% 28%, #fff 0 5%, transparent 6%),
    linear-gradient(135deg, var(--swatch-a), var(--swatch-b));
  color: #ffffff;
  font-size: clamp(30px, 6vw, 54px);
  text-shadow: 0 3px 0 rgba(48, 39, 80, .65), 0 0 15px rgba(255,255,255,.6);
}
.shop-preview::after {
  content: "";
  position: absolute;
  inset: auto -15% -42% 25%;
  height: 70%;
  border-radius: 50%;
  background: rgba(255,255,255,.3);
  transform: rotate(-9deg);
}
.shop-preview span { position: relative; z-index: 1; }
.shop-item-name {
  display: block;
  overflow: hidden;
  font-size: 15px;
  font-weight: 900;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.shop-item-action {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 9px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #ffdf5a;
  font-size: 12px;
  font-weight: 900;
}
.shop-card.owned:not(.equipped) .shop-item-action { background: #8fe9ff; }
.shop-card.equipped .shop-item-action { background: #70dd4b; }
.shop-notice {
  position: absolute;
  left: 50%;
  bottom: 18px;
  padding: 9px 16px;
  border: 3px solid var(--ink);
  border-radius: 999px;
  background: #8cf08c;
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px) scale(.9);
  transition: opacity .18s ease, transform .18s ease;
}
.shop-notice.visible { opacity: 1; transform: translate(-50%, 0) scale(1); }
.shop-notice.error { background: #ff8c8c; }

/* ---- First-play control hint ---- */
#controls-hint {
  position: absolute;
  left: 0; right: 0; bottom: 17%;
  display: flex;
  justify-content: center;
  padding: 0 16px;
  opacity: 0;
  pointer-events: none; /* let swipes pass through to the game */
  transform: translateY(10px);
  transition: opacity .35s ease, transform .35s ease;
  z-index: 30;
}
#controls-hint.visible { opacity: 1; transform: none; }
.ch-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 14px 22px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  backdrop-filter: blur(8px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .4);
  text-align: center;
}
.ch-keys { display: flex; align-items: center; gap: 6px; }
.ch-key {
  min-width: 32px;
  height: 32px;
  padding: 0 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, .09);
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
}
.ch-or { margin-left: 4px; color: var(--muted); font-size: 13px; font-weight: 800; }
.ch-swipe { color: var(--text); font-size: 17px; font-weight: 800; }
.ch-text { color: var(--muted); font-size: 13px; font-weight: 700; letter-spacing: .03em; }
/* Show the touch hint on touch devices, the key hint elsewhere (mirrors #dpad). */
.ch-keys-touch { display: none; }
@media (pointer: coarse) {
  .ch-keys-desktop { display: none; }
  .ch-keys-touch { display: flex; }
}

/* ---- D-pad ---- */
#dpad {
  position: absolute;
  right: max(22px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  display: none;
  grid-template-columns: repeat(3, var(--dpad-cell, 56px));
  grid-template-rows: repeat(3, var(--dpad-cell, 56px));
  gap: 6px;
  opacity: 0;
  transition: opacity .3s ease;
}
#dpad.visible { display: grid; opacity: .92; }
@media (pointer: fine) { #dpad.visible { display: none; } }

.dpad-btn {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  color: var(--text);
  border-radius: 14px;
  font-size: 20px;
  cursor: pointer;
  backdrop-filter: blur(6px);
}
.dpad-btn:active { background: var(--neon); box-shadow: 0 0 18px var(--neon); }
.dpad-up { grid-area: 1 / 2 / 2 / 3; }
.dpad-left { grid-area: 2 / 1 / 3 / 2; }
.dpad-right { grid-area: 2 / 3 / 3 / 4; }
.dpad-down { grid-area: 3 / 2 / 4 / 3; }

/* ---- Settings Overlay ---- */
#settings {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 10, 26, .85);
  backdrop-filter: blur(8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease-out;
}
#settings.visible {
  opacity: 1;
  pointer-events: auto;
}
.settings-panel {
  max-width: 500px;
}
#settings.visible .settings-panel { transform: none; }
.settings-content {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 24px;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: clamp(16px, 4vw, 22px);
  background: rgba(255, 248, 220, 0.4);
  padding: 12px 20px;
  border-radius: 16px;
  border: 3px solid rgba(0, 0, 0, 0.1);
}
.setting-toggle {
  background: var(--neon);
  color: #fff;
  border: none;
  padding: 8px 24px;
  border-radius: 12px;
  font-family: inherit;
  font-size: clamp(14px, 4vw, 20px);
  cursor: pointer;
  transition: transform 0.1s, background 0.2s;
  box-shadow: 0 4px 0 rgba(0,0,0,0.3);
  min-width: 120px;
}
.setting-toggle:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 rgba(0,0,0,0.3);
}
.setting-toggle.off {
  background: #ff4f9a;
}

/* ---- Loading + boot ---- */
#loading, #boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: rgba(5, 6, 13, .82);
  z-index: 40;
}
#loading { opacity: 0; pointer-events: none; transition: opacity .25s ease; background: rgba(5,6,13,.55); }
#loading.visible { opacity: 1; }
#boot { z-index: 60; }

.spinner {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 5px solid rgba(120, 130, 255, .25);
  border-top-color: var(--neon);
  animation: spin 0.9s linear infinite;
  box-shadow: 0 0 20px rgba(255, 53, 224, .35);
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text, .boot-text { color: var(--muted); font-weight: 600; letter-spacing: .08em; }

/* ---- Fade transition ---- */
#fade {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .38s ease;
  z-index: 50;
}
#fade.opaque { opacity: 1; }

/* ---- Win screen ---- */
#win-screen {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  opacity: 0;
  transition: opacity .25s ease;
  z-index: 45;
}
#win-screen.visible { opacity: 1; }

.win-message {
  position: absolute;
  top: 40%; left: 50%;
  transform: translate(-50%, -50%) rotate(var(--tilt, 0deg)) scale(0);
  font-size: clamp(44px, 12vw, 96px);
  font-weight: 900;
  letter-spacing: .02em;
  white-space: nowrap;
  text-shadow: 0 0 22px currentColor, 0 6px 0 rgba(0, 0, 0, .25);
  animation: winpop .5s cubic-bezier(.2, .8, .2, 1.4) forwards;
}
@keyframes winpop {
  0% { transform: translate(-50%, -50%) rotate(calc(var(--tilt) - 18deg)) scale(0); }
  70% { transform: translate(-50%, -50%) rotate(var(--tilt)) scale(1.12); }
  100% { transform: translate(-50%, -50%) rotate(var(--tilt)) scale(1); }
}

.win-reward {
  position: absolute;
  top: 56%; left: 50%;
  transform: translate(-50%, -50%) scale(0);
  font-size: clamp(28px, 6vw, 46px);
  font-weight: 800;
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255, 210, 63, .8);
  animation: winpop .4s .15s cubic-bezier(.2, .8, .2, 1.4) forwards;
}
.win-reward .star-ico { color: var(--gold); }

.win-sticker {
  position: absolute;
  top: 40%; left: 50%;
  font-size: 42px;
  transform: translate(-50%, -50%) scale(0);
  text-shadow: 0 0 10px currentColor;
  animation: stickerpop .45s cubic-bezier(.2, .8, .2, 1.6) forwards;
}
@keyframes stickerpop {
  to { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) rotate(var(--rot)) scale(1); }
}

.confetti {
  position: absolute;
  top: -10vh;
  width: 11px; height: 16px;
  border-radius: 2px;
  opacity: .95;
  animation: fall linear forwards;
}
@keyframes fall {
  0% { transform: translateY(0) rotate(0deg); }
  100% { transform: translateY(120vh) rotate(var(--spin, 360deg)); }
}

@media (max-width: 520px) {
  #difficulty-buttons { grid-template-columns: 1fr 1fr; }
  .hud-chip { padding: 8px 11px; }
  #stars-hud { font-size: 17px; }
  #progress-hud { min-width: 120px; }
  .shop-panel { padding: 16px 13px; }
  .shop-items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shop-header h2 { font-size: 30px; }
  .shop-wallet { font-size: 15px; padding: 6px 10px; }
  .shop-card { padding: 8px; }
}

/* ---- Narrow phones (mainly portrait): keep the top HUD on one row ----
   Stars + progress + the 4 action buttons (settings/gift/retry/back) must coexist
   on ~360px. Pin the progress chip and action group at usable sizes and let the
   star count be the one that shrinks (ellipsis) — so a huge balance can't squeeze
   the progress bar down to nothing. */
@media (max-width: 430px) {
  #hud {
    gap: 7px;
    padding: max(12px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 12px max(10px, env(safe-area-inset-left));
  }
  .hud-chip { padding: 7px 9px; border-radius: 12px; }
  #stars-hud { font-size: 15px; gap: 5px; min-width: 0; flex: 0 1 auto; }
  #stars-count { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  #progress-hud { min-width: 92px; flex: 0 0 auto; }
  #hud-difficulty { font-size: 10px; margin-bottom: 4px; }
  #hud-actions { gap: 5px; flex: 0 0 auto; }
  .icon-btn { width: 36px; height: 36px; font-size: 16px; border-radius: 11px; }
}

@media (max-height: 620px) {
  .menu-panel {
    padding: 18px 22px 16px;
    width: min(88vw, 540px);
  }
  .logo { height: 78px; width: auto; margin: 2px auto 8px; }
  .title { font-size: clamp(32px, 8vh, 48px); }
  .subtitle { margin: 5px 0 12px; }
  .diff-btn { padding: 9px 13px; }
  .menu-foot { margin-top: 13px; padding: 5px 12px; }
  .shop-open-btn { margin-top: 13px; }
  .how-to { margin-top: 9px; font-size: 11.5px; }
  .legal-note { margin-top: 6px; font-size: 10px; }
}

@media (max-height: 450px) {
  .menu-panel { width: min(94vw, 680px); padding: 12px 18px; }
  .logo { height: 56px; width: auto; margin: 0 auto 6px; }
  .title { font-size: 32px; }
  .subtitle { display: none; }
  #difficulty-buttons { grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 8px; }
  .diff-btn { padding: 8px 10px; }
  .diff-name { font-size: 15px; }
  .menu-foot { margin-top: 10px; }
  .menu-bottom-row { gap: 6px; }
  .how-to { display: none; }
  .legal-note { margin-top: 5px; font-size: 9.5px; line-height: 1.35; }
}

/* ---- Mobile landscape: short viewport ----
   In landscape the height is the scarce axis. Shrink the D-pad so it doesn't eat
   half the screen, and give the menu panel a little breathing room from notches. */
@media (orientation: landscape) and (max-height: 520px) {
  #dpad { --dpad-cell: 46px; gap: 5px; }
  .dpad-btn { font-size: 17px; border-radius: 12px; }
  /* Keep the menu clear of side notches when the panel is wide. */
  #menu { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
}

/* ---- HUD collapse (landscape phones only) ----
   The top HUD bar overlaps the maze in landscape, so offer a toggle to hide it.
   Collapsed keeps only the menu (☰) and the toggle itself, flush in the corner,
   so the top of the maze is clear but the player can still bail out or restore.
   Scoped to landscape: in portrait the full HUD always shows (and the toggle is
   hidden), so rotating a collapsed HUD into portrait can never strand the user. */
@media (orientation: landscape) and (max-height: 600px) {
  #hud-actions #btn-hud-toggle { display: inline-flex; align-items: center; justify-content: center; }
  #hud.collapsed { justify-content: flex-end; }
  #hud.collapsed #stars-hud,
  #hud.collapsed #progress-hud,
  #hud.collapsed #btn-settings-hud,
  #hud.collapsed #btn-retry { display: none; }
}

/* ---- Very short landscape (small phones): trim the D-pad further ---- */
@media (orientation: landscape) and (max-height: 380px) {
  #dpad { --dpad-cell: 40px; }
}

/* ---- Cinematic Camera Director (toggle with M) ---- */
#movie-mode {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 252px;
  display: none; /* hidden until M; .visible flips to flex */
  flex-direction: column;
  gap: 9px;
  padding: 12px 14px 11px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  box-shadow: 0 10px 34px rgba(0, 0, 0, .5), 0 0 0 1px rgba(255, 53, 224, .12);
  color: var(--text);
  font-size: 13px;
  z-index: 30;
}
#movie-mode.visible { display: flex; }

.mm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}
.mm-title {
  font-weight: 800;
  letter-spacing: .03em;
  color: var(--neon2);
  text-shadow: 0 0 12px rgba(54, 224, 255, .45);
}
.mm-x {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.mm-x:hover { color: var(--text); }

.mm-row {
  display: grid;
  grid-template-columns: 64px 1fr 30px;
  align-items: center;
  gap: 8px;
}
.mm-row > span { color: var(--muted); font-weight: 600; font-size: 12px; }
.mm-row > b { color: var(--neon); font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }

#movie-mode select,
#movie-mode input[type="range"] {
  width: 100%;
  grid-column: 2 / span 2;
}
#movie-mode select {
  appearance: none;
  background: rgba(8, 8, 20, .7);
  color: var(--text);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 5px 8px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
}
#movie-mode input[type="range"] {
  grid-column: 2 / 3;
  accent-color: var(--neon);
  cursor: pointer;
}

.mm-actions { display: flex; gap: 8px; margin-top: 2px; }
.mm-btn {
  flex: 1;
  padding: 8px 6px;
  border-radius: 9px;
  border: 1px solid var(--panel-border);
  background: rgba(8, 8, 20, .6);
  color: var(--text);
  font-family: inherit;
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: transform .08s ease, box-shadow .12s ease, background .12s ease;
}
.mm-btn:hover { transform: translateY(-1px); }
.mm-btn:active { transform: translateY(0); }
.mm-play {
  background: linear-gradient(180deg, var(--neon), #c01ba8);
  border-color: transparent;
  box-shadow: 0 4px 16px rgba(255, 53, 224, .4);
}
.mm-play.playing {
  background: linear-gradient(180deg, var(--neon2), #1597c0);
  box-shadow: 0 4px 16px rgba(54, 224, 255, .4);
}
.mm-hint {
  margin: 1px 0 0;
  font-size: 10.5px;
  color: var(--muted);
  text-align: center;
  letter-spacing: .02em;
}
.mm-hint b { color: var(--neon2); }
