/* ==========================================================================
   Palabra · CEIP Carlos III
   ========================================================================== */

@font-face {
  font-family: "Fraunces";
  src: url("../assets/fonts/fraunces-latin-full-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Fraunces";
  src: url("../assets/fonts/fraunces-latin-full-italic.woff2") format("woff2");
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Inter";
  src: url("../assets/fonts/inter-latin-wght-normal.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  --bg: #F3EDE2;
  --bg-2: #EAE2D3;
  --surface: #FBF8F2;
  --ink: #1C1A16;
  --ink-2: #4A453C;
  --muted: #7B7366;
  --line: #D8CEBC;
  --line-strong: #B4A892;

  --tile-bg: rgba(255, 252, 245, .55);
  --tile-border: #D3C8B5;
  --tile-filled: #8F826C;

  --correct: #2F7A58;
  --correct-2: #25654A;
  --present: #D69E1E;
  --present-2: #B98614;
  --absent: #8C8577;
  --absent-2: #7A7366;
  --on-color: #FFFDF8;

  --key: #E3DACA;
  --key-hover: #D9CFBC;
  --key-ink: #1C1A16;

  --accent: #C4492B;
  --pill: #FBF8F2;
  --aura-1: rgba(214, 158, 30, .20);
  --aura-2: rgba(47, 122, 88, .14);
  --aura-3: rgba(196, 73, 43, .10);

  --shadow-lg: 0 30px 80px -20px rgba(58, 44, 20, .35), 0 8px 24px -8px rgba(58, 44, 20, .18);
  --shadow-tile: inset 0 1px 0 rgba(255, 255, 255, .6), 0 1px 0 rgba(58, 44, 20, .04);
  --grain-opacity: .07;

  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --ease-spring: cubic-bezier(.34, 1.56, .64, 1);
  --font-display: "Fraunces", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --radius: 12px;
  --gap: 7px;
  --maxw: 520px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #11100E;
  --bg-2: #191815;
  --surface: #1B1A17;
  --ink: #F2ECE0;
  --ink-2: #CFC7B8;
  --muted: #8E8676;
  --line: #2C2A25;
  --line-strong: #4A463E;
  --tile-bg: rgba(255, 250, 240, .025);
  --tile-border: #34312B;
  --tile-filled: #6C655A;
  --correct: #3A9068;
  --correct-2: #2F7A58;
  --present: #D2A02C;
  --present-2: #B38620;
  --absent: #36332E;
  --absent-2: #2E2B27;
  --on-color: #FFFDF8;
  --key: #2A2824;
  --key-hover: #35322D;
  --key-ink: #F2ECE0;
  --accent: #E0694A;
  --pill: #37342F;
  --aura-1: rgba(210, 160, 44, .10);
  --aura-2: rgba(58, 144, 104, .10);
  --aura-3: rgba(224, 105, 74, .07);
  --shadow-lg: 0 30px 80px -20px rgba(0, 0, 0, .7), 0 8px 24px -8px rgba(0, 0, 0, .5);
  --shadow-tile: inset 0 1px 0 rgba(255, 255, 255, .03);
  --grain-opacity: .05;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #11100E;
    --bg-2: #191815;
    --surface: #1B1A17;
    --ink: #F2ECE0;
    --ink-2: #CFC7B8;
    --muted: #8E8676;
    --line: #2C2A25;
    --line-strong: #4A463E;
    --tile-bg: rgba(255, 250, 240, .025);
    --tile-border: #34312B;
    --tile-filled: #6C655A;
    --correct: #3A9068;
    --correct-2: #2F7A58;
    --present: #D2A02C;
    --present-2: #B38620;
    --absent: #36332E;
    --absent-2: #2E2B27;
    --on-color: #FFFDF8;
    --key: #2A2824;
    --key-hover: #35322D;
    --key-ink: #F2ECE0;
    --accent: #E0694A;
  --pill: #37342F;
    --aura-1: rgba(210, 160, 44, .10);
    --aura-2: rgba(58, 144, 104, .10);
    --aura-3: rgba(224, 105, 74, .07);
    --shadow-lg: 0 30px 80px -20px rgba(0, 0, 0, .7), 0 8px 24px -8px rgba(0, 0, 0, .5);
    --shadow-tile: inset 0 1px 0 rgba(255, 255, 255, .03);
    --grain-opacity: .05;
    color-scheme: dark;
  }
}

/* Alto contraste (daltonismo) */
:root.hc {
  --correct: #E8672C;
  --correct-2: #C9551F;
  --present: #3C8FD9;
  --present-2: #2F76B6;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-feature-settings: "ss01", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .5s var(--ease-out), color .5s var(--ease-out);
}
button { font: inherit; color: inherit; }
svg { display: block; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; border-radius: 8px; }
::selection { background: var(--present); color: var(--ink); }

/* ---------- Ambient ---------- */
.grain {
  position: fixed; inset: -50%;
  pointer-events: none; z-index: 0;
  opacity: var(--grain-opacity);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 1 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: multiply;
}
:root[data-theme="dark"] .grain { mix-blend-mode: screen; filter: invert(1); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .grain { mix-blend-mode: screen; filter: invert(1); } }

.aura { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.aura i {
  position: absolute; border-radius: 50%;
  filter: blur(60px);
  animation: drift 26s ease-in-out infinite alternate;
}
.aura i:nth-child(1) { width: 60vmax; height: 60vmax; left: -22vmax; top: -26vmax; background: radial-gradient(circle, var(--aura-1), transparent 65%); }
.aura i:nth-child(2) { width: 55vmax; height: 55vmax; right: -24vmax; bottom: -20vmax; background: radial-gradient(circle, var(--aura-2), transparent 65%); animation-duration: 32s; animation-delay: -8s; }
.aura i:nth-child(3) { width: 40vmax; height: 40vmax; right: -10vmax; top: 10vh; background: radial-gradient(circle, var(--aura-3), transparent 65%); animation-duration: 38s; animation-delay: -16s; }
@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(4vmax, 3vmax, 0) scale(1.08); }
  100% { transform: translate3d(-3vmax, 5vmax, 0) scale(.96); }
}

/* ---------- Layout ---------- */
.app {
  position: relative; z-index: 1;
  height: 100vh; height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(12px, env(safe-area-inset-left));
}

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 14px 0 6px;
}
.top-right { display: flex; justify-content: flex-end; gap: 2px; }

.icon-btn {
  position: relative;
  width: 44px; height: 44px;
  display: grid; place-items: center;
  background: transparent; border: 0; border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  transition: background-color .25s var(--ease-out), transform .25s var(--ease-out);
}
.icon-btn svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn svg .fill { fill: currentColor; }
.icon-btn:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.icon-btn:active { transform: scale(.92); }
@media (hover: hover) {
  .icon-btn[data-tip]::after {
    content: attr(data-tip);
    position: absolute; top: calc(100% + 4px); left: 50%;
    transform: translate(-50%, -4px);
    padding: 5px 9px; border-radius: 7px;
    background: var(--ink); color: var(--bg);
    font-size: 11.5px; font-weight: 500; letter-spacing: .01em; white-space: nowrap;
    opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s var(--ease-out);
    z-index: 5;
  }
  .icon-btn[data-tip]:hover::after { opacity: 1; transform: translate(-50%, 0); transition-delay: .35s; }
}

.brand {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 560;
  font-size: clamp(30px, 8.4vw, 40px);
  line-height: 1;
  letter-spacing: -.035em;
  font-variation-settings: "opsz" 144, "SOFT" 60, "WONK" 1;
  font-style: italic;
  user-select: none;
}
.brand-word { display: inline-flex; }
.brand-word span {
  display: inline-block;
  animation: rise .9s var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 45ms + 80ms);
}
.brand-word span:first-child { font-style: normal; font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 0; font-weight: 640; padding-right: .02em; }
.brand-word span:last-child::after {
  content: ""; display: inline-block;
  width: .17em; height: .17em; border-radius: 50%;
  background: var(--accent);
  margin-left: .04em;
  transform: translateY(-.02em);
}
@keyframes rise {
  from { opacity: 0; transform: translateY(.45em) rotate(4deg); filter: blur(4px); }
  to { opacity: 1; transform: none; filter: none; }
}

.dateline {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 6px 0 10px;
  font-size: 10.5px; font-weight: 560;
  letter-spacing: .13em; text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
  animation: fade 1s .35s var(--ease-out) both;
}
.dl-school { color: var(--ink-2); }
.dl-sep { width: 3px; height: 3px; border-radius: 50%; background: var(--line-strong); flex: none; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* Modos */
.modes {
  position: relative;
  display: grid; grid-template-columns: 1fr 1fr;
  width: min(300px, 100%);
  margin: 12px auto 0;
  padding: 3px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 4%, transparent);
  animation: fade 1s .45s var(--ease-out) both;
}
.mode {
  position: relative; z-index: 1;
  border: 0; background: none; cursor: pointer;
  padding: 7px 10px;
  font-size: 13px; font-weight: 560; letter-spacing: -.005em;
  color: var(--muted);
  border-radius: 999px;
  transition: color .35s var(--ease-out);
}
.mode.is-active { color: var(--ink); }
.mode-pill {
  position: absolute; z-index: 0;
  top: 3px; bottom: 3px; left: 3px;
  width: calc(50% - 3px);
  border-radius: 999px;
  background: var(--pill);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08), 0 4px 14px -4px rgba(0, 0, 0, .12);
  transition: transform .5s var(--ease-spring);
}
.modes[data-mode="free"] .mode-pill { transform: translateX(100%); }
.modes[data-mode="none"] .mode-pill { opacity: 0; }

.banner {
  align-self: center;
  margin: 10px auto 0;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  font-size: 12.5px; font-weight: 520;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--present) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--present) 30%, transparent);
  display: flex; align-items: center; gap: 8px;
  max-width: 100%;
}
.banner[hidden] { display: none; }
.banner b { font-weight: 650; color: var(--ink); }
.banner .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--present); box-shadow: 0 0 0 4px color-mix(in srgb, var(--present) 25%, transparent); flex: none; }
.banner button { border: 0; background: none; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; color: var(--ink); font-weight: 600; font-size: 12.5px; padding: 0; }

/* ---------- Tablero ---------- */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid; place-items: center;
  container-type: size;
  padding: 14px 0;
}
.board {
  --tile: min(68px, calc((100cqw - 4 * var(--gap)) / 5), calc((100cqh - 5 * var(--gap)) / 6));
  display: grid;
  grid-template-rows: repeat(6, var(--tile));
  gap: var(--gap);
  perspective: 1200px;
}
.row {
  display: grid;
  grid-template-columns: repeat(5, var(--tile));
  gap: var(--gap);
}
.row.shake { animation: shake .5s cubic-bezier(.36, .07, .19, .97); }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(3px); }
  30%, 50%, 70% { transform: translateX(-6px); }
  40%, 60% { transform: translateX(6px); }
}

.tile {
  position: relative;
  width: var(--tile); height: var(--tile);
  transform-style: preserve-3d;
  animation: tileIn .7s var(--ease-out) both;
  animation-delay: calc(var(--r) * 45ms + var(--c) * 25ms + 250ms);
}
@keyframes tileIn { from { opacity: 0; transform: translateY(14px) scale(.94); } to { opacity: 1; transform: none; } }

.tile .face {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: calc(var(--tile) * .54);
  font-variation-settings: "opsz" 72, "SOFT" 50;
  line-height: 1;
  text-transform: uppercase;
  user-select: none;
}
.tile .front {
  background: var(--tile-bg);
  box-shadow: inset 0 0 0 1.5px var(--tile-border), var(--shadow-tile);
  color: var(--ink);
  transition: box-shadow .15s var(--ease-out);
}
.tile .back {
  transform: rotateX(180deg);
  color: var(--on-color);
  background: var(--absent);
}
.tile .back::before {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: linear-gradient(180deg, rgba(255, 255, 255, .16), rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, .06));
  pointer-events: none;
}
.tile[data-state="correct"] .back { background: var(--correct); box-shadow: 0 10px 22px -12px var(--correct-2); }
.tile[data-state="present"] .back { background: var(--present); box-shadow: 0 10px 22px -12px var(--present-2); }
.tile[data-state="absent"] .back { background: var(--absent); }

.tile.filled .front { box-shadow: inset 0 0 0 2px var(--tile-filled), var(--shadow-tile); }
.tile.pop .front { animation: pop .14s var(--ease-out); }
@keyframes pop { 0% { transform: scale(.9); } 55% { transform: scale(1.08); } 100% { transform: scale(1); } }

.tile.flip { animation: flip .62s var(--ease-out) both; animation-delay: var(--d, 0ms); }
.tile.revealed { transform: rotateX(180deg); animation: none; }
@keyframes flip {
  0% { transform: rotateX(0); }
  100% { transform: rotateX(180deg); }
}
.tile.win { animation: win .9s var(--ease-out) both; animation-delay: var(--d, 0ms); transform: rotateX(180deg); }
@keyframes win {
  0% { transform: rotateX(180deg) translateY(0); }
  30% { transform: rotateX(180deg) translateY(22px); }
  55% { transform: rotateX(180deg) translateY(-6px); }
  75% { transform: rotateX(180deg) translateY(3px); }
  100% { transform: rotateX(180deg) translateY(0); }
}

.row.current .tile:not(.filled) .front { box-shadow: inset 0 0 0 1.5px var(--tile-border), var(--shadow-tile); }
.row.current .tile.cursor .front::after {
  content: ""; position: absolute; bottom: 18%; left: 50%;
  width: 28%; height: 2px; border-radius: 2px;
  background: var(--ink);
  transform: translateX(-50%);
  animation: caret 1.1s steps(1) infinite;
  opacity: .5;
}
@keyframes caret { 50% { opacity: 0; } }

/* ---------- Teclado ---------- */
.keyboard {
  display: grid; gap: 7px;
  padding: 4px 0 max(10px, env(safe-area-inset-bottom));
  user-select: none;
  touch-action: manipulation;
  animation: kbIn .9s .5s var(--ease-out) both;
}
@keyframes kbIn { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.kb-row { display: flex; gap: 5px; justify-content: center; }
.key {
  --kc: var(--key);
  flex: 1 1 0; min-width: 0;
  height: clamp(48px, 7.4dvh, 58px);
  border: 0; border-radius: 9px; padding: 0;
  background: var(--kc);
  color: var(--key-ink);
  font-family: var(--font-ui);
  font-size: 15px; font-weight: 620;
  letter-spacing: .01em;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 1px 0 color-mix(in srgb, var(--ink) 10%, transparent), inset 0 1px 0 rgba(255, 255, 255, .25);
  transition: background-color .45s var(--ease-out), color .45s var(--ease-out), transform .12s var(--ease-out), box-shadow .2s;
  -webkit-user-select: none;
}
.key.wide { flex: 1.55 1 0; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; font-weight: 650; }
.key svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linejoin: round; stroke-linecap: round; }
@media (hover: hover) { .key:hover { filter: brightness(.97); } }
.key:active, .key.pressed { transform: translateY(1px) scale(.95); box-shadow: none; }
.key[data-state="correct"] { --kc: var(--correct); color: var(--on-color); }
.key[data-state="present"] { --kc: var(--present); color: var(--on-color); }
.key[data-state="absent"] { --kc: var(--absent); color: var(--on-color); }
:root[data-theme="dark"] .key[data-state="absent"] { color: color-mix(in srgb, var(--ink) 40%, transparent); }
@media (prefers-color-scheme: dark) { :root[data-theme="auto"] .key[data-state="absent"] { color: color-mix(in srgb, var(--ink) 40%, transparent); } }
.key.enter { background: var(--ink); color: var(--bg); }
.key.enter.ready { animation: ready 1.6s var(--ease-out) infinite; }
@keyframes ready {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ink) 35%, transparent); }
  70%, 100% { box-shadow: 0 0 0 9px transparent; }
}

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 60; left: 50%; top: calc(118px + env(safe-area-inset-top));
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px);
}
.toast {
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--ink); color: var(--bg);
  font-size: 14px; font-weight: 600; letter-spacing: -.005em;
  box-shadow: var(--shadow-lg);
  animation: toastIn .45s var(--ease-spring) both;
  text-align: center;
}
.toast.big {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 20px; font-weight: 520;
  font-variation-settings: "opsz" 72, "SOFT" 100, "WONK" 1;
  padding: 12px 24px;
}
.toast.out { animation: toastOut .35s var(--ease-out) both; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.92); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-6px) scale(.97); } }

.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 70; }

/* ---------- Diálogos ---------- */
dialog.sheet {
  border: 0; padding: 0;
  background: transparent; color: var(--ink);
  width: min(460px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  overflow: visible;
}
dialog.sheet::backdrop {
  background: color-mix(in srgb, var(--bg) 55%, transparent);
  backdrop-filter: blur(10px) saturate(1.1);
  -webkit-backdrop-filter: blur(10px) saturate(1.1);
  animation: fade .35s var(--ease-out);
}
dialog.sheet[open] .sheet-inner { animation: sheetIn .55s var(--ease-spring) both; }
dialog.sheet.closing .sheet-inner { animation: sheetOut .25s var(--ease-out) both; }
dialog.sheet.closing::backdrop { animation: fade .25s reverse both; }
@keyframes sheetIn { from { opacity: 0; transform: translateY(24px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes sheetOut { to { opacity: 0; transform: translateY(12px) scale(.98); } }

.sheet-inner {
  position: relative;
  max-height: calc(100dvh - 32px);
  overflow: auto;
  overscroll-behavior: contain;
  padding: 30px 26px 26px;
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow-lg), inset 0 0 0 1px color-mix(in srgb, var(--ink) 6%, transparent);
  scrollbar-width: thin;
}
.close {
  position: absolute; top: 14px; right: 14px;
  width: 38px; height: 38px; border-radius: 50%;
  border: 0; background: color-mix(in srgb, var(--ink) 6%, transparent);
  display: grid; place-items: center; cursor: pointer;
  transition: background-color .2s, transform .3s var(--ease-spring);
}
.close:hover { background: color-mix(in srgb, var(--ink) 11%, transparent); transform: rotate(90deg); }
.close svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }

.eyebrow {
  margin: 0 0 10px;
  font-size: 10.5px; font-weight: 640;
  letter-spacing: .16em; text-transform: uppercase;
  color: var(--muted);
}
.display {
  margin: 0 0 18px;
  font-family: var(--font-display);
  font-weight: 520;
  font-size: 32px;
  line-height: 1.02;
  letter-spacing: -.03em;
  font-variation-settings: "opsz" 144, "SOFT" 40;
}
.display em { font-style: italic; color: var(--ink-2); font-variation-settings: "opsz" 144, "SOFT" 100, "WONK" 1; }
.display.small { font-size: 22px; margin-bottom: 8px; }

.rules { margin: 0 0 20px; padding: 0; list-style: none; display: grid; gap: 10px; }
.rules li { position: relative; padding-left: 20px; font-size: 14.5px; line-height: 1.5; color: var(--ink-2); }
.rules li::before { content: ""; position: absolute; left: 2px; top: .62em; width: 7px; height: 7px; border-radius: 2px; background: var(--line-strong); transform: rotate(45deg); }
.rules strong { color: var(--ink); font-weight: 650; }
kbd {
  font-family: var(--font-ui); font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  padding: 2px 6px; border-radius: 5px; background: var(--ink); color: var(--bg);
}

.examples { display: grid; gap: 16px; padding: 18px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ex p { margin: 8px 0 0; font-size: 13.5px; color: var(--ink-2); }
.ex-row { --tile: 40px; display: flex; gap: 5px; perspective: 800px; }
.ex-row .tile { animation: none; }
.ex-row .face { font-size: 21px; border-radius: 9px; }

.fine { font-size: 13px; line-height: 1.55; color: var(--muted); margin: 16px 0 20px; }
.fine strong { color: var(--ink-2); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 46px; padding: 0 20px;
  border-radius: 999px; border: 0; cursor: pointer;
  font-size: 14.5px; font-weight: 620; letter-spacing: -.005em;
  text-decoration: none;
  transition: transform .2s var(--ease-out), background-color .2s, box-shadow .2s, filter .2s;
  white-space: nowrap;
}
.btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--ink); color: var(--bg); box-shadow: 0 8px 20px -10px color-mix(in srgb, var(--ink) 70%, transparent); }
.btn.primary:hover { filter: brightness(1.15); }
.btn.ghost { background: color-mix(in srgb, var(--ink) 6%, transparent); color: var(--ink); }
.btn.ghost:hover { background: color-mix(in srgb, var(--ink) 11%, transparent); }
.btn.wide { width: 100%; }

/* Resultado */
.result { text-align: center; padding: 4px 0 22px; margin-bottom: 22px; border-bottom: 1px solid var(--line); }
.result[hidden] { display: none; }
.reveal-word {
  display: flex; justify-content: center; gap: 6px;
  margin: 6px 0 14px;
  perspective: 800px;
}
.reveal-word .tile { --tile: 50px; animation: none; }
.reveal-word .face { font-size: 27px; }
.reveal-word .tile.flip { animation: flip .62s var(--ease-out) both; animation-delay: var(--d, 0ms); }
.result-line {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-size: 19px; font-style: italic; font-weight: 450;
  font-variation-settings: "opsz" 72, "SOFT" 100, "WONK" 1;
  color: var(--ink-2);
}
.result-line b { font-style: normal; font-weight: 620; color: var(--ink); }
.result-actions { display: flex; justify-content: center; gap: 8px; }
.result-actions .btn { height: 38px; font-size: 13px; padding: 0 16px; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 26px; }
.stat { text-align: center; }
.stat b {
  display: block;
  font-family: var(--font-display);
  font-size: 38px; font-weight: 480; line-height: 1;
  letter-spacing: -.03em;
  font-variation-settings: "opsz" 144;
  font-variant-numeric: lining-nums tabular-nums;
}
.stat span { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); font-weight: 520; line-height: 1.25; }

.dist { list-style: none; margin: 0 0 24px; padding: 0; display: grid; gap: 6px; }
.dist li { display: grid; grid-template-columns: 14px 1fr; align-items: center; gap: 10px; font-size: 13px; font-weight: 620; font-variant-numeric: tabular-nums; }
.dist .bar {
  --w: 0;
  height: 24px; min-width: 30px;
  width: calc(8% + var(--w) * 92%);
  display: flex; align-items: center; justify-content: flex-end;
  padding: 0 9px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--ink) 12%, transparent);
  color: var(--ink);
  font-size: 12.5px;
  transform-origin: left center;
  animation: barIn .9s var(--ease-out) both;
  animation-delay: calc(var(--i) * 60ms + 150ms);
}
.dist .bar.hit { background: var(--correct); color: var(--on-color); }
@keyframes barIn { from { transform: scaleX(.05); opacity: 0; } to { transform: none; opacity: 1; } }

.footer-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding-top: 20px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.countdown .eyebrow { margin-bottom: 4px; display: block; }
.countdown time {
  font-family: var(--font-display);
  font-size: 30px; font-weight: 450; letter-spacing: -.01em;
  font-variant-numeric: tabular-nums lining-nums;
  font-variation-settings: "opsz" 72;
}
.countdown[hidden] { display: none; }
.footer-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Ajustes */
.settings { display: grid; margin-bottom: 26px; }
.setting {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.setting:first-child { border-top: 1px solid var(--line); cursor: default; }
.setting strong { display: block; font-size: 14.5px; font-weight: 620; }
.setting span { display: block; font-size: 12.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }

.switch {
  appearance: none; -webkit-appearance: none;
  flex: none;
  width: 46px; height: 28px; margin: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 15%, transparent);
  position: relative; cursor: pointer;
  transition: background-color .3s var(--ease-out);
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: transform .4s var(--ease-spring);
}
.switch:checked { background: var(--correct); }
.switch:checked::after { transform: translateX(18px); }

.seg { display: flex; padding: 3px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 7%, transparent); flex: none; }
.seg button { border: 0; background: none; cursor: pointer; padding: 6px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 580; color: var(--muted); transition: all .3s var(--ease-out); }
.seg button[aria-checked="true"] { background: var(--pill); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }

.challenge {
  padding: 22px 20px 20px;
  border-radius: 18px;
  background:
    radial-gradient(120% 120% at 100% 0%, color-mix(in srgb, var(--present) 16%, transparent), transparent 55%),
    color-mix(in srgb, var(--ink) 4%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ink) 6%, transparent);
}
.challenge .fine { margin: 0 0 14px; }
.challenge-form, .challenge-out { display: flex; gap: 8px; }
.challenge-out { margin-top: 10px; }
.challenge-out[hidden] { display: none; }
.challenge input {
  flex: 1; min-width: 0; height: 46px;
  padding: 0 16px;
  border: 0; border-radius: 999px;
  background: var(--surface);
  box-shadow: inset 0 0 0 1.5px var(--line);
  color: var(--ink);
  font: 600 16px/1 var(--font-ui);
  letter-spacing: .14em; text-transform: uppercase;
  transition: box-shadow .2s;
}
.challenge input#challenge-url { font-size: 12.5px; letter-spacing: 0; text-transform: none; font-weight: 500; color: var(--ink-2); }
.challenge input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--ink); }
.challenge input::placeholder { color: var(--muted); letter-spacing: .06em; font-weight: 500; }

.colophon { margin: 22px 0 0; font-size: 11.5px; line-height: 1.6; color: var(--muted); text-align: center; }

.noscript { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 99; font-family: var(--font-display); font-size: 22px; }

/* ---------- Modo pizarra ---------- */
:root.board-mode { --maxw: 980px; --gap: 10px; --radius: 16px; }
:root.board-mode .board { --tile: min(104px, calc((100cqw - 4 * var(--gap)) / 5), calc((100cqh - 5 * var(--gap)) / 6)); }
:root.board-mode .key { height: clamp(48px, 7dvh, 70px); font-size: 22px; border-radius: 12px; }
:root.board-mode .key.wide { font-size: 15px; }
:root.board-mode .kb-row { gap: 8px; }
:root.board-mode .keyboard { gap: 9px; max-width: 720px; width: 100%; margin: 0 auto; }
:root.board-mode .brand { font-size: 52px; }
:root.board-mode .dateline { font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 360px) {
  .key { font-size: 13.5px; border-radius: 7px; }
  .kb-row { gap: 4px; }
  .key.wide { font-size: 10.5px; letter-spacing: .02em; }
  .dateline .dl-school, .dateline .dl-sep1 { display: none; }
  .sheet-inner { padding: 26px 18px 20px; }
  .stat b { font-size: 32px; }
}
@media (max-height: 640px) {
  .top { padding-top: 6px; }
  .modes { margin-top: 8px; }
  .dateline { padding-bottom: 7px; }
  .key { height: 44px; }
}
@media (min-width: 768px) and (min-height: 760px) {
  .top { padding-top: 26px; }
}

/* ---------- Movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
  .aura i { animation: none; }
  .tile.flip, .tile.win { transform: rotateX(180deg); }
}
.sheet-inner:focus { outline: none; }
#stats-block[hidden] { display: none; }
.result:last-child, .result.solo { border-bottom: 0; margin-bottom: 0; }
.footer-actions { flex: 1 1 260px; }
.footer-actions .btn { flex: 1 1 0; }
.footer-actions .btn[hidden] { display: none; }

/* ---------- Ranking de clases ---------- */
.top-left { display: flex; gap: 2px; }
.icon-btn[hidden] { display: none; }
.setting[hidden], .rank-note[hidden] { display: none; }

.select {
  appearance: none; -webkit-appearance: none;
  flex: none; max-width: 52%;
  height: 40px; padding: 0 34px 0 14px;
  border: 0; border-radius: 999px;
  background: color-mix(in srgb, var(--ink) 7%, transparent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238C8577' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E") no-repeat right 12px center / 16px;
  color: var(--ink);
  font: 600 13.5px/1 var(--font-ui);
  cursor: pointer;
  text-overflow: ellipsis;
}
.select:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.select option { color: #1C1A16; background: #FBF8F2; }

.rank-note {
  margin: 18px auto 0;
  max-width: 360px;
  display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--present) 13%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--present) 28%, transparent);
  font-size: 13.5px; color: var(--ink-2);
  animation: rise .7s .4s var(--ease-out) both;
}
.rank-note b { color: var(--ink); font-weight: 650; }
.rank-note label { width: 100%; font-weight: 560; }
.rank-note .select { max-width: 100%; background-color: var(--surface); }
.link { border: 0; background: none; padding: 0; cursor: pointer; font-weight: 650; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-size: 13.5px; }

.rank-seg { width: 100%; margin-bottom: 18px; }
.rank-seg button { flex: 1; padding: 8px 6px; }

.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; min-height: 120px; }
.rank-row {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 12px;
  padding: 10px 12px 10px 6px;
  border-radius: 14px;
  animation: rise .6s var(--ease-out) both;
  animation-delay: calc(var(--i) * 40ms);
}
.rank-row.mine { background: color-mix(in srgb, var(--correct) 10%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--correct) 30%, transparent); }
.rank-row.idle { opacity: .5; }
.rank-pos {
  text-align: center;
  font-family: var(--font-display); font-size: 22px; font-weight: 520;
  font-variant-numeric: lining-nums tabular-nums;
  font-variation-settings: "opsz" 72; color: var(--muted);
}
.rank-row:nth-child(-n+3):not(.idle) .rank-pos {
  width: 30px; height: 30px; margin: 0 auto; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 16px; font-weight: 640; color: var(--on-color);
}
.rank-row:nth-child(1):not(.idle) .rank-pos { background: var(--present); box-shadow: 0 6px 14px -6px var(--present-2); }
.rank-row:nth-child(2):not(.idle) .rank-pos { background: #9C9A92; }
.rank-row:nth-child(3):not(.idle) .rank-pos { background: #B07A4E; }
.rank-name { font-size: 15px; font-weight: 640; display: flex; align-items: center; gap: 8px; }
.rank-name .tag { font-style: normal; font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; padding: 3px 7px; border-radius: 999px; background: var(--correct); color: var(--on-color); }
.rank-bar { height: 5px; margin: 7px 0 6px; border-radius: 999px; background: color-mix(in srgb, var(--ink) 7%, transparent); overflow: hidden; }
.rank-bar i { display: block; height: 100%; width: calc(var(--w) * 100%); border-radius: inherit; background: var(--correct); transform-origin: left; animation: barIn 1s var(--ease-out) both; animation-delay: calc(var(--i) * 40ms + 200ms); }
.rank-meta { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.rank-pts { text-align: right; font-family: var(--font-display); font-size: 26px; font-weight: 500; letter-spacing: -.02em; font-variant-numeric: lining-nums tabular-nums; font-variation-settings: "opsz" 72; line-height: 1; }
.rank-pts small { display: block; margin-top: 3px; font-family: var(--font-ui); font-size: 10px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.rank-skel { height: 58px; border-radius: 14px; background: linear-gradient(90deg, color-mix(in srgb, var(--ink) 5%, transparent) 0 40%, color-mix(in srgb, var(--ink) 9%, transparent) 50%, color-mix(in srgb, var(--ink) 5%, transparent) 60% 100%) 0 0 / 300% 100%; animation: skel 1.4s linear infinite; }
@keyframes skel { to { background-position: -150% 0; } }
.rank-empty { padding: 30px 10px; text-align: center; color: var(--muted); font-size: 14px; line-height: 1.5; }
.rank-help { margin-bottom: 0; }

:root.board-mode #dlg-rank { width: min(760px, calc(100vw - 24px)); }
:root.board-mode .rank-name { font-size: 20px; }
:root.board-mode .rank-pts { font-size: 34px; }
:root.board-mode .rank-pos { font-size: 28px; }
.toasts[popover] { inset: auto; left: 50%; top: calc(118px + env(safe-area-inset-top)); margin: 0; padding: 0; border: 0; background: none; overflow: visible; color: inherit; }
.rank-idle { margin-top: 10px; padding: 14px 4px 0; border-top: 1px solid var(--line); font-size: 12.5px; line-height: 1.6; color: var(--muted); animation: rise .6s var(--ease-out) both; animation-delay: calc(var(--i) * 40ms); }
.rank-idle b { color: var(--ink-2); font-weight: 620; }
.rank-idle strong { color: var(--correct); }
.rank-list { transition: opacity .3s var(--ease-out); }
.rank-list.is-updating { opacity: .55; }
