:root {
  --bg: #F7F5EF;
  --surface: #FFFFFF;
  --tile: #EDEBE3;
  --tile-hover: #E4E1D7;
  --ink: #17181C;
  --ink-2: #4A4C55;
  --muted: #7A7D88;
  --line: #DDDAD0;
  --brand: #17181C;
  --brand-ink: #F7F5EF;
  --g1: #F3D24B; --g1-ink: #3A3000;
  --g2: #8FCB74; --g2-ink: #10300A;
  --g3: #86B7EA; --g3-ink: #0B2748;
  --g4: #BC93E4; --g4-ink: #2E0F4E;
  --danger: #B3261E;
  --shadow: 0 1px 2px rgba(23,24,28,.06), 0 10px 30px -18px rgba(23,24,28,.3);
  --radius: 10px;
  --f: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --f-num: "Segoe UI", ui-monospace, "Cascadia Mono", Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131417; --surface: #1B1C21; --tile: #26282F; --tile-hover: #2F323A;
    --ink: #EEEDE8; --ink-2: #C2C3CB; --muted: #8B8E9A; --line: #2E3038;
    --brand: #EEEDE8; --brand-ink: #131417;
    --g1: #D9B93A; --g1-ink: #1F1900; --g2: #7DB865; --g2-ink: #0A1F06;
    --g3: #6FA3DA; --g3-ink: #061A33; --g4: #A87FD3; --g4-ink: #1E0A36;
    --danger: #F28B82;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -18px rgba(0,0,0,.8);
  }
}
:root[data-theme="dark"] {
  --bg: #131417; --surface: #1B1C21; --tile: #26282F; --tile-hover: #2F323A;
  --ink: #EEEDE8; --ink-2: #C2C3CB; --muted: #8B8E9A; --line: #2E3038;
  --brand: #EEEDE8; --brand-ink: #131417;
  --g1: #D9B93A; --g1-ink: #1F1900; --g2: #7DB865; --g2-ink: #0A1F06;
  --g3: #6FA3DA; --g3-ink: #061A33; --g4: #A87FD3; --g4-ink: #1E0A36;
  --danger: #F28B82;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px -18px rgba(0,0,0,.8);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--f); font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; padding: 0 16px 80px;
}
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, a:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 6px; }
.wrap { max-width: 560px; margin: 0 auto; }
.prose { max-width: 62ch; }

/* ---------- cabecera ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand .mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand);
  display: grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 5px;
}
.brand .mark i { display: block; border-radius: 2px; }
.brand .mark i:nth-child(1) { background: var(--g1); }
.brand .mark i:nth-child(2) { background: var(--g2); }
.brand .mark i:nth-child(3) { background: var(--g3); }
.brand .mark i:nth-child(4) { background: var(--g4); }
.brand b { font-weight: 800; letter-spacing: -.02em; font-size: 1.05rem; }
.brand small { display: block; color: var(--muted); font-size: .72rem; font-weight: 500; letter-spacing: .02em; margin-top: -2px; }
.icons { display: flex; gap: 4px; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: grid; place-items: center; color: var(--ink-2);
}
.iconbtn:hover { background: var(--tile); color: var(--ink); }
.iconbtn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- título de partida ---------- */
.gamehead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.gamehead h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -.03em; line-height: 1.1; margin: 0; }
.gamehead .n { color: var(--muted); font-weight: 600; font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.hint { color: var(--ink-2); font-size: .95rem; margin: 0 0 14px; }

/* ---------- tablero ---------- */
.board { display: flex; flex-direction: column; gap: 8px; }
.solved {
  border-radius: var(--radius); padding: 14px 12px; text-align: center;
  display: flex; flex-direction: column; gap: 2px; min-height: 72px; justify-content: center;
  animation: pop .35s cubic-bezier(.2,.8,.2,1);
}
.solved.l1 { background: var(--g1); color: var(--g1-ink); }
.solved.l2 { background: var(--g2); color: var(--g2-ink); }
.solved.l3 { background: var(--g3); color: var(--g3-ink); }
.solved.l4 { background: var(--g4); color: var(--g4-ink); }
.solved b { font-weight: 800; letter-spacing: .01em; font-size: 1rem; text-transform: uppercase; }
.solved span { font-size: .95rem; font-weight: 500; }
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.tile {
  border: 0; border-radius: var(--radius); background: var(--tile); color: var(--ink);
  min-height: 72px; padding: 6px 4px; font-weight: 800; font-size: .95rem; letter-spacing: -.01em;
  text-transform: uppercase; line-height: 1.1; white-space: nowrap; overflow: hidden;
  transition: transform .12s ease, background .15s ease, color .15s ease;
  user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent;
}
.tile:hover { background: var(--tile-hover); }
.tile:active { transform: scale(.96); }
.tile[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); transform: scale(.98); }
.tile.long { font-size: .8rem; }
.tile.xlong { font-size: .68rem; letter-spacing: -.02em; }
.tile.shake { animation: shake .4s ease; }
.tile.bump { animation: bump .28s ease; }
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-5px)} 40%{transform:translateX(5px)} 60%{transform:translateX(-4px)} 80%{transform:translateX(4px)} }
@keyframes bump { 0%{transform:translateY(0)} 40%{transform:translateY(-6px)} 100%{transform:translateY(0)} }
@keyframes pop { 0%{transform:scale(.94);opacity:.4} 100%{transform:scale(1);opacity:1} }
@media (max-width: 380px) {
  .tile { min-height: 64px; font-size: .84rem; }
  .tile.long { font-size: .72rem; } .tile.xlong { font-size: .62rem; }
}

/* ---------- intentos + acciones ---------- */
.lives { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 18px 0 14px; color: var(--ink-2); font-size: .95rem; }
.lives .dots { display: flex; gap: 7px; }
.lives .dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); display: block; transition: transform .25s ease, opacity .25s ease; }
.lives .dots i.off { transform: scale(.4); opacity: .18; }
.actions { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.btn {
  border-radius: 999px; padding: 12px 20px; font-weight: 700; font-size: .95rem;
  border: 1.5px solid var(--ink); background: transparent; color: var(--ink);
  transition: background .15s ease, color .15s ease, opacity .15s ease;
}
.btn:hover:not(:disabled) { background: var(--tile); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover:not(:disabled) { opacity: .9; }
.btn:disabled { opacity: .35; cursor: default; border-color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; top: 18px; transform: translateX(-50%) translateY(-10px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-weight: 700; font-size: .95rem; opacity: 0; pointer-events: none; transition: all .2s ease; z-index: 50;
  box-shadow: var(--shadow); max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- modales ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 40; }
.modal.open { display: flex; }
.card {
  background: var(--surface); color: var(--ink); border-radius: 16px; max-width: 460px; width: 100%;
  padding: 24px 22px 22px; box-shadow: var(--shadow); position: relative; max-height: calc(100vh - 32px); overflow: auto;
  animation: pop .25s ease;
}
.card h2 { margin: 0 0 6px; font-size: 1.35rem; font-weight: 800; letter-spacing: -.02em; }
.card p { margin: 0; color: var(--ink-2); font-size: .95rem; }
.card .stack { display: flex; flex-direction: column; gap: 12px; }
.card .close { position: absolute; top: 10px; right: 10px; }
.legend { display: grid; gap: 8px; margin-top: 4px; }
.legend div { display: flex; align-items: center; gap: 10px; font-size: .92rem; color: var(--ink-2); }
.legend i { width: 18px; height: 18px; border-radius: 4px; flex: none; }
.legend .l1 { background: var(--g1); } .legend .l2 { background: var(--g2); } .legend .l3 { background: var(--g3); } .legend .l4 { background: var(--g4); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 6px 0 4px; }
.stats b { display: block; font-size: 1.6rem; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.stats span { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.dist { display: flex; flex-direction: column; gap: 5px; margin-top: 4px; }
.dist .row { display: grid; grid-template-columns: 26px 1fr; align-items: center; gap: 8px; font-size: .85rem; }
.dist .bar { background: var(--tile); border-radius: 4px; height: 20px; position: relative; }
.dist .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--ink); border-radius: 4px; min-width: 22px; }
.dist .bar i.me { background: var(--g2); }
.dist .bar em { position: absolute; right: 6px; top: 0; bottom: 0; display: flex; align-items: center; font-style: normal; font-weight: 700; font-size: .78rem; color: var(--bg); mix-blend-mode: difference; }
.result { text-align: center; }
.result .emoji { font-size: 1.35rem; line-height: 1.25; letter-spacing: .05em; margin: 8px 0 4px; white-space: pre; font-family: var(--f-num); }
.result .next { color: var(--muted); font-size: .9rem; margin-top: 6px; }
.result .next b { color: var(--ink); font-variant-numeric: tabular-nums; }
.share { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }

/* ---------- contenido de apoyo ---------- */
.content { margin-top: 56px; display: flex; flex-direction: column; gap: 32px; }
.content h2 { font-size: 1.2rem; font-weight: 800; letter-spacing: -.02em; margin: 0 0 8px; }
.content h3 { font-size: 1rem; font-weight: 700; margin: 14px 0 4px; }
.content p, .content li { color: var(--ink-2); font-size: .95rem; }
.content ul, .content ol { margin: 0; padding-left: 1.2em; }
.archive { display: flex; flex-wrap: wrap; gap: 8px; }
.archive a {
  text-decoration: none; border: 1px solid var(--line); background: var(--surface);
  border-radius: 8px; padding: 6px 11px; font-size: .88rem; font-weight: 600; color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.archive a:hover { border-color: var(--ink); color: var(--ink); }
.archive a.done { border-color: var(--g2); }
.faq details { border-top: 1px solid var(--line); padding: 10px 0; }
.faq details:last-child { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; font-weight: 700; color: var(--ink); font-size: .95rem; list-style: none; display: flex; justify-content: space-between; }
.faq summary::after { content: "+"; color: var(--muted); font-weight: 400; }
.faq details[open] summary::after { content: "–"; }
.faq details p { margin-top: 6px; }
footer { margin-top: 48px; padding-top: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: .82rem; display: flex; flex-wrap: wrap; gap: 6px 16px; }
footer a { color: var(--muted); }
.ad-slot { min-height: 0; }

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