* {
  box-sizing: border-box;
}

:root {
  --bg-page: #0f172a;
  --bg-page-gradient: radial-gradient(circle at top, #1d3557 0, #020617 55%);
  --bg-board-frame: #ffffff;
  --bg-cell-empty: #f7f8fb;
  --bg-cell-border: #d5d9e2;
  --blue-block: linear-gradient(145deg, #0f74ff, #0b57c9);
  --blue-block-highlight: #3b82f6;
  --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.35);
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --accent: #fbbf24;
}

/* PAGE */

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg-page-gradient);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  color: var(--text-main);
}

/* APP WRAPPER */

.bb-app {
  width: min(480px, 100%);
  max-height: 900px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* USER-BAR OBEN */

.bb-user-bar {
  width: 100%;
  text-align: center;
  font-size: 12px;
  margin-bottom: 4px;
}

/* HEADER – Score wirklich mittig (Grid 3 Spalten) */

.bb-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 12px;
  padding: 4px 4px 0;
  color: var(--text-main);
}

.bb-best-score {
  justify-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 700;
  font-size: 18px;
  color: #fbbf24;
  text-shadow: 0 0 8px rgba(251, 191, 36, 0.7);
}

.bb-crown {
  font-size: 20px;
}

.bb-current-score {
  justify-self: center;
  font-size: 40px;
  font-weight: 800;
  color: #e5e7eb;
  text-shadow: 0 0 10px rgba(59, 130, 246, 0.8);
}

.bb-header-right {
  justify-self: flex-end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bb-user-info {
  font-size: 12px;
  color: var(--text-muted);
}

.bb-link-button {
  border: none;
  background: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: #93c5fd;
  cursor: pointer;
  text-decoration: underline;
}

/* Buttons rechts */

.bb-btn-restart,
.bb-btn-leaderboard {
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.12s ease-out,
    box-shadow 0.12s ease-out,
    filter 0.12s ease-out;
}

.bb-btn-restart {
  background: #ffd54a;
  color: #7c2d12;
  font-size: 22px;
}

.bb-btn-leaderboard {
  background: #1e293b;
  color: #facc15;
}

.bb-btn-restart:hover,
.bb-btn-leaderboard:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

/* MAIN LAYOUT */

.bb-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* BOARD */

.bb-board-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.bb-board-frame {
  background: var(--bg-board-frame);
  border-radius: 22px;
  padding: 14px;
  box-shadow: var(--shadow-soft);
  border: 1px solid #e5e7eb;
}

/* 8x8 Grid */

.board {
  display: grid;
  grid-template-columns: repeat(8, 36px);
  grid-template-rows: repeat(8, 36px);
  gap: 2px;
  background: #e5e7eb;
  border-radius: 14px;
  padding: 4px;
}

.cell {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-cell-empty);
  box-shadow: inset 0 0 0 1px var(--bg-cell-border);
  cursor: pointer;
  transition:
    transform 0.06s ease-out,
    box-shadow 0.06s ease-out,
    background 0.08s ease-out;
}

.cell:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px #9ca3af;
}

/* befüllte Blöcke -> blaue "Knöpfe" */

.cell.filled {
  background: var(--blue-block);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.4),
    inset 0 -3px 4px rgba(15, 23, 42, 0.35),
    0 3px 6px rgba(15, 23, 42, 0.45);
}

/* Löschanimation */

.cell.clearing {
  animation: bb-clear-flash 0.25s ease-out forwards;
}

@keyframes bb-clear-flash {
  0% {
    transform: scale(1);
    background: var(--blue-block);
  }
  50% {
    transform: scale(1.1);
    background: #fef3c7;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.9);
  }
  100% {
    transform: scale(0.9);
    background: var(--bg-cell-empty);
    box-shadow: inset 0 0 0 1px var(--bg-cell-border);
  }
}

/* Vorschau beim Drag */

.cell.preview-valid {
  box-shadow:
    0 0 0 2px var(--blue-block-highlight),
    inset 0 0 0 1px rgba(255, 255, 255, 0.6);
}

.cell.preview-invalid {
  box-shadow:
    0 0 0 2px #ef4444,
    inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

/* Combo-Text */

.bb-combo {
  font-size: 20px;
  font-weight: 700;
  color: #f97316;
  text-align: center;
  min-height: 24px;
  opacity: 0;
  transform: translateY(8px) scale(0.9);
  transition:
    opacity 0.2s ease-out,
    transform 0.2s ease-out;
  pointer-events: none;
}

.bb-combo.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

/* MESSAGE */

.bb-message {
  font-size: 13px;
  color: #cbd5f5;
  text-align: center;
  padding: 0 8px;
}

/* PIECES unten – feste Höhe */

.bb-pieces-section {
  width: 100%;
  height: 150px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 10px;
}

.pieces {
  display: flex;
  gap: 32px;
  justify-content: center;
  align-items: center;
}

/* Piece "im freien Raum" */

.piece {
  user-select: none;
  cursor: grab;
  /* NEU: größerer unsichtbarer Klick-/Touchbereich */
  padding: 16px 20px;
  min-width: 80px;
  min-height: 80px;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  transition:
    transform 0.1s ease-out,
    box-shadow 0.1s ease-out;
}

.piece:active {
  cursor: grabbing;
}

.piece:hover {
  transform: translateY(-3px);
}

.piece.selected {
  transform: translateY(-3px) scale(1.02);
}

/* Einzelblöcke in den Shapes */

.piece-grid {
  display: inline-block;
}

.piece-row {
  display: flex;
}

.piece-cell {
  width: 24px;
  height: 24px;
  margin: 1px;
  border-radius: 6px;
  background: var(--blue-block);
  box-shadow:
    inset 0 2px 3px rgba(255, 255, 255, 0.4),
    inset 0 -3px 4px rgba(15, 23, 42, 0.35),
    0 3px 6px rgba(15, 23, 42, 0.35);
}

/* OVERLAY (Game Over) */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

.overlay-content {
  background: #ffffff;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 18px 20px 14px;
  text-align: center;
  width: min(320px, 90vw);
  color: #111827;
}

.overlay-content h2 {
  margin: 0 0 6px;
  font-size: 22px;
}

.overlay-content p {
  margin: 0 0 8px;
  font-size: 14px;
  color: #4b5563;
}

.overlay-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 10px;
}

.overlay-label {
  font-size: 11px;
  color: #6b7280;
}

.overlay-value {
  font-size: 20px;
  font-weight: 700;
}

.overlay-button {
  border: none;
  border-radius: 999px;
  padding: 8px 18px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: var(--blue-block);
  color: #f9fafb;
  box-shadow: var(--shadow-soft);
}

.overlay-button:hover {
  filter: brightness(1.05);
}

/* AUTH & LEADERBOARD OVERLAY */

.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 30;
}

.auth-overlay.hidden {
  display: none;
}

.auth-dialog {
  background: #ffffff;
  border-radius: 18px;
  box-shadow: var(--shadow-soft);
  padding: 18px 20px 16px;
  width: min(360px, 95vw);
  position: relative;
  color: #111827;
}

.auth-close {
  position: absolute;
  right: 10px;
  top: 8px;
  border: none;
  background: none;
  font-size: 20px;
  cursor: pointer;
}

.auth-title {
  margin: 0 0 10px;
  font-size: 20px;
}

.auth-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.auth-tab {
  flex: 1;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  padding: 6px 0;
  font-size: 13px;
  background: #f9fafb;
  cursor: pointer;
}

.auth-tab.active {
  background: #2563eb;
  border-color: #2563eb;
  color: #f9fafb;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.auth-form.hidden {
  display: none;
}

.auth-form label {
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.auth-form input {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  font-size: 14px;
}

.auth-submit {
  margin-top: 6px;
  border-radius: 999px;
  border: none;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: #2563eb;
  color: #f9fafb;
}

.auth-message {
  margin-top: 6px;
  font-size: 12px;
  color: #b91c1c;
}

/* LEADERBOARD SPEZIFISCH */

.leaderboard-dialog {
  max-height: 80vh;
}

.leaderboard-subtitle {
  margin: 0 0 8px;
  font-size: 13px;
  color: #6b7280;
}

.leaderboard-wrapper {
  max-height: 260px;
  overflow: auto;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  background: #f9fafb;
}

.leaderboard-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.leaderboard-table th,
.leaderboard-table td {
  padding: 6px 8px;
  text-align: left;
}

.leaderboard-table thead {
  background: #e5e7eb;
  position: sticky;
  top: 0;
}

.leaderboard-table tbody tr:nth-child(odd) {
  background: #f9fafb;
}

.leaderboard-table tbody tr:nth-child(even) {
  background: #eef2ff;
}

/* Medaillen & eigener Eintrag */

.leaderboard-table th:nth-child(1),
.leaderboard-table td:nth-child(1) {
  width: 40px;
}

.leaderboard-table td:nth-child(3) {
  text-align: right;
  font-weight: 600;
}

.leaderboard-row-me {
  background: #fef3c7 !important;
}

.leaderboard-row-me td:nth-child(2) {
  font-weight: 700;
}

/* Hinweis eigener Platz */

.leaderboard-own-rank {
  margin-top: 8px;
  font-size: 12px;
  color: #4b5563;
}

/* RESPONSIVE */

@media (max-width: 420px) {
  .board {
    grid-template-columns: repeat(8, 32px);
    grid-template-rows: repeat(8, 32px);
  }

  .cell {
    width: 32px;
    height: 32px;
  }

  .piece-cell {
    width: 22px;
    height: 22px;
  }
}

/* Board & Pieces: Touch-Scroll deaktivieren, damit Drag&Drop sauber läuft */

.board,
.pieces,
.piece {
  touch-action: none;
}
