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

body {
  background: #0f0f1a;
  font-family: 'Segoe UI', sans-serif;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
  touch-action: manipulation;
}

/* ── HUD ── */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 56px;
  background: rgba(255,255,255,0.05);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  z-index: 10;
}

.hud-item {
  color: #e0e0ff;
  font-size: 1.3rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.hud-item span { color: #a78bfa; }

#timer.urgent {
  color: #f87171 !important;
  animation: pulse 0.6s infinite alternate;
}

@keyframes pulse {
  from { opacity: 1; }
  to   { opacity: 0.4; }
}

/* ── Board wrapper ── */
#board-wrap {
  position: fixed;
  top: 56px; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
}

/* ── Grid board ──
   Square grid (COLS=ROWS=7).
   Width = min of: height-derived size, viewport width, 440px cap. */
#board {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
  width: min(calc(100vh - 72px), calc(100vw - 16px), 440px);
  aspect-ratio: 1 / 1;
}

/* ── Cell ── */
.cell {
  border-radius: 10px;
  cursor: pointer;
  aspect-ratio: 1;
  position: relative;
  transition: filter 0.1s ease;
  position: relative;
}

.cell:hover  { filter: brightness(1.25); }

/* Selected */
.cell.selected {
  outline: 3px solid #fff;
  outline-offset: -3px;
  filter: brightness(1.3);
  z-index: 2;
}

/* Special (cross-bomb) cell */
.cell.special {
  box-shadow: 0 0 10px 3px rgba(255, 255, 255, 0.35);
}

.cell.special::after {
  content: '✦';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  color: rgba(255, 255, 255, 0.9);
  pointer-events: none;
  animation: sparkle 1.6s ease-in-out infinite;
}

@keyframes sparkle {
  0%, 100% { opacity: 0.6; transform: scale(0.9) rotate(0deg); }
  50%       { opacity: 1;   transform: scale(1.2) rotate(20deg); }
}

/* Animations */
.cell.anim-pop {
  animation: pop-in 0.22s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.cell.anim-drop {
  animation: drop-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.cell.anim-match {
  animation: match-burst 0.36s ease forwards;
  pointer-events: none;
}

.cell.anim-shake {
  animation: shake 0.28s ease;
}

@keyframes pop-in {
  from { transform: scale(0.2); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

@keyframes drop-in {
  from { transform: translateY(-48px) scale(0.7); opacity: 0; }
  to   { transform: translateY(0)     scale(1);   opacity: 1; }
}

@keyframes match-burst {
  0%   { transform: scale(1);   opacity: 1; filter: brightness(1); }
  45%  { transform: scale(1.35); opacity: 1; filter: brightness(2.5); }
  100% { transform: scale(0);   opacity: 0; }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-7px); }
  75%       { transform: translateX(7px); }
}

/* ── Floating combo label ── */
.float-combo {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: 800;
  color: #fde68a;
  pointer-events: none;
  white-space: nowrap;
  animation: float-up 1s ease forwards;
  z-index: 20;
  text-shadow: 0 0 12px rgba(253,230,138,0.7);
}

@keyframes float-up {
  0%   { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  60%  { opacity: 1; transform: translate(-50%, -80%) scale(1.15); }
  100% { opacity: 0; transform: translate(-50%, -110%) scale(0.9); }
}

/* ── Shuffle notice ── */
.shuffle-notice {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(124, 58, 237, 0.85);
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  padding: 14px 28px;
  border-radius: 14px;
  z-index: 50;
  pointer-events: none;
  animation: fade-in-out 0.7s ease;
}

@keyframes fade-in-out {
  0%   { opacity: 0; transform: translate(-50%, -50%) scale(0.8); }
  20%  { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  80%  { opacity: 1; }
  100% { opacity: 0; }
}

/* ── Overlay (start / end) ── */
#overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 26, 0.88);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

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

#overlay-box {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 20px;
  padding: 48px 56px;
  text-align: center;
  color: #e0e0ff;
  max-width: 420px;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
}

#overlay-box h1 {
  font-size: 2.6rem;
  font-weight: 800;
  color: #a78bfa;
  margin-bottom: 16px;
}

#overlay-box p {
  font-size: 1rem;
  line-height: 1.7;
  color: #c4c4e0;
  margin-bottom: 28px;
}

#overlay-box .result-score {
  font-size: 3.5rem;
  font-weight: 900;
  color: #fde68a;
  display: block;
  margin: 12px 0 4px;
}

#overlay-box .result-combo {
  font-size: 1rem;
  color: #a78bfa;
  margin-bottom: 28px;
  display: block;
}

#start-btn, #restart-btn {
  background: #7c3aed;
  color: #fff;
  border: none;
  padding: 14px 40px;
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 50px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

#start-btn:hover, #restart-btn:hover   { background: #6d28d9; transform: scale(1.04); }
#start-btn:active, #restart-btn:active { transform: scale(0.97); }

/* ── Score table ── */
.scores-heading {
  font-size: 1rem;
  font-weight: 700;
  color: #a78bfa;
  margin: 20px 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.score-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  font-size: 0.92rem;
}

.score-table th {
  color: #7c6fa0;
  font-weight: 600;
  padding: 4px 8px;
  text-align: left;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.score-table td {
  color: #d4d4f0;
  padding: 6px 8px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.score-table tr.new-entry td {
  color: #fde68a;
  font-weight: 700;
}

.no-scores {
  font-size: 0.9rem;
  color: #7c6fa0;
  margin-bottom: 24px !important;
}
