:root {
  /* --- Paleta --- */
  --bg: #f3eefb;
  --bg-soft: #ece2fa;
  --ink: #2b2640;
  --ink-soft: #6b6285;
  --card: #fffdf9;
  --accent: #ff6b81;
  --accent-dark: #e8536a;
  --accent-2: #2ec4b6;
  --gold: #f5b942;

  /* Paleta de habitaciones (pasteles, se ciclan) */
  --room-1: #bfeae3;
  --room-2: #bfe0f5;
  --room-3: #fbd8b8;
  --room-4: #ead9fb;
  --room-5: #fdeab0;
  --room-6: #f6d6d9;

  --cell-size: 62px;
  --gap: 5px;
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(255,255,255,0.6) 0, transparent 45%),
    radial-gradient(circle at 90% 85%, rgba(255,255,255,0.5) 0, transparent 40%);
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  padding-bottom: 48px;
}

h1, h2, .display-font {
  font-family: "Baloo 2", sans-serif;
}

.app-header {
  text-align: center;
  padding: 26px 12px 6px;
}

.app-header h1 {
  margin: 0;
  font-size: 30px;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: 0.5px;
}

.app-header h1::after {
  content: " 🔎";
}

.subtitle {
  font-family: "Baloo 2", sans-serif;
  display: inline-block;
  margin: 10px 0 0;
  padding: 6px 18px;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
}

main {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 16px;
}

.game-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

@media (min-width: 720px) {
  .game-layout {
    grid-template-columns: 220px 1fr;
  }
}

/* --- Pantalla de autenticacion --- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 28px 26px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 0 var(--ink);
  text-align: center;
}

.auth-title {
  font-family: "Baloo 2", sans-serif;
  font-size: 24px;
  margin: 0;
}

.auth-title::after {
  content: " 🔎";
}

.auth-subtitle {
  font-size: 13px;
  color: var(--ink-soft);
  font-weight: 700;
  margin: 6px 0 18px;
}

.auth-error {
  background: #fbdada;
  color: #a3283f;
  border: 2px solid #a3283f;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 12px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.auth-form label {
  font-family: "Baloo 2", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.auth-form input {
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 10px;
  font-family: "Nunito", sans-serif;
  font-size: 14px;
  background: #fff;
}

.auth-form button {
  margin-top: 4px;
}

.auth-link-btn {
  background: none;
  border: none;
  box-shadow: none;
  color: var(--accent-dark);
  font-family: "Nunito", sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-decoration: underline;
  margin-top: 12px;
  cursor: pointer;
  padding: 4px;
}

.auth-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.auth-divider::before, .auth-divider::after {
  content: "";
  flex: 1;
  height: 2px;
  background: #e4defa;
}

.auth-google-btn {
  background: #fff;
  color: var(--ink);
  border: 2.5px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink);
  margin-bottom: 10px;
}

.auth-guest-btn {
  background: var(--card);
  color: var(--ink-soft);
  border: 2.5px dashed var(--ink-soft);
  box-shadow: none;
}

/* --- Fila de cuenta en el encabezado --- */
.account-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 8px;
}

.account-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
}

.account-signout-btn {
  width: auto;
  padding: 4px 10px;
  font-size: 10px;
  background: var(--card);
  color: var(--ink-soft);
  border: 2px solid var(--ink-soft);
  box-shadow: none;
}

/* --- Marcador de puntaje / tiempo --- */
.score-header {
  display: flex;
  gap: 12px;
  margin: 18px 0 0;
}

.score-chip {
  flex: 1;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  text-align: center;
  box-shadow: 0 3px 0 var(--ink);
}

.score-chip-label {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-soft);
  font-weight: 700;
}

.score-chip-value {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 20px;
  font-weight: 800;
  color: var(--ink);
}

.score-chip-solved {
  background: #eaf7e6;
}

.score-chip-solved .score-chip-value {
  color: #1f6b3a;
}

.score-chip-failed {
  background: #fbe9ea;
}

.score-chip-failed .score-chip-value {
  color: #a3283f;
}

/* --- Barra de nivel actual --- */
.level-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: 0 3px 0 var(--ink);
}

.level-bar-label {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 10px;
  text-transform: uppercase;
  color: var(--ink-soft);
  font-weight: 700;
}

.level-bar-current {
  display: block;
  font-family: "Baloo 2", sans-serif;
  font-size: 16px;
  font-weight: 800;
  color: var(--ink);
}

.level-bar-btn {
  flex: none;
  width: auto;
  padding: 8px 14px;
  background: var(--accent-2);
  box-shadow: 0 3px 0 #1c9a8f;
  font-size: 12px;
}

.level-bar-btn:active {
  box-shadow: 0 1px 0 #1c9a8f;
}

/* --- Mapa de niveles --- */
.level-map {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin: 0 0 14px;
}

.level-card {
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 10px;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 0.1s ease;
}

.level-card:active {
  transform: translateY(2px);
}

.level-card.active {
  border-color: var(--accent-dark);
  box-shadow: 0 3px 0 var(--accent-dark);
}

.level-card.locked {
  opacity: 0.55;
  cursor: not-allowed;
}

.level-card-title {
  font-family: "Baloo 2", sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
  margin-bottom: 6px;
}

.level-card-stars {
  font-size: 13px;
  color: var(--gold);
  margin-bottom: 6px;
}

.level-card-stars .dim, .celebration-star.dim {
  color: #ded8ee;
}

.level-card-progress {
  height: 6px;
  background: #ded8ee;
  border-radius: 4px;
  overflow: hidden;
}

.level-card-progress-fill {
  height: 100%;
  background: var(--accent-2);
}

.level-card-lock {
  font-family: "Baloo 2", sans-serif;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-soft);
}

/* --- Celebracion --- */
.celebration-overlay {
  position: fixed;
  inset: 0;
  background: rgba(43, 38, 64, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.celebration-card {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 8px 0 var(--ink);
  max-width: 320px;
}

.celebration-title {
  font-family: "Baloo 2", sans-serif;
  font-size: 22px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 10px;
}

.celebration-stars {
  font-size: 32px;
  color: var(--gold);
  letter-spacing: 6px;
  margin-bottom: 10px;
}

.celebration-points {
  font-family: "Baloo 2", sans-serif;
  font-size: 24px;
  font-weight: 800;
  color: var(--accent-dark);
  margin-bottom: 8px;
}

.celebration-levelup {
  background: #d3f2d0;
  color: #1f6b3a;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 999px;
  display: inline-block;
  margin-bottom: 8px;
}

.celebration-sub {
  font-size: 12px;
  color: var(--ink-soft);
  font-weight: 600;
}

/* --- Panel de configuracion --- */
.setup-panel {
  display: flex;
  gap: 12px;
  margin: 20px 0;
}

.setup-panel label {
  flex: 1;
  font-family: "Baloo 2", sans-serif;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.setup-panel select {
  background: var(--card);
  color: var(--ink);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 10px;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 3px 0 var(--ink);
}

/* --- Vidas --- */
.lives-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 14px;
}

.lives-label {
  font-family: "Baloo 2", sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-soft);
}

.lives-display {
  display: flex;
  gap: 4px;
}

.life-heart {
  font-size: 22px;
  color: var(--accent);
  filter: drop-shadow(0 1px 0 var(--ink));
  transition: transform 0.15s ease;
}

.life-heart.lost {
  color: #d8d3e6;
}

/* --- Texto de ayuda --- */
.hint-text {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
  margin: 14px 0 0;
  line-height: 1.5;
  background: var(--card);
  border: 2px dashed var(--ink-soft);
  border-radius: var(--radius-md);
  padding: 10px 14px;
}

/* --- Panel de pistas: burbujas, fijo al lado del tablero --- */
.clues-panel {
  margin: 0;
  position: static;
}

@media (min-width: 720px) {
  .clues-panel {
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }
}

.clues-panel h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-soft);
  margin: 0 0 10px 6px;
  font-weight: 800;
}

#cluesList {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#cluesList li {
  position: relative;
  background: var(--card);
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 3px 0 var(--ink);
}

#cluesList li::before {
  content: "💬";
  margin-right: 6px;
}

/* --- Brujula y tablero --- */
.board-wrapper {
  display: flex;
  justify-content: center;
  margin: 18px 0;
}

.board-frame {
  position: relative;
  display: inline-grid;
  padding: 30px;
}

.compass-label {
  position: absolute;
  font-family: "Baloo 2", sans-serif;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--accent-dark);
}

.compass-north { top: 4px; left: 50%; transform: translateX(-50%); }
.compass-south { bottom: 4px; left: 50%; transform: translateX(-50%); }
.compass-west { left: 2px; top: 50%; transform: translateY(-50%) rotate(-90deg); }
.compass-east { right: 2px; top: 50%; transform: translateY(-50%) rotate(90deg); }

.board {
  display: grid;
  gap: var(--gap);
  background: var(--ink);
  padding: var(--gap);
  border-radius: var(--radius-lg);
  box-shadow: 0 8px 0 rgba(43,38,64,0.25), 0 8px 20px rgba(43,38,64,0.25);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  cursor: pointer;
  position: relative;
  border: 2px solid transparent;
  transition: transform 0.12s ease, border-color 0.12s ease;
}

.cell:active {
  transform: scale(0.94);
}

.cell.selected {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 3px #fff;
}

/* Patron sutil tipo cuadros dentro de cada celda para dar textura, como en libros ilustrados */
.cell.pattern-a {
  background-image: linear-gradient(135deg, rgba(255,255,255,0.35) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.35) 75%);
  background-size: 16px 16px;
}

.room-pill {
  position: absolute;
  bottom: 2px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 2px 7px;
  font-family: "Baloo 2", sans-serif;
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--ink);
  white-space: nowrap;
  z-index: 3;
  box-shadow: 0 2px 0 var(--ink);
}

.cell .furniture-tag {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  pointer-events: none;
}

.furniture-icon {
  width: 34px;
  height: 34px;
  filter: drop-shadow(0 2px 1px rgba(43,38,64,0.35));
}

.furniture-icon-svg {
  width: 100%;
  height: 100%;
  display: block;
}

.cell .entity-token {
  width: 42px;
  height: 42px;
  z-index: 2;
}

.person-icon-svg, .victim-icon-svg {
  width: 100%;
  height: 100%;
  display: block;
  filter: drop-shadow(0 2px 2px rgba(43,38,64,0.45));
}

/* --- Fichas de sospechosos estilo polaroid --- */
.entity-picker h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-soft);
  margin: 0 0 10px 6px;
  font-weight: 800;
}

.entity-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
}

.entity-chip {
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 8px 8px 10px;
  width: 92px;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  text-align: center;
}

.entity-chip:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 var(--ink);
}

.chip-photo {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  margin-bottom: 6px;
  border: 2px solid var(--ink);
}

.chip-avatar {
  width: 100%;
  height: 100%;
  display: block;
}

.chip-name {
  font-family: "Caveat", cursive;
  font-size: 20px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1;
  display: block;
}

.entity-chip.active {
  border-color: var(--accent-dark);
  box-shadow: 0 4px 0 var(--accent-dark);
}

.entity-chip.placed {
  opacity: 0.5;
}

/* --- Controles --- */
.controls {
  display: flex;
  gap: 10px;
  margin: 24px 0 10px;
}

button {
  flex: 1;
  padding: 13px;
  border: 2.5px solid var(--ink);
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #fff;
  font-family: "Baloo 2", sans-serif;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--accent-dark);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--accent-dark);
}

button#resetBtn, button#newPuzzleBtn {
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
}

button#resetBtn:active, button#newPuzzleBtn:active {
  box-shadow: 0 1px 0 var(--ink);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

/* --- Resultado --- */
.result-banner {
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--radius-md);
  text-align: center;
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 15px;
  border: 2.5px solid var(--ink);
}

.result-banner.success {
  background: #d3f2d0;
  color: #1f6b3a;
  box-shadow: 0 4px 0 #1f6b3a;
}

.result-banner.error {
  background: #fbdada;
  color: #a3283f;
  box-shadow: 0 4px 0 #a3283f;
}

.hidden {
  display: none;
}
