:root {
  --bg: #080808;
  --bg2: #0f0f0f;
  --bg3: #171717;
  --card: rgba(17, 17, 17, 0.74);
  --border: rgba(255, 255, 255, 0.08);
  --border2: rgba(232, 213, 163, 0.2);
  --ink: #f2ede7;
  --muted: #9b958d;
  --accent: #e8d5a3;
  --accent2: #c4a96e;
  --blue: #6aafd4;
  --green: #6ec9a0;
  --purple: #a08fd4;
  --red: #d4879a;
  --cursor-x: 20%;
  --cursor-y: 12%;
  --game-hue: 185;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: "";
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 0;
  background:
    radial-gradient(ellipse 45% 42% at var(--cursor-x) var(--cursor-y), rgba(232, 213, 163, 0.1), transparent 68%),
    radial-gradient(ellipse 55% 48% at 82% 12%, rgba(106, 175, 212, 0.09), transparent 72%),
    radial-gradient(ellipse 48% 42% at 12% 88%, rgba(160, 143, 212, 0.08), transparent 70%),
    linear-gradient(180deg, rgba(8, 8, 8, 0.22), rgba(8, 8, 8, 0.96));
}

body::after {
  content: "";
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 3;
  opacity: 0.48;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
}

#page-bg,
.page-grid,
.ambient-lines {
  inset: 0;
  pointer-events: none;
  position: fixed;
}

#page-bg {
  height: 100vh;
  width: 100vw;
  z-index: 1;
}

.page-grid {
  animation: gridBreathe 7s ease-in-out infinite alternate;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.026) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.026) 1px, transparent 1px);
  background-size: 70px 70px;
  mask-image: radial-gradient(ellipse 80% 68% at 50% 32%, black 18%, transparent 82%);
  z-index: 1;
}

.ambient-lines {
  animation: lineSweep 11s linear infinite;
  background:
    linear-gradient(100deg, transparent 0 36%, rgba(232, 213, 163, 0.08) 37%, transparent 39% 100%),
    linear-gradient(80deg, transparent 0 58%, rgba(106, 175, 212, 0.055) 59%, transparent 61% 100%);
  background-size: 520px 100%, 740px 100%;
  opacity: 0.8;
  z-index: 1;
}

.game-shell {
  width: min(1050px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 36px;
  position: relative;
  z-index: 2;
}

.game-shell::before {
  background: linear-gradient(180deg, rgba(232, 213, 163, 0.055), rgba(255, 255, 255, 0.015));
  border: 1px solid var(--border);
  border-radius: 24px;
  content: "";
  inset: 18px -14px 22px;
  pointer-events: none;
  position: absolute;
  z-index: -1;
  backdrop-filter: blur(4px);
}

.hero {
  align-items: stretch;
  display: grid;
  grid-template-columns: 1fr 220px;
  gap: 14px;
  margin-bottom: 14px;
}

.eyebrow {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  margin: 0 0 8px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(2.4rem, 7vw, 5.4rem);
  letter-spacing: 0;
  line-height: 0.92;
  margin: 0 0 12px;
  text-shadow: 0 0 38px rgba(232, 213, 163, 0.12);
}

p {
  color: var(--muted);
}

.high-score,
.hud article,
.legend span,
canvas,
.mobile-controls button {
  border-radius: 8px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.36), 0 0 36px rgba(232, 213, 163, 0.055);
}

.high-score,
.hud article,
.legend span {
  background: var(--card);
  border: 1px solid var(--border);
  backdrop-filter: blur(18px);
}

.high-score {
  display: grid;
  align-content: center;
  padding: 18px;
}

.high-score span,
.hud span {
  color: var(--muted);
  display: block;
  font-weight: 900;
}

.high-score strong {
  color: var(--accent);
  font-size: 3rem;
}

.hud {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, 1fr) auto auto;
  margin-bottom: 12px;
}

.hud article {
  padding: 12px;
}

.hud strong {
  font-size: 1.7rem;
}

button {
  background: var(--accent);
  border: 0;
  border-radius: 8px;
  color: var(--bg);
  cursor: pointer;
  font: inherit;
  font-weight: 900;
  padding: 12px 16px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

#pauseBtn {
  background: transparent;
  border: 1px solid rgba(232, 213, 163, 0.36);
  color: var(--accent);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.legend span {
  font-weight: 900;
  padding: 9px 12px;
}

canvas {
  background: linear-gradient(180deg, #080808, #111111);
  border: 1px solid var(--border2);
  box-shadow: 0 28px 80px rgba(0,0,0,0.52), 0 0 55px rgba(232, 213, 163, 0.08);
  display: block;
  width: 100%;
}

.mobile-controls {
  display: none;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
  margin-top: 12px;
}

.mobile-controls button {
  background: var(--bg3);
  color: var(--accent);
  border: 1px solid var(--border2);
}

.hint {
  font-weight: 800;
}

@keyframes lineSweep {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 520px 0, -740px 0;
  }
}

@keyframes gridBreathe {
  0% {
    opacity: 0.34;
    transform: scale(1);
  }
  100% {
    opacity: 0.58;
    transform: scale(1.035);
  }
}

@media (max-width: 820px) {
  .hero,
  .hud {
    grid-template-columns: 1fr 1fr;
  }

  .mobile-controls {
    display: grid;
  }
}
