:root {
  --bg: #0a0a14;
  --panel: #12121f;
  --border: #1e1e3a;
  --glow-cyan: #00f5ff;
  --glow-pink: #ff006e;
  --glow-yellow: #ffe600;
  --glow-green: #39ff14;
  --text: #e0e0ff;
  --muted: #5a5a8a;
  --cell: #0d0d1e;
  --cell-border: #1a1a30;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Rajdhani', sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 20% 80%, rgba(0,245,255,0.04) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 20%, rgba(255,0,110,0.04) 0%, transparent 60%);
  pointer-events: none;
}

h1 {
  font-family: 'Orbitron', monospace;
  font-size: clamp(1.2rem, 4vw, 2rem);
  font-weight: 900;
  letter-spacing: 0.15em;
  text-align: center;
  padding: 14px 0 6px;
  background: linear-gradient(90deg, var(--glow-cyan), var(--glow-pink), var(--glow-yellow));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 12px rgba(0,245,255,0.4));
}

#app {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 700px;
  padding: 0 8px 16px;
  gap: 10px;
}

#scorebar {
  display: flex;
  gap: 12px;
  width: 100%;
  justify-content: center;
}

.stat-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  text-align: center;
  flex: 1;
  max-width: 140px;
  position: relative;
  overflow: hidden;
}

.stat-box::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
}

.stat-box.score::before { background: linear-gradient(90deg, var(--glow-cyan), var(--glow-pink)); }
.stat-box.best::before  { background: linear-gradient(90deg, var(--glow-yellow), var(--glow-green)); }
.stat-box.level::before { background: linear-gradient(90deg, var(--glow-pink), var(--glow-cyan)); }

.stat-label {
  font-family: 'Orbitron', monospace;
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
}

.stat-value {
  font-family: 'Orbitron', monospace;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-box.score .stat-value { color: var(--glow-cyan); }
.stat-box.best  .stat-value { color: var(--glow-yellow); }
.stat-box.level .stat-value { color: var(--glow-pink); }

#game-area {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

#board-wrap { position: relative; }

#board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 0 30px rgba(0,245,255,0.06), inset 0 0 20px rgba(0,0,0,0.5);
}

.cell {
  width: 38px;
  height: 38px;
  background: var(--cell);
  border: 1px solid var(--cell-border);
  border-radius: 5px;
  position: relative;
  cursor: default;
  transition: background 0.06s;
}

.cell.filled { border-color: transparent; }

.cell.filled::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  right: 3px;
  height: 35%;
  background: rgba(255,255,255,0.2);
  border-radius: 3px 3px 0 0;
  pointer-events: none;
}

.cell.hint-valid {
  border-color: rgba(57,255,20,0.5) !important;
  background: rgba(57,255,20,0.12) !important;
}

.cell.hint-invalid {
  border-color: rgba(255,60,60,0.4) !important;
  background: rgba(255,30,30,0.1) !important;
}

.cell.clearing { animation: clearFlash 0.35s forwards; }

@keyframes clearFlash {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.15); filter: brightness(2.5); }
  100% { transform: scale(0); opacity: 0; }
}

#side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 120px;
}

.panel-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.panel-center { text-align: center; }

.panel-title {
  font-family: 'Orbitron', monospace;
  font-size: 0.5rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  text-align: center;
}

.next-grid-container {
  display: flex;
  justify-content: center;
}

.mini-cell {
  width: 20px;
  height: 20px;
  background: var(--cell);
  border: 1px solid var(--cell-border);
  border-radius: 3px;
}

.mini-cell.filled { border-color: transparent; }
.mini-cell.empty { background: transparent !important; border-color: transparent; box-shadow: none !important; }

.lines-value {
  font-family: 'Orbitron', monospace;
  font-size: 1.3rem;
  color: var(--glow-green);
  font-weight: 700;
}

.combo-value {
  font-family: 'Orbitron', monospace;
  font-size: 1.3rem;
  color: var(--glow-pink);
  font-weight: 700;
}

#pieces-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  width: 100%;
}

.piece-slot {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s, opacity 0.15s;
  min-height: 80px;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.piece-slot:active { cursor: grabbing; }
.piece-slot.used { opacity: 0.25; pointer-events: none; }
.piece-slot.dragging { opacity: 0.4; transform: scale(0.95); border-color: var(--glow-cyan); }

.piece-grid {
  display: grid;
  gap: 2px;
  pointer-events: none;
}

.piece-cell {
  width: 18px;
  height: 18px;
  border-radius: 3px;
  pointer-events: none;
}

.piece-cell.empty {
  background: transparent !important;
  box-shadow: none !important;
}

#ghost {
  position: fixed;
  pointer-events: none;
  z-index: 200;
  opacity: 0.82;
  filter: drop-shadow(0 4px 16px rgba(0,0,0,0.7));
  transform: translate(-50%, -50%);
}

#ghost .piece-grid { gap: 2px; }
#ghost .piece-cell { width: 34px; height: 34px; border-radius: 5px; }
#ghost .piece-cell.empty { background: transparent !important; box-shadow: none !important; }

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(5,5,20,0.88);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 40px;
  text-align: center;
  max-width: 340px;
  width: 90%;
  box-shadow: 0 0 60px rgba(0,245,255,0.12), 0 0 120px rgba(255,0,110,0.06);
  position: relative;
  overflow: hidden;
}

.modal::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--glow-cyan), var(--glow-pink), var(--glow-yellow));
}

.modal h2 {
  font-family: 'Orbitron', monospace;
  font-size: 1.4rem;
  font-weight: 900;
  margin-bottom: 6px;
  background: linear-gradient(135deg, var(--glow-cyan), var(--glow-pink));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal .subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal .final-score {
  font-family: 'Orbitron', monospace;
  font-size: 2.2rem;
  font-weight: 900;
  color: var(--glow-yellow);
  filter: drop-shadow(0 0 10px rgba(255,230,0,0.5));
  margin: 10px 0 4px;
}

.modal .final-label {
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin-bottom: 24px;
}

#play-btn {
  font-family: 'Orbitron', monospace;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  padding: 14px 32px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--glow-cyan), #0088ff);
  color: #000;
  box-shadow: 0 0 20px rgba(0,245,255,0.3);
  transition: all 0.15s;
}

#play-btn:hover {
  box-shadow: 0 0 30px rgba(0,245,255,0.55);
  transform: translateY(-1px);
}

#combo-display {
  position: fixed;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: 'Orbitron', monospace;
  font-size: 2.5rem;
  font-weight: 900;
  pointer-events: none;
  z-index: 50;
  opacity: 0;
  text-shadow: 0 0 30px currentColor;
}

.combo-anim { animation: comboFly 1s forwards; }

@keyframes comboFly {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(0.5); }
  30%  { opacity: 1; transform: translate(-50%, -65%) scale(1.2); }
  70%  { opacity: 0.8; transform: translate(-50%, -80%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -95%) scale(0.8); }
}

#instructions {
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  padding: 0 16px;
  line-height: 1.6;
}

@media (max-width: 500px) {
  .cell { width: 30px; height: 30px; }
  .piece-cell { width: 15px; height: 15px; }
  #ghost .piece-cell { width: 28px; height: 28px; }
}

@media (max-width: 380px) {
  .cell { width: 26px; height: 26px; }
  .piece-cell { width: 13px; height: 13px; }
  #ghost .piece-cell { width: 24px; height: 24px; }
}