/*
 * Maze Chase presentation layer.
 *
 * Colours that change with the active maze layout (floor, wall fill, wall
 * outline, ghost bodies, drop glyphs, particles) are set as SVG presentation
 * attributes from JavaScript. CSS deliberately does not declare `fill` or
 * `stroke` for those elements, because a CSS declaration would win over the
 * attribute and freeze the theme.
 */

:root {
  color-scheme: dark;
  --bg: #050510;
  --surface: rgba(13, 14, 35, 0.82);
  --surface-strong: #10112a;
  --line: rgba(135, 145, 255, 0.18);
  --cyan: #36f6ff;
  --blue: #5b65ff;
  --violet: #a45cff;
  --pink: #ff4fbd;
  --yellow: #ffe33b;
  --mint: #4dffc3;
  --sky: #8ec6ff;
  --text: #f7f7ff;
  --muted: #8e91b3;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -15%, rgba(72, 77, 220, 0.22), transparent 42rem),
    linear-gradient(180deg, #070717 0%, #04040d 100%);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  content: "";
  opacity: 0.16;
  background-image:
    linear-gradient(rgba(110, 119, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(110, 119, 255, 0.08) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.visually-hidden {
  position: absolute;
  overflow: hidden;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  border: 0;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: -60px;
  left: 12px;
  z-index: 10;
  padding: 9px 14px;
  border-radius: 0 0 10px 10px;
  color: #080912;
  background: var(--cyan);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-decoration: none;
  transition: top 160ms ease;
}

.skip-link:focus {
  top: 0;
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 26rem;
  height: 26rem;
  border-radius: 50%;
  filter: blur(100px);
  pointer-events: none;
  opacity: 0.12;
}

.ambient-one {
  top: 18%;
  left: -12rem;
  background: var(--violet);
}

.ambient-two {
  right: -13rem;
  bottom: 8%;
  background: var(--cyan);
}

.app-shell {
  width: min(100% - 28px, 710px);
  margin: 0 auto;
  padding: 24px 0 calc(28px + var(--safe-bottom));
}

.brand-row,
.hud,
.game-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand-row {
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  letter-spacing: -0.04em;
  user-select: none;
}

.brand-kicker {
  padding: 4px 7px;
  border: 1px solid rgba(54, 246, 255, 0.55);
  border-radius: 4px;
  color: var(--cyan);
  font-size: 0.61rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  box-shadow: inset 0 0 12px rgba(54, 246, 255, 0.08);
}

.brand-title {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 900;
  letter-spacing: -0.07em;
}

.brand-slash {
  margin: 0 0.08em;
  color: var(--yellow);
  text-shadow: 0 0 14px rgba(255, 227, 59, 0.7);
}

.header-actions {
  display: flex;
  gap: 8px;
}

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  place-items: center;
  color: #b8bbda;
  background: rgba(14, 15, 35, 0.72);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.035);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    color 160ms ease,
    transform 160ms ease;
}

.icon-button:hover {
  border-color: rgba(54, 246, 255, 0.5);
  color: var(--cyan);
  transform: translateY(-1px);
}

.icon-button-off {
  color: #5b5f7d;
}

.hud {
  padding: 0 8px 10px;
}

.hud-block {
  display: flex;
  min-width: 30%;
  flex-direction: column;
  gap: 3px;
}

.hud-block-center {
  align-items: center;
}

.hud-block-right {
  align-items: flex-end;
}

.hud-label,
.footer-label {
  color: var(--muted);
  font-size: clamp(0.55rem, 2vw, 0.67rem);
  font-weight: 800;
  letter-spacing: 0.16em;
}

.hud-value {
  font-variant-numeric: tabular-nums;
  font-size: clamp(1.05rem, 4vw, 1.45rem);
  font-weight: 750;
  letter-spacing: 0.045em;
}

.hud-value-accent {
  color: var(--yellow);
  text-shadow: 0 0 16px rgba(255, 227, 59, 0.25);
}

.maze-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 10px;
}

.maze-name {
  color: var(--cyan);
  font-size: 0.63rem;
  font-weight: 850;
  letter-spacing: 0.24em;
  white-space: nowrap;
}

.progress-wrap {
  display: block;
  flex: 1;
}

.clear-progress {
  display: block;
  width: 100%;
  height: 4px;
  border: 0;
  border-radius: 999px;
  appearance: none;
  background: rgba(120, 129, 224, 0.16);
}

.clear-progress::-webkit-progress-bar {
  border-radius: 999px;
  background: rgba(120, 129, 224, 0.16);
}

.clear-progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
}

.clear-progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--cyan));
}

.game-frame {
  position: relative;
  padding: clamp(5px, 1.4vw, 9px);
  border: 1px solid rgba(100, 111, 255, 0.28);
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(75, 82, 184, 0.14), transparent 28%),
    rgba(6, 7, 22, 0.9);
  box-shadow:
    0 22px 70px rgba(0, 0, 0, 0.48),
    0 0 0 1px rgba(5, 6, 20, 0.8),
    inset 0 1px rgba(255, 255, 255, 0.045);
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  border-radius: 15px;
  background: #02020a;
}

/* ---------- SVG stage ---------- */

.stage {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 28 / 31;
  touch-action: none;
}

/* The stage is the skip-link target, so it needs a visible focus ring. */
.stage:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: -3px;
}

#stageVignette {
  opacity: 0.85;
  pointer-events: none;
}

.maze-glow {
  fill: none;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.75;
  filter: url(#neonGlow);
}

.maze-outline {
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.maze-door {
  fill: none;
  stroke: rgba(255, 101, 218, 0.85);
  stroke-width: 3;
  stroke-linecap: round;
}

.pellet-dot {
  fill: #ffe6bc;
}

.pellet-power {
  fill: #f4fdff;
  filter: url(#softGlow);
  transform-box: fill-box;
  transform-origin: center;
  animation: pellet-pulse 1.6s ease-in-out infinite;
}

@keyframes pellet-pulse {
  0%,
  100% {
    transform: scale(0.82);
    opacity: 0.82;
  }
  50% {
    transform: scale(1.12);
    opacity: 1;
  }
}

.gate {
  pointer-events: none;
}

.gate-tile {
  fill: rgba(164, 92, 255, 0.16);
  stroke: rgba(164, 92, 255, 0.5);
  stroke-width: 1.4;
  opacity: 0;
  transition: opacity 220ms ease;
}

.gate-open .gate-tile {
  opacity: 1;
}

.gate-warning .gate-tile {
  animation: gate-blink 0.4s steps(2, end) infinite;
}

@keyframes gate-blink {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.25;
  }
}

.drop-plate {
  fill: rgba(6, 10, 26, 0.85);
  stroke-width: 1.8;
  transform-box: fill-box;
  transform-origin: center;
  animation: drop-breathe 1.5s ease-in-out infinite;
}

.drop-glyph {
  pointer-events: none;
}

.drop-fading {
  animation: drop-fade 0.45s steps(2, end) infinite;
}

@keyframes drop-breathe {
  0%,
  100% {
    transform: scale(0.94);
  }
  50% {
    transform: scale(1.06);
  }
}

@keyframes drop-fade {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.35;
  }
}

.player-body {
  fill: var(--yellow);
  filter: url(#softGlow);
}

.player-aura {
  fill: none;
  stroke: var(--mint);
  stroke-width: 2;
  stroke-dasharray: 5 6;
  transform-box: fill-box;
  transform-origin: center;
  animation: aura-spin 1.1s linear infinite;
}

.player-shield {
  fill: none;
  stroke: var(--sky);
  stroke-width: 2.4;
}

.player-invulnerable .player-body {
  animation: blink 0.24s steps(2, end) infinite;
}

@keyframes aura-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes blink {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.35;
  }
}

.ghost-body {
  filter: url(#softGlow);
}

.ghost-sclera {
  fill: #f8fbff;
}

.ghost-pupil {
  fill: #2735a8;
}

.ghost-scared-eye {
  fill: #f3f5ff;
}

.ghost-scared-mouth {
  fill: none;
  stroke: #f3f5ff;
  stroke-width: 1.7;
}

.ghost-eaten .ghost-sclera {
  fill: #dfe8ff;
}

.particle {
  pointer-events: none;
}

.stage-tint {
  fill: #36f6ff;
  pointer-events: none;
  mix-blend-mode: screen;
  transition: opacity 160ms ease;
}

/* State hooks the renderer toggles on the <svg> root. */
.stage-powered .maze-glow {
  opacity: 1;
}

.stage-clearing .maze-outline {
  opacity: 0.75;
}

/* Low-quality tier: drop every filter, which is the expensive part. */
.quality-low .maze-glow,
.quality-low .pellet-power,
.quality-low .player-body,
.quality-low .ghost-body {
  filter: none;
}

.quality-low .maze-glow {
  opacity: 0.35;
}

.motion-reduced .pellet-power,
.motion-reduced .drop-plate,
.motion-reduced .player-aura,
.motion-reduced .gate-warning .gate-tile,
.motion-reduced .drop-fading,
.motion-reduced .player-invulnerable .player-body {
  animation: none;
}

/* ---------- overlay + hud chrome ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  padding: 22px;
  place-items: center;
  visibility: hidden;
  opacity: 0;
  background: rgba(3, 4, 16, 0.34);
  backdrop-filter: blur(2px);
  transition:
    opacity 220ms ease,
    visibility 220ms ease;
}

.overlay-visible {
  visibility: visible;
  opacity: 1;
}

.overlay-card {
  width: min(100%, 390px);
  padding: clamp(25px, 8vw, 44px) clamp(20px, 7vw, 38px);
  border: 1px solid rgba(111, 121, 255, 0.31);
  border-radius: 22px;
  text-align: center;
  background:
    radial-gradient(circle at 50% 0%, rgba(83, 91, 220, 0.2), transparent 60%),
    rgba(8, 9, 28, 0.92);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.55),
    inset 0 1px rgba(255, 255, 255, 0.05);
  transform: translateY(8px) scale(0.98);
  transition: transform 240ms ease;
}

.overlay-visible .overlay-card {
  transform: translateY(0) scale(1);
}

.eyebrow {
  color: var(--cyan);
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.22em;
}

.overlay h1 {
  margin: 10px 0 7px;
  font-size: clamp(2rem, 10vw, 3.3rem);
  font-weight: 900;
  letter-spacing: -0.075em;
  line-height: 1;
  text-shadow: 0 0 35px rgba(123, 130, 255, 0.25);
}

.overlay p {
  margin: 0;
  color: #a8aac7;
  font-size: 0.85rem;
  line-height: 1.6;
}

.primary-button {
  display: flex;
  width: 100%;
  min-height: 51px;
  margin: 24px 0 18px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #080912;
  background: var(--yellow);
  box-shadow: 0 8px 28px rgba(255, 227, 59, 0.2);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  cursor: pointer;
  transition:
    filter 160ms ease,
    transform 160ms ease;
}

.primary-button:hover {
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.button-arrow {
  font-size: 1.15rem;
  line-height: 1;
}

.key-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

kbd {
  display: inline-grid;
  min-width: 23px;
  height: 23px;
  padding: 0 5px;
  border: 1px solid rgba(153, 158, 209, 0.22);
  border-bottom-color: rgba(153, 158, 209, 0.42);
  border-radius: 5px;
  place-items: center;
  color: #c4c6e0;
  background: rgba(255, 255, 255, 0.045);
  font-family: inherit;
  font-size: 0.64rem;
  box-shadow: 0 2px rgba(0, 0, 0, 0.25);
}

.key-hint span {
  margin-left: 7px;
  font-size: 0.68rem;
}

.status-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 3;
  padding: 8px 14px;
  border: 1px solid rgba(54, 246, 255, 0.25);
  border-radius: 999px;
  opacity: 0;
  color: var(--cyan);
  background: rgba(5, 7, 23, 0.85);
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.15em;
  pointer-events: none;
  transform: translate(-50%, -42%);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.status-toast-visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.game-footer {
  min-height: 52px;
  padding: 10px 9px 0;
  gap: 10px;
}

.lives {
  display: flex;
  min-width: 22%;
  align-items: center;
  gap: 10px;
}

.life-icons {
  display: flex;
  gap: 5px;
}

.life-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: conic-gradient(
    from 35deg,
    transparent 0deg 70deg,
    var(--yellow) 70deg 360deg
  );
  filter: drop-shadow(0 0 5px rgba(255, 227, 59, 0.35));
}

.status-chips {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #6a6e8d;
  font-size: 0.56rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  white-space: nowrap;
  transition: color 180ms ease;
}

.chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.chip-active {
  color: var(--cyan);
}

.chip-active .chip-dot {
  box-shadow: 0 0 8px currentColor;
}

.chip-boost.chip-active {
  color: var(--mint);
}

.chip-shield.chip-active {
  color: var(--sky);
}

.text-button {
  min-width: 22%;
  padding: 7px 0;
  border: 0;
  color: #777b9c;
  background: transparent;
  font-size: 0.61rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-align: right;
  cursor: pointer;
  transition: color 160ms ease;
}

.text-button:hover {
  color: var(--text);
}

.touch-controls {
  display: none;
  width: 178px;
  height: 142px;
  margin: 14px auto 0;
  grid-template: repeat(3, 44px) / repeat(3, 52px);
  gap: 5px;
}

.touch-key,
.touch-center {
  border-radius: 12px;
}

.touch-key {
  border: 1px solid rgba(120, 129, 224, 0.26);
  color: #c9cbea;
  background: rgba(18, 20, 48, 0.86);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.04),
    0 4px 12px rgba(0, 0, 0, 0.2);
  font-size: 1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.touch-key:active,
.touch-key-active {
  border-color: rgba(54, 246, 255, 0.55);
  color: var(--cyan);
  background: rgba(32, 42, 78, 0.95);
  transform: translateY(1px);
}

.touch-up {
  grid-area: 1 / 2;
}

.touch-left {
  grid-area: 2 / 1;
}

.touch-center {
  grid-area: 2 / 2;
  border: 1px solid rgba(120, 129, 224, 0.1);
  background: rgba(10, 11, 28, 0.45);
}

.touch-right {
  grid-area: 2 / 3;
}

.touch-down {
  grid-area: 3 / 2;
}

.desktop-help {
  display: flex;
  margin: 5px 0 0;
  justify-content: center;
  gap: 18px;
  color: #555975;
  font-size: 0.61rem;
}

.desktop-help span {
  display: flex;
  align-items: center;
  gap: 5px;
}

.desktop-help kbd {
  min-width: 19px;
  height: 19px;
  font-size: 0.55rem;
}

@media (max-width: 620px), (pointer: coarse) {
  .app-shell {
    width: min(100% - 18px, 570px);
    padding-top: 14px;
  }

  .brand-row {
    margin-bottom: 10px;
  }

  .icon-button {
    width: 37px;
    height: 37px;
    border-radius: 10px;
  }

  .status-chips {
    gap: 6px;
  }

  .chip {
    font-size: 0.5rem;
  }

  .touch-controls {
    display: grid;
  }

  .desktop-help {
    display: none;
  }
}

@media (max-height: 790px) and (pointer: coarse) {
  .touch-controls {
    width: 158px;
    height: 116px;
    grid-template: repeat(3, 36px) / repeat(3, 46px);
    gap: 4px;
  }

  .game-footer {
    min-height: 43px;
    padding-top: 7px;
  }
}

@media (prefers-contrast: more) {
  .maze-glow {
    opacity: 0.2;
  }

  .chip {
    color: #b9bcd6;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
