@import url("https://fonts.googleapis.com/css2?family=Bungee:wght@400&family=Space+Grotesk:wght@400;500;700&family=JetBrains+Mono:wght@500;700&family=Orbitron:wght@600;800&display=swap");

:root {
  --bg-0: #08131d;
  --bg-1: #0e1d2b;
  --panel: rgba(9, 18, 29, 0.88);
  --panel-strong: rgba(6, 13, 22, 0.94);
  --line: rgba(124, 247, 212, 0.34);
  --line-strong: rgba(124, 247, 212, 0.74);
  --text: #ecf4ff;
  --muted: #9fb8cc;
  --accent: #7cf7d4;
  --accent-2: #ffbe6e;
  --accent-3: #71a9ff;
  --danger: #ff6c68;
  --radius: 16px;
  --control-size: 64px;
  --stick-size: 138px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  min-height: 100%;
}

body {
  min-height: 100dvh;
  width: 100%;
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 190, 110, 0.12), transparent 28%),
    radial-gradient(circle at 84% 82%, rgba(124, 247, 212, 0.14), transparent 34%),
    linear-gradient(165deg, var(--bg-0), #040910 46%, var(--bg-1));
  background-size: 130% 130%, 120% 120%, auto;
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 1.2vh, 14px) clamp(10px, 2vw, 28px) clamp(12px, 1.8vh, 20px);
  gap: clamp(8px, 1.1vh, 12px);
  animation: body-shift 18s ease-in-out infinite alternate;
}

.bg-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -4;
}

.bg-pixel {
  z-index: -4;
  opacity: 0.76;
  background:
    linear-gradient(180deg, rgba(3, 6, 11, 0.92), rgba(4, 9, 16, 0.98)),
    repeating-linear-gradient(0deg, rgba(124, 247, 212, 0.11) 0 1px, transparent 1px 20px),
    repeating-linear-gradient(90deg, rgba(124, 247, 212, 0.11) 0 1px, transparent 1px 20px);
  background-size: 100% 100%, 20px 20px, 20px 20px;
  transform-origin: center;
  animation: pixel-grid-drift 24s linear infinite;
}

.bg-pixel::before {
  content: "";
  position: absolute;
  inset: -18%;
  background: radial-gradient(
    circle at 50% 50%,
    rgba(255, 190, 110, 0.24) 0%,
    rgba(113, 169, 255, 0.14) 18%,
    rgba(124, 247, 212, 0.05) 34%,
    transparent 62%
  );
  filter: blur(4px);
  animation: pixel-ripple 8s ease-in-out infinite;
}

.bg-pixel::after {
  content: "";
  position: absolute;
  inset: -30%;
  background:
    radial-gradient(circle at 20% 28%, rgba(124, 247, 212, 0.18), transparent 28%),
    radial-gradient(circle at 80% 72%, rgba(255, 190, 110, 0.14), transparent 26%);
  mix-blend-mode: screen;
  opacity: 0.85;
  animation: pixel-orbit 18s linear infinite;
}

.bg-stars {
  z-index: -3;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(255, 190, 110, 0.2), transparent 34%),
    radial-gradient(circle at 80% 15%, rgba(124, 247, 212, 0.16), transparent 30%),
    radial-gradient(circle at 70% 90%, rgba(124, 247, 212, 0.12), transparent 26%),
    linear-gradient(rgba(124, 247, 212, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124, 247, 212, 0.05) 1px, transparent 1px);
  background-size: auto, auto, auto, 36px 36px, 36px 36px;
  animation: stars-drift 70s linear infinite;
}

.bg-flow {
  z-index: -1;
  opacity: 0.56;
  background:
    conic-gradient(
      from 0deg at 50% 50%,
      rgba(124, 247, 212, 0.12) 0deg,
      rgba(113, 169, 255, 0.09) 110deg,
      rgba(255, 190, 110, 0.12) 210deg,
      rgba(124, 247, 212, 0.12) 360deg
    );
  filter: blur(68px);
  transform: scale(1.08);
  animation: bg-flow-spin 38s linear infinite;
}

.bg-radial {
  z-index: -3;
  background:
    radial-gradient(circle at 50% -10%, rgba(124, 247, 212, 0.22), transparent 50%),
    radial-gradient(circle at 52% 112%, rgba(255, 190, 110, 0.17), transparent 44%);
  animation: bg-pulse 9s ease-in-out infinite alternate;
}

.site-header {
  width: min(1360px, 100%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: enter-down 460ms ease both;
}

.header-pill {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(124, 247, 212, 0.08), transparent 46%),
    linear-gradient(140deg, rgba(10, 20, 30, 0.9), rgba(9, 16, 24, 0.78));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: clamp(8px, 1.2vw, 11px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 14px 36px rgba(0, 0, 0, 0.38);
  position: relative;
  overflow: hidden;
}

.header-pill::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(
      125deg,
      transparent 0%,
      rgba(124, 247, 212, 0.12) 36%,
      transparent 70%
    );
  transform: translateX(-45%);
  pointer-events: none;
  animation: header-sheen 5.5s linear infinite;
}

.identity-kicker {
  font-family: "JetBrains Mono", monospace;
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--accent);
  opacity: 0.9;
}

.identity-name {
  margin-top: 4px;
  display: flex;
  align-items: baseline;
  gap: clamp(5px, 0.7vw, 10px);
  flex-wrap: wrap;
}

.title-main {
  font-family: "Bungee", "Orbitron", sans-serif;
  font-size: clamp(24px, 3.4vw, 44px);
  line-height: 0.9;
  letter-spacing: 0.1em;
  color: #ffee95;
  text-shadow:
    0 0 10px rgba(255, 190, 110, 0.55),
    0 0 26px rgba(255, 190, 110, 0.25);
}

.identity-subline {
  margin-top: 4px;
  font-size: clamp(10px, 1.05vw, 12px);
  letter-spacing: 0.05em;
  color: var(--muted);
}

.header-badges {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.header-badge {
  border: 1px solid rgba(124, 247, 212, 0.42);
  border-radius: 999px;
  padding: 4px 9px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  background: rgba(8, 16, 25, 0.88);
}

.header-links {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.header-link {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  text-decoration: none;
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  text-align: center;
  background: linear-gradient(170deg, rgba(18, 30, 45, 0.9), rgba(10, 16, 26, 0.9));
  transition: transform 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.header-link:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  color: var(--accent);
}

.game-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 7px;
  animation: enter-up 500ms 80ms ease both;
}

.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.desktop-only {
  display: inline-flex;
}

.action-btn {
  border: 1px solid rgba(255, 190, 110, 0.44);
  border-radius: 12px;
  min-width: 104px;
  padding: 8px 11px;
  background: linear-gradient(170deg, rgba(21, 31, 45, 0.9), rgba(8, 14, 23, 0.95));
  color: var(--accent-2);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.04),
    0 8px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

.action-btn:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  color: var(--accent);
}

.action-btn.compact {
  min-width: auto;
  font-size: 11px;
  padding: 6px 8px;
}

.action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  color: var(--muted);
  border-color: rgba(255, 255, 255, 0.2);
}

.action-btn[aria-pressed="true"] {
  border-color: var(--line-strong);
  color: var(--accent);
}

.game-shell {
  width: min(1360px, 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: enter-up 520ms 140ms ease both;
}

.canvas-shell {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: clamp(10px, 1.7vw, 16px);
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.03),
    0 22px 34px rgba(0, 0, 0, 0.38),
    0 0 42px rgba(124, 247, 212, 0.08);
}

#canvas {
  display: block;
  border: 2px solid rgba(242, 249, 255, 0.85);
  background: #000;
  touch-action: none;
}

.touch-controls {
  display: none;
  margin-top: 12px;
  grid-template-columns: repeat(3, var(--control-size));
  grid-template-areas:
    ". up ."
    "left down right";
  gap: 10px;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

.touch-btn {
  width: var(--control-size);
  height: var(--control-size);
  border-radius: 14px;
  border: 1px solid rgba(124, 247, 212, 0.6);
  background: rgba(7, 16, 26, 0.95);
  color: var(--accent);
  font-size: clamp(18px, calc(var(--control-size) * 0.36), 28px);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.touch-btn:active {
  transform: scale(0.97);
}

.touch-up { grid-area: up; }
.touch-left { grid-area: left; }
.touch-right { grid-area: right; }
.touch-down { grid-area: down; }

.virtual-stick {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 10px;
  gap: 8px;
}

.stick-base {
  width: var(--stick-size);
  height: var(--stick-size);
  border-radius: 50%;
  border: 1px solid rgba(124, 247, 212, 0.64);
  background: radial-gradient(circle at 35% 30%, rgba(124, 247, 212, 0.2), rgba(7, 15, 23, 0.94));
  position: relative;
  touch-action: none;
}

.stick-knob {
  width: calc(var(--stick-size) * 0.4);
  height: calc(var(--stick-size) * 0.4);
  border-radius: 50%;
  position: absolute;
  left: calc(var(--stick-size) * 0.3);
  top: calc(var(--stick-size) * 0.3);
  border: 1px solid rgba(255, 255, 255, 0.58);
  background: rgba(255, 190, 110, 0.95);
  pointer-events: none;
}

.stick-help {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.settings-panel {
  width: min(1360px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  overflow: hidden;
  animation: enter-up 540ms 170ms ease both;
}

.settings-panel summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 14px;
  font-family: "JetBrains Mono", monospace;
  color: var(--accent);
  font-weight: 700;
}

.settings-panel summary::-webkit-details-marker {
  display: none;
}

.settings-grid {
  padding: 4px 14px 14px;
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 10px;
}

.settings-item {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 12px;
  background: rgba(12, 21, 32, 0.86);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
}

.settings-item span {
  color: var(--text);
  font-weight: 700;
}

.settings-item input[type="range"],
.settings-item select {
  width: 100%;
}

.settings-item input[type="number"] {
  width: 100%;
  padding: 7px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(4, 10, 17, 0.9);
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
}

.action-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.settings-inline-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.gamepad-binds {
  grid-column: 1 / -1;
}

.gamepad-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(100px, 1fr));
  gap: 8px;
}

.gamepad-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 11px;
  font-family: "JetBrains Mono", monospace;
}

.daily-panel,
.leaderboard-panel,
.seed-tools,
.sim-debug,
.replay-tools,
.settings-transfer {
  grid-column: 1 / -1;
}

.leaderboard-output {
  white-space: pre-wrap;
  background: rgba(4, 11, 19, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 9px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  color: var(--accent);
  max-height: 180px;
  overflow: auto;
}

.settings-toggle {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}

.settings-toggle input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.keybinds {
  grid-column: 1 / -1;
}

.keybind-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 8px;
}

.keybind-btn {
  border: 1px solid rgba(255, 190, 110, 0.5);
  border-radius: 10px;
  background: rgba(7, 14, 22, 0.95);
  color: var(--accent-2);
  padding: 8px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  cursor: pointer;
}

.keybind-btn.rebinding {
  border-color: var(--line-strong);
  color: var(--accent);
}

.settings-help {
  font-size: 12px;
  color: var(--muted);
}

.site-footer {
  width: min(1360px, 100%);
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  padding-top: 8px;
  text-align: center;
  animation: enter-up 580ms 220ms ease both;
}

.footer-line {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.05em;
  color: var(--accent);
}

.footer-muted {
  margin-top: 3px;
  color: var(--muted);
}

body.arcade-view {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

body.arcade-view .settings-panel,
body.arcade-view .site-footer {
  display: none;
}

body.arcade-view .header-pill {
  display: none;
}

body.arcade-view .site-header {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 0;
  pointer-events: none;
  z-index: 12;
}

body.arcade-view .game-shell {
  width: 100%;
  max-width: none;
  min-height: 100dvh;
  padding: clamp(8px, 1.4vh, 18px);
  justify-content: center;
}

body.arcade-view .canvas-shell {
  width: min(1700px, 100%);
  min-height: calc(100dvh - clamp(16px, 2.2vh, 28px));
  justify-content: center;
  padding: clamp(10px, 1.8vw, 22px);
}

body.arcade-view .game-actions {
  pointer-events: auto;
  position: fixed;
  right: clamp(8px, 1.2vw, 18px);
  top: clamp(8px, 1.2vw, 18px);
  z-index: 12;
  border: 1px solid rgba(124, 247, 212, 0.34);
  border-radius: 13px;
  padding: 8px;
  background: rgba(7, 15, 25, 0.9);
  backdrop-filter: blur(8px);
}

body.reduced-motion,
body.reduced-motion * {
  animation: none !important;
  transition: none !important;
}

body.one-handed .touch-controls {
  margin-left: auto;
  margin-right: 0;
}

body.landscape-mobile .game-actions {
  gap: 5px;
}

body.landscape-mobile .action-btn {
  min-width: 82px;
  padding: 7px 9px;
  font-size: 11px;
}

@keyframes enter-down {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes enter-up {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes header-sheen {
  0% {
    transform: translateX(-55%);
  }
  100% {
    transform: translateX(180%);
  }
}

@keyframes pixel-grid-drift {
  0% {
    transform: scale(1) translate3d(0, 0, 0);
    background-position: 0 0, 0 0, 0 0;
  }
  100% {
    transform: scale(1.08) translate3d(-2%, -1%, 0);
    background-position: 0 0, 0 20px, 20px 0;
  }
}

@keyframes pixel-ripple {
  0%,
  100% {
    transform: scale(0.72);
    opacity: 0.44;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.78;
  }
}

@keyframes pixel-orbit {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

@keyframes stars-drift {
  0% {
    background-position: 0 0, 0 0, 0 0, 0 0, 0 0;
  }
  100% {
    background-position: 0 0, 0 0, 0 0, 500px 360px, 500px 360px;
  }
}

@keyframes bg-flow-spin {
  0% {
    transform: scale(1.08) rotate(0deg);
  }
  100% {
    transform: scale(1.08) rotate(360deg);
  }
}

@keyframes bg-pulse {
  0% {
    opacity: 0.8;
  }
  100% {
    opacity: 1;
  }
}

@keyframes body-shift {
  0% {
    background-position: 0% 0%, 100% 100%, 0 0;
  }
  100% {
    background-position: 12% 7%, 88% 93%, 0 0;
  }
}

@media (hover: none), (pointer: coarse) {
  .touch-controls {
    display: grid;
  }

  .desktop-only {
    display: none !important;
  }
}

@media (max-width: 880px) {
  .header-pill {
    flex-direction: column;
    align-items: flex-start;
  }

  .header-links {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .keybind-grid {
    grid-template-columns: repeat(2, minmax(110px, 1fr));
  }

  .gamepad-grid {
    grid-template-columns: repeat(2, minmax(110px, 1fr));
  }

  .desktop-only {
    display: none !important;
  }
}

@media (max-width: 640px) {
  body {
    padding: 8px 9px 14px;
  }

  .title-main {
    font-size: 27px;
  }

  .identity-subline {
    font-size: 10px;
  }

  .header-link {
    font-size: 10px;
  }

  .action-btn {
    min-width: 94px;
    padding: 8px 10px;
    font-size: 11px;
  }

  .touch-controls {
    gap: 8px;
  }
  
}

@media (max-width: 768px) {
  .bg-layer,
  .bg-pixel,
  .bg-pixel::before,
  .bg-pixel::after,
  .bg-stars,
  .bg-flow,
  .bg-radial {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    animation: none !important;
  }

  body {
    animation: none !important;
    background: #08131d !important;
  }

  .header-pill::after {
    display: none !important;
    animation: none !important;
  }
}

@media (max-width: 768px) {
  html,
  body {
    height: auto !important;
    min-height: 100vh !important;
    overflow-x: hidden !important;
    justify-content: flex-start !important;
  }

  .game-shell,
  .canvas-shell {
    width: 100% !important;
    max-width: 100% !important;
  }

  .canvas-shell {
    padding: 6px !important;
    overflow: hidden !important;
  }

  #canvas {
    width: 96vw !important;
    max-width: 96vw !important;
    height: auto !important;
    display: block !important;
    margin: 0 auto !important;
    transform: none !important;
  }

  .settings-panel,
  .site-footer {
    display: none !important;
  }
}
