:root {
  --celeste: #6cace4;
  --celeste-soft: #dcebf8;
  --celeste-dark: #2b6aa3;
  --sol: #f6b40e;
  --sol-soft: #fdeab8;
  --ink: #1b2433;
  --muted: #667085;
  --bg: #f3f7fb;
  --card: #fff;
  --line: #d5dde8;
  --wrong: #d64545;
  --ok: #2f9e5b;
  --surface: #fff;          /* celdas, botones, inputs */
  --accent: #2b6aa3;        /* texto en celeste */
  --header-top: #6cace4;
  --cell-border: #9aa8bb;
  --solved: #e7f6ec;
  --wrong-line: #d6454566;
  --radius: 12px;
  --cell: min(40px, calc((100vw - 28px) / var(--cols, 10)));
  color-scheme: light;
}

:root[data-theme="dark"] {
  --celeste-soft: #1e3550;
  --celeste-dark: #3d82c4;
  --sol-soft: #4d3b0e;
  --ink: #e6edf6;
  --muted: #93a1b5;
  --bg: #0e141e;
  --card: #161f2d;
  --line: #2a384c;
  --wrong: #ff6b6b;
  --ok: #5fd08f;
  --surface: #1c2738;
  --accent: #8cc3f0;
  --header-top: #2a5a87;
  --cell-border: #4a5b74;
  --solved: #16362a;
  --wrong-line: #ff6b6b88;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }

.top {
  background: linear-gradient(180deg, var(--header-top) 0 60%, var(--card) 60% 100%);
  padding: 14px 14px 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 1px 0 var(--celeste-dark);
}
.brand .sub { margin: 4px 0 0; font-size: 0.8rem; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle {
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface); font-size: 1.05rem; line-height: 1; padding: 0;
}
.tabs { display: flex; gap: 4px; background: var(--celeste-soft); padding: 3px; border-radius: 999px; }
.tabs button {
  border: 0; background: none; padding: 6px 14px; border-radius: 999px; font-weight: 600; color: var(--accent);
}
.tabs button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px #0002; }

main { width: 100%; max-width: 760px; margin: 0 auto; padding: 14px; flex: 1; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 { margin: 0 0 6px; font-size: 1.15rem; }
.narrow { max-width: 380px; margin: 24px auto; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--wrong); font-size: 0.9rem; margin: 0; }

form { display: grid; gap: 12px; margin-top: 12px; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
label input {
  font: inherit; font-weight: 400; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
label input, .name-input {
  font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
label input:focus, .name-input:focus { outline: 2px solid var(--celeste); border-color: transparent; }

.primary {
  background: var(--celeste-dark); color: #fff; border: 0; border-radius: 10px; padding: 11px 18px; font-weight: 700;
}
.primary:hover { filter: brightness(1.08); }
.primary.big { font-size: 1.15rem; padding: 14px 32px; }
.ghost {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; font-weight: 600;
}
.ghost small { color: var(--muted); font-weight: 400; }
.ghost:disabled { opacity: 0.5; cursor: default; }
.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 0; }

/* Barra de estado */
.statusbar { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.spacer { flex: 1; }

/* Grilla */
.board-wrap { position: relative; display: flex; justify-content: center; }
.grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-auto-rows: var(--cell);
  gap: 0;
  user-select: none;
}
.cell { position: relative; }
.cell.white {
  background: var(--surface);
  border: 1px solid var(--cell-border);
  margin: 0 -1px -1px 0;
}
.cell .num {
  position: absolute; top: 1px; left: 2px;
  font-size: calc(var(--cell) * 0.27); line-height: 1; color: var(--muted); pointer-events: none; z-index: 1;
}
.cell input {
  width: 100%; height: 100%;
  border: 0; padding: 0; margin: 0;
  background: transparent;
  text-align: center;
  font: 700 calc(var(--cell) * 0.55) / 1 ui-sans-serif, system-ui, sans-serif;
  text-transform: uppercase;
  color: var(--ink);
  caret-color: transparent;
  border-radius: 0;
}
.cell input:focus { outline: none; }
.cell.in-word { background: var(--celeste-soft); }
.cell.active { background: var(--sol-soft); box-shadow: inset 0 0 0 2px var(--sol); }
.cell.wrong input { color: var(--wrong); }
.cell.wrong::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(to top right, transparent calc(50% - 1px), var(--wrong-line) 50%, transparent calc(50% + 1px));
}
.grid.solved .cell.white { background: var(--solved); }
.grid.solved input { color: var(--ok); }

.clue-bar {
  margin: 12px auto 0;
  max-width: 560px;
  background: var(--celeste-soft);
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  min-height: 2.8em;
  display: flex; align-items: center;
}
.clue-bar b { color: var(--accent); margin-right: 8px; white-space: nowrap; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  margin: 0; padding: 10px 16px; border-radius: 999px; max-width: calc(100vw - 32px);
  background: var(--ink); color: var(--bg); font-weight: 600; text-align: center;
  box-shadow: 0 4px 16px #0004;
}

/* Sopa de letras */
.center { text-align: center; }
.sopa-count { font-weight: 700; }
.sopa-count small { color: var(--muted); font-weight: 400; }
.sopa-wrap { position: relative; }
.sopa-grid {
  --sopa-cell: min(38px, calc((100vw - 36px) / var(--sopa-size, 12)));
  display: grid;
  grid-template-columns: repeat(var(--sopa-size, 12), var(--sopa-cell));
  grid-auto-rows: var(--sopa-cell);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.sopa-cell {
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: calc(var(--sopa-cell) * 0.5);
  border-radius: 50%;
  cursor: pointer;
  position: relative; z-index: 1;
}
.sopa-cell.sel { background: var(--sol); color: #1b2433; }
.sopa-cell.anchor { box-shadow: inset 0 0 0 2px var(--sol); }
.sopa-marks { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 2; overflow: visible; }
.sopa-marks rect { fill: hsl(var(--hue) 80% 55% / 0.14); stroke: hsl(var(--hue) 75% 50%); stroke-width: 2.5; }
:root[data-theme="dark"] .sopa-marks rect { stroke: hsl(var(--hue) 80% 65%); }
.hint-bar {
  margin: 0 auto 12px; max-width: 560px;
  background: var(--sol-soft); border-radius: 10px; padding: 10px 14px; font-weight: 600;
}
.hint-bar small { color: var(--muted); font-weight: 400; margin-left: 6px; }
.sopa-words {
  list-style: none; padding: 0; margin: 12px auto 0; max-width: 560px;
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
}
.sopa-words li {
  padding: 5px 12px; border-radius: 999px; font-weight: 600; letter-spacing: 0.04em;
  border: 2px solid hsl(var(--hue) 75% 50%); background: hsl(var(--hue) 80% 55% / 0.14);
}

.clues { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
@media (max-width: 560px) { .clues { grid-template-columns: 1fr; } }
.clues h3 { margin: 0 0 6px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.clues ol { list-style: none; margin: 0; padding: 0; }
.clues li {
  display: flex; gap: 8px; padding: 6px 8px; border-radius: 8px; cursor: pointer; line-height: 1.3;
}
.clues li b { min-width: 1.6em; text-align: right; color: var(--accent); }
.clues li .len { color: var(--muted); font-size: 0.85em; white-space: nowrap; }
.clues li:hover { background: var(--surface); }
.clues li.current { background: var(--celeste-soft); }
.clues li.done { color: var(--muted); }
.clues li.done span:first-of-type { text-decoration: line-through; text-decoration-color: var(--muted); }

/* Resultado */
.result { text-align: center; margin-top: 14px; }
.result .actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }

/* Tablas */
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; margin-top: 8px; }
.table th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.table th, .table td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.me td { background: var(--sol-soft); }
.table .empty { text-align: center; color: var(--muted); padding: 18px; }

footer {
  text-align: center; padding: 16px; color: var(--muted); font-size: 0.85rem; display: flex; gap: 10px; justify-content: center;
}

.result .tomorrow {
  margin: 14px auto 0; padding: 8px 14px; width: fit-content;
  background: var(--celeste-soft); color: var(--accent); border-radius: 999px; font-weight: 700;
}
