:root {
  --bg-deep: #02040b;
  --bg-mid: #050819;
  --neon-cyan: #66fff7;
  --neon-soft: rgba(102, 255, 247, 0.2);
  --wave-soft: rgba(145, 200, 255, 0.18);
  --text-main: rgba(245, 245, 255, 0.96);
  --text-dim: rgba(200, 208, 240, 0.7);
  --panel-bg: rgba(6, 10, 24, 0.95);
  --panel-border: rgba(150, 230, 255, 0.5);
  --hud-bg: radial-gradient(circle at top left, #151a32, #050816);
  --radius-lg: 18px;
  --radius-pill: 999px;
  --font-main: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden; /* Prevent scrollbars during shake */
}

body {
  font-family: var(--font-main);
  background-color: #000;
  color: var(--text-main);
  -webkit-font-smoothing: antialiased;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.game-shell {
  width: 100%;
  max-width: 900px;
  height: 100vh;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  z-index: 2;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 16px;
  border-radius: var(--radius-lg);
  background: var(--hud-bg);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: 0 0 24px rgba(0, 0, 0, 0.65);
  font-size: 0.9rem;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(4px);
}

.hud-left,
.hud-right,
.hud-center {
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  z-index: 1;
}

.logo {
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.logo span {
  color: var(--neon-cyan);
  text-shadow: 0 0 10px var(--neon-soft);
}

.tag {
  font-size: 0.65rem;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: rgba(200, 208, 240, 0.8);
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

#time-display {
  font-variant-numeric: tabular-nums;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  color: var(--neon-cyan);
  text-shadow: 0 0 15px rgba(102, 255, 247, 0.4);
}

#score-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: var(--text-dim);
}

#score-display {
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: rgba(220, 225, 250, 0.9);
}

.stability-pill {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(102, 255, 247, 0.4);
  color: rgba(215, 245, 255, 0.95);
  transition: all 0.2s ease;
}

.game-main {
  position: relative;
  flex: 1;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 0 50px rgba(0, 0, 0, 0.95);
  background: #000;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  /* Canvas background handled in JS for dynamic grid */
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  transition: opacity 0.3s ease;
  backdrop-filter: blur(0px);
  z-index: 10;
}

.overlay.active {
  backdrop-filter: blur(8px);
  background: rgba(0, 0, 0, 0.4);
}

.overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#help-overlay {
  z-index: 20;
}

.help-list {
  text-align: left;
  list-style: none;
  padding: 0;
  margin: 10px 0;
  font-size: 0.85rem;
  color: rgba(239, 241, 255, 0.8);
}

.help-list li {
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.help-list kbd {
  min-width: 24px;
  text-align: center;
}

.panel {
  min-width: min(460px, 100% - 40px);
  padding: 30px 26px;
  border-radius: 22px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  box-shadow: 0 0 60px rgba(102, 255, 247, 0.15),
    inset 0 0 20px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(16px);
  text-align: center;
}

.panel h1,
.panel h2 {
  margin: 0;
  font-size: 1.7rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: #f7f7ff;
}

.panel h2 {
  font-size: 1.4rem;
  margin-bottom: 15px;
  color: var(--neon-cyan);
  text-shadow: 0 0 12px var(--neon-soft);
}

.panel h1 span {
  color: var(--neon-cyan);
  text-shadow: 0 0 12px var(--neon-cyan);
}

.subtitle {
  margin: 8px 0 20px;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.hint {
  font-size: 0.85rem;
  line-height: 1.6;
  color: rgba(239, 241, 255, 0.9);
  margin-bottom: 18px;
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  border-radius: 12px;
}

.hint p {
  margin: 6px 0;
}

.legend-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  color: var(--text-dim);
  background: rgba(0, 0, 0, 0.3);
}

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  box-shadow: 0 0 6px currentColor;
}

.status {
  font-size: 0.9rem;
  margin: 1rem 0 1rem 0;
  color: var(--neon-cyan);
  text-shadow: 0 0 8px rgba(102, 255, 247, 0.4);
}

.status span {
  font-weight: 600;
  border-bottom: 1px solid currentColor;
}

.hint-small {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 8px;
  opacity: 0.7;
}

kbd {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.75em;
  font-family: inherit;
  color: #fff;
}

.footer {
  font-size: 0.75rem;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 2px;
  opacity: 0.6;
}

.quality-indicator {
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.4rem;
  font-weight: 800;
  font-style: italic;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  text-shadow: 0 0 20px currentColor;
  text-align: center;
  white-space: pre;
  z-index: 5;
}

.quality-indicator.show {
  animation: qualityPop 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes qualityPop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.2) rotate(-5deg);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.4) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(1);
  }
}

.audio-toggle {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(5, 10, 22, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.7rem;
  transition: all 0.2s;
  z-index: 100;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  backdrop-filter: blur(4px);
}

.audio-toggle:hover {
  background: rgba(102, 255, 247, 0.1);
  border-color: var(--neon-cyan);
}

.high-score {
  margin-top: 16px;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: monospace;
}

@media (max-width: 768px) {
  .hud {
    padding-inline: 10px;
  }
  .panel {
    padding: 20px 18px;
  }
  #time-display {
    font-size: 1.2rem;
  }
}
