:root {
  color-scheme: light;
  --bg: #f7f3ec;
  --bg-2: #fde7d7;
  --bg-3: #dfeafc;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --text: #2b2520;
  --muted: #857a6f;
  --line: #ddd3c5;
  --line-strong: #4f453d;
  --accent: #e2683c;
  --accent-ink: #ffffff;
  --accent-soft: #fbe1d5;
  --blue: #2f6fdc;
  --blue-soft: #dbe6fb;
  --danger: #d43f3f;
  --danger-soft: #fbe0e0;
  --ok: #2f9a5c;
  --gold: #f5b82e;

  --c0: #ef5b4c;
  --c1: #f59f2a;
  --c2: #f2c52e;
  --c3: #3fb56b;
  --c4: #2fa7d8;
  --c5: #4a6cf0;
  --c6: #a35be0;
  --board-bg: #263052;
  --cell-empty: #313d66;

  --radius: 16px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 6px 18px rgb(0 0 0 / .07);
  --shadow-lg: 0 2px 4px rgb(0 0 0 / .06), 0 14px 34px rgb(60 30 10 / .13);
  --font: ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --vh: 1vh;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #17141c;
    --bg-2: #2a1a2e;
    --bg-3: #172238;
    --surface: #232029;
    --surface-2: #2f2a35;
    --text: #f2ede6;
    --muted: #a69c92;
    --line: #3b3640;
    --line-strong: #c4b9ad;
    --accent: #f07b4e;
    --accent-ink: #1a1210;
    --accent-soft: #4b2c22;
    --blue: #7aa6f5;
    --blue-soft: #263450;
    --danger: #f27272;
    --danger-soft: #4b2526;
    --ok: #5cc98a;
    --board-bg: #1c2238;
    --cell-empty: #283150;
    --shadow: 0 1px 2px rgb(0 0 0 / .3), 0 6px 18px rgb(0 0 0 / .3);
    --shadow-lg: 0 2px 4px rgb(0 0 0 / .3), 0 14px 34px rgb(0 0 0 / .45);
  }
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow-x: hidden;
}

/* Fondo con manchas de color que se mueven despacio (sin blur: barato en celulares). */
body::before, body::after {
  content: "";
  position: fixed;
  z-index: -1;
  width: 70vmax; height: 70vmax;
  border-radius: 50%;
  pointer-events: none;
  animation: drift 26s ease-in-out infinite alternate;
}
body::before { left: -25vmax; top: -30vmax; background: radial-gradient(circle, var(--bg-2), transparent 65%); }
body::after { right: -30vmax; bottom: -30vmax; background: radial-gradient(circle, var(--bg-3), transparent 65%); animation-delay: -13s; }
@keyframes drift { to { transform: translate(8vmax, 6vmax) scale(1.1); } }

body.game {
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font: inherit; color: inherit; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px 6px;
  max-width: 520px;
  margin: 0 auto;
}
.topbar .back, .icon-btn {
  flex: none;
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; border-radius: 13px;
  color: var(--text);
  text-decoration: none;
  font-size: 30px; line-height: 1;
  background: var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:active, .topbar .back:active { transform: scale(.93); }
.sound-btn .off { display: none; }
.sound-btn.muted .on { display: none; }
.sound-btn.muted .off { display: inline; }
.sound-btn.muted { color: var(--muted); }
.topbar .title { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar h1 { font-size: 23px; margin: 0; letter-spacing: -.01em; font-weight: 800; }

.chip {
  font-size: 12px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
  white-space: nowrap;
}

.btn {
  border: 0; cursor: pointer;
  border-radius: 14px;
  padding: 12px 18px;
  font-weight: 750;
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  transition: transform .1s;
}
.btn:active { transform: scale(.96); }
.btn:focus { outline: none; }
.btn:focus-visible { outline: 3px solid var(--accent-soft); outline-offset: 2px; }
.btn-primary {
  background: linear-gradient(180deg, #f3895c, var(--accent));
  color: #fff;
  box-shadow: 0 4px 0 #b84a22, 0 8px 18px rgb(226 104 60 / .35);
}
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 #b84a22, 0 4px 10px rgb(226 104 60 / .3); }
.btn-small { padding: 9px 14px; font-size: 15px; }
.btn-block { display: block; width: 100%; }

dialog {
  border: 0;
  border-radius: 24px;
  padding: 24px 22px 20px;
  width: min(92vw, 380px);
  max-height: 90vh;
  overflow: auto;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / .35);
  text-align: center;
}
dialog::backdrop { background: rgb(20 15 10 / .4); }
dialog h2 { margin: 4px 0 6px; font-size: 25px; font-weight: 850; }
dialog p { margin: 4px 0; color: var(--muted); }
dialog .actions { display: grid; gap: 10px; margin-top: 18px; }
dialog[open] { animation: pop-in .35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes pop-in { from { transform: scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }

/* <dialog> emulado para Safari viejo (ver shared/compat.js) */
.no-dialog dialog { display: none; position: fixed; z-index: 100; left: 50%; top: 50%; transform: translate(-50%, -50%); margin: 0; }
.no-dialog dialog[open] { display: block; animation: none; }
.no-dialog.dialog-open body::after {
  content: ""; position: fixed; inset: 0; z-index: 99; width: auto; height: auto;
  border-radius: 0; background: rgb(20 15 10 / .4); animation: none;
}

.big-num { font-size: 46px; font-weight: 900; color: var(--text); margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.record { color: var(--ok); font-weight: 800; }

/* Efectos compartidos */
.fx-canvas { position: fixed; left: 0; top: 0; z-index: 40; pointer-events: none; }
.fx-shake { animation: fx-shake .4s; }
@keyframes fx-shake {
  15% { transform: translate(calc(var(--shake) * -1), calc(var(--shake) * .5)); }
  30% { transform: translate(var(--shake), calc(var(--shake) * -.6)); }
  45% { transform: translate(calc(var(--shake) * -.7), calc(var(--shake) * -.3)); }
  60% { transform: translate(calc(var(--shake) * .5), calc(var(--shake) * .4)); }
  80% { transform: translate(calc(var(--shake) * -.2), 0); }
}

/* Palabra grande de festejo */
.cheer {
  position: fixed; left: 50%; top: 42%; z-index: 45;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-size: clamp(34px, 11vw, 64px); font-weight: 900; letter-spacing: -.02em;
  white-space: nowrap;
  color: #ffd43b;
  background: linear-gradient(180deg, #fff6b0 10%, #ffcf33 45%, #ff8a1f 90%);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  -webkit-text-stroke: 2px rgb(120 50 0 / .35);
  filter: drop-shadow(0 4px 0 rgb(120 50 0 / .35)) drop-shadow(0 8px 20px rgb(0 0 0 / .25));
  animation: cheer 1.1s cubic-bezier(.2, 1.4, .4, 1) forwards;
}
@keyframes cheer {
  0% { transform: translate(-50%, -50%) scale(.3) rotate(-8deg); opacity: 0; }
  25% { transform: translate(-50%, -50%) scale(1.1) rotate(2deg); opacity: 1; }
  70% { transform: translate(-50%, -50%) scale(1) rotate(0); opacity: 1; }
  100% { transform: translate(-50%, -80%) scale(.9); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  body::before, body::after { animation: none; }
  dialog[open] { animation: none; }
}
