* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  height: 100%;
  height: 100dvh; /* Dynamic viewport height for mobile browsers */
  background-color: #03030c;
  color: #ffffff;
  font-family: 'Fredoka', sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
}

#game-container {
  position: relative;
  width: 100vw;
  max-width: 800px;
  height: 100vh;
  height: 100dvh;
  background-color: #03030c;
  overflow: hidden;
  box-shadow: 0 0 40px rgba(0, 240, 255, 0.15);
}

@media (min-width: 800px) {
  #game-container {
    height: 900px;
    max-height: 95dvh;
    border: 2px solid #1f2a44;
    border-radius: 16px;
  }
}

canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

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

.screen {
  position: absolute;
  inset: 0;
  background: rgba(5, 7, 24, 0.92);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  text-align: center;
  pointer-events: auto;
  overflow-y: auto;
}

.hidden {
  display: none !important;
  pointer-events: none !important;
}

.game-title {
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 900;
  background: linear-gradient(180deg, #00f0ff, #7000ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px rgba(0, 240, 255, 0.4);
  margin-bottom: 4px;
}

.subtitle {
  color: #a0aec0;
  font-size: clamp(0.9rem, 3vw, 1.1rem);
  margin-bottom: 20px;
}

.menu-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  max-width: 320px;
}

.btn {
  font-family: 'Orbitron', sans-serif;
  font-size: 1rem;
  font-weight: 800;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s ease, background-color 0.2s ease;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.96);
}

.primary-btn {
  background: linear-gradient(135deg, #00f0ff, #0072ff);
  color: #fff;
  border-bottom: 3px solid #004499;
}

.secondary-btn {
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid #334155;
}

.select-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.75rem;
  color: #94a3b8;
}

select {
  background: #0f172a;
  color: #00f0ff;
  border: 1px solid #334155;
  padding: 10px;
  border-radius: 8px;
  font-family: 'Fredoka', sans-serif;
  font-size: 1rem;
  outline: none;
}

#high-score-box {
  margin-top: 15px;
  font-size: 0.85rem;
  color: #f1f5f9;
  background: rgba(255,255,255,0.05);
  padding: 6px 14px;
  border-radius: 20px;
  border: 1px solid rgba(255,255,255,0.1);
}

/* Instructions & Leaderboard Screen */
.instructions-card, .leaderboard-table {
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid #334155;
  padding: 12px;
  border-radius: 12px;
  width: 100%;
  max-width: 420px;
  margin-bottom: 12px;
  text-align: left;
}

.instructions-card p {
  margin-bottom: 8px;
  font-size: 0.9rem;
  line-height: 1.3;
}

.leaderboard-table {
  max-height: 280px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.lb-row {
  display: grid;
  grid-template-columns: 30px 1fr 70px 45px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  font-size: 0.85rem;
}

.lb-rank { color: #ffdd59; font-weight: bold; font-family: 'Orbitron', sans-serif; }
.lb-name { color: #fff; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: #00f0ff; font-weight: bold; text-align: right; }
.lb-acc { color: #94a3b8; text-align: right; font-size: 0.75rem; }
.lb-loading { padding: 15px; color: #94a3b8; text-align: center; }

.controls-guide {
  margin-bottom: 15px;
  font-size: 0.8rem;
  color: #94a3b8;
}

/* In-Game HUD */
#hud-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: 8px 10px;
  z-index: 5;
  pointer-events: none;
}

.hud-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(15, 23, 42, 0.88);
  border: 1px solid rgba(0, 240, 255, 0.3);
  backdrop-filter: blur(4px);
  padding: 6px 10px;
  border-radius: 10px;
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(0.7rem, 2.5vw, 0.85rem);
  pointer-events: auto;
}

.hud-item { display: flex; align-items: center; gap: 4px; }
.hud-label { color: #64748b; font-size: 0.65rem; }
#score-val { color: #00f0ff; font-weight: bold; }
#streak-val { color: #ff9f43; font-weight: bold; }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 2px 6px;
}

#question-box {
  margin-top: 6px;
  background: rgba(11, 15, 25, 0.94);
  border: 2px solid #00f0ff;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.2);
  border-radius: 12px;
  padding: 10px 12px;
  text-align: center;
  pointer-events: auto;
}

.q-tag {
  font-family: 'Orbitron', sans-serif;
  font-size: 0.65rem;
  color: #a0aec0;
  text-transform: uppercase;
  margin-bottom: 2px;
}

.q-text {
  font-size: clamp(0.95rem, 3.5vw, 1.2rem);
  font-weight: 600;
  color: #ffffff;
  line-height: 1.3;
}

.hint-btn {
  margin-top: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: #ffdd59;
  font-size: 0.7rem;
  padding: 3px 8px;
  border-radius: 8px;
}

.hint-text {
  font-size: 0.8rem;
  color: #ffdd59;
  margin-top: 4px;
  font-style: italic;
}

#feedback-popup {
  position: absolute;
  top: 42%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', sans-serif;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  font-weight: 900;
  padding: 10px 20px;
  border-radius: 14px;
  z-index: 8;
  pointer-events: none;
  text-align: center;
  white-space: nowrap;
}

#feedback-popup.correct {
  background: rgba(46, 213, 115, 0.95);
  color: #fff;
  box-shadow: 0 0 20px rgba(46, 213, 115, 0.6);
}

#feedback-popup.incorrect {
  background: rgba(255, 71, 87, 0.95);
  color: #fff;
  box-shadow: 0 0 20px rgba(255, 71, 87, 0.6);
}

/* Mobile Controls Layout */
#mobile-controls {
  position: absolute;
  bottom: 12px;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 16px;
  z-index: 6;
  pointer-events: auto;
  touch-action: none;
}

.dpad {
  display: flex;
  gap: 10px;
}

.touch-btn {
  background: rgba(255, 255, 255, 0.15);
  border: 2px solid rgba(255, 255, 255, 0.3);
  color: #fff;
  font-size: 1.4rem;
  width: 58px;
  height: 54px;
  border-radius: 14px;
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-btn:active {
  background: rgba(0, 240, 255, 0.4);
  border-color: #00f0ff;
}

.fire-btn {
  width: 100px;
  background: rgba(255, 71, 87, 0.4);
  border-color: #ff4757;
  font-family: 'Orbitron', sans-serif;
  font-size: 0.9rem;
  font-weight: bold;
}

.fire-btn:active {
  background: rgba(255, 71, 87, 0.8);
}

/* Game Over Stats Grid */
.stars { font-size: 2rem; margin: 4px 0; }

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 340px;
  margin-bottom: 12px;
}

.stat-card {
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  padding: 8px;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.stat-label { font-size: 0.65rem; color: #94a3b8; font-family: 'Orbitron', sans-serif; }
.stat-value { font-size: 1.1rem; font-weight: bold; color: #00f0ff; margin-top: 2px; }

.submit-box {
  display: flex;
  gap: 6px;
  width: 100%;
  max-width: 340px;
  margin-bottom: 12px;
}

.submit-box input {
  flex: 1;
  background: #0f172a;
  border: 1px solid #334155;
  color: #00f0ff;
  padding: 8px 12px;
  border-radius: 8px;
  font-family: 'Fredoka', sans-serif;
  font-size: 0.95rem;
  outline: none;
}

.small-btn { padding: 8px 14px; font-size: 0.8rem; }

.submit-msg { color: #2ed573; font-weight: bold; margin-bottom: 10px; font-size: 0.85rem; }

.explanation-box {
  background: rgba(255, 71, 87, 0.1);
  border: 1px solid rgba(255, 71, 87, 0.3);
  padding: 8px 12px;
  border-radius: 8px;
  max-width: 340px;
  font-size: 0.8rem;
  margin-bottom: 12px;
  text-align: left;
}

.button-row { display: flex; gap: 8px; }

/* Mobile Height Compression Overrides */
@media (max-height: 600px) {
  .game-title { font-size: 1.6rem; }
  .subtitle { margin-bottom: 10px; display: none; }
  #question-box { padding: 6px 8px; }
  .q-text { font-size: 0.85rem; }
  .touch-btn { height: 46px; width: 50px; font-size: 1.1rem; }
  .fire-btn { width: 85px; font-size: 0.8rem; }
  .stats-grid { gap: 4px; margin-bottom: 6px; }
  .stat-card { padding: 4px; }
}