:root {
  --bg: #0f0f1a;
  --card: #1a1a2e;
  --border: #2a2a4a;
  --accent: #e94560;
  --accent-2: #ffb84d;
  --text: #e6e6f0;
  --muted: #8a8aa3;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: 'Segoe UI', Roboto, system-ui, sans-serif; }

.game-shell {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
}

.hud {
  display: flex;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  justify-content: center;
}
.hud-cell {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  text-align: center;
  min-width: 92px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}
.hud-label { font-size: 11px; color: var(--muted); letter-spacing: 1.5px; text-transform: uppercase; }
.hud-value { font-size: 22px; font-weight: 700; color: var(--accent); margin-top: 2px; }

.board-row {
  display: flex;
  gap: 14px;
  justify-content: center;
  align-items: flex-start;
}

.side-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  width: 140px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}
.panel-label {
  font-size: 11px;
  letter-spacing: 1.5px;
  color: var(--muted);
  text-transform: uppercase;
  margin-bottom: 8px;
}
.keyhint {
  font-size: 10px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.3;
}
#holdCanvas, #nextCanvas {
  background: #0a0a14;
  border: 1px solid var(--border);
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}
.btn-mini {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  background: #23234a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}
.btn-mini:hover { background: #2d2d5a; }

.board-wrap {
  position: relative;
  display: inline-block;
}
#board {
  background: #0a0a14;
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 24px rgba(233, 69, 96, 0.15);
  display: block;
}

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(15, 15, 26, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  z-index: 10;
}
.overlay.hidden { display: none; }
.overlay-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px 28px;
  text-align: center;
  max-width: 90%;
}
.overlay-card h2 { margin: 0 0 12px; color: var(--accent); }
.overlay-text { margin: 8px 0; color: var(--text); font-size: 14px; }
.overlay-text.small { font-size: 12px; color: var(--muted); }
kbd {
  display: inline-block;
  background: #2a2a4a;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 2px 6px;
  font-family: monospace;
  font-size: 12px;
  color: var(--accent-2);
}

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 24px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  margin-top: 12px;
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.15s;
  box-shadow: 0 2px 12px rgba(233, 69, 96, 0.4);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(233, 69, 96, 0.55); }
.btn-primary:active { transform: translateY(0); }

/* Mobile controls */
.mobile-controls {
  display: none;
  margin-top: 16px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}
.mobile-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}
.mbtn {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 20px;
  width: 60px;
  height: 50px;
  cursor: pointer;
  font-family: inherit;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.mbtn.wide { width: 130px; font-size: 14px; font-weight: 600; letter-spacing: 1px; }
.mbtn:active { background: var(--accent); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px 32px;
  width: 92%;
  max-width: 520px;
  position: relative;
  max-height: 86vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover { color: var(--accent); }
.modal-card h2 { margin: 0 0 18px; color: var(--accent); text-align: center; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.stat-card {
  background: #15152a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  text-align: center;
}
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: 1.5px; text-transform: uppercase; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--accent-2); margin-top: 2px; }

/* Line-clear flash */
@keyframes lineFlash {
  0% { background-color: rgba(255,255,255,0.85); }
  100% { background-color: transparent; }
}
.line-flash {
  animation: lineFlash 0.35s ease-out;
}

/* Score popup */
@keyframes scorePop {
  0% { transform: translateY(0) scale(1); opacity: 1; }
  100% { transform: translateY(-30px) scale(1.3); opacity: 0; }
}
.score-pop {
  position: absolute;
  color: var(--accent-2);
  font-weight: 700;
  font-size: 18px;
  pointer-events: none;
  animation: scorePop 1s ease-out forwards;
  text-shadow: 0 0 8px rgba(255, 184, 77, 0.8);
}

@media (max-width: 720px) {
  .side-panel { width: 90px; padding: 8px; }
  #holdCanvas, #nextCanvas { width: 80px; }
  #holdCanvas { height: 80px; }
  #nextCanvas { height: 240px; }
  .mobile-controls { display: block; }
  #board { width: 240px; height: 480px; }
}

@media (max-width: 480px) {
  .hud-cell { min-width: 64px; padding: 6px 10px; }
  .hud-value { font-size: 18px; }
  #board { width: 200px; height: 400px; }
}