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

:root{
  --void: #0d0b14;
  --void-2: #16121f;
  --paper: #efe9de;
  --ink-soft: #9a92a8;
  --amber: #ffb020;
  --cyan: #38e0d0;
  --wall-w: 3px;
  --radius: 10px;
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100%;
  background: var(--void);
  color: var(--paper);
  font-family: 'JetBrains Mono', monospace;
  overscroll-behavior: none;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

body{
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  position: relative;
  overflow-y: auto;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

button{ touch-action: manipulation; }

.bg-canvas{
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.55;
}

.scene{
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 580px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  will-change: transform;
}

.scene.shake{ animation: shake 0.28s ease; }
@keyframes shake{
  0%   { transform: translate(0,0); }
  20%  { transform: translate(-3px, 2px); }
  40%  { transform: translate(3px, -2px); }
  60%  { transform: translate(-2px, -1px); }
  80%  { transform: translate(2px, 1px); }
  100% { transform: translate(0,0); }
}

/* ---------- HUD ---------- */
.hud{
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 16px;
  border-bottom: var(--wall-w) solid transparent;
  border-image: linear-gradient(90deg, var(--amber), transparent 40%, transparent 60%, var(--cyan)) 1;
  gap: 10px;
}

.wordmark{
  font-family: 'Orbitron', sans-serif;
  font-weight: 800;
  font-size: clamp(22px, 6vw, 30px);
  letter-spacing: 0.01em;
  margin: 0;
  order: 2;
  color: var(--paper);
  text-shadow: 0 0 18px rgba(255,176,32,0.25);
  flex: 1;
  text-align: center;
}
.wm-accent{
  background: linear-gradient(90deg, var(--amber), var(--cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.stat{
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 60px;
}
.stat-left{  order: 1; align-items: flex-start; }
.stat-right{ order: 3; align-items: flex-end; }

.stat-label{
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--ink-soft);
}
.stat-value{
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(20px, 5vw, 27px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--amber);
  transition: transform 0.18s ease;
}
.stat-value.bump{ animation: bump 0.28s ease; }
@keyframes bump{
  0%{ transform: scale(1); }
  40%{ transform: scale(1.25); }
  100%{ transform: scale(1); }
}

/* ---------- Board ---------- */
.board-wrap{ width: 100%; display: flex; justify-content: center; }

.board-stage{
  position: relative;
  filter: drop-shadow(0 12px 40px rgba(0,0,0,0.55));
  touch-action: none;
  max-width: 100%;
}
.board-stage.clear-punch{ animation: clearPunch 0.5s cubic-bezier(.2,.8,.2,1); }
@keyframes clearPunch{
  0%   { transform: scale(1); }
  30%  { transform: scale(1.06); filter: drop-shadow(0 12px 40px rgba(0,0,0,0.55)) brightness(1.35); }
  100% { transform: scale(1); }
}

.board{
  position: relative;
  background:
    radial-gradient(circle at 30% 20%, rgba(56,224,208,0.06), transparent 55%),
    radial-gradient(circle at 80% 80%, rgba(255,176,32,0.06), transparent 55%),
    var(--void-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.fx-canvas{
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

.maze-canvas{
  position: absolute;
  inset: 0;
  z-index: 1;
  display: block;
}

.board::after{
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 30%, rgba(56,224,208,0.10) 45%, rgba(255,176,32,0.14) 50%, transparent 65%);
  background-size: 260% 260%;
  background-position: 100% 0%;
  animation: shimmerSweep 5.5s ease-in-out infinite;
  mix-blend-mode: screen;
}
@keyframes shimmerSweep{
  0%, 100% { background-position: 120% -20%; }
  50%      { background-position: -20% 120%; }
}

.mark{ position: absolute; border-radius: 50%; }

.player{
  --glow-blur: 18px;
  background: radial-gradient(circle at 35% 30%, #fff, var(--amber) 55%, #b96f00 100%);
  box-shadow: 0 0 0 6px rgba(255,176,32,0.15), 0 0 var(--glow-blur) rgba(255,176,32,0.6);
  transition: left 0.13s cubic-bezier(.3,.7,.2,1), top 0.13s cubic-bezier(.3,.7,.2,1), box-shadow 0.25s ease;
  z-index: 4;
}
.player.bump-wall{ animation: wallBump 0.16s ease; }
@keyframes wallBump{
  0%   { transform: translate(0,0); }
  45%  { transform: translate(var(--bx,0), var(--by,0)); }
  100% { transform: translate(0,0); }
}

.trail{
  position: absolute;
  border-radius: 50%;
  background: var(--amber);
  pointer-events: none;
  z-index: 3;
  animation: trailFade 0.5s ease forwards;
}
@keyframes trailFade{
  0%   { opacity: 0.45; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.3); }
}

.goal{
  border: var(--wall-w) solid var(--cyan);
  border-radius: 6px;
  box-shadow: 0 0 16px rgba(56,224,208,0.55), inset 0 0 10px rgba(56,224,208,0.35);
  animation: goalPulse 1.6s ease-in-out infinite;
  z-index: 2;
}
.goal::after{
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 6px; height: 6px;
  margin: -3px 0 0 -3px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 8px 2px rgba(255,176,32,0.8);
  animation: goalOrbit 2.4s linear infinite;
  transform-origin: 3px 3px;
}
@keyframes goalOrbit{
  from { transform: rotate(0deg) translateX(140%) rotate(0deg); }
  to   { transform: rotate(360deg) translateX(140%) rotate(-360deg); }
}
@keyframes goalPulse{
  0%, 100% { opacity: 0.65; }
  50%      { opacity: 1; }
}

/* ---------- Controls ---------- */
.controls{ width: 100%; display: flex; flex-direction: column; align-items: center; gap: 14px; }

.best{ font-size: 12px; color: var(--ink-soft); letter-spacing: 0.02em; }
.best b{ color: var(--cyan); font-weight: 700; }

.reload-btn{
  position: relative;
  overflow: hidden;
  appearance: none;
  border: none;
  background: linear-gradient(120deg, var(--amber), #ff7a3d);
  color: #1a1206;
  font-family: 'Orbitron', sans-serif;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.08em;
  padding: 16px 50px;
  border-radius: 999px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(255,176,32,0.35);
  transition: transform 0.08s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.reload-btn::after{
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: radial-gradient(circle, rgba(255,255,255,0.55), transparent 60%);
  opacity: 0;
  transform: scale(0.4);
  pointer-events: none;
}
.reload-btn.ripple::after{ animation: rippleOut 0.5s ease-out; }
@keyframes rippleOut{
  0%   { opacity: 0.7; transform: scale(0.3); }
  100% { opacity: 0; transform: scale(1.6); }
}
.reload-btn:hover{
  background: linear-gradient(120deg, var(--cyan), var(--amber));
  box-shadow: 0 10px 30px rgba(56,224,208,0.4);
}
.reload-btn:active{ transform: scale(0.94); }
.reload-btn:focus-visible{ outline: 3px solid var(--cyan); outline-offset: 3px; }

.reload-icon{
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  display: inline-block;
  transition: transform 0.35s ease;
}
.reload-btn.spin .reload-icon{ transform: rotate(360deg); }

.reload-btn.urgent{
  animation: urgentPulse 0.85s ease-in-out infinite;
  background: linear-gradient(120deg, #ff4d4d, var(--amber));
  box-shadow: 0 8px 26px rgba(255,77,77,0.45);
}
@keyframes urgentPulse{
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.055); }
}

.hint{ font-size: 11px; color: var(--ink-soft); letter-spacing: 0.02em; text-align: center; }

/* ---------- D-pad (touch) ---------- */
.dpad{
  display: none;
  grid-template-columns: repeat(3, 54px);
  grid-template-rows: repeat(2, 54px);
  gap: 6px;
  justify-content: center;
  margin-top: 2px;
}
body.touch .dpad{ display: grid; }

.dpad-btn{
  appearance: none;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.05);
  color: var(--paper);
  font-size: 16px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.dpad-btn:active{
  background: linear-gradient(120deg, var(--amber), var(--cyan));
  color: #14101c;
}
.dpad-up{    grid-column: 2; grid-row: 1; }
.dpad-left{  grid-column: 1; grid-row: 2; }
.dpad-right{ grid-column: 3; grid-row: 2; }
.dpad-down{  grid-column: 2; grid-row: 2; }

.hidden{ display: none !important; }

/* ---------- Title / slot select ---------- */
.title-screen{
  position: relative;
  z-index: 2;
  width: 100%;
  max-width: 460px;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 0;
  overflow: hidden;
}
.title-screen::before{
  content: '';
  position: absolute;
  inset: -50%;
  z-index: -1;
  background-image:
    linear-gradient(rgba(56,224,208,0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,176,32,0.05) 1px, transparent 1px);
  background-size: 42px 42px;
  animation: gridDrift 18s linear infinite;
  mask-image: radial-gradient(circle at 50% 40%, #000 30%, transparent 72%);
  -webkit-mask-image: radial-gradient(circle at 50% 40%, #000 30%, transparent 72%);
}
@keyframes gridDrift{
  from { transform: translate(0, 0); }
  to   { transform: translate(42px, 42px); }
}
.title-inner{
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  animation: titleIn 0.6s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes titleIn{
  0%   { opacity: 0; transform: translateY(14px); }
  100% { opacity: 1; transform: translateY(0); }
}

.title-logo{
  font-family: 'Orbitron', sans-serif;
  font-weight: 800;
  font-size: clamp(40px, 12vw, 58px);
  margin: 0;
  color: var(--paper);
  text-shadow: 0 0 30px rgba(255,176,32,0.35), 0 0 60px rgba(56,224,208,0.15);
  animation: logoGlow 3.2s ease-in-out infinite;
}
.title-dot{ color: var(--cyan); }
@keyframes logoGlow{
  0%, 100% { text-shadow: 0 0 26px rgba(255,176,32,0.3), 0 0 50px rgba(56,224,208,0.12); }
  50%      { text-shadow: 0 0 40px rgba(255,176,32,0.55), 0 0 76px rgba(56,224,208,0.28); }
}

.title-tag{
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  text-align: center;
}

.title-note{
  margin: 0;
  font-size: 11px;
  color: var(--ink-soft);
  text-align: center;
  max-width: 320px;
  line-height: 1.6;
}

.slot-list{
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.slot-card{
  position: relative;
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.1);
  background: linear-gradient(135deg, rgba(255,255,255,0.05), rgba(255,255,255,0.015));
  backdrop-filter: blur(6px);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  text-align: left;
  color: var(--paper);
  font-family: 'JetBrains Mono', monospace;
  transition: border-color 0.2s ease, transform 0.12s ease, background 0.2s ease;
}
.slot-card:hover{
  border-color: var(--amber);
  transform: translateY(-2px);
}
.slot-card:active{ transform: scale(0.98); }

.slot-main{ display: flex; flex-direction: column; gap: 4px; }
.slot-id{
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  letter-spacing: 0.14em;
  color: var(--cyan);
}
.slot-info{ font-size: 15px; font-weight: 700; }
.slot-sub{ font-size: 11px; color: var(--ink-soft); }
.slot-time{ font-size: 10px; color: var(--ink-soft); opacity: 0.7; }
.slot-empty .slot-info{ color: var(--ink-soft); font-weight: 500; }

.slot-actions{ display: flex; align-items: center; gap: 8px; }
.slot-play{
  font-family: 'Orbitron', sans-serif;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 8px 14px;
  border-radius: 999px;
  background: linear-gradient(120deg, var(--amber), #ff7a3d);
  color: #1a1206;
  white-space: nowrap;
}
.slot-empty .slot-play{
  background: rgba(255,255,255,0.08);
  color: var(--paper);
}
.slot-reset{
  appearance: none;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 15px;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
}
.slot-reset:hover{ color: #ff6b6b; }

/* ---------- Menu button (in-game, back to title) ---------- */
.menu-btn{
  appearance: none;
  border: 1px solid rgba(255,255,255,0.14);
  background: rgba(255,255,255,0.04);
  color: var(--paper);
  width: 34px;
  height: 34px;
  border-radius: 10px;
  font-size: 15px;
  cursor: pointer;
  order: 0;
  align-self: flex-start;
}
.menu-btn:hover{ border-color: var(--cyan); color: var(--cyan); }

/* ---------- Mute ---------- */
.mute-btn{
  position: fixed;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  z-index: 20;
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.04);
  color: var(--paper);
  font-size: 16px;
  cursor: pointer;
}
.mute-btn.off{ color: var(--ink-soft); }

/* ---------- Toast ---------- */
.toast{
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translate(-50%, 24px) scale(0.9);
  background: linear-gradient(120deg, var(--amber), var(--cyan));
  color: #12101a;
  font-family: 'Orbitron', sans-serif;
  font-weight: 800;
  padding: 14px 26px;
  border-radius: 999px;
  font-size: 14px;
  letter-spacing: 0.06em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 30;
  box-shadow: 0 10px 34px rgba(0,0,0,0.45), 0 0 24px rgba(56,224,208,0.35);
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast::before{
  content: '✦';
  font-size: 13px;
}
.toast.show{
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
  transition: opacity 0.2s ease, transform 0.4s cubic-bezier(.34,1.56,.64,1);
}

/* ---------- Glitch overlay ---------- */
.glitch-overlay{
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 15;
  opacity: 0;
  mix-blend-mode: screen;
  background:
    repeating-linear-gradient(0deg, rgba(56,224,208,0.12) 0 2px, transparent 2px 4px);
}
.glitch-overlay.play{ animation: glitchSweep 0.32s steps(6); }
@keyframes glitchSweep{
  0%   { opacity: 0; transform: translateX(0); }
  15%  { opacity: 0.9; transform: translateX(-6px); }
  30%  { opacity: 0.6; transform: translateX(5px); }
  45%  { opacity: 0.8; transform: translateX(-3px); }
  60%  { opacity: 0.4; transform: translateX(4px); }
  100% { opacity: 0; transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce){
  .scene.shake{ animation: none; }
  .goal{ animation: none; }
  .goal::after{ animation: none; }
  .player{ transition: none; }
  .player.bump-wall{ animation: none; }
  .reload-btn.urgent{ animation: none; }
  .reload-btn.ripple::after{ animation: none; }
  .board::after{ animation: none; }
  .board-stage.clear-punch{ animation: none; }
  .title-screen::before{ animation: none; }
  .glitch-overlay.play{ animation: none; }
}

@media (max-width: 400px){
  .reload-btn{ padding: 13px 32px; font-size: 14px; }
  .scene{ gap: 18px; }
  .hint{ display: none; }
  .mute-btn{ width: 38px; height: 38px; }
}

@media (max-height: 700px){
  .scene{ gap: 14px; }
  .hud{ padding-bottom: 10px; }
  .controls{ gap: 8px; }
}
