:root {
  --bg: #f7efe6;
  --bg-2: #fbf6f0;
  --card: #ffffff;
  --ink: #4b2f26;
  --ink-soft: #8a6a5c;
  --line: #ead9ca;
  --accent: #f0922b;
  --accent-dark: #d97a14;
  --accent-2: #8fa0ee;
  --accent-2-dark: #7286e0;
  --danger: #e2483d;
  --ok: #2fa66a;
  --cell-gap: 4px;
  --radius: 18px;
  --shadow: 0 6px 18px rgba(120, 72, 40, .12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; touch-action: manipulation; }
.board-wrap, .board, .cell { touch-action: none; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  background-image:
    radial-gradient(circle at 20% 0%, #fff6ea 0, transparent 40%),
    radial-gradient(circle at 100% 100%, #f3e3d4 0, transparent 45%);
  background-attachment: fixed;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
a { color: var(--accent-dark); }

.screen { display: none; min-height: 100dvh; max-width: 520px; margin: 0 auto;
  padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); }
.screen.active { display: flex; flex-direction: column; }

/* ---------- Botones ---------- */
.icon-btn {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--card); box-shadow: var(--shadow);
  font-size: 22px; display: grid; place-items: center; font-weight: 800;
  transition: transform .12s;
}
.icon-btn:active { transform: scale(.92); }
.pill { background: var(--card); border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow);
  font-family: 'Fredoka'; font-weight: 600; font-size: 20px; }

.big-btn {
  width: 100%; border-radius: 999px; padding: 20px 10px;
  font-family: 'Fredoka'; font-weight: 700; font-size: 30px; color: #fff;
  box-shadow: 0 6px 0 rgba(0,0,0,.12), var(--shadow);
  position: relative; transition: transform .1s, box-shadow .1s;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,.12); }
.big-btn.primary { background: linear-gradient(180deg, #f6a13f, var(--accent)); }
.big-btn.secondary { background: linear-gradient(180deg, #a2b1f3, var(--accent-2)); }
.big-btn small { display: block; font-size: 15px; font-weight: 600; opacity: .95; margin-top: 2px; }
.link-btn { font-weight: 800; color: var(--ink-soft); text-decoration: underline; padding: 8px; }

/* ---------- Menú ---------- */
.menu-top { display: flex; justify-content: space-between; align-items: center; }
.logo { text-align: center; margin-top: 18px; }
.logo h1 { font-family: 'Fredoka'; font-weight: 700; font-size: clamp(48px, 15vw, 72px); margin: 6px 0 0;
  letter-spacing: 1px; color: #8a5a3c; line-height: 1; }
.logo h1 span { color: var(--accent); }
.tagline { margin: 4px 0 0; font-weight: 800; color: var(--ink-soft); letter-spacing: 3px; text-transform: uppercase; font-size: 13px; }
.logo-box { position: relative; width: 96px; height: 92px; margin: 0 auto; }
.urn { position: absolute; bottom: 0; left: 6px; right: 6px; height: 58px; border-radius: 12px 12px 16px 16px;
  background: linear-gradient(180deg, #8fa0ee, #6f84df); display: grid; place-items: center;
  box-shadow: inset 0 -6px 0 rgba(0,0,0,.1); }
.urn::before { content: ''; position: absolute; top: 8px; left: 22px; right: 22px; height: 6px; border-radius: 4px; background: #46549b; }
.urn span { font-family: 'Fredoka'; color: #fff; font-weight: 700; font-size: 22px; margin-top: 10px; }
.ballot { position: absolute; left: 30px; top: 0; width: 36px; height: 46px; background: #fff; border-radius: 4px;
  box-shadow: var(--shadow); transform: rotate(-8deg); animation: drop 2.8s ease-in-out infinite; }
.ballot::after { content: '✕'; position: absolute; inset: 0; display: grid; place-items: center; color: var(--accent); font-weight: 900; }
@keyframes drop { 0%, 100% { transform: translateY(0) rotate(-8deg); } 50% { transform: translateY(10px) rotate(-4deg); } }

.countdown { margin: 18px auto 0; text-align: center; background: var(--card); border-radius: var(--radius);
  padding: 10px 18px; box-shadow: var(--shadow); font-weight: 800; color: var(--ink-soft); }
.countdown b { font-family: 'Fredoka'; color: var(--ink); font-size: 26px; }

.mascot-parade { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 22px 0; }
.mascot-parade span { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center;
  font-size: 24px; box-shadow: 0 3px 0 rgba(0,0,0,.1); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-5px); } }

.menu-actions { margin-top: auto; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.disclaimer { margin-top: 18px; font-size: 12px; line-height: 1.45; text-align: center; color: var(--ink-soft); }

/* ---------- Juego ---------- */
.game-top { display: flex; align-items: center; justify-content: space-between; }
.stat { text-align: center; font-family: 'Fredoka'; }
.stat small { display: block; font-size: 20px; color: #9b6d5b; font-weight: 500; }
.stat strong { font-size: 30px; color: #8a4f42; }

.lives { display: flex; justify-content: center; gap: 6px; margin: 10px auto 0; background: var(--card);
  border-radius: 999px; padding: 6px 16px; box-shadow: var(--shadow); width: max-content; }
.lives span { font-size: 26px; transition: transform .3s, filter .3s, opacity .3s; }
.lives span.lost { filter: grayscale(1); opacity: .3; transform: scale(.8); }

.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 12px; background: var(--card);
  border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); }
.rule { background: var(--bg-2); border-radius: 12px; padding: 6px; display: flex; align-items: center; gap: 6px;
  font-weight: 800; font-size: 12px; line-height: 1.15; color: #7a4b3c; }
.mini { flex: 0 0 30px; height: 30px; border-radius: 5px; background-size: 100% 100%; }
.mini.m1 { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cg fill='%23ead2c2'%3E%3Crect x='0' y='0' width='9' height='9' rx='2'/%3E%3Crect x='10' y='0' width='9' height='9' rx='2'/%3E%3Crect x='20' y='0' width='9' height='9' rx='2'/%3E%3Crect x='0' y='10' width='9' height='9' rx='2'/%3E%3Crect x='0' y='20' width='9' height='9' rx='2'/%3E%3C/g%3E%3Cg fill='%23f0922b'%3E%3Crect x='10' y='10' width='9' height='9' rx='2'/%3E%3Crect x='20' y='10' width='9' height='9' rx='2'/%3E%3Crect x='10' y='20' width='9' height='9' rx='2'/%3E%3Crect x='20' y='20' width='9' height='9' rx='2'/%3E%3C/g%3E%3Ccircle cx='14.5' cy='14.5' r='3' fill='%23fff'/%3E%3C/svg%3E"); }
.mini.m2 { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cg fill='%23ead2c2'%3E%3Crect x='0' y='0' width='9' height='9' rx='2'/%3E%3Crect x='20' y='0' width='9' height='9' rx='2'/%3E%3Crect x='0' y='10' width='9' height='9' rx='2'/%3E%3Crect x='20' y='10' width='9' height='9' rx='2'/%3E%3Crect x='0' y='20' width='9' height='9' rx='2'/%3E%3Crect x='20' y='20' width='9' height='9' rx='2'/%3E%3C/g%3E%3Cg fill='%23c99d86'%3E%3Crect x='10' y='10' width='9' height='9' rx='2'/%3E%3Crect x='10' y='20' width='9' height='9' rx='2'/%3E%3C/g%3E%3Crect x='10' y='0' width='9' height='9' rx='2' fill='%23f0922b'/%3E%3Ccircle cx='14.5' cy='4.5' r='3' fill='%23fff'/%3E%3C/svg%3E"); }
.mini.m3 { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Cg fill='%23c99d86'%3E%3Crect x='0' y='0' width='9' height='9' rx='2'/%3E%3Crect x='10' y='0' width='9' height='9' rx='2'/%3E%3Crect x='20' y='0' width='9' height='9' rx='2'/%3E%3Crect x='0' y='10' width='9' height='9' rx='2'/%3E%3Crect x='20' y='10' width='9' height='9' rx='2'/%3E%3Crect x='0' y='20' width='9' height='9' rx='2'/%3E%3Crect x='10' y='20' width='9' height='9' rx='2'/%3E%3Crect x='20' y='20' width='9' height='9' rx='2'/%3E%3C/g%3E%3Crect x='10' y='10' width='9' height='9' rx='2' fill='%23f0922b'/%3E%3Ccircle cx='14.5' cy='14.5' r='3' fill='%23fff'/%3E%3C/svg%3E"); }

.party-bar { display: flex; flex-wrap: nowrap; justify-content: center; gap: 4px; margin: 14px auto 0;
  background: var(--card); border-radius: var(--radius) var(--radius) 0 0; padding: 8px 12px 4px; max-width: 100%; }
.chip { width: var(--chip, 38px); height: var(--chip, 38px); flex: 0 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: calc(var(--chip, 38px) * .58);
  opacity: .35; filter: grayscale(.6); transition: all .25s; position: relative; }
.chip.placed { opacity: 1; filter: none; transform: scale(1.08); }
.chip.placed::after { content: '✓'; position: absolute; right: -2px; bottom: -2px; width: 15px; height: 15px; border-radius: 50%;
  background: var(--ok); color: #fff; font-size: 10px; display: grid; place-items: center; font-weight: 900; }

.board-wrap { background: var(--card); border-radius: var(--radius); padding: 10px; box-shadow: var(--shadow); }
.board { display: grid; gap: var(--cell-gap); touch-action: none; }
.cell { position: relative; aspect-ratio: 1; border-radius: 7px; display: grid; place-items: center;
  font-size: var(--emoji, 24px); line-height: 1; transition: transform .1s; }
.cell.x::before { content: ''; position: absolute; inset: 22%;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='M4 4l12 12M16 4L4 16' stroke='white' stroke-width='3.6' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  opacity: .95; }
.cell.x.auto::before { opacity: .55; }
.cell .m { width: 80%; aspect-ratio: 1; border-radius: 50%; background: rgba(255,255,255,.88); display: grid; place-items: center;
  box-shadow: 0 2px 0 rgba(0,0,0,.12); animation: pop .28s cubic-bezier(.3,1.6,.5,1); }
.cell.bad .m { background: #ffd9d6; animation: shake .4s; }
.cell.hinted .m { box-shadow: 0 0 0 3px #ffe27a, 0 2px 0 rgba(0,0,0,.12); }
@keyframes pop { from { transform: scale(.2); } to { transform: scale(1); } }
@keyframes shake { 0%,100% { transform: translateX(0);} 25% { transform: translateX(-5px);} 75% { transform: translateX(5px);} }
.board.won .cell { animation: wave .6s ease both; }
@keyframes wave { 50% { transform: scale(.85); } }

.tools { display: flex; justify-content: center; gap: 22px; margin-top: 18px; }
.tool { width: 78px; height: 78px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; transition: transform .1s; }
.tool:active { transform: scale(.92); }
.tool span { font-size: 28px; line-height: 1; font-weight: 900; color: #8a4f42; }
.tool small { font-size: 11px; font-weight: 800; color: var(--ink-soft); margin-top: 3px; }
.tool:disabled { opacity: .45; }
.badge { position: absolute; top: -4px; right: -4px; background: var(--danger); color: #fff; font-family: 'Fredoka';
  font-size: 15px; min-width: 28px; height: 28px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; }
.hint-text { text-align: center; font-size: 12px; color: var(--ink-soft); font-weight: 700; margin: 14px 8px 0; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(60, 35, 25, .45); display: grid; place-items: center; padding: 18px; z-index: 50;
  animation: fade .2s; }
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.modal-card { background: var(--bg-2); border-radius: 26px; padding: 22px 20px; width: 100%; max-width: 440px; max-height: 88dvh;
  overflow: auto; box-shadow: 0 20px 50px rgba(0,0,0,.25); animation: rise .3s cubic-bezier(.3,1.4,.5,1); text-align: center; }
@keyframes rise { from { transform: translateY(30px) scale(.95); opacity: 0; } }
.modal-card h2 { font-family: 'Fredoka'; font-size: 30px; margin: 4px 0 8px; color: #8a4f42; }
.modal-card p { margin: 8px 0; line-height: 1.45; font-weight: 600; }
.modal-card .big-emoji { font-size: 56px; }
.modal-card .stats { display: flex; justify-content: center; gap: 10px; margin: 14px 0; }
.modal-card .stats div { background: var(--card); border-radius: 14px; padding: 10px 14px; min-width: 84px; box-shadow: var(--shadow); }
.modal-card .stats b { display: block; font-family: 'Fredoka'; font-size: 24px; }
.modal-card .stats small { font-weight: 800; color: var(--ink-soft); }
.modal-card .actions { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
.modal-card .big-btn { font-size: 22px; padding: 14px; }
.modal-card .text-left { text-align: left; }
.party-list { display: grid; gap: 8px; margin-top: 12px; text-align: left; }
.party-row { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 14px; padding: 8px 10px; }
.party-row .dot { width: 44px; height: 44px; flex: 0 0 44px; border-radius: 12px; display: grid; place-items: center; font-size: 26px; }
.party-row b { display: block; }
.party-row small { color: var(--ink-soft); font-weight: 700; }
.setting { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--card);
  border-radius: 14px; padding: 14px; margin-top: 10px; text-align: left; font-weight: 800; }
.setting small { display: block; font-weight: 600; color: var(--ink-soft); }
.switch { width: 52px; height: 30px; border-radius: 999px; background: #d9c8bb; position: relative; flex: 0 0 52px; transition: background .2s; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.switch.on { background: var(--ok); }
.switch.on::after { transform: translateX(22px); }
.demo { display: grid; grid-template-columns: repeat(4, 34px); gap: 3px; justify-content: center; margin: 12px 0; }
.demo div { height: 34px; border-radius: 6px; display: grid; place-items: center; font-size: 20px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 200%); visibility: hidden; background: #4b2f26; color: #fff;
  padding: 12px 18px; border-radius: 999px; font-weight: 800; font-size: 14px; transition: transform .3s; z-index: 60;
  max-width: 92vw; text-align: center; }
.toast.show { transform: translate(-50%, 0); visibility: visible; }

.confetti { position: fixed; top: -20px; font-size: 22px; pointer-events: none; z-index: 40; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }

@media (max-height: 700px) {
  .rules { display: none; }
  .tools { margin-top: 12px; }
  .tool { width: 64px; height: 64px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Online: cuenta, ranking, grupos ---------- */
.pill.account { font-size: 17px; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-row { display: flex; gap: 12px; width: 100%; }
.mid-btn { flex: 1; background: var(--card); border-radius: 999px; padding: 14px 8px; box-shadow: var(--shadow);
  font-family: 'Fredoka'; font-weight: 600; font-size: 19px; color: #8a4f42; }
.mid-btn:active { transform: scale(.97); }
.field { width: 100%; font: inherit; font-size: 16px; font-weight: 700; padding: 14px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: #fff; color: var(--ink); margin-top: 10px; -webkit-user-select: text; user-select: text; }
.field:focus { outline: none; border-color: var(--accent); }
.form-row { display: flex; gap: 8px; align-items: stretch; }
.form-row .field { flex: 1; }
.small-btn { background: var(--accent); color: #fff; border-radius: 14px; padding: 0 16px; font-weight: 800; margin-top: 10px; white-space: nowrap; }
.small-btn.ghost { background: var(--card); color: var(--ink); box-shadow: inset 0 0 0 2px var(--line); }
.msg { font-size: 14px; font-weight: 700; min-height: 20px; margin-top: 8px; }
.msg.err { color: var(--danger); } .msg.ok { color: var(--ok); }
.tabs { display: flex; background: var(--card); border-radius: 999px; padding: 4px; gap: 4px; margin-top: 10px; box-shadow: var(--shadow); }
.tabs button { flex: 1; padding: 10px 4px; border-radius: 999px; font-weight: 800; font-size: 14px; color: var(--ink-soft); }
.tabs button.on { background: var(--accent); color: #fff; }
.select { appearance: none; -webkit-appearance: none; background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238a6a5c' stroke-width='2' fill='none'/%3E%3C/svg%3E") right 14px center/12px no-repeat; }
.board-list { margin-top: 12px; display: grid; gap: 6px; text-align: left; }
.lb-row { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 8px; background: var(--card); border-radius: 12px; padding: 10px 12px; font-weight: 800; }
.lb-row .pos { font-family: 'Fredoka'; font-size: 18px; color: var(--ink-soft); text-align: center; }
.lb-row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-row .val { font-family: 'Fredoka'; font-size: 18px; text-align: right; }
.lb-row .val small { display: block; font-family: 'Nunito'; font-size: 11px; color: var(--ink-soft); font-weight: 700; }
.lb-row.me { box-shadow: inset 0 0 0 3px var(--accent); background: #fff6ea; }
.lb-gap { text-align: center; color: var(--ink-soft); font-weight: 800; }
.empty { color: var(--ink-soft); font-weight: 700; padding: 18px 0; }
.group-card { background: var(--card); border-radius: 14px; padding: 12px; text-align: left; display: flex; align-items: center; gap: 10px; }
.group-card b { display: block; }
.group-card small { color: var(--ink-soft); font-weight: 700; }
.group-card .grow { flex: 1; min-width: 0; }
.group-card button { font-size: 20px; width: 40px; height: 40px; border-radius: 50%; background: var(--bg-2); }
.online-result { font-weight: 800; color: #8a4f42; }
.online-result .cta { display: inline-block; margin-top: 4px; }
.section-title { font-family: 'Fredoka'; font-size: 18px; text-align: left; margin: 18px 0 4px; color: #8a4f42; }

/* 4 herramientas */
.tools { gap: 12px; }
.tool { width: 72px; height: 72px; }
.tool.toggle span { font-size: 26px; color: var(--ink-soft); }
.tool.toggle.on { background: var(--ok); }
.tool.toggle.on span, .tool.toggle.on small { color: #fff; }
.badge.mini-badge { font-size: 11px; height: 22px; min-width: 0; padding: 0 6px; background: var(--ink-soft); top: -6px; right: -8px; }
.tool.toggle.on .mini-badge { background: var(--danger); }
#mode-label { font-size: clamp(14px, 4.4vw, 20px); white-space: nowrap; }
