:root {
  --bg: #050510;
  --panel: rgba(10, 12, 30, 0.92);
  --accent: #00f0ff;
  --accent2: #ff2a6d;
  --good: #05ffa1;
  --bad: #ff4d4d;
  --text: #e8f0ff;
  --muted: #8a94b8;
  --hud-bg: rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
  touch-action: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#game-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: 0;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
  z-index: 10;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
}

#hud.screen {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 1rem;
  opacity: 0;
}

#hud.screen.active {
  opacity: 1;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(0, 240, 255, 0.25);
  border-radius: 20px;
  padding: 2rem;
  max-width: 560px;
  width: 90%;
  text-align: center;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.12), inset 0 0 40px rgba(0, 240, 255, 0.05);
  backdrop-filter: blur(12px);
}

h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(2rem, 7vw, 4rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  margin: 0 0 1rem;
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  color: var(--accent);
}

p {
  line-height: 1.55;
  color: var(--text);
  font-size: 1rem;
}

.tagline {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0.4rem;
  padding: 0.85rem 1.6rem;
  border: 1px solid rgba(0, 240, 255, 0.35);
  border-radius: 12px;
  background: rgba(0, 240, 255, 0.08);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, box-shadow 0.15s ease;
}

button:hover, button:focus-visible {
  background: rgba(0, 240, 255, 0.18);
  box-shadow: 0 0 20px rgba(0, 240, 255, 0.2);
  transform: translateY(-1px);
  outline: none;
}

button.primary {
  background: linear-gradient(135deg, rgba(0, 240, 255, 0.18), rgba(255, 42, 109, 0.12));
  border-color: rgba(0, 240, 255, 0.5);
}

button.secondary {
  background: transparent;
  border-color: rgba(138, 148, 184, 0.4);
  color: var(--muted);
}

button.secondary:hover {
  color: var(--text);
}

.controls-hint {
  margin-top: 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.controls-hint span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

kbd {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 5px;
  padding: 0.15rem 0.45rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  color: var(--accent);
}

.hud-top {
  display: flex;
  gap: 1rem;
  justify-content: flex-start;
  flex-wrap: wrap;
  pointer-events: none;
}

.hud-group {
  background: var(--hud-bg);
  border: 1px solid rgba(0, 240, 255, 0.15);
  border-radius: 12px;
  padding: 0.5rem 1rem;
  min-width: 72px;
  text-align: center;
  backdrop-filter: blur(6px);
}

.hud-label {
  display: block;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.hud-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.hud-center {
  align-self: center;
  text-align: center;
  width: min(720px, 92vw);
}

.timer-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.timer-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  transform-origin: left;
  transition: transform 0.08s linear, background 0.3s ease;
}

.question-text {
  font-size: clamp(1.1rem, 3.5vw, 1.65rem);
  font-weight: 700;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  background: rgba(5, 5, 16, 0.65);
  padding: 0.85rem 1.2rem;
  border-radius: 14px;
  border: 1px solid rgba(0, 240, 255, 0.12);
  margin-bottom: 0.5rem;
  line-height: 1.4;
}

.question-category {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent2);
}

.combo-flash {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(2rem, 8vw, 5rem);
  font-weight: 900;
  color: var(--good);
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 0 30px var(--good);
}

.combo-flash.animate {
  animation: comboPulse 0.65s ease-out;
}

@keyframes comboPulse {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3); }
}

#feedback-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 20;
}

.feedback {
  font-size: clamp(2.5rem, 10vw, 6rem);
  font-weight: 900;
  text-transform: uppercase;
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.15s ease, transform 0.3s ease;
  text-shadow: 0 0 40px currentColor;
}

.feedback.show {
  opacity: 1;
  transform: scale(1);
}

.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.toast {
  position: absolute;
  bottom: 7rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  max-width: min(680px, 92vw);
  padding: 1rem 1.25rem;
  background: rgba(5, 5, 16, 0.94);
  border: 1px solid rgba(0, 240, 255, 0.18);
  border-radius: 14px;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.missed-list {
  text-align: left;
  max-height: 240px;
  overflow-y: auto;
  margin: 1rem 0;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 12px;
}

.missed-item {
  padding: 0.65rem 0.8rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 0.9rem;
}

.missed-item:last-child { border-bottom: none; }

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.6rem;
  margin: 1rem 0;
}

.badge {
  background: rgba(0, 240, 255, 0.1);
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 999px;
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: var(--accent);
}

.setting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin: 0.7rem 0;
  cursor: pointer;
  color: var(--text);
}

#mobile-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: linear-gradient(0deg, rgba(0,0,0,0.8), transparent);
  z-index: 15;
  pointer-events: auto;
}

#mobile-controls.active {
  display: flex;
}

.mc-dir, .mc-action {
  margin: 0;
  border-radius: 50%;
  width: 64px;
  height: 64px;
  font-size: 1.6rem;
  border-color: rgba(0, 240, 255, 0.35);
  background: rgba(0, 240, 255, 0.08);
}

.mc-action {
  width: 72px;
  height: 72px;
  background: radial-gradient(circle at 30% 30%, var(--accent2), var(--accent));
  border: none;
  color: #000;
  font-size: 2rem;
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.3);
}

@media (hover: none) and (pointer: coarse) {
  #mobile-controls.active {
    display: flex;
  }
}

@media (max-width: 640px) {
  .panel {
    padding: 1.3rem;
  }
  .hud-top {
    gap: 0.5rem;
  }
  .hud-group {
    padding: 0.4rem 0.65rem;
    min-width: 58px;
  }
  .hud-value {
    font-size: 1rem;
  }
  .question-text {
    padding: 0.65rem 0.85rem;
  }
}

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