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

:root {
  color-scheme: dark;
  --bg: #0b111a;
  --bg-elevated: #111827;
  --bg-panel: #151f2e;
  --border: #233044;
  --border-soft: #1f2a3b;
  --text: #e5e7eb;
  --text-muted: #9aa5b1;
  --primary: #4f9cf5;
  --primary-strong: #2b7de9;
  --accent: #f4d35e;
  --success: #28c76f;
  --shadow: 0 16px 40px rgba(2, 8, 23, 0.45);
  --shadow-soft: 0 10px 28px rgba(2, 8, 23, 0.3);
}

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top, #142136, var(--bg));
}

.top-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(10, 16, 30, 0.75);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 18px 32px rgba(2, 8, 23, 0.35);
}

.top-bar::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    120deg,
    rgba(79, 156, 245, 0.12),
    transparent 55%
  );
  pointer-events: none;
}

.top-bar > * {
  position: relative;
  z-index: 1;
}

.hidden {
  display: none;
}

.game-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.control {
  display: flex;
  flex-direction: column;
  font-size: 0.85rem;
  color: var(--text-muted);
  gap: 4px;
}

.control.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--text);
}

.control.checkbox input {
  width: 16px;
  height: 16px;
  margin: 0;
  order: 1;
}

.control input,
.control select {
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-panel);
  color: var(--text);
  min-width: 110px;
}

.control input::placeholder {
  color: var(--text-muted);
}

.control input:focus,
.control select:focus {
  outline: 2px solid rgba(79, 156, 245, 0.35);
  border-color: var(--primary);
}

.btn {
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #ffffff;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease, box-shadow 0.2s ease,
    filter 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  position: relative;
  overflow: hidden;
}

.btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    120deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  transform: translateX(-120%);
  transition: transform 0.35s ease;
  opacity: 0.7;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
  box-shadow: 0 12px 28px rgba(79, 156, 245, 0.35);
}

.btn:hover::after {
  transform: translateX(120%);
}

.btn:disabled {
  background: #52606d;
  cursor: not-allowed;
  box-shadow: none;
  filter: none;
}

.btn.secondary {
  background: #273245;
}

.btn-icon {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex: 0 0 auto;
}

.pill-icon {
  width: 14px;
  height: 14px;
  display: inline-block;
  margin-right: 6px;
  opacity: 0.8;
}

.scoreboard {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.score {
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(79, 156, 245, 0.15);
  color: var(--text);
  font-weight: 600;
  min-width: 90px;
  text-align: center;
}

.score.active {
  background: rgba(244, 211, 94, 0.25);
  color: #fef3c7;
}

.game {
  display: grid;
  grid-template-columns: 70% 30%;
  gap: 16px;
  padding: 20px;
  flex: 1;
  min-height: 0;
}

.lobby {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lobby-room {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 20px;
}

.entrance {
  min-height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
  overflow: hidden;
}

.entrance::before {
  content: "";
  position: absolute;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(79, 156, 245, 0.35),
    transparent 70%
  );
  top: -220px;
  right: -180px;
  filter: blur(10px);
  opacity: 0.6;
  pointer-events: none;
}

.entrance::after {
  content: "";
  position: absolute;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(244, 211, 94, 0.18),
    transparent 70%
  );
  bottom: -220px;
  left: -160px;
  filter: blur(6px);
  opacity: 0.55;
  pointer-events: none;
}

.entrance-layout {
  position: relative;
  z-index: 1;
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: minmax(260px, 1.15fr) minmax(280px, 0.85fr);
  gap: 32px;
  align-items: center;
}

.entrance-hero {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand-pill {
  align-self: flex-start;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #dbeafe;
  background: rgba(79, 156, 245, 0.2);
  border: 1px solid rgba(79, 156, 245, 0.35);
  letter-spacing: 0.02em;
}

.hero-title {
  margin: 0;
  font-size: clamp(2rem, 3vw, 2.75rem);
  line-height: 1.1;
  color: var(--text);
}

.hero-subtitle {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-muted);
  max-width: 520px;
}

.hero-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.feature-card {
  padding: 14px 16px;
  border-radius: 12px;
  background: rgba(17, 24, 39, 0.7);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-soft);
}

.feature-card h3 {
  margin: 0 0 6px;
  font-size: 0.95rem;
  color: var(--text);
}

.feature-card p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.entrance-card {
  width: min(420px, 100%);
  justify-self: center;
}

.card {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--border-soft);
}

.card h2 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--text);
}

.room-card {
  min-height: 240px;
  justify-content: space-between;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.badge {
  background: rgba(79, 156, 245, 0.2);
  color: #dbeafe;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.players-list {
  display: grid;
  gap: 8px;
}

.player-pill {
  background: #1b2638;
  padding: 8px 12px;
  border-radius: 10px;
  font-weight: 600;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--border-soft);
}

.room-pill {
  background: rgba(79, 156, 245, 0.25);
  color: #dbeafe;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
}

.placement-info {
  display: grid;
  gap: 2px;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 140px;
}

.hint {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.puzzle-pane {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border: 1px solid var(--border-soft);
}

.puzzle-grid {
  display: grid;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background: #121a27;
  border-radius: 10px;
  overflow: hidden;
  border: 2px dashed #3a4a62;
  position: relative;
}

.puzzle-grid.preview {
  display: block;
  border: none;
  background: transparent;
}

.puzzle-preview {
  display: block;
  position: absolute;
  inset: 0;
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.15);
}

.puzzle-grid.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 360px;
}

.placeholder {
  margin: 0;
  color: var(--text-muted);
  font-size: 1rem;
}

.slot {
  border: 1px solid var(--border);
  background: #0f1724;
}

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

.slot-classic {
  position: relative;
  overflow: visible;
  background: transparent;
  border: none;
}

.slot-canvas {
  position: absolute;
  pointer-events: none;
}

.pieces-pane {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.pieces-pane h2 {
  margin: 0 0 12px 0;
  font-size: 1rem;
  color: var(--text);
}

.pieces-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(80px, 1fr));
  column-gap: 10px;
  row-gap: 16px;
  overflow-y: auto;
  overflow-x: visible;
  padding-left: 12px;
  padding-top: 12px;
  padding-right: 6px;
  min-height: 0;
}

.piece {
  border-radius: 6px;
  cursor: grab;
  box-shadow: 0 6px 14px rgba(2, 8, 23, 0.45);
  background-repeat: no-repeat;
  background-color: transparent;
  touch-action: none;
  margin-bottom: 2px;
}

.piece:active {
  cursor: grabbing;
}

.piece.locked {
  box-shadow: none;
  cursor: default;
}

.piece-classic {
  border-radius: 12px;
  box-shadow: none;
  background: transparent;
}

.pieces-grid .piece {
  background: transparent;
}

.piece.dragging {
  position: fixed;
  z-index: 30;
  cursor: grabbing;
  box-shadow: 0 16px 32px rgba(2, 8, 23, 0.6);
  pointer-events: none;
  background: transparent;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--bg-elevated);
  border-radius: 12px;
  padding: 16px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow);
}

.modal-content img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 8px;
}

@media (max-width: 920px) {
  .top-bar {
    padding: 10px 14px;
    gap: 10px;
  }

  .controls {
    gap: 8px;
  }

  .room-pill {
    padding: 4px 10px;
    font-size: 0.85rem;
  }

  .game {
    grid-template-columns: 1fr;
    padding: 12px;
    gap: 12px;
  }

  .entrance-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .entrance-card {
    width: min(500px, 100%);
    justify-self: stretch;
  }

  .pieces-grid {
    grid-template-columns: repeat(3, minmax(90px, 1fr));
  }
}

@media (max-width: 720px) {
  .entrance {
    min-height: auto;
    padding: 18px;
  }

  .hero-title {
    font-size: 2rem;
  }

  .hero-features {
    grid-template-columns: 1fr;
  }
  .game {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
  }

  .puzzle-pane {
    padding: 12px;
  }

  .pieces-pane {
    padding: 12px;
  }

  .pieces-grid {
    grid-template-columns: repeat(3, minmax(70px, 1fr));
    gap: 8px;
  }

  .scoreboard {
    gap: 8px;
  }

  .score {
    min-width: 70px;
    font-size: 0.85rem;
  }
}

@media (max-width: 480px) {
  .top-bar {
    flex-direction: column;
    align-items: flex-start;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .pieces-grid {
    grid-template-columns: repeat(2, minmax(70px, 1fr));
  }

  .room-pill {
    font-size: 0.8rem;
  }

  .brand-pill {
    font-size: 0.8rem;
  }
}
