:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --accent: #38bdf8;
  --ok: #22c55e;
  --c1: #38bdf8;
  --c2: #f472b6;
  --c3: #a78bfa;
  --c4: #fbbf24;
  --c5: #4ade80;
  --c6: #fb923c;
  --c7: #f87171;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% 10%, rgba(56, 189, 248, 0.18), transparent 42%),
    radial-gradient(circle at 85% 0%, rgba(167, 139, 250, 0.16), transparent 38%),
    linear-gradient(180deg, #0b1220, #111827);
}

body[data-theme="fusta"] {
  --c1: #d97706;
  --c2: #b45309;
  --c3: #92400e;
  --c4: #f59e0b;
  --c5: #a16207;
  --c6: #78350f;
  --c7: #fbbf24;
  background:
    radial-gradient(circle at 20% 0%, rgba(217, 119, 6, 0.35), transparent 45%),
    linear-gradient(180deg, #1c1006, #0f172a);
}

body[data-theme="neona"] {
  --c1: #22d3ee;
  --c2: #e879f9;
  --c3: #a3e635;
  --c4: #facc15;
  --c5: #38bdf8;
  --c6: #fb7185;
  --c7: #c084fc;
  background:
    radial-gradient(circle at 80% 10%, rgba(34, 211, 238, 0.35), transparent 40%),
    radial-gradient(circle at 20% 80%, rgba(232, 121, 249, 0.25), transparent 40%),
    linear-gradient(180deg, #020617, #0f172a);
}

body[data-theme="neona"] .cell.filled {
  box-shadow: 0 0 10px currentColor, inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}

body[data-theme="pastel"] {
  --c1: #f9a8d4;
  --c2: #a5b4fc;
  --c3: #86efac;
  --c4: #fde68a;
  --c5: #fdba74;
  --c6: #c4b5fd;
  --c7: #7dd3fc;
  background:
    radial-gradient(circle at 30% 0%, rgba(249, 168, 212, 0.35), transparent 45%),
    linear-gradient(180deg, #1e1030, #0f172a);
}

body[data-theme="magma"] {
  --c1: #ef4444;
  --c2: #f97316;
  --c3: #fbbf24;
  --c4: #dc2626;
  --c5: #fb923c;
  --c6: #991b1b;
  --c7: #fde047;
  background:
    radial-gradient(circle at 50% 0%, rgba(239, 68, 68, 0.4), transparent 45%),
    radial-gradient(circle at 20% 80%, rgba(249, 115, 22, 0.25), transparent 40%),
    linear-gradient(180deg, #450a0a, #0f172a);
}

body[data-theme="magma"] .cell.filled {
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.55), inset 0 -2px 0 rgba(0, 0, 0, 0.3);
}

.hidden {
  display: none !important;
}

.header {
  text-align: center;
  padding: 1.4rem 1rem 0.4rem;
}

.header h1 {
  margin: 0.35rem 0;
  letter-spacing: 0.02em;
}

.header p {
  margin: 0;
  color: var(--muted);
}

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.back:hover {
  color: var(--text);
}

.panel {
  max-width: 420px;
  margin: 0 auto;
  padding: 1rem 1rem 1.5rem;
  text-align: center;
}

.rules {
  text-align: left;
  color: var(--muted);
  line-height: 1.55;
  margin: 0 auto 1.25rem;
  max-width: 320px;
  padding-left: 1.2rem;
}

.stats {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.9rem;
  font-size: 0.95rem;
  color: var(--muted);
}

.stats strong {
  color: var(--text);
}

.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  width: min(92vw, 360px);
  margin: 0 auto;
  padding: 8px;
  background: rgba(15, 23, 42, 0.75);
  border-radius: 12px;
  border: 1px solid var(--line);
  touch-action: none;
  user-select: none;
}

.cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 5px;
  padding: 0;
  background: #1e293b;
  pointer-events: auto;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.cell.filled {
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.25);
}

.cell.preview-ok {
  outline: 2px solid rgba(34, 197, 94, 0.85);
  outline-offset: -2px;
  opacity: 0.92;
}

.cell.preview-bad {
  outline: 2px solid rgba(248, 113, 113, 0.7);
  outline-offset: -2px;
}

.cell.flash {
  animation: clear-pop 0.35s ease;
}

@keyframes clear-pop {
  0% {
    transform: scale(1);
    filter: brightness(1.4);
  }
  100% {
    transform: scale(0.92);
    opacity: 0.35;
  }
}

.cell.c1 { background: var(--c1); }
.cell.c2 { background: var(--c2); }
.cell.c3 { background: var(--c3); }
.cell.c4 { background: var(--c4); }
.cell.c5 { background: var(--c5); }
.cell.c6 { background: var(--c6); }
.cell.c7 { background: var(--c7); }

.status {
  min-height: 1.4em;
  margin: 0.85rem 0 0.6rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.tray {
  display: flex;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 0.5rem 0 1rem;
}

.piece {
  width: 100px;
  height: 100px;
  border: 2px solid transparent;
  border-radius: 12px;
  background: rgba(30, 41, 59, 0.9);
  display: grid;
  place-items: center;
  cursor: grab;
  padding: 6px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.piece:disabled {
  opacity: 0.35;
  cursor: default;
}

.piece.selected,
.piece.dragging-source {
  border-color: var(--accent);
  opacity: 0.35;
}

.piece:active {
  cursor: grabbing;
}

.drag-ghost {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 1000;
  pointer-events: none;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
  opacity: 0.95;
  will-change: transform;
}

body.dragging {
  cursor: grabbing;
  user-select: none;
  -webkit-user-select: none;
}

body.dragging .piece {
  cursor: grabbing;
}

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

.piece-grid span {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: transparent;
}

.piece-grid span.c1 { background: var(--c1); }
.piece-grid span.c2 { background: var(--c2); }
.piece-grid span.c3 { background: var(--c3); }
.piece-grid span.c4 { background: var(--c4); }
.piece-grid span.c5 { background: var(--c5); }
.piece-grid span.c6 { background: var(--c6); }
.piece-grid span.c7 { background: var(--c7); }

.actions {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
}

.primary,
.ghost {
  border: 0;
  border-radius: 8px;
  padding: 0.7rem 1.2rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.primary {
  background: var(--accent);
  color: #0f172a;
}

.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.primary:hover,
.ghost:hover {
  filter: brightness(1.06);
}

.final-score {
  font-size: 1.35rem;
  margin: 0.5rem 0 1rem;
}
