:root {
  color-scheme: dark;
  --ink: #fffaff;
  --muted: #d0bfe0;
  --night: #0c0315;
  --violet: #a84dff;
  --blue: #6330a8;
  --gold: #ffb13b;
  --pink: #ff8bbc;
  --pumpkin: #ff7a1a;
}

* { box-sizing: border-box; }

body {
  min-height: 100svh;
  margin: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(141, 56, 218, .38), transparent 34rem),
    radial-gradient(circle at 85% 85%, rgba(86, 27, 139, .32), transparent 30rem),
    var(--night);
  color: var(--ink);
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", system-ui, sans-serif;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .3;
  background-image: radial-gradient(#c9a3ff 1px, transparent 1px);
  background-size: 34px 34px;
}

button { font: inherit; }

.locked .game-shell { display: none; }

.access-gate {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

body:not(.locked) .access-gate { display: none; }

.access-wrap {
  display: grid;
  justify-items: center;
  gap: 22px;
}

.access-panel {
  width: min(92vw, 410px);
  padding: 34px 26px 30px;
  border: 3px solid #a84dff;
  border-radius: 16px;
  text-align: center;
  background: #1b082e;
  box-shadow: 0 0 0 4px #4b176f, 10px 10px 0 #050109, 0 0 34px rgba(168, 77, 255, .42);
}

.access-key-art {
  display: block;
  width: 82px;
  height: 112px;
  margin: -8px auto 10px;
  object-fit: contain;
  image-rendering: pixelated;
  transform: rotate(38deg);
  animation: key-flash 1.4s steps(2, end) infinite;
}

@keyframes key-flash {
  50% { filter: brightness(1.22) drop-shadow(0 0 7px rgba(255, 216, 77, .65)); }
}

.access-panel h1 {
  margin: 0 0 22px;
  font: 900 clamp(.95rem, 4.2vw, 1.45rem)/1.35 ui-monospace, monospace;
  letter-spacing: .02em;
  white-space: nowrap;
}

.access-form { display: grid; gap: 12px; }

.access-form input {
  width: 100%;
  padding: 13px 14px;
  border: 2px solid #9b5bd2;
  border-radius: 8px;
  outline: none;
  color: white;
  background: #0c0315;
  font: 800 1rem/1.2 ui-monospace, monospace;
  letter-spacing: .08em;
  text-align: center;
}

.access-form input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 216, 77, .18); }

.access-form button {
  padding: 12px 20px;
  border: 0;
  border-radius: 8px;
  color: #171000;
  background: var(--gold);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #a96d00;
}

.access-form button:active { transform: translateY(3px); box-shadow: 0 2px 0 #a96d00; }

.access-error { min-height: 1.4em; margin: 14px 0 0; color: #ff9fb9; font-weight: 700; }

.subscription-guide {
  max-width: 410px;
  margin: 0;
  color: #c6c2df;
  font-size: .84rem;
  line-height: 1.7;
  text-align: center;
}

.subscription-guide p { margin: 0 0 8px; }

.subscription-guide a,
.guide-back {
  color: var(--gold);
  font-weight: 800;
  text-underline-offset: 4px;
}

.guide-shell {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.guide-card {
  width: min(92vw, 480px);
  padding: 30px 26px;
  border: 3px solid #a84dff;
  border-radius: 16px;
  background: #1b082e;
  box-shadow: 0 0 0 4px #4b176f, 10px 10px 0 #050109, 0 0 34px rgba(168, 77, 255, .42);
}

.guide-card h1 {
  margin: 0 0 24px;
  color: var(--gold);
  font: 900 1.35rem/1.45 ui-monospace, monospace;
  text-align: center;
}

.guide-steps {
  margin: 0 0 26px;
  padding-left: 1.5em;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.8;
}

.guide-steps li + li { margin-top: 10px; }

.guide-note {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.7;
}

.guide-back {
  display: block;
  text-align: center;
}


.game-shell {
  width: min(94vw, 720px);
  margin: 0 auto;
  padding: 24px 0 max(24px, env(safe-area-inset-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.logo-lockup {
  display: grid;
  justify-items: start;
  gap: 2px;
  min-width: 0;
}

.game-logo {
  display: block;
  width: min(100%, 430px);
  height: auto;
  mix-blend-mode: screen;
  image-rendering: pixelated;
}

.edition-label {
  margin-left: 8px;
  color: #ffb13b;
  font: 900 clamp(.68rem, 2.2vw, .92rem)/1 ui-monospace, monospace;
  letter-spacing: .18em;
  text-shadow: 2px 2px 0 #54176e, 0 0 10px rgba(255, 122, 26, .55);
}

.icon-button {
  flex: none;
  min-width: 72px;
  padding: 9px 12px;
  border: 1px solid #9d61cb;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(52, 15, 76, .92);
  cursor: pointer;
}

.sound-controls {
  flex: none;
  display: grid;
  justify-items: center;
  gap: 7px;
  width: 120px;
}

.volume-control {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 6px;
  width: 100%;
  color: var(--muted);
  font-size: .72rem;
}

.volume-control input {
  width: 100%;
  margin: 0;
  accent-color: var(--gold);
  cursor: pointer;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr 1.15fr;
  gap: 8px;
  margin-bottom: 10px;
}

.scoreboard div {
  padding: 9px 12px;
  border: 1px solid rgba(182, 92, 235, .58);
  border-radius: 10px;
  background: rgba(31, 8, 46, .9);
  box-shadow: inset 0 0 16px rgba(177, 72, 230, .12);
}

.scoreboard span {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: .73rem;
}

.scoreboard strong {
  color: var(--gold);
  font: 800 1rem/1 ui-monospace, monospace;
}

#power.active {
  color: #ffd08a;
  animation: blessing-flash .28s steps(2, end) infinite;
}

@keyframes blessing-flash {
  0% { text-shadow: 0 0 4px #ff7a1a; transform: scale(1); }
  100% { text-shadow: 0 0 14px #fff, 0 0 24px #ff9b3d; transform: scale(1.08); }
}

.game-stage {
  position: relative;
  overflow: hidden;
  border: 3px solid #a84dff;
  border-radius: 14px;
  background: #09010f;
  box-shadow: 0 0 0 3px #4b176f, 0 0 30px rgba(168, 77, 255, .48);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  touch-action: none;
}

canvas.gate-opening {
  animation: gate-shake 1.25s steps(2, end);
}

@keyframes gate-shake {
  0%, 100% { transform: translate(0, 0); filter: brightness(1); }
  8% { transform: translate(-7px, 5px); filter: brightness(1.8); }
  16% { transform: translate(8px, -6px); }
  24% { transform: translate(-6px, -4px); }
  34% { transform: translate(6px, 5px); }
  46% { transform: translate(-4px, 3px); }
  60% { transform: translate(3px, -3px); }
  76% { transform: translate(-2px, 2px); }
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(10, 1, 18, .78);
  backdrop-filter: blur(3px);
}

.overlay.hidden { display: none; }

.panel {
  width: min(92%, 390px);
  padding: 25px 22px;
  border: 2px solid var(--violet);
  border-radius: 16px;
  text-align: center;
  background: #200936;
  box-shadow: 8px 8px 0 #08010d;
}

.big-star {
  display: block;
  color: var(--gold);
  font-size: 3rem;
  filter: drop-shadow(0 0 12px rgba(255, 122, 26, .7));
}

.panel h2 { margin: 5px 0 8px; font-size: 1.35rem; }
.panel p { margin: 0 0 18px; color: #d2cfea; line-height: 1.65; font-size: .92rem; }

.overlay-actions { display: flex; flex-direction: column; align-items: center; gap: 11px; }

#startButton {
  min-width: 150px;
  padding: 12px 20px;
  border: 0;
  border-radius: 8px;
  color: #171000;
  background: var(--gold);
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 5px 0 #a96d00;
}

#startButton:active { transform: translateY(3px); box-shadow: 0 2px 0 #a96d00; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-areas: ". up ." "left down right";
  justify-content: center;
  gap: 7px;
  margin-top: 15px;
}

.dpad button {
  width: 64px;
  height: 52px;
  border: 1px solid #9f62cc;
  border-radius: 11px;
  color: white;
  background: linear-gradient(#4f1d6d, #281038);
  font-size: 1.25rem;
  cursor: pointer;
  touch-action: manipulation;
  box-shadow: 0 4px 0 #09081e;
}

.dpad button:active { transform: translateY(3px); box-shadow: 0 1px 0 #09081e; background: #7c35a8; }
.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="down"] { grid-area: down; }
.dpad [data-dir="right"] { grid-area: right; }

.hint { margin: 14px 0 0; text-align: center; color: var(--muted); font-size: .86rem; }

@media (min-width: 760px) {
  .game-shell { padding-top: 32px; }
  .dpad { display: none; }
}

@media (max-width: 420px) {
  .game-shell { width: 95vw; padding-top: 14px; }
  .topbar { gap: 8px; }
  .logo-lockup { width: calc(100% - 112px); }
  .game-logo { width: 100%; }
  .sound-controls { width: 104px; }
  .icon-button { min-width: 70px; padding-inline: 9px; }
  .scoreboard { grid-template-columns: 1fr 1fr; }
  .scoreboard div { padding: 8px; }
  .scoreboard strong { font-size: .9rem; }
}
