:root {
  /* Identidad visual Puzlia — homenaje a Joan Miró (ver BRAND.md) */
  --page-bg: #faf7f0;           /* hueso Miró */
  --card-bg: #ffffff;
  --grid-line: #ddd5c7;         /* líneas del tablero */
  --cell-bg: #ffffff;
  --given-bg: #f1ece1;          /* celdas prefijadas */
  --ink: #1b1b1b;
  --muted: #6b6455;
  --accent: #2a6bd4;            /* azul Miró */
  --pill: #f0eadd;
  --pill-hover: #e6decd;
  --dark-btn: #1b1b1b;
  --dark-btn-hover: #000000;
  --error-bg: #fdecea;
  --error: #d93025;
  --border-soft: #e6dfd2;
  --dark-btn-ink: #ffffff;
  --cell: 64px;
}

/* ---------- Modo oscuro (Miró nocturno) ---------- */
html[data-theme="dark"] {
  --page-bg: #15130f;
  --card-bg: #201c17;
  --grid-line: #3e382e;
  --cell-bg: #2a251f;
  --given-bg: #353028;
  --ink: #f2eee4;
  --muted: #a89e8c;
  --accent: #5b8fe0;
  --pill: #2e2922;
  --pill-hover: #3b342b;
  --dark-btn: #f2eee4;
  --dark-btn-hover: #ffffff;
  --dark-btn-ink: #1b1b1b;
  --error-bg: #46211c;
  --border-soft: #3a342b;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Oxygen,
    Cantarell, "Fira Sans", "Droid Sans", "Helvetica Neue", Arial, sans-serif;
  background: var(--page-bg);
  color: var(--ink);
}

/* ---------- Cabecera del juego ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border-soft);
}

.back {
  text-decoration: none;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.topbar h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.topbar .spacer { flex: 1; }

.brand { display: flex; color: var(--ink); text-decoration: none; }
.brand svg { display: block; height: 40px; width: auto; }

.level-pill {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--pill);
  border: none;
  border-radius: 999px;
  padding: 9px 16px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  text-align: center;
}

.pill {
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  background: var(--pill);
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
}

.pill:hover { background: var(--pill-hover); color: var(--ink); }

/* ---------- Contenedor del juego ---------- */
main {
  max-width: 520px;
  margin: 24px auto 60px;
  padding: 0 16px;
}

.game-card {
  background: var(--card-bg);
  border-radius: 8px;
  padding: 20px 16px;
}

.hud {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 14px;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
}

.hud svg { display: block; }

#puzzle-label { color: var(--muted); font-weight: 400; }

/* ---------- Tablero ---------- */
.board-wrap { display: flex; justify-content: center; }

.board {
  display: grid;
  grid-template-columns: repeat(6, var(--cell));
  grid-template-rows: repeat(6, var(--cell));
  background: var(--grid-line);
  gap: 1px;
  border: 1px solid var(--grid-line);
  border-radius: 4px;
  overflow: visible;
}

.cell {
  position: relative;
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.cell:first-child { border-top-left-radius: 3px; }
.cell:nth-child(6) { border-top-right-radius: 3px; }
.cell:nth-child(31) { border-bottom-left-radius: 3px; }
.cell:last-child { border-bottom-right-radius: 3px; }

.cell.given { background: var(--given-bg); cursor: default; }
.cell.error { background: var(--error-bg); box-shadow: inset 0 0 0 2px var(--error); }
.cell.flash { animation: flash .8s; }

@keyframes flash {
  0%, 100% { box-shadow: none; }
  30% { box-shadow: inset 0 0 0 3px var(--accent); }
}

.symbol { display: flex; width: 46%; color: var(--ink); }
.symbol svg { width: 100%; height: auto; display: block; }

/* signos = / × sobre las líneas del tablero */
.sign {
  position: absolute;
  width: 18px;
  height: 18px;
  z-index: 2;
  pointer-events: none;
  filter: drop-shadow(0 0 1px rgba(0,0,0,.12));
}

.sign svg { display: block; width: 100%; height: 100%; }
.sign circle { fill: var(--cell-bg); stroke: var(--grid-line); }
.sign path { stroke: var(--muted); }
.sign.h { right: -9.5px; top: 50%; transform: translateY(-50%); }
.sign.v { bottom: -9.5px; left: 50%; transform: translateX(-50%); }

/* ---------- Tablero de Estrellas ---------- */
.qboard {
  --n: 8;
  --qcell: min(calc(408px / var(--n)), calc(82vw / var(--n)));
  display: grid;
  grid-template-columns: repeat(var(--n), var(--qcell));
  grid-template-rows: repeat(var(--n), var(--qcell));
  gap: 1px;
  background: #1b1b1b;
  border: 3px solid #1b1b1b;
  border-radius: 8px;
}

.qcell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.qcell.error::after {
  content: '';
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(45deg,
    rgba(217, 48, 37, .35) 0 4px, transparent 4px 8px);
  pointer-events: none;
}

.qcell.flash { animation: flash .8s; }

.qsymbol { display: flex; width: 52%; color: #1b1b1b; } /* regiones siempre pastel */
.qsymbol.is-mark { width: 44%; opacity: .9; }
.qsymbol svg { width: 100%; height: auto; display: block; }

.hint-msg {
  margin: 12px 2px 0;
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--ink);
}

.footnote {
  text-align: center;
  color: var(--muted);
  font-size: 12.5px;
  margin: 14px 0 0;
}

/* ---------- Botones bajo el tablero ---------- */
.actions {
  display: flex;
  gap: 12px;
  margin: 18px 2px 0;
}

.actions .pill { flex: 1; padding: 11px 0; text-align: center; }

.dark-btn {
  display: block;
  width: 100%;
  margin-top: 18px;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--dark-btn-ink);
  background: var(--dark-btn);
  border: none;
  border-radius: 999px;
  padding: 13px 0;
  cursor: pointer;
}

.dark-btn:hover { background: var(--dark-btn-hover); }

/* ---------- Cómo se juega ---------- */
.howto {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 16px 20px;
  margin-top: 18px;
}

.howto h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }

.howto ul {
  margin: 0;
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--ink);
}

.howto li { margin-bottom: 6px; }

.howto .mini {
  color: var(--ink);
  display: inline-block;
  width: 15px;
  height: 15px;
  vertical-align: -2px;
}

.howto .mini svg { display: block; width: 100%; height: 100%; }

/* ---------- Modal de victoria ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

.modal {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 28px 32px;
  text-align: center;
  max-width: 340px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .2);
}

.modal h2 { margin: 0 0 6px; font-size: 22px; }
.modal p { color: var(--muted); margin: 4px 0; font-size: 14px; }
.modal .time { font-size: 36px; font-weight: 700; margin: 10px 0; }
.modal .buttons { display: flex; gap: 10px; justify-content: center; margin-top: 18px; }
.modal .pill { padding: 10px 20px; }
.modal .dark-btn { width: auto; margin: 0; padding: 10px 22px; }

.hidden { display: none !important; }

/* ---------- Home ---------- */
.home main { max-width: 720px; }
.hero { text-align: center; margin: 28px 0 32px; }
.hero h1 { font-size: 30px; margin: 0 0 8px; }
.hero p { color: var(--muted); margin: 0; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 24px 20px;
  text-align: center;
  text-decoration: none;
  color: var(--ink);
  transition: transform .12s, box-shadow .12s;
}

.card:not(.disabled):hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .08);
}

.card .icon { height: 44px; display: flex; align-items: center; justify-content: center; gap: 4px; font-size: 36px; }
.card .icon svg { width: 34px; height: 34px; }
.card h2 { margin: 12px 0 4px; font-size: 19px; }
.card p { color: var(--muted); font-size: 14px; margin: 0; }
.card.disabled { opacity: .55; cursor: default; }
.card .soon {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  background: var(--pill);
  border-radius: 999px;
  padding: 3px 10px;
  color: var(--muted);
}

@media (max-width: 460px) {
  :root { --cell: min(13.5vw, 58px); }
}
