:root {
  --bg: #f3ecdf;
  --bg-deep: #e6dcc9;
  --ink: #1d1a16;
  --muted: #3f3830;
  --line: #d8ccb6;
  --white: #fffaf3;
  --terra: #c4321f;
  --teal: #0f766e;
  --gold: #e8a317;
  --navy: #243056;
  --blue: #2f5d9f;
  --shadow: 0 14px 30px rgba(48, 32, 12, 0.08);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background-color: var(--bg);
  background-image: radial-gradient(rgba(29, 26, 22, 0.08) 1px, transparent 1px);
  background-size: 22px 22px;
  font-family: Outfit, "Avenir Next", "Segoe UI", sans-serif;
  font-size: 1.05rem;
  line-height: 1.5;
}

h1, h2, h3, .brand strong, .kicker, .stamp {
  font-family: Fraunces, Georgia, "Iowan Old Style", serif;
  font-weight: 560;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(2.2rem, 5vw, 4.4rem); line-height: 0.95; margin: 0.45rem 0 0.6rem; }
h2 { font-size: 1.7rem; margin: 0 0 0.4rem; }
h3 { font-size: 1.35rem; margin: 0 0 0.35rem; }

p { margin: 0.35rem 0; }

a { color: inherit; }

button, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus-visible {
  outline: 3px solid var(--teal);
  outline-offset: 2px;
}

.wrap {
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  background: #f3ecdf;
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 4.4rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
}

.logo {
  display: grid;
  place-items: center;
  width: 2.7rem;
  height: 2.7rem;
  border-radius: 10px;
  background: var(--terra);
  color: white;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
  font-size: 0.95rem;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text strong { font-size: 1.25rem; }
.brand-text small { color: var(--muted); font-size: 0.82rem; }

.btn {
  border: 2px solid var(--ink);
  background: var(--white);
  border-radius: 999px;
  padding: 0.62rem 1rem;
  font-weight: 650;
  box-shadow: 3px 3px 0 var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
.btn:active { transform: translate(2px, 2px); box-shadow: 0 0 0 var(--ink); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-small { padding: 0.4rem 0.75rem; font-size: 0.92rem; box-shadow: 2px 2px 0 var(--ink); }
.btn-primary { background: var(--terra); color: white; }
.btn-teal { background: var(--teal); color: white; }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-pressed { background: var(--navy); color: white; }

.row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; }

main { padding: 1.4rem 0 3rem; }

.hero { display: grid; gap: 1.2rem; margin-bottom: 1.4rem; }

.stamp {
  display: inline-block;
  border: 3px solid var(--terra);
  color: var(--terra);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  padding: 0.28rem 0.5rem;
  border-radius: 8px;
  transform: rotate(-4deg);
  transform-origin: left center;
  margin: 0 0 1.35rem;
}

.lede, .game-head .lede { max-width: 42rem; color: var(--muted); font-size: 1.12rem; }

.pipeline {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 0.55rem;
  list-style: none;
  padding: 0;
  margin: 0.4rem 0 0;
}

.pipeline li {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 0.65rem 0.7rem 0.75rem;
  box-shadow: 3px 3px 0 var(--bg-deep);
  min-height: 6.2rem;
}

.pipeline .step {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--terra);
}

.pipeline strong { display: block; font-size: 0.98rem; line-height: 1.2; margin: 0.15rem 0; }
.pipeline span { display: block; color: var(--muted); font-size: 0.84rem; }

.game-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.game-card {
  display: grid;
  grid-template-columns: 7.5rem 1fr;
  gap: 0.9rem;
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 0.9rem;
  text-decoration: none;
  box-shadow: var(--shadow);
  min-height: 11rem;
}

.game-card:hover { transform: translateY(-3px); }

.card-art {
  border-radius: 14px;
  border: 2px solid var(--ink);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.card-art svg { width: 100%; height: auto; display: block; }

.game-card h2 { font-size: 1.55rem; }
.game-card p { color: var(--muted); margin: 0.2rem 0 0.55rem; }
.best { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 0.78rem; color: var(--navy); }

.home-note {
  margin-top: 1.2rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.game { position: relative; display: grid; gap: 1rem; }

.game-head h1 { font-size: clamp(2rem, 4vw, 3.2rem); }

.kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--teal);
}

.help {
  background: var(--white);
  border: 1px dashed var(--ink);
  border-radius: 12px;
  padding: 0.35rem 0.8rem;
  max-width: 44rem;
}

.help summary { cursor: pointer; font-weight: 650; }
.help p { color: var(--muted); }

.toolbar, .status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
  justify-content: space-between;
}

.status-bar {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 14px;
  padding: 0.55rem 0.75rem;
}

.score {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.92rem;
}

.announce { min-height: 1.4rem; font-weight: 650; }

.sopa-layout, .xw-layout, .lot-layout {
  display: grid;
  gap: 1rem;
  align-items: start;
}

.sopa-layout { grid-template-columns: minmax(18rem, 1.15fr) minmax(16rem, 22rem); }
.xw-layout { grid-template-columns: minmax(16rem, 38rem) minmax(16rem, 1fr); }
.lot-layout { grid-template-columns: minmax(16rem, 22rem) minmax(18rem, 1fr); }

.board-frame {
  background: var(--navy);
  padding: 0.7rem;
  border-radius: 16px;
  border: 2px solid var(--ink);
  box-shadow: var(--shadow);
  width: min(100%, 40rem);
  max-width: 100%;
  overflow-x: auto;
}

.sopa-grid {
  display: grid;
  gap: 3px;
  touch-action: none;
  user-select: none;
  width: max(100%, calc(var(--n, 10) * 2rem));
}

.cell, .xw-cell {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-weight: 600;
}

.cell {
  aspect-ratio: 1;
  border: 0;
  border-radius: 5px;
  background: var(--white);
  display: grid;
  place-items: center;
  padding: 0;
  font-size: clamp(0.68rem, 1.5vw, 1rem);
  line-height: 1;
  touch-action: none;
}

.cell.selecting { background: #fde68a; outline: 2px solid var(--gold); }
.cell.kb { outline: 2px solid var(--teal); }
.cell.hint { background: #fb7185; color: white; }

.word-list, .clue-col, .history, .pool, .sentence, .phase-list {
  display: grid;
  gap: 0.4rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.word-item, .clue, .history li, .chip, .phase {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 12px;
}

.word-item {
  padding: 0.45rem 0.6rem;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.15rem 0.45rem;
}

.word-item strong {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  letter-spacing: 0.04em;
}

.word-item.found strong { text-decoration: line-through; }
.word-item small, .history small, .phase small { color: var(--muted); grid-column: 2; }

.swatch {
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 99px;
  border: 2px solid var(--ink);
  margin-top: 0.2rem;
  background: transparent;
}

.panel {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 0.9rem;
  box-shadow: var(--shadow);
}

.canto-kicker {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--terra);
}

.canto-text {
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(1.35rem, 2.4vw, 1.85rem);
  line-height: 1.25;
  margin: 0.4rem 0 0.8rem;
}

.tabla {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.55rem;
}

.carta {
  position: relative;
  aspect-ratio: 3 / 3.7;
  border: 3px solid var(--ink);
  border-radius: 12px;
  padding: 0.4rem;
  display: flex;
  flex-direction: column;
  text-align: left;
  box-shadow: inset 0 0 0 4px rgba(255, 250, 243, 0.65), 3px 3px 0 var(--ink);
  color: var(--ink);
}

.carta-num {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  font-size: 0.75rem;
  font-weight: 600;
}

.carta-icon { flex: 1; display: grid; place-items: center; min-height: 0; }
.carta-icon svg { width: min(100%, 4.5rem); height: auto; }

.carta-nombre {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: 8px;
  text-align: center;
  font-weight: 700;
  line-height: 1.15;
  padding: 0.28rem 0.2rem;
  font-size: clamp(0.68rem, 1.3vw, 0.92rem);
}

.carta.marked .ficha { display: grid; }
.carta.win { outline: 4px solid var(--gold); outline-offset: 2px; }
.carta.hinting { animation: pulse 0.7s ease-in-out 2; }

.ficha {
  display: none;
  place-items: center;
  position: absolute;
  inset: 16% 10% 22%;
  border: 6px solid rgba(168, 28, 18, 0.9);
  border-radius: 50%;
  background: rgba(196, 50, 31, 0.16);
  color: #8f1d12;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(0.85rem, 1.6vw, 1.2rem);
  transform: rotate(-12deg);
  animation: stamp 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
  pointer-events: none;
}

.history { max-height: 16rem; overflow: auto; margin-top: 0.8rem; }
.history li { padding: 0.4rem 0.6rem; }
.history strong { display: block; }

.xw-board {
  display: grid;
  gap: 0;
  width: min(100%, 38rem);
  background: var(--ink);
  border: 2px solid var(--ink);
  user-select: none;
}

.xw-cell {
  position: relative;
  aspect-ratio: 1;
  border: 0;
  margin: 0;
  padding: 0 0 0.12rem;
  background: var(--white);
  box-shadow: inset -1px -1px 0 #cfc3ae, inset 1px 1px 0 #fff;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: clamp(0.72rem, 1.7vw, 1.05rem);
  text-transform: uppercase;
}

.xw-cell.black { background: var(--ink); box-shadow: none; }
.xw-cell.word { background: #f6e2b8; }
.xw-cell.good { background: #b7e4c7; }
.xw-cell.bad { background: #ffb4a8; }
.xw-cell.revealed { background: #d6e4ff; }
.xw-cell.cursor { outline: 3px solid var(--navy); outline-offset: -3px; z-index: 1; }

.xw-num {
  position: absolute;
  top: 1px;
  left: 2px;
  font-family: Outfit, sans-serif;
  font-size: clamp(0.48rem, 1vw, 0.62rem);
  font-weight: 700;
  line-height: 1;
}

.keycatch {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  border: 0;
  padding: 0;
}

.clue-groups { display: grid; gap: 0.8rem; }
.clue-groups h3 { font-size: 1.05rem; margin-bottom: 0.3rem; }

.clue {
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.55rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.45rem;
  align-items: start;
}

.clue.active { background: #f6e2b8; }
.clue.done { background: #e5f6ee; }
.clue-n { font-family: "IBM Plex Mono", ui-monospace, monospace; font-weight: 600; }
.clue-len { color: var(--muted); font-size: 0.78rem; }

.mode-switch { display: flex; gap: 0.4rem; flex-wrap: wrap; margin: 0.2rem 0 0.6rem; }

.challenge { display: grid; gap: 0.8rem; }

.sentence, .pool, .slots, .phase-list { display: flex; flex-wrap: wrap; gap: 0.45rem; }

.slots { min-height: 3.2rem; }

.slot, .chip, .phase {
  border-radius: 999px;
  padding: 0.45rem 0.7rem;
  font-weight: 650;
  box-shadow: 2px 2px 0 var(--ink);
}

.slot {
  min-width: 2.2rem;
  min-height: 2.6rem;
  display: grid;
  place-items: center;
  background: var(--white);
  border: 2px dashed var(--ink);
  border-radius: 12px;
  font-family: "IBM Plex Mono", ui-monospace, monospace;
}

.slot.filled { border-style: solid; background: #f6e2b8; }

.chip { background: var(--white); }
.chip:disabled { opacity: 0.35; }

.phase {
  width: 100%;
  border-radius: 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.55rem;
  align-items: center;
  text-align: left;
  padding: 0.65rem 0.75rem;
}

.phase .index {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  width: 1.8rem;
  height: 1.8rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--bg);
  border: 2px solid var(--ink);
}

.phase.ok { background: #e5f6ee; }
.phase.bad { background: #ffe0db; }
.phase small { grid-column: 2; }

.mini-actions { display: flex; gap: 0.3rem; }

.win-panel {
  background: var(--white);
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: 5px 5px 0 var(--gold);
}

.win-kicker {
  font-family: "IBM Plex Mono", ui-monospace, monospace;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--terra);
  font-size: 0.78rem;
}

.review { margin: 0.4rem 0 0.7rem; padding-left: 1.1rem; }
.review li { margin: 0.2rem 0; }

.shake { animation: shake 0.35s linear; }

.confetti { pointer-events: none; position: absolute; inset: 0; overflow: hidden; z-index: 3; }
.confetti i {
  position: absolute;
  top: -12px;
  width: 8px;
  height: 14px;
  animation: fall 1.25s ease-in forwards;
}

.loading { color: var(--muted); }

@media (max-width: 860px) {
  .pipeline, .game-grid, .sopa-layout, .xw-layout, .lot-layout { grid-template-columns: 1fr; }
  .pipeline { grid-template-columns: repeat(2, 1fr); }
  .game-card { grid-template-columns: 5.5rem 1fr; }
  .board-frame, .xw-board { width: 100%; max-width: 40rem; }
}

@media (max-width: 560px) {
  .pipeline { grid-template-columns: 1fr 1fr; }
  .carta { aspect-ratio: 3 / 4.1; }
  .phase { grid-template-columns: auto 1fr; }
  .mini-actions { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}

@keyframes shake {
  20% { transform: translateX(-5px); }
  40% { transform: translateX(5px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}

@keyframes stamp {
  from { transform: scale(1.5) rotate(-24deg); opacity: 0; }
  to { transform: scale(1) rotate(-12deg); opacity: 1; }
}

@keyframes fall {
  to { transform: translateY(26rem) rotate(180deg); opacity: 0.15; }
}

@keyframes pulse {
  50% { filter: brightness(1.25); transform: scale(1.04); }
}
