:root {
  --bg: #050505;
  --fg: #f3f3f0;
  --muted: #a7a7a0;
  --line: rgba(255, 255, 255, 0.18);
  --glass: rgba(255, 255, 255, 0.06);
  --strong: rgba(255, 255, 255, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  min-height: 100vh;
  overflow: hidden;
  place-items: center;
  background: var(--bg);
  color: var(--fg);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  line-height: 1.5;
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -3;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    radial-gradient(circle at 50% 10%, rgba(255, 255, 255, 0.12), transparent 34rem);
  background-size: 44px 44px, 44px 44px, auto;
}

#p5-stage,
#fallback-canvas {
  position: fixed;
  inset: 0;
  z-index: -2;
  width: 100%;
  height: 100%;
}

#fallback-canvas {
  z-index: -4;
  background: var(--bg);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
}

.game-shell {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(100% - 1.4rem, 58rem);
  min-height: 100vh;
  align-content: center;
  padding: 1rem 0;
}

.cabinet {
  display: grid;
  grid-template-rows: auto minmax(22rem, 58vh) auto;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(5, 5, 5, 0.62);
  box-shadow: 0 2rem 5rem rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(16px);
}

.cabinet-top {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  min-height: 5.4rem;
  padding: 1rem clamp(1rem, 3vw, 1.5rem);
  border-bottom: 1px solid var(--line);
}

h1,
p {
  margin: 0;
  overflow-wrap: anywhere;
}

h1 {
  font-size: clamp(2rem, 6vw, 4.8rem);
  font-weight: 780;
  line-height: 0.9;
}

.cabinet-top p {
  color: var(--muted);
  font-size: clamp(0.72rem, 2vw, 0.9rem);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-align: right;
  text-transform: uppercase;
}

.game-stage {
  position: relative;
  min-height: 22rem;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.055), transparent 28%),
    rgba(0, 0, 0, 0.18);
}

.game-stage canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.controls {
  display: grid;
  justify-items: center;
  padding: 0.8rem clamp(1rem, 3vw, 1.4rem);
  border-top: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent 42%),
    rgba(255, 255, 255, 0.035);
}

.controls button {
  position: relative;
  display: grid;
  width: min(100%, 22rem);
  min-height: 4.4rem;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.34);
  border-radius: 999px;
  background:
    radial-gradient(circle at 50% 18%, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.22) 34%, rgba(255, 255, 255, 0.07) 68%),
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.04));
  box-shadow:
    inset 0 0.42rem 0.7rem rgba(255, 255, 255, 0.28),
    inset 0 -0.55rem 0.85rem rgba(0, 0, 0, 0.58),
    0 0.55rem 0 rgba(255, 255, 255, 0.08),
    0 1.2rem 2.5rem rgba(0, 0, 0, 0.5);
  color: #050505;
  cursor: pointer;
  transition:
    filter 160ms ease,
    opacity 160ms ease,
    transform 120ms ease;
}

.controls button::before {
  position: absolute;
  inset: 0.42rem 1.2rem auto;
  height: 0.9rem;
  border-radius: 999px;
  pointer-events: none;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.74), transparent);
  opacity: 0.72;
}

.controls button:hover,
.controls button:focus-visible,
.controls button.is-active {
  filter: brightness(1.14);
  outline: none;
}

.controls button.is-active {
  transform: translateY(0.28rem);
  box-shadow:
    inset 0 0.2rem 0.62rem rgba(255, 255, 255, 0.2),
    inset 0 -0.3rem 0.72rem rgba(0, 0, 0, 0.68),
    0 0.2rem 0 rgba(255, 255, 255, 0.08),
    0 0.8rem 2rem rgba(0, 0, 0, 0.44);
}

.controls button:disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(0.58);
  opacity: 0.58;
  transform: translateY(0.18rem);
}

.complete-message {
  position: fixed;
  inset: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transition: opacity 12s linear;
}

.complete-message[hidden] {
  display: none;
}

.complete-message.is-visible {
  opacity: 1;
}

.complete-message span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.complete-message canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.complete-message::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
  background-size: 18px 18px;
  mix-blend-mode: screen;
  opacity: 0.16;
}

@media (max-width: 620px) {
  .game-shell {
    width: min(100% - 0.9rem, 58rem);
  }

  .cabinet {
    grid-template-rows: auto minmax(25rem, 62vh) auto;
  }

  .cabinet-top {
    display: grid;
    align-items: start;
  }

  .cabinet-top p {
    text-align: left;
  }
}

@media (prefers-reduced-motion: reduce) {
  #p5-stage,
  #fallback-canvas {
    opacity: 0.32;
  }
}
