:root {
  --bg: #ffffff; --fg: #111111; --muted: #6b6b6b; --card: #f3f3f3; --line: #111111;
  --x: #111111; --o: #111111; --accent: #111111; --accent-fg: #ffffff; --hl: rgba(0,0,0,.12);
  --radius: 14px; --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
[data-theme="noche"] { --bg:#0d0d0d; --fg:#f5f5f5; --muted:#9a9a9a; --card:#1b1b1b; --line:#f5f5f5; --x:#f5f5f5; --o:#f5f5f5; --accent:#f5f5f5; --accent-fg:#0d0d0d; --hl:rgba(255,255,255,.14); }
[data-theme="papel"] { --bg:#f4ecd8; --fg:#3b2f1e; --muted:#7d6d55; --card:#eadfc3; --line:#3b2f1e; --x:#a3361f; --o:#25508a; --accent:#3b2f1e; --accent-fg:#f4ecd8; --hl:rgba(59,47,30,.14); }
[data-theme="mar"]   { --bg:#06283d; --fg:#e6f6ff; --muted:#8fb8cf; --card:#0b3b57; --line:#5cc8ff; --x:#ffd166; --o:#5cc8ff; --accent:#5cc8ff; --accent-fg:#06283d; --hl:rgba(92,200,255,.18); }
[data-theme="neon"]  { --bg:#0b0014; --fg:#f2e9ff; --muted:#a58bd1; --card:#1a0630; --line:#ff2bd6; --x:#ff2bd6; --o:#2bf0ff; --accent:#ff2bd6; --accent-fg:#0b0014; --hl:rgba(255,43,214,.2); }
[data-theme="retro"] { --bg:#101820; --fg:#c8ffb0; --muted:#76b35f; --card:#17242f; --line:#c8ffb0; --x:#ffb000; --o:#7dff4d; --accent:#7dff4d; --accent-fg:#101820; --hl:rgba(125,255,77,.18); --font: "Courier New", ui-monospace, monospace; }
[data-theme="oro"]   { --bg:#14100a; --fg:#fff3d1; --muted:#b59a5a; --card:#241c0e; --line:#e8b923; --x:#ffd24d; --o:#fff3d1; --accent:#e8b923; --accent-fg:#14100a; --hl:rgba(232,185,35,.2); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--font); line-height: 1.45; min-height: 100vh; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip { position: absolute; left: -999px; } .skip:focus { left: 8px; top: 8px; background: var(--accent); color: var(--accent-fg); padding: 8px; z-index: 9; }
[hidden] { display: none !important; }

button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 2px solid var(--line); background: var(--bg); border-radius: var(--radius); padding: 10px 16px; min-height: 44px; }
button:hover { background: var(--card); }
button.primary { background: var(--accent); color: var(--accent-fg); }
button.primary:hover { filter: brightness(1.1); }
button.icon { border: 0; background: transparent; font-size: 1.4rem; padding: 6px 10px; }
button.link { border: 0; background: none; text-decoration: underline; min-height: 40px; padding: 8px 12px; color: var(--muted); }
button.chip { border-radius: 999px; padding: 6px 12px; min-height: 36px; font-size: .85rem; }
input, select { border: 2px solid var(--line); background: var(--bg); border-radius: 10px; padding: 8px 10px; min-height: 40px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px max(16px, env(safe-area-inset-left)); border-bottom: 2px solid var(--line); flex-wrap: wrap; }
#brand { margin: 0; font-size: 1.4rem; font-weight: 800; letter-spacing: .02em; }
#brand .logo { font-size: 1.7rem; letter-spacing: .08em; }
.top-actions { display: flex; align-items: center; gap: 6px; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
.lead { color: var(--muted); margin-top: 4px; }
.h { font-size: 1.1rem; margin: 18px 0 8px; }
.msg { min-height: 1.4em; color: var(--muted); text-align: center; }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.mode { text-align: left; padding: 12px; display: flex; flex-direction: column; gap: 4px; }
.mode b { font-size: 1rem; }
.mode small { color: var(--muted); font-size: .8rem; line-height: 1.3; }
.mode[aria-checked="true"] { background: var(--accent); color: var(--accent-fg); }
.mode[aria-checked="true"] small { color: inherit; opacity: .85; }
.mode .mini { font-size: 1.3rem; letter-spacing: 2px; }

.field { margin: 16px 0 8px; display: flex; flex-direction: column; gap: 4px; max-width: 320px; }
.play { display: grid; gap: 10px; margin-top: 10px; }
.big { width: 100%; font-size: 1.1rem; padding: 14px; font-weight: 700; }
.ai-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.join-row { display: grid; grid-template-columns: 110px 1fr; gap: 8px; }
#joinCode { text-transform: uppercase; letter-spacing: .15em; text-align: center; }

/* PARTIDA */
.scorebar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; margin-bottom: 6px; }
.who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.who.opp { justify-content: flex-end; }
.who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who i { font-style: normal; font-size: 1.6rem; font-weight: 800; }
.sym { font-size: 1.4rem; font-weight: 800; }
.mid { text-align: center; font-size: .85rem; color: var(--muted); display: flex; flex-direction: column; }
.status { text-align: center; font-weight: 700; font-size: 1.15rem; min-height: 1.6em; margin: 6px 0; }

.board { --n: 3; display: grid; grid-template-columns: repeat(var(--n), 1fr); gap: 6px; width: min(94vw, 520px, calc(100vh - 280px)); min-width: 260px; margin: 0 auto; aspect-ratio: 1; }
.cell { aspect-ratio: 1; padding: 0; border-radius: 12px; font-weight: 800; line-height: 1; display: grid; place-items: center; font-size: clamp(1.6rem, 11vw, 4rem); background: var(--card); border-color: var(--line); transition: transform .08s; }
.board[data-size="5"] .cell { font-size: clamp(1.2rem, 8vw, 2.8rem); }
.cell:disabled { cursor: default; color: inherit; opacity: 1; }
.cell:not(:disabled):hover { transform: scale(1.04); }
.cell.x { color: var(--x); } .cell.o { color: var(--o); }
.cell.last { box-shadow: inset 0 0 0 3px var(--accent); }
.cell.win { background: var(--accent); animation: pulse .8s ease-in-out infinite alternate; }
.cell.win.x, .cell.win.o { color: var(--accent-fg); }
.cell.fading { opacity: .45; border-style: dashed; }
.cell .pop { animation: pop .18s ease-out; display: inline-block; }
@keyframes pop { from { transform: scale(.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pulse { to { transform: scale(1.06); } }

/* Definitivo */
.board.ult { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.sub { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; min-width: 0; padding: 3px; border: 2px solid var(--line); border-radius: 10px; }
.sub.active { background: var(--hl); box-shadow: 0 0 0 3px var(--accent); }
.sub.closed .cell { opacity: .25; }
.sub .cell { min-height: 0; min-width: 0; border-radius: 6px; border-width: 1px; font-size: clamp(.8rem, 4.6vw, 1.7rem); }
.sub .badge { position: absolute; inset: 0; display: none; place-items: center; font-weight: 900; font-size: clamp(2.4rem, 16vw, 5rem); background: color-mix(in srgb, var(--bg) 80%, transparent); border-radius: 8px; pointer-events: none; }
.sub.closed .badge { display: grid; }
.sub.won-x .badge { color: var(--x); } .sub.won-o .badge { color: var(--o); }
.sub.draw .badge { color: var(--muted); font-size: 2rem; }
.sub.glow { box-shadow: 0 0 0 4px var(--accent); }

.invite { text-align: center; margin: 14px auto; max-width: 460px; }
.copy-row { display: flex; gap: 6px; } .copy-row input { flex: 1; min-width: 0; }
.code { font-size: 1.2rem; letter-spacing: .2em; }
.reacts { display: flex; justify-content: center; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.reacts button { min-height: 34px; padding: 4px 10px; font-size: .85rem; }
.bubble { text-align: center; min-height: 1.4em; font-weight: 700; color: var(--accent); }
.game-actions { display: flex; justify-content: center; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.seo { margin-top: 28px; color: var(--muted); }
.seo h2, .seo h3 { color: var(--fg); }
.seo dt { font-weight: 700; color: var(--fg); margin-top: 10px; } .seo dd { margin: 2px 0 0; }
.howto { margin-top: 40px; color: var(--muted); }
.howto h2 { color: var(--fg); }
.foot { text-align: center; padding: 24px 16px 32px; color: var(--muted); font-size: .85rem; }

/* diálogos */
dialog { max-width: min(560px, 94vw); width: 100%; border: 2px solid var(--line); border-radius: 18px; background: var(--bg); color: var(--fg); padding: 0; max-height: 90vh; overflow: auto; }
dialog::backdrop { background: rgba(0,0,0,.55); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--card); }
.dlg-head h2 { margin: 0; }
.dlg-body { padding: 8px 16px 20px; }
.dlg-body h3 { margin: 18px 0 8px; font-size: 1rem; }
.xpbar { height: 12px; border-radius: 6px; background: var(--card); overflow: hidden; border: 1px solid var(--line); }
#xpFill { height: 100%; background: var(--accent); width: 0; transition: width .4s; }
.muted { color: var(--muted); font-size: .9rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; }
.stats div { background: var(--card); border-radius: 10px; padding: 8px; text-align: center; }
.stats b { display: block; font-size: 1.3rem; }
.stats span { font-size: .75rem; color: var(--muted); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.opt { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 6px; font-size: .85rem; }
.opt[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.opt:disabled { opacity: .5; cursor: not-allowed; }
.opt .pv { font-size: 1.3rem; font-weight: 800; display: flex; gap: 6px; }
.opt small { color: inherit; opacity: .75; font-size: .7rem; text-align: center; }
.swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); }
.colors { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.colors input[type=color] { padding: 0; width: 44px; height: 36px; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.ach { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.ach li { display: flex; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--card); opacity: .5; }
.ach li.done { opacity: 1; }

.toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); display: grid; gap: 6px; z-index: 20; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--accent); color: var(--accent-fg); padding: 10px 14px; border-radius: 12px; font-weight: 700; text-align: center; animation: pop .2s; }

.gold-x { color: #e8b923 !important; text-shadow: 0 0 10px rgba(232,185,35,.7); }

@media (max-width: 420px) {
  #brand { font-size: 1.15rem; } #brand .logo { font-size: 1.4rem; }
  .join-row { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
