:root {
  --bg-dark: #0a0e17;
  --panel-bg: rgba(22, 31, 49, 0.85);
  --panel-border: rgba(56, 189, 248, 0.25);
  --neon-cyan: #38bdf8;
  --neon-pink: #f43f5e;
  --neon-gold: #f59e0b;
  --neon-green: #10b981;
  --neon-purple: #a855f7;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-heading: 'Orbitron', sans-serif;
  --font-body: 'Rajdhani', sans-serif;
}

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

body, html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-dark);
  background-image: 
    radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.15), transparent 70%),
    radial-gradient(circle at 50% 100%, rgba(168, 85, 247, 0.1), transparent 70%);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 16px;
}

/* Animated Screen Shake */
.shake {
  animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes shake {
  10%, 90% { transform: translate3d(-2px, 0, 0); }
  20%, 80% { transform: translate3d(4px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-6px, 0, 0); }
  40%, 60% { transform: translate3d(6px, 0, 0); }
}

/* Screen Management */
.screen {
  display: none;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  max-width: 540px;
  margin: 0 auto;
  padding: 16px;
  justify-content: space-between;
  align-items: center;
  position: relative;
  z-index: 10;
}

.screen.active {
  display: flex;
}

/* UI Titles & Text */
.game-logo {
  text-align: center;
  margin-top: 10px;
}

.game-logo h1 {
  font-family: var(--font-heading);
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 2px;
  background: linear-gradient(135deg, #38bdf8, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  text-shadow: 0 0 20px rgba(56, 189, 248, 0.4);
  line-height: 1.1;
}

.game-logo p {
  color: var(--neon-gold);
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  margin-top: 4px;
}

/* Modern Glass Panel Containers */
.glass-card {
  width: 100%;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Form Controls */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
}

input, select {
  width: 100%;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(10, 14, 23, 0.8);
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 600;
  outline: none;
  transition: all 0.25s ease;
}

input:focus, select:focus {
  border-color: var(--neon-cyan);
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.3);
}

/* Buttons */
.btn {
  width: 100%;
  padding: 14px 20px;
  border-radius: 12px;
  border: none;
  font-family: var(--font-heading);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #38bdf8);
  color: #04111d;
  box-shadow: 0 4px 20px rgba(56, 189, 248, 0.4);
}

.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 2px 10px rgba(56, 189, 248, 0.3);
}

.btn-secondary {
  background: rgba(30, 41, 59, 0.8);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:active {
  background: rgba(51, 65, 85, 0.9);
  transform: scale(0.97);
}

.btn-danger {
  background: linear-gradient(135deg, #9f1239, #f43f5e);
  color: white;
  box-shadow: 0 4px 15px rgba(244, 63, 94, 0.3);
}

.error-msg {
  color: var(--neon-pink);
  font-size: 0.9rem;
  font-weight: 600;
  text-align: center;
  min-height: 1.2em;
}

/* Top Gaming HUD */
#hud-panel {
  width: 100%;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.5);
}

.hud-top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.hud-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hud-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.hud-value {
  font-family: var(--font-heading);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--neon-cyan);
}

.lives-container {
  display: flex;
  gap: 4px;
  color: var(--neon-pink);
  font-size: 0.9rem;
}

.hud-bottom-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.streak-badge {
  background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(244, 63, 94, 0.2));
  border: 1px solid var(--neon-gold);
  border-radius: 20px;
  padding: 2px 10px;
  font-family: var(--font-heading);
  font-size: 0.75rem;
  color: var(--neon-gold);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Game Canvas Container */
#canvas-container {
  position: relative;
  width: 100%;
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 8px 0;
  min-height: 0;
}

canvas {
  background: rgba(2, 6, 23, 0.95);
  border: 2px solid var(--neon-cyan);
  border-radius: 16px;
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.2), inset 0 0 15px rgba(0, 0, 0, 0.8);
  max-width: 100%;
  max-height: 100%;
}

/* Arcade Controls */
.controls {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(2, 48px);
  gap: 8px;
  width: 100%;
  max-width: 280px;
}

.btn-ctrl {
  background: linear-gradient(145deg, #1e293b, #0f172a);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: var(--neon-cyan);
  font-size: 1.3rem;
  border-radius: 12px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,0.4);
  transition: all 0.1s ease;
}

.btn-ctrl:active {
  background: var(--neon-cyan);
  color: #0a0e17;
  box-shadow: 0 0 15px var(--neon-cyan);
  transform: translateY(2px);
}

#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }

/* Animated Question Overlay Modal */
.modal {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(10, 14, 23, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 12px;
  z-index: 100;
  border-radius: 16px;
  animation: fadeIn 0.25s ease-out;
}

.modal.active { display: flex; }

@keyframes fadeIn {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.q-box {
  background: var(--panel-bg);
  border: 1px solid var(--neon-purple);
  box-shadow: 0 0 30px rgba(168, 85, 247, 0.3);
  padding: 20px;
  border-radius: 16px;
  width: 100%;
  max-height: 95%;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 8px;
}

.q-tag {
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--neon-purple);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.q-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.4;
}

.opts-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.opt-btn {
  background: rgba(30, 41, 59, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text-main);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 600;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.opt-btn:active {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--neon-cyan);
}

.opt-badge {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--neon-cyan);
  color: var(--neon-cyan);
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Modal Feedback States */
.opt-btn.correct {
  background: rgba(16, 185, 129, 0.25) !important;
  border-color: var(--neon-green) !important;
  animation: pulseGreen 0.5s ease;
}

.opt-btn.wrong {
  background: rgba(244, 63, 94, 0.25) !important;
  border-color: var(--neon-pink) !important;
  animation: pulseRed 0.5s ease;
}

@keyframes pulseGreen {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes pulseRed {
  0%, 100% { transform: scale(0.98); }
}

/* Leaderboard Styling */
.lb-table-container {
  width: 100%;
  max-height: 260px;
  overflow-y: auto;
  background: rgba(10, 14, 23, 0.8);
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th, td {
  padding: 10px 14px;
  text-align: left;
}

th {
  background: rgba(30, 41, 59, 0.9);
  font-family: var(--font-heading);
  font-size: 0.8rem;
  color: var(--neon-cyan);
  letter-spacing: 1px;
  position: sticky;
  top: 0;
}

tr {
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }

/* Audio Toggle Floating Icon */
#audio-toggle {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  color: var(--neon-cyan);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 1000;
}

/* Mobile Responsive Overrides */
@media screen and (max-width: 768px), screen and (max-height: 750px) {
  body, html {
    height: 100dvh;
  }

  .screen {
    height: 100dvh;
    padding: 6px 12px 30px 12px;
  }

  .game-logo {
    margin-top: 2px;
  }

  .game-logo h1 {
    font-size: 1.6rem;
  }

  .game-logo p {
    font-size: 0.8rem;
  }

  .glass-card {
    padding: 14px;
    gap: 10px;
    border-radius: 14px;
  }

  input, select {
    padding: 10px 12px;
    font-size: 0.95rem;
    border-radius: 10px;
  }

  .btn {
    padding: 10px 14px;
    font-size: 0.88rem;
    border-radius: 10px;
  }

  #hud-panel {
    padding: 6px 10px;
    gap: 4px;
    border-radius: 12px;
  }

  .hud-value {
    font-size: 0.95rem;
  }

  .hud-label {
    font-size: 0.68rem;
  }

  .streak-badge {
    font-size: 0.68rem;
    padding: 2px 8px;
  }

  #canvas-container {
    margin: 4px 0 10px 0;
    flex: 1 1 0%;
  }

  .controls {
    grid-template-rows: repeat(2, 42px);
    max-width: 220px;
    gap: 6px;
    margin-bottom: 12px;
  }

  .btn-ctrl {
    font-size: 1.1rem;
    border-radius: 10px;
  }

  .lb-table-container {
    max-height: 200px;
  }

  .q-box {
    padding: 14px;
    gap: 10px;
  }

  .q-text {
    font-size: 0.95rem;
  }

  .opt-btn {
    padding: 10px;
    font-size: 0.9rem;
  }
}