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

:root {
  --accent: #00e5ff;
  --accent-glow: rgba(0, 229, 255, 0.3);
  --panel-bg: rgba(10, 10, 20, 0.55);
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-primary: rgba(255, 255, 255, 0.95);
  --text-secondary: rgba(255, 255, 255, 0.45);
  --text-dim: rgba(255, 255, 255, 0.25);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #080810;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  user-select: none;
  -webkit-user-select: none;
}

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

/* ─── UI Overlay ───────────────────────────────────────────── */
#ui-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
}

/* ─── Music toggle ─────────────────────────────────────────── */
.music-toggle {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: all;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  transition: all 0.2s ease;
  z-index: 15;
}

.music-toggle:hover {
  border-color: rgba(0, 229, 255, 0.3);
  box-shadow: 0 0 20px rgba(0, 229, 255, 0.15);
}

.music-toggle .music-off {
  display: none;
  opacity: 0.3;
}

.music-toggle.muted .music-on {
  display: none;
}

.music-toggle.muted .music-off {
  display: block;
}

.ui-panel {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  pointer-events: none;
}

.left-panel {
  left: 0;
  top: 0;
  bottom: 0;
  justify-content: flex-start;
  padding-top: 40px;
}

.right-panel {
  right: 0;
  top: 0;
  bottom: 0;
  justify-content: flex-start;
  padding-top: 40px;
  align-items: flex-end;
  text-align: right;
}

.panel-section {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 16px 20px;
  min-width: 140px;
}

.right-panel .panel-section {
  min-width: 160px;
}

.panel-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 3px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
}

.stat-value {
  font-size: 28px;
  font-weight: 300;
  letter-spacing: 1px;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ─── Hold / Next previews ─────────────────────────────────── */
.hold-container,
.next-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.next-container {
  align-items: flex-start;
}

.hold-container:empty::after,
.next-container:empty::after {
  content: '—';
  color: var(--text-dim);
  font-size: 20px;
}

.piece-preview {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
}

.piece-preview.disabled {
  opacity: 0.35;
  filter: grayscale(0.6);
}

.preview-row {
  display: flex;
  gap: 2px;
}

.preview-cell {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: transparent;
}

.preview-cell.filled {
  border-radius: 3px;
}

.next-container .piece-preview:first-child {
  padding: 6px;
}

.next-container .piece-preview:first-child .preview-cell {
  width: 18px;
  height: 18px;
}

/* ─── Controls ─────────────────────────────────────────────── */
.controls-section {
  margin-top: auto;
}

.controls-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
}

.control-row span {
  margin-left: 4px;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 500;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset,
              0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ─── Line clear text ──────────────────────────────────────── */
#line-clear-text {
  position: fixed;
  top: 35%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 48px;
  font-weight: 200;
  letter-spacing: 8px;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
  opacity: 0;
  pointer-events: none;
  z-index: 20;
  white-space: nowrap;
}

#line-clear-text.show {
  animation: lineClearPop 1.2s ease-out forwards;
}

@keyframes lineClearPop {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  20% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
  40% { transform: translate(-50%, -50%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1); }
}

/* ─── Overlays ─────────────────────────────────────────────── */
.overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 5, 12, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: all;
}

.overlay-content {
  text-align: center;
  padding: 40px;
}

/* ─── Start screen ─────────────────────────────────────────── */
.title {
  font-size: 80px;
  font-weight: 200;
  letter-spacing: 12px;
  color: var(--text-primary);
  margin-bottom: 4px;
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.15);
}

.title-3d {
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 30px var(--accent-glow);
  margin-left: 4px;
}

.subtitle {
  font-size: 14px;
  font-weight: 300;
  letter-spacing: 6px;
  color: var(--text-secondary);
  text-transform: uppercase;
  margin-bottom: 48px;
}

.start-button {
  font-size: 14px;
  font-weight: 400;
  letter-spacing: 2px;
  color: var(--text-secondary);
  padding: 16px 32px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: inline-block;
  animation: pulseGlow 2.5s ease-in-out infinite;
}

.start-button kbd {
  margin: 0 4px;
  background: rgba(0, 229, 255, 0.1);
  border-color: rgba(0, 229, 255, 0.25);
  color: var(--accent);
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(0, 229, 255, 0); }
  50% { box-shadow: 0 0 30px rgba(0, 229, 255, 0.15); }
}

/* ─── Pause ────────────────────────────────────────────────── */
.pause-title {
  font-size: 48px;
  font-weight: 200;
  letter-spacing: 16px;
  color: var(--text-primary);
  margin-bottom: 32px;
}

/* ─── Game over ────────────────────────────────────────────── */
.gameover-title {
  font-size: 56px;
  font-weight: 200;
  letter-spacing: 10px;
  color: #ff1744;
  text-shadow: 0 0 40px rgba(255, 23, 68, 0.3);
  margin-bottom: 40px;
}

.gameover-stats {
  display: flex;
  gap: 40px;
  margin-bottom: 48px;
  justify-content: center;
}

.gameover-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.gameover-stat .stat-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 3px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.gameover-stat .stat-number {
  font-size: 36px;
  font-weight: 300;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ─── Loading ──────────────────────────────────────────────── */
.loading-spinner {
  width: 40px;
  height: 40px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 0.8s linear infinite;
}

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

#loading-overlay p {
  font-size: 12px;
  letter-spacing: 4px;
  color: var(--text-secondary);
  text-transform: uppercase;
}

/* ─── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .ui-panel {
    padding: 12px;
    gap: 10px;
  }

  .panel-section {
    padding: 10px 14px;
    min-width: 100px;
  }

  .stat-value {
    font-size: 20px;
  }

  .controls-section {
    display: none;
  }

  .title {
    font-size: 48px;
    letter-spacing: 8px;
  }

  .gameover-stats {
    gap: 24px;
  }

  .gameover-stat .stat-number {
    font-size: 24px;
  }

  #line-clear-text {
    font-size: 32px;
  }
}
