:root {
  --bg: #05070a;
  --player: #00ff88;
  --enemy: #ff3366;
  --wall: #1a1f2e;
  --path: #0d1117;
  --goal: #ffcc00;
  --ui-text: #8b949e;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  background-color: var(--bg);
  background-image:
    radial-gradient(at 0% 0%, rgba(0, 255, 136, 0.05) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(255, 51, 102, 0.05) 0px, transparent 50%);
  color: #ffffff;
  font-family: 'Segoe UI Mono', 'Courier New', monospace;
  margin: 0;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

/* ---------- UI LAYOUT ---------- */
#startScreen { text-align: center; z-index: 10; padding: 20px; }

.logo-container {
  width: 150px;
  height: 150px;
  margin: 0 auto 20px;
  border: 2px solid var(--player);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.2);
  animation: glitchFlicker 3s infinite;
  filter: drop-shadow(0 0 5px rgba(0, 255, 136, 0.3));
}
.logo-container img { width: 100%; height: 100%; object-fit: cover; }

@keyframes glitchFlicker {
    0%, 100% { opacity: 1; filter: brightness(1); }
    33% { opacity: 0.8; filter: brightness(1.2); }
    34% { opacity: 1; filter: brightness(1); }
    66% { opacity: 0.9; filter: brightness(1.1); }
    67% { opacity: 0.4; filter: brightness(0.8); }
    68% { opacity: 1; filter: brightness(1); }
    90% { opacity: 0.9; filter: brightness(1.5); }
}

.title-glow {
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 900;
  letter-spacing: -2px;
  margin: 0;
  background: linear-gradient(to right, var(--player), #3bbcff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 10px rgba(0,255,136,0.3));
}

#game-canvas {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 450px;
}

/* ---------- HUD ---------- */
#hud {
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding: 10px 5px;
  font-size: 14px;
  color: var(--ui-text);
  text-transform: uppercase;
  letter-spacing: 2px;
}
#hud span { color: #fff; font-weight: bold; }

#timer-container {
  width: 100%;
  height: 4px;
  background: rgba(255,255,255,0.05);
  margin-bottom: 15px;
}
#timer-bar { width: 100%; height: 100%; background: var(--player); box-shadow: 0 0 10px var(--player); }

/* ---------- MAZE CORE ---------- */
#maze {
  display: grid;
  background: rgba(0,0,0,0.3);
  padding: 8px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 4px;
  gap: 2px;
}

.cell {
  width: clamp(18px, 5.5vw, 24px);
  height: clamp(18px, 5.5vw, 24px);
  border-radius: 2px;
}

.wall { background: var(--wall); }
.path { background: var(--path); }
.player { background: var(--player); box-shadow: 0 0 15px var(--player); border-radius: 50%; transform: scale(0.8); z-index: 2; }
.enemy { background: var(--enemy); box-shadow: 0 0 15px var(--enemy); transform: scale(0.85); z-index: 2; }
.goal { background: var(--goal); box-shadow: 0 0 15px var(--goal); clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%); animation: goalFloat 1s infinite alternate; }

@keyframes goalFloat { from { transform: scale(0.7); } to { transform: scale(0.9); } }

@keyframes moveIn {
    from { transform: scale(0.4); opacity: 0; }
    to { transform: scale(0.8); opacity: 1; }
}

.player {
    background: var(--player);
    box-shadow: 0 0 15px var(--player);
    transform: scale(0.8);
    z-index: 2;
    /* This adds a "pop" animation every time the cell is rendered */
    animation: moveIn 0.1s ease-out;
}

.enemy {
    background: var(--enemy);
    box-shadow: 0 0 15px var(--enemy);
    transform: scale(0.85);
    z-index: 2;
    /* A slightly different animation for the enemy */
    animation: moveIn 0.2s ease-in-out;
}

.cell {
    width: clamp(18px, 5.5vw, 24px);
    height: clamp(18px, 5.5vw, 24px);
    border-radius: 2px;
    /* This makes the maze walls shifting feel "liquid" */
    transition: background-color 0.3s ease;
}

/* ---------- MOBILE CONTROLS ---------- */
#controls {
  display: none;
  grid-template-columns: repeat(3, 70px);
  gap: 10px;
  margin-top: 25px;
}

.ctrl {
  width: 70px;
  height: 70px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 15px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 24px;
  color: #fff;
  user-select: none;
  cursor: pointer;
}

.ctrl:active {
  background: var(--player);
  color: #000;
  transform: scale(0.95);
}

/* ---------- ANIMATIONS ---------- */
.warning-active { animation: glitch 0.2s infinite; }
@keyframes glitch {
  0% { transform: translate(0); }
  25% { transform: translate(-2px, 1px); }
  75% { transform: translate(2px, -1px); }
}
.shake { animation: impact 0.3s ease-out; }
@keyframes impact { 0% { transform: scale(1.05); } 100% { transform: scale(1); } }

button {
  background: #fff; color: #000; border: none; padding: 15px 40px;
  font-weight: bold; text-transform: uppercase; letter-spacing: 2px;
  cursor: pointer; transition: 0.3s; margin-top: 10px;
}
button:hover { background: var(--player); box-shadow: 0 5px 15px rgba(0,255,136,0.4); }
