:root {
  --bg: #f4efe4;
  --sheet: #fbf8f1;
  --ink: #1b1a17;
  --muted: #6b6457;
  --rule: #d6cdbb;
  --accent: #b3261e;
  --def: #b3261e;
  --ind: #1f4fa3;
  --ind-bg: rgba(31, 79, 163, .07);
  --mat: #2e7d4f;
  --mat-bg: rgba(46, 125, 79, .10);
  --cell: #ffffff;
  --serif: "Libre Caslon Text", Georgia, serif;
  --sans: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12110f;
    --sheet: #1b1a17;
    --ink: #ece6d8;
    --muted: #9a9283;
    --rule: #38352f;
    --accent: #ef6b5f;
    --def: #ef6b5f;
    --ind: #86a9ec;
    --ind-bg: rgba(134, 169, 236, .10);
    --mat: #6cc28f;
    --mat-bg: rgba(108, 194, 143, .12);
    --cell: #23221e;
  }
}
:root[data-theme="dark"] {
  --bg: #12110f;
  --sheet: #1b1a17;
  --ink: #ece6d8;
  --muted: #9a9283;
  --rule: #38352f;
  --accent: #ef6b5f;
  --def: #ef6b5f;
  --ind: #86a9ec;
  --ind-bg: rgba(134, 169, 236, .10);
  --mat: #6cc28f;
  --mat-bg: rgba(108, 194, 143, .12);
  --cell: #23221e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
}
button { font: inherit; color: inherit; cursor: pointer; }

/* --- Cabecera tipo periódico --- */
.masthead {
  max-width: 760px; margin: 0 auto; padding: 20px 16px 0;
  border-bottom: 3px double var(--ink);
}
.masthead-row {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 12px;
}
.edition { font: 12px var(--mono); color: var(--muted); }
.brand {
  margin: 0; font: 700 clamp(34px, 7vw, 48px)/1 var(--serif); letter-spacing: -.01em;
}
.tools { justify-self: end; display: flex; gap: 6px; }
.tool {
  background: none; border: 1px solid var(--rule); padding: 4px 10px;
  font-size: 13px; border-radius: 2px;
}
.tool:hover { border-color: var(--ink); }
.tagline {
  text-align: center; margin: 6px 0 10px;
  font: italic 14px var(--serif); color: var(--muted);
}

.page { max-width: 760px; margin: 0 auto; padding: 24px 16px 48px; }

/* --- Ficha del críptico --- */
.sheet {
  background: var(--sheet); border: 1px solid var(--rule);
  padding: 22px clamp(16px, 4vw, 36px) 28px;
}
.facts {
  display: flex; gap: 28px; flex-wrap: wrap; margin: 0 0 18px;
  padding-bottom: 12px; border-bottom: 1px solid var(--rule);
}
.facts dt { font: 11px var(--mono); text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; font-size: 15px; }
#meta-tipo { color: var(--muted); font-style: italic; font-weight: 400; }
#meta-tipo.revealed { color: var(--mat); font-style: normal; font-weight: 600; }
.bars { font-family: var(--mono); letter-spacing: 1px; }

/* --- Enunciado --- */
.clue {
  font: 400 clamp(24px, 4.6vw, 32px)/1.6 var(--serif);
  margin: 4px 0 26px;
}
.clue .enum { font: 16px var(--mono); color: var(--muted); margin-left: 8px; white-space: nowrap; }
.clue .seg { transition: background .2s, outline-color .2s, text-decoration-color .2s; }

/* Cada pista activa una clase en el contenedor del enunciado. */
.show-definicion .seg[data-rol="definicion"],
.show-all .seg[data-rol="definicion"],
.s-def {
  text-decoration: underline solid var(--def);
  text-decoration-thickness: 2px; text-underline-offset: 6px;
}
.show-indicador .seg[data-rol="indicador"],
.show-all .seg[data-rol="indicador"],
.s-ind {
  outline: 1.5px solid var(--ind); outline-offset: 1px;
  background: var(--ind-bg); border-radius: 2px;
}
.show-material .seg[data-rol="material"],
.show-all .seg[data-rol="material"],
.s-mat {
  background: var(--mat-bg);
  text-decoration: underline dotted var(--mat);
  text-decoration-thickness: 2.5px; text-underline-offset: 6px;
}

/* --- Casillas estilo crucigrama --- */
.grid { display: flex; flex-wrap: wrap; gap: 14px 0; cursor: text; }
.grid .gap { width: 16px; }
.cell {
  width: 54px; height: 54px; margin-left: -2px;
  display: grid; place-items: center; position: relative;
  font: 600 24px var(--serif); text-transform: uppercase;
  background: var(--cell); border: 2px solid var(--ink);
}
.grid .cell:first-child, .grid .gap + .cell { margin-left: 0; }
.cell.active { box-shadow: inset 0 0 0 3px var(--accent); }
.grid.ok .cell { background: var(--ink); color: var(--sheet); }
.grid.revealed .cell {
  color: var(--muted);
  background: repeating-linear-gradient(-45deg, var(--cell) 0 6px, var(--rule) 6px 7px);
}
.grid.shake { animation: shake .4s; }
@keyframes shake {
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
@media (max-width: 420px) {
  .cell { width: 44px; height: 44px; font-size: 20px; }
}

/* Input real, invisible: recoge el teclado (también en móvil). */
.answer-input { position: absolute; opacity: 0; pointer-events: none; width: 1px; height: 1px; }
.feedback { min-height: 24px; margin: 10px 0 6px; font-size: 14px; color: var(--muted); }
.feedback.bad { color: var(--accent); }

/* --- Botones --- */
.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.btn { border-radius: 2px; padding: 10px 20px; font-weight: 600; border: 2px solid var(--ink); background: none; }
.btn-ink { background: var(--ink); color: var(--sheet); }
.btn-ink:hover { background: var(--accent); border-color: var(--accent); }
.btn-line:hover { background: var(--bg); }
.btn-small { padding: 4px 10px; font-size: 13px; font-weight: 500; border-width: 1px; border-color: var(--rule); }
.btn-small:hover:not(:disabled) { border-color: var(--ink); }
.btn:disabled { opacity: .4; cursor: default; }

/* --- Pistas --- */
.hintbox { margin-top: 30px; border-top: 1px solid var(--rule); padding-top: 16px; }
.hintbox h2 { font: 600 15px var(--sans); margin: 0 0 12px; }
.hintbox h2 span { font-weight: 400; color: var(--muted); font-size: 13px; }
.hint-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hint {
  text-align: left; background: none; border: 1px solid var(--rule); border-radius: 2px;
  padding: 10px 12px; display: grid; gap: 2px;
}
.hint:hover:not(:disabled) { border-color: var(--ink); }
.hint-sample { justify-self: start; font: 15px var(--serif); margin-bottom: 4px; }
.hint-name { font-weight: 600; font-size: 14px; }
.hint-desc { font-size: 12.5px; color: var(--muted); line-height: 1.35; }
.hint.used { background: var(--bg); }
.hint.used .hint-name::after { content: " ✓"; color: var(--muted); }
.hint:disabled { cursor: default; }
@media (max-width: 560px) { .hint-list { grid-template-columns: 1fr; } }

/* --- Solución --- */
.solution { margin-top: 30px; border-top: 3px double var(--ink); padding-top: 22px; position: relative; }
.stamp {
  position: absolute; right: 0; top: 18px; transform: rotate(-7deg);
  border: 2.5px solid var(--accent); color: var(--accent); padding: 3px 10px;
  font: 600 13px var(--mono); letter-spacing: .14em; text-transform: uppercase;
}
.stamp.revealed { border-color: var(--muted); color: var(--muted); }
.solution-word { margin: 0; font: 700 34px var(--serif); letter-spacing: .06em; }
.solution-sub { margin: 2px 0 18px; font-size: 14px; color: var(--muted); }
.rule-title {
  font: 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; color: var(--muted);
  margin: 0 0 6px;
}
.clue-sm { font-size: 21px; margin: 0 0 16px; }
.breakdown { margin: 0; display: grid; gap: 6px; }
.breakdown div { display: grid; grid-template-columns: 130px 1fr; gap: 10px; align-items: baseline; }
.breakdown dt { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.breakdown dd { margin: 0; font: 16px var(--serif); }
.key { width: 14px; height: 10px; display: inline-block; flex: none; }
.k-def { border-bottom: 2px solid var(--def); }
.k-ind { border: 1.5px solid var(--ind); background: var(--ind-bg); }
.k-mat { border-bottom: 2.5px dotted var(--mat); background: var(--mat-bg); }
.explain-text { margin: 18px 0 0; padding: 12px 14px; background: var(--bg); border-left: 3px solid var(--ink); }

/* --- Depuración --- */
.debug {
  margin-top: 18px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  font-size: 13px; color: var(--muted);
}
.debug-label { font: 11px var(--mono); text-transform: uppercase; letter-spacing: .1em; margin-right: 4px; }
.pager { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; }

/* --- Guía (panel lateral) --- */
.drawer {
  margin: 0 0 0 auto; height: 100vh; max-height: 100vh;
  width: min(520px, 100vw); padding: 0;
  background: var(--sheet); color: var(--ink);
  border: none; border-left: 3px double var(--ink);
}
.drawer::backdrop { background: rgba(0, 0, 0, .45); }
.drawer-head {
  position: sticky; top: 0; z-index: 1; background: var(--sheet);
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--rule);
}
.drawer-head h2 { margin: 0; font: 700 22px var(--serif); }
.drawer-head form { margin: 0; }
.drawer-sec { padding: 4px 20px 12px; }
.drawer-sec h3 { font: 700 17px var(--serif); margin: 14px 0 8px; }
.anatomy { padding-left: 18px; }
.anatomy li { margin-bottom: 6px; }
.muted { color: var(--muted); font-size: 14px; }

.type { border-bottom: 1px solid var(--rule); }
.type summary {
  cursor: pointer; padding: 10px 0; display: flex; justify-content: space-between; gap: 10px;
  font-weight: 600; list-style: none;
}
.type summary::-webkit-details-marker { display: none; }
.type summary::before { content: "+"; font-family: var(--mono); color: var(--muted); width: 14px; }
.type[open] summary::before { content: "−"; }
.type summary .name { flex: 1; }
.type summary .count { font: 12px var(--mono); color: var(--muted); font-weight: 400; }
.type .body { padding: 0 0 14px 24px; font-size: 14px; }
.type .body p { margin: 0 0 6px; }
.type .example { font: 13px var(--mono); color: var(--muted); margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font: 13px var(--serif); padding: 1px 8px; border-radius: 2px;
  outline: 1px solid var(--ind); background: var(--ind-bg);
}
.abbr { width: 100%; border-collapse: collapse; font-size: 14px; }
.abbr td { padding: 6px 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.abbr td:last-child { font-family: var(--mono); font-size: 13px; padding-left: 12px; }
