/* ==========================================================
   NÚCLEO — estilos
   Minimalista, alto contraste, 100 % responsivo
   ========================================================== */

:root {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #b8b8b8;
  --dim: #6e6e6e;
  --line: #8c8c8c;
  --panel: #0b0b0b;
  --border: #353535;
  --accent: #ffd60a;
  --ok: #2bff88;
  --bad: #ff5a5a;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #3d3d3d;
  --dim: #9a9a9a;
  --line: #4d4d4d;
  --panel: #f5f5f5;
  --border: #c9c9c9;
  --accent: #0040ff;
  --ok: #00824a;
  --bad: #c80000;
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Cabecera ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 16px 8px;
}

.brand h1 {
  margin: 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 900;
  letter-spacing: 0.18em;
  line-height: 1;
}

.tag {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border: 2px solid var(--fg);
  border-radius: 50%;
  background: transparent;
  font-size: 1.2rem;
  cursor: pointer;
}

.icon-btn:hover {
  background: var(--fg);
  color: var(--bg);
}

.top-actions {
  display: flex;
  gap: 8px;
}

.icon-btn#btn-help {
  font-weight: 900;
}

/* ---------- Pantalla de inicio ---------- */
.intro {
  max-width: 1000px;
  margin: 0 auto;
  padding: 8px 16px 0;
}

.intro-hero h2 {
  margin: 8px 0 8px;
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.intro-lead {
  margin: 0 0 16px;
  max-width: 70ch;
  font-size: 1rem;
}

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

.intro-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
}

.intro-card h3,
.intro-levels h3 {
  margin: 0 0 10px;
  font-size: 0.9rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.small {
  font-size: 0.88rem;
  margin: 0 0 8px;
}

.intro-svg {
  display: block;
  width: 100%;
  max-width: 340px;
  height: auto;
  margin: 0 auto 8px;
}

.intro-svg text {
  font-family: var(--font);
}

.ill-shape {
  fill: var(--fg);
  stroke: var(--fg);
  stroke-width: 2.5;
}

.ill-val {
  fill: var(--bg);
  font-size: 24px;
  font-weight: 900;
}

.ill-tgt {
  fill: var(--bg);
  font-size: 12px;
  font-weight: 800;
}

.ill-pip {
  fill: var(--fg);
  stroke: var(--fg);
  stroke-width: 1.2;
}

.ill-pip.used {
  fill: var(--bg);
  stroke: var(--dim);
}

.ill-badge {
  fill: var(--accent);
}

.ill-badge-t {
  fill: var(--bg);
  font-size: 13px;
  font-weight: 900;
}

.ill-id {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.ill-notes text {
  fill: var(--fg);
  font-size: 12.5px;
  font-weight: 600;
}

.steps {
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: step;
}

.steps li {
  position: relative;
  padding-left: 34px;
  margin-bottom: 10px;
  font-size: 0.9rem;
  counter-increment: step;
}

.steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -1px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--fg);
  color: var(--bg);
  font-weight: 900;
  font-size: 0.8rem;
  display: grid;
  place-items: center;
}

.chip {
  display: inline-block;
  padding: 0 7px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--bg);
  font-weight: 900;
  font-size: 0.8rem;
}

.tools {
  margin: 0 0 8px;
}

.tools dt {
  font-weight: 900;
}

.tools dd {
  margin: 0 0 8px;
  font-size: 0.88rem;
  color: var(--muted);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0 5px;
  border: 1px solid var(--fg);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.8rem;
  text-align: center;
}

.intro-levels {
  margin-top: 16px;
}

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

.level-cards button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-content: start;
  min-height: 96px;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.level-cards button:hover {
  border-color: var(--fg);
}

.level-cards button[aria-checked="true"] {
  border-color: var(--fg);
  background: var(--fg);
  color: var(--bg);
}

.lc-name {
  font-weight: 900;
  font-size: 1rem;
}

.lc-field {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.8rem;
}

.lc-desc {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  opacity: 0.85;
}

.intro-cta {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 0 calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 2px solid var(--border);
}

.intro-cta .small {
  margin: 0;
  color: var(--muted);
}

.play-btn {
  min-width: 180px;
  min-height: 52px;
  font-size: 1.1rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (max-width: 520px) {
  .intro {
    padding: 4px 10px 0;
  }

  .intro-cta {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  .play-btn {
    width: 100%;
  }
}

/* ---------- Distribución ---------- */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px 16px;
}

@media (min-width: 980px) {
  .layout {
    grid-template-columns: minmax(0, 1fr) 350px;
    align-items: start;
  }

  .side {
    position: sticky;
    top: 12px;
    max-height: calc(100vh - 24px);
    overflow-y: auto;
  }
}

.play {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

/* ---------- Selector de niveles ---------- */
.levels {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.levels button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 6px 4px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: transparent;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}

.levels button small {
  display: block;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--muted);
}

.levels button:hover {
  border-color: var(--fg);
}

.levels button[aria-selected="true"] {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.levels button[aria-selected="true"] small {
  color: var(--bg);
}

/* ---------- Estadísticas ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 0;
}

.stat .k {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}

.stat .v {
  font-family: var(--mono);
  font-weight: 800;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Tablero ---------- */
.board-wrap {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 4px;
}

#board {
  display: block;
  width: 100%;
  height: auto;
  max-height: 72vh;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#board text {
  font-family: var(--font);
  pointer-events: none;
}

.edge {
  stroke: var(--line);
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
}

.edge.hot {
  stroke: var(--accent);
  stroke-width: 3.5;
}

.arrow-head {
  fill: var(--line);
}

.arrow-head.hot {
  fill: var(--accent);
}

.wlabel circle {
  fill: var(--bg);
  stroke: var(--line);
  stroke-width: 1.5;
}

.wlabel text {
  fill: var(--fg);
  font-size: 12px;
  font-weight: 800;
}

.wlabel.hot circle {
  stroke: var(--accent);
  stroke-width: 2;
}

.wlabel.hot text {
  fill: var(--accent);
}

.node {
  cursor: pointer;
  outline: none;
}

.node.anchor {
  cursor: help;
}

.node .shape {
  fill: var(--fg);
  stroke: var(--fg);
  stroke-width: 2.5;
  transition: fill 0.12s ease, stroke 0.12s ease;
}

.node .val {
  fill: var(--bg);
  font-size: 24px;
  font-weight: 900;
}

.node .tgt {
  fill: var(--bg);
  opacity: 0.8;
  font-size: 12px;
  font-weight: 800;
}

.node.ok .shape {
  fill: var(--bg);
  stroke: var(--ok);
  stroke-width: 3.5;
}

.node.ok .val,
.node.ok .tgt {
  fill: var(--ok);
  opacity: 1;
}

.node .ring {
  fill: none;
  stroke: transparent;
  stroke-width: 3;
}

.node.selected .ring {
  stroke: var(--accent);
  stroke-width: 4;
}

.node.hinted .ring {
  stroke: var(--ok);
  stroke-dasharray: 6 5;
}

.node.selected.hinted .ring {
  stroke: var(--accent);
  stroke-dasharray: none;
}

.node:focus-visible .ring {
  stroke: var(--accent);
  stroke-dasharray: 3 4;
}

.node .nid {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.pip {
  fill: var(--fg);
  stroke: var(--fg);
  stroke-width: 1.2;
}

.pip.used {
  fill: var(--bg);
  stroke: var(--dim);
}

.badge rect {
  fill: var(--accent);
}

.badge text {
  fill: var(--bg);
  font-size: 13px;
  font-weight: 900;
}

.badge.src rect {
  fill: var(--bg);
  stroke: var(--accent);
  stroke-width: 2;
}

.badge.src text {
  fill: var(--accent);
}

/* ---------- Leyenda ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.78rem;
  color: var(--muted);
}

.legend li {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.lg {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
}

.lg-off {
  background: var(--fg);
  border: 2px solid var(--fg);
}

.lg-ok {
  background: var(--bg);
  border: 2px solid var(--ok);
}

.lg-anchor {
  border-radius: 3px;
  background: var(--fg);
}

.lg-pip {
  width: 8px;
  height: 8px;
  background: var(--fg);
}

.selection-info {
  margin: 0;
  min-height: 1.45em;
  font-size: 0.9rem;
  color: var(--fg);
}

.selection-info b {
  color: var(--accent);
}

/* ---------- Botones ---------- */
.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  gap: 8px;
}

.btn {
  min-height: 44px;
  padding: 8px 12px;
  border: 2px solid var(--fg);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font-weight: 800;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.btn:hover:not(:disabled) {
  background: var(--fg);
  color: var(--bg);
}

.btn.primary {
  background: var(--fg);
  color: var(--bg);
}

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--bg);
}

.btn.danger {
  border-color: var(--bad);
  color: var(--bad);
}

.btn.danger:hover:not(:disabled) {
  background: var(--bad);
  color: var(--bg);
}

.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ---------- Mensajes ---------- */
.message {
  margin: 0;
  min-height: 3em;
  padding: 10px 12px;
  border-left: 4px solid var(--border);
  background: var(--panel);
  border-radius: 0 8px 8px 0;
  font-size: 0.92rem;
}

.message:empty {
  visibility: hidden;
}

.message.ok {
  border-left-color: var(--ok);
}

.message.bad {
  border-left-color: var(--bad);
}

.message.info {
  border-left-color: var(--accent);
}

/* ---------- Panel lateral ---------- */
.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px 14px;
}

.card h2,
.card summary {
  margin: 0 0 10px;
  font-size: 0.95rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card summary {
  margin: 0;
  cursor: pointer;
  list-style: none;
}

.card summary::-webkit-details-marker {
  display: none;
}

.card summary::before {
  content: "+ ";
  font-family: var(--mono);
}

.card[open] summary::before {
  content: "− ";
}

.card[open] summary {
  margin-bottom: 10px;
}

.card h3 {
  margin: 14px 0 6px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.seed-form {
  display: flex;
  gap: 8px;
}

.seed-form input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid var(--fg);
  border-radius: 8px;
  background: var(--bg);
  font-family: var(--mono);
  font-weight: 700;
}

.seed-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.86rem;
  cursor: pointer;
}

.check input {
  width: 20px;
  height: 20px;
  margin: 1px 0 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.rules {
  font-size: 0.88rem;
}

.rules p {
  margin: 0 0 8px;
}

.rules ul {
  margin: 0 0 8px;
  padding-left: 1.1em;
}

.rules li {
  margin-bottom: 4px;
}

.rules .tip {
  border-left: 3px solid var(--accent);
  padding-left: 8px;
  color: var(--muted);
}

.rules code,
.mono {
  font-family: var(--mono);
}

.table-wrap {
  overflow-x: auto;
}

.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.records th,
.records td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.records th {
  color: var(--muted);
  font-weight: 700;
}

.records td {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.records td:first-child {
  font-family: var(--font);
  font-weight: 800;
}

.recent {
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.recent button {
  width: 100%;
  min-height: 40px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-family: var(--mono);
  font-size: 0.8rem;
  cursor: pointer;
}

.recent button:hover {
  border-color: var(--fg);
}

.recent .empty {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ---------- Modal de victoria ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.82);
}

.modal {
  width: 100%;
  max-width: 440px;
  padding: 20px;
  border: 2px solid var(--fg);
  border-radius: var(--radius);
  background: var(--bg);
}

.modal h2 {
  margin: 0 0 12px;
  font-size: 1.3rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.modal dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0 0 12px;
}

.modal dt {
  color: var(--muted);
}

.modal dd {
  margin: 0;
  font-family: var(--mono);
  font-weight: 800;
  text-align: right;
}

.modal .verdict {
  margin: 0 0 14px;
  padding: 8px 10px;
  border-left: 4px solid var(--ok);
  background: var(--panel);
  font-size: 0.9rem;
}

.modal .verdict.subopt {
  border-left-color: var(--accent);
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* ---------- Pie ---------- */
.foot {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  color: var(--muted);
  font-size: 0.78rem;
}

.noscript {
  padding: 16px;
  text-align: center;
  font-weight: 800;
}

/* ---------- Pantallas pequeñas ---------- */
@media (max-width: 520px) {
  .top {
    padding: 12px 12px 4px;
  }

  .layout {
    padding: 6px 10px 12px;
    gap: 12px;
  }

  .levels button {
    font-size: 0.78rem;
    min-height: 48px;
  }

  .stat .k {
    font-size: 0.6rem;
    letter-spacing: 0.02em;
  }

  .stat .v {
    font-size: 0.92rem;
  }

  .actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .actions #btn-activate {
    grid-column: 1 / -1;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
}
