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

:root {
  --pixel-font: 'Courier New', 'Press Start 2P', monospace;
  --title-font: Impact, Haettenschweiler, 'Arial Narrow Bold', 'Bangers', fantasy;
  --ui-font: 'Trebuchet MS', 'Avenir Next', 'Segoe UI', 'Nunito', sans-serif;
  --bg: #111;
  --bg-deep: #08111c;
  --accent: #ffaa00;
  --accent-2: #5de2ff;
  --hp-green: #33cc33;
  --hp-red: #cc3333;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: #000;
}

body {
  font-family: var(--ui-font);
}

.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;
}

#game-container {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-canvas {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
}

.hidden { display: none !important; }

/* === TITLE SCREEN === */
#title-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
  overflow: hidden;
}

.title-bg {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 50% 50%, rgba(93, 226, 255, 0.12) 0%, transparent 22%),
    linear-gradient(140deg, #050914 0%, #102238 38%, #25120c 70%, #07150d 100%);
  animation: titleBg 14s ease infinite alternate;
}

.title-bg::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 18% 24%, rgba(255, 173, 48, 0.18) 0%, transparent 34%),
    radial-gradient(circle at 78% 62%, rgba(93, 226, 255, 0.14) 0%, transparent 38%),
    radial-gradient(circle at 55% 82%, rgba(64, 255, 156, 0.1) 0%, transparent 34%);
  animation: titleParticles 8s ease infinite alternate;
}

@keyframes titleBg {
  0% {
    transform: scale(1);
    filter: hue-rotate(0deg);
  }
  100% {
    transform: scale(1.08);
    filter: hue-rotate(-12deg);
  }
}

@keyframes titleParticles {
  0% { opacity: 0.8; }
  100% { opacity: 1; transform: scale(1.05); }
}

.title-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(93, 226, 255, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(93, 226, 255, 0.08) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(circle at center, rgba(0, 0, 0, 0.9), transparent 78%);
  opacity: 0.35;
  animation: titleGridDrift 14s linear infinite;
}

.title-orbit {
  position: absolute;
  border: 1px solid rgba(93, 226, 255, 0.18);
  border-radius: 50%;
  mix-blend-mode: screen;
}

.title-orbit--outer {
  width: min(92vw, 820px);
  height: min(92vw, 820px);
  box-shadow: 0 0 80px rgba(93, 226, 255, 0.08);
  animation: titleSpin 26s linear infinite;
}

.title-orbit--inner {
  width: min(70vw, 560px);
  height: min(70vw, 560px);
  border-color: rgba(255, 170, 0, 0.22);
  animation: titleSpin 18s linear infinite reverse;
}

.title-panel {
  position: relative;
  z-index: 1;
  width: min(92vw, 720px);
  padding: clamp(1.4rem, 3vw, 2.4rem);
  border: 1px solid rgba(153, 220, 255, 0.2);
  background:
    linear-gradient(180deg, rgba(9, 17, 30, 0.92), rgba(10, 14, 22, 0.88));
  box-shadow:
    0 28px 80px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.title-kicker {
  color: rgba(93, 226, 255, 0.92);
  font-family: Consolas, 'Share Tech Mono', monospace;
  font-size: clamp(0.72rem, 1.5vw, 0.95rem);
  letter-spacing: 0.24em;
  text-align: center;
  margin-bottom: 0.8rem;
}

#game-title {
  font-family: var(--title-font);
  font-size: clamp(2rem, 6vw, 5rem);
  color: #ffcc33;
  text-align: center;
  text-shadow:
    0 0 30px rgba(255,204,51,0.6),
    0 4px 0 #aa6600,
    0 6px 20px rgba(0,0,0,0.5);
  margin-bottom: 1rem;
  line-height: 1.3;
  letter-spacing: 0.05em;
  z-index: 1;
  position: relative;
}

#game-title::after {
  content: '';
  position: absolute;
  inset: -10px -20px;
  background: radial-gradient(ellipse at center, rgba(255,204,51,0.25) 0%, transparent 70%);
  z-index: -1;
  animation: titleGlow 3s ease-in-out infinite;
  pointer-events: none;
}

@keyframes titleGlow {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.subtitle {
  font-family: var(--ui-font);
  font-weight: 700;
  font-size: clamp(0.85rem, 2vw, 1.18rem);
  color: #dffcff;
  margin: 0 auto 1.4rem;
  max-width: 34rem;
  text-align: center;
  opacity: 0;
  animation: fadeIn 2s 0.5s forwards;
  text-shadow: 0 0 22px rgba(93, 226, 255, 0.2);
  z-index: 1;
}

@keyframes fadeIn { to { opacity: 1; } }

@keyframes titleGridDrift {
  0% { transform: translate3d(0, 0, 0); }
  100% { transform: translate3d(36px, 28px, 0); }
}

@keyframes titleSpin {
  to { transform: rotate(360deg); }
}

.feature-strip {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.7rem;
  margin: 0 auto 1.35rem;
  max-width: 36rem;
}

.feature-strip span {
  padding: 0.45rem 0.8rem;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.05);
  color: #eef9ff;
  font-size: clamp(0.72rem, 1.5vw, 0.95rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.controls-hint {
  z-index: 1;
  margin: 0 auto 1.75rem;
  max-width: 34rem;
  color: rgba(255, 255, 255, 0.76);
  text-align: center;
  font-size: clamp(0.7rem, 1.6vw, 0.95rem);
  line-height: 1.6;
  text-wrap: balance;
}

.controls-hint span {
  display: block;
  color: rgba(93, 226, 255, 0.88);
}

#title-menu {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 2rem;
  z-index: 1;
}

.menu-btn {
  font-family: var(--ui-font);
  font-weight: 900;
  font-size: clamp(0.8rem, 2vw, 1.1rem);
  padding: 0.8em 2.5em;
  background: rgba(10, 14, 22, 0.75);
  color: #fff;
  border: 2px solid rgba(255,255,255,0.14);
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.2s ease, border-color 0.2s ease, color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.menu-btn:hover, .menu-btn:focus {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255,170,0,0.1);
  text-shadow: 0 0 10px rgba(255,170,0,0.5);
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(255,170,0,0.2), inset 0 0 12px rgba(255,170,0,0.05);
}

.menu-btn:active {
  transform: scale(0.97);
  transition-duration: 0.05s;
}

.menu-btn:focus-visible,
.touch-btn:focus-visible {
  outline: 3px solid rgba(255, 204, 51, 0.85);
  outline-offset: 3px;
}

.credit {
  font-family: var(--pixel-font);
  font-size: 0.5rem;
  color: rgba(255, 255, 255, 0.36);
  position: absolute;
  bottom: 1rem;
  z-index: 1;
}

/* === HUD === */
#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

#hud {
  position: absolute;
  top: 4px;
  left: 4px;
  pointer-events: none;
}

/* === DIALOGUE BOX === */
#dialogue-box {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: rgba(0,0,0,0.9);
  border-top: 2px solid #555;
  padding: 12px;
  font-family: var(--ui-font);
  font-size: 0.9rem;
  color: #fff;
  line-height: 1.8;
  z-index: 20;
  pointer-events: auto;
}

/* === TOUCH CONTROLS === */
#touch-controls {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 50;
}

#joystick-zone {
  position: absolute;
  bottom: 20px;
  left: 20px;
  width: 140px;
  height: 140px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 45% 35%, rgba(255,255,255,0.18), rgba(255,255,255,0.05) 45%, rgba(7,14,22,0.76) 100%);
  border: 2px solid rgba(170,226,255,0.24);
  box-shadow:
    0 18px 40px rgba(0,0,0,0.35),
    inset 0 0 18px rgba(93,226,255,0.08);
  pointer-events: auto;
  touch-action: none;
}

#buttons-zone {
  position: absolute;
  bottom: 25px;
  right: 25px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
  gap: 12px;
  max-width: 220px;
  pointer-events: auto;
}

.touch-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.24);
  background:
    radial-gradient(circle at 35% 30%, rgba(255,255,255,0.18), rgba(255,255,255,0.08) 42%, rgba(8,12,18,0.86) 100%);
  color: rgba(240,247,255,0.92);
  font-family: var(--ui-font);
  font-weight: 900;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow:
    0 14px 28px rgba(0,0,0,0.32),
    inset 0 0 0 1px rgba(255,255,255,0.05),
    inset 0 6px 12px rgba(255,255,255,0.05);
  text-shadow: 0 0 10px rgba(255,255,255,0.22);
}

.touch-btn--small {
  width: 68px;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
}

.touch-btn--time {
  width: 74px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(93, 226, 255, 0.24), rgba(7, 24, 34, 0.92));
  color: rgba(212, 250, 255, 0.96);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}

#btn-a {
  border-color: rgba(255, 214, 112, 0.42);
  color: #ffe8ac;
}

#btn-x {
  border-color: rgba(255, 183, 107, 0.42);
  color: #ffd9a6;
}

#btn-b {
  border-color: rgba(255, 220, 120, 0.34);
  color: #fff0a8;
}

.touch-btn:active {
  background: rgba(255,255,255,0.18);
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 12px rgba(255,170,0,0.35), inset 0 0 8px rgba(255,170,0,0.1);
  transform: scale(0.93);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}

.touch-btn--time:active {
  border-color: var(--accent-2);
  color: var(--accent-2);
  box-shadow: 0 0 16px rgba(93,226,255,0.45), inset 0 0 8px rgba(93,226,255,0.15);
}

/* Pause title animations when hidden to save CPU/GPU */
#title-screen.hidden .title-bg,
#title-screen.hidden .title-bg::before,
#title-screen.hidden .title-grid,
#title-screen.hidden .title-orbit {
  animation-play-state: paused !important;
}

.noscript-warning {
  position: fixed;
  inset: auto 1rem 1rem 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(0, 0, 0, 0.9);
  color: #fff;
  text-align: center;
  z-index: 500;
}

/* === MENU OVERLAY === */
#menu-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 30;
  pointer-events: auto;
}

@media (max-width: 768px) {
  #buttons-zone {
    right: 16px;
    bottom: 16px;
    gap: 10px;
  }

  #joystick-zone {
    left: 16px;
    bottom: 16px;
    width: 124px;
    height: 124px;
  }

  .touch-btn {
    width: 56px;
    height: 56px;
    box-shadow:
      0 12px 24px rgba(0,0,0,0.36),
      inset 0 0 0 1px rgba(255,255,255,0.06);
  }

  .touch-btn--small {
    width: 64px;
    font-size: 0.75rem;
  }

  .touch-btn--time {
    width: 70px;
    font-size: 0.72rem;
  }

  .controls-hint {
    margin-bottom: 1.25rem;
  }

  .title-panel {
    padding: 1.25rem 1rem 1.5rem;
  }

  .feature-strip {
    gap: 0.5rem;
  }

  .feature-strip span {
    font-size: 0.7rem;
  }
}

/* === FEEDBACK BUTTON === */
#feedback-btn {
  position: fixed;
  bottom: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(93, 226, 255, 0.3);
  background: rgba(10, 20, 30, 0.8);
  color: rgba(93, 226, 255, 0.9);
  font-family: var(--ui-font);
  font-weight: 900;
  font-size: 1.1rem;
  cursor: pointer;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, border-color 0.2s;
}

#feedback-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.1);
}

/* === FEEDBACK MODAL === */
#feedback-modal {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.7);
}

.feedback-panel {
  background: rgba(10, 16, 26, 0.95);
  border: 1px solid rgba(93, 226, 255, 0.2);
  padding: 1.5rem;
  width: min(90vw, 400px);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.feedback-panel h2 {
  font-family: var(--ui-font);
  font-size: 1.2rem;
  color: #dffcff;
  text-align: center;
  margin: 0;
}

.feedback-type-toggle {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.feedback-type-btn {
  font-family: var(--ui-font);
  font-size: 0.85rem;
  padding: 0.4em 1.2em;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.05);
  color: #ccc;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.feedback-type-btn.active {
  background: rgba(93, 226, 255, 0.15);
  color: #5de2ff;
  border-color: rgba(93, 226, 255, 0.4);
}

#feedback-text {
  width: 100%;
  padding: 0.6rem;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  font-family: var(--ui-font);
  font-size: 0.85rem;
  resize: vertical;
  min-height: 60px;
}

#feedback-text:focus {
  outline: 1px solid rgba(93, 226, 255, 0.4);
}

.feedback-context {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.4);
  text-align: center;
  margin: 0;
}

.feedback-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
}

.feedback-actions .menu-btn {
  font-size: 0.8rem;
  padding: 0.5em 1.5em;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  .title-bg,
  .title-bg::before,
  .title-grid,
  .title-orbit,
  #game-title,
  .subtitle {
    animation: none !important;
  }
}
