/* AXIS: Kinetic Tension — capa visual W2.
   Style Bible v1.0 es LEY: tokens hex exactos (asserts del smoke), jerarquía
   luminosa (nada brilla más que un tether), oro EXCLUSIVO de .core/.genius,
   z-order como tokens. prefers-reduced-motion va AL FINAL de la cascada
   (invariante, bug pagado en FADE). */

:root {
  /* ── paleta 3+1 (Style Bible §2 — TESTS, no sugerencias) ── */
  --bg-deep:   #070B14;
  --bg-board:  #0D1322;
  --grid-line: #1A2338;
  --block:     #2A3654;
  --block-edge:#3D4E78;
  --peg:       #8E9FC9;
  --peg-dot:   #D5DEF5;
  --tether:    #5CE1FF;
  --tether-hot:#FFFFFF;
  --gold:      #FFC83D;
  --danger:    #FF4D5E;
  --text-hi:   #C9D4EE;
  --text-lo:   #5A6A8C;
  /* ── constantes de identidad con assert (§3/§6) ── */
  --pulse-core: 2.4s;
  --vib-amp: 1px;
  --vib-freq: 8;
  /* ── z-order como tokens (§9, anti-erosión CD) ── */
  --z-board: 10;
  --z-canvas-tethers: 20;
  --z-scorepops: 30;
  --z-hud: 40;
  --z-overlay: 50;
  --z-genius: 52;
  /* geometría fluida (JS fija --cell en px al medir el viewport) */
  --cell: 46px;
  --slotw: 30px;
  --font-display: "Archivo Black", "Arial Black", "Helvetica Neue", sans-serif;
  --font-ui: "Inter", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg-deep);
  /* nebulosa sutil — MUY por debajo del umbral del glance gate (media <40) */
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(142,159,201,.20), transparent 100%),
    radial-gradient(1px 1px at 78% 9%,  rgba(142,159,201,.14), transparent 100%),
    radial-gradient(1.5px 1.5px at 88% 64%, rgba(142,159,201,.12), transparent 100%),
    radial-gradient(1px 1px at 30% 82%, rgba(142,159,201,.14), transparent 100%),
    radial-gradient(1px 1px at 55% 38%, rgba(142,159,201,.10), transparent 100%),
    radial-gradient(60% 30% at 75% 30%, rgba(42,54,84,.14), transparent 100%);
  color: var(--text-hi);
  font: 15px/1.4 var(--font-ui);
  overflow: hidden;
  user-select: none;
}
.hidden { display: none !important; }

#app {
  height: 100%; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) 0 max(8px, env(safe-area-inset-bottom));
}

/* ── HUD ultrafino (§4: mínimo absoluto; --text-hi pierde contra el tether EN GRIS) ── */
#hud-top {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 6px 22px 10px; border-bottom: 1px solid var(--grid-line);
  font-family: var(--font-display); font-size: 17px; letter-spacing: .14em;
  color: var(--text-hi); z-index: var(--z-hud); position: relative;
  white-space: nowrap;
}
#hud-top b { font-weight: 900; color: var(--text-hi); }
#gametitle { color: var(--text-lo); }
#gametitle b { color: var(--text-hi); margin-left: 2px; }
#streak { color: var(--text-lo); margin-left: 12px; display: inline-flex; align-items: center; gap: 3px; font-size: 14px; }
#movesline { color: var(--text-lo); font-size: 15px; }
#movesline b { font-size: 17px; }

#guide {
  min-height: 22px; text-align: center; padding: 8px 24px 0;
  color: var(--text-hi); font-size: 14.5px; letter-spacing: .04em;
  z-index: var(--z-hud); position: relative;
}

/* ── escenario ── */
/* el tablero al centro ÓPTICO: leve sesgo hacia abajo evita la banda muerta
   inferior en viewports altos (composición A — objeción AD) */
#stage { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; padding-top: 4vh; }
#wrap {
  position: relative; z-index: var(--z-board);
  display: grid;
  grid-template-columns: var(--slotw) calc(var(--cell) * 7) var(--slotw);
  grid-template-rows: var(--slotw) calc(var(--cell) * 7) var(--slotw);
}
#board {
  position: relative; display: grid;
  grid-template-columns: repeat(7, var(--cell));
  grid-template-rows: repeat(7, var(--cell));
  background: var(--bg-board);
  border: 1px solid var(--grid-line);
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(26,35,56,.5), 0 18px 50px rgba(0,0,0,.5);
}
/* celdas: línea de grid sutil + punto de intersección (mockup A) */
.c { position: relative; border-right: 1px solid var(--grid-line); border-bottom: 1px solid var(--grid-line); }
.c:nth-child(7n) { border-right: none; }
.c:nth-child(n+43) { border-bottom: none; }
.c::before {
  content: ''; position: absolute; right: -2px; bottom: -2px; width: 3px; height: 3px;
  border-radius: 50%; background: rgba(142,159,201,.28); z-index: 1;
}
.c:nth-child(7n)::before, .c:nth-child(n+43)::before { display: none; }

.c > i { position: absolute; inset: 0; display: block; }

/* bloque obstáculo: denso, volumen sutil, borde luminoso frío (§3) */
.c.block > i {
  inset: 9%; border-radius: 14%;
  background: linear-gradient(180deg, #33416680 0%, var(--block) 45%, #232D47 100%);
  background-color: var(--block);
  border: 1px solid var(--block-edge);
  box-shadow: inset 0 2px 3px rgba(255,255,255,.10), inset 0 -3px 6px rgba(0,0,0,.35),
              0 3px 8px rgba(0,0,0,.45);
}

/* núcleo: ROMBO 45° canónico, oro EXCLUSIVO, pulso lento --pulse-core (§3).
   Área ≈80% de la del bloque (los vértices asoman apenas de la celda, como en
   el mockup) — y luminoso: en el vistazo 100×100 el oro debe sobrevivir. */
.c.core > i {
  inset: 14%; border-radius: 0;
  transform: rotate(45deg) scale(1.02);
  background:
    linear-gradient(135deg, #FFF0B8 0%, #FFD968 30%, var(--gold) 55%, #E09B18 80%, #C08414 100%);
  box-shadow:
    inset 0 0 0 1px rgba(255,240,185,.9),
    inset 3px 3px 7px rgba(255,248,215,.7),
    inset -4px -4px 9px rgba(150,95,10,.5),
    0 0 calc(var(--cell) * .34) rgba(255,200,61,.5);
  animation: corePulse var(--pulse-core) ease-in-out infinite;
}
/* facetado interior de la gema (mockup A) */
.c.core > i::after {
  content: ''; position: absolute; inset: 20%;
  background: linear-gradient(135deg, rgba(255,248,220,.95), rgba(255,216,104,.4) 55%, transparent);
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
@keyframes corePulse {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.22); }
}

/* peg: cilindro visto desde arriba — metal frío, anillo, punto interior (§3) */
.c.peg > i {
  inset: 12%; border-radius: 50%;
  background: radial-gradient(circle at 36% 32%, #C3CFE8 0%, var(--peg) 42%, #5F7099 78%, #46557E 100%);
  border: 1px solid #A9B8DC;
  box-shadow: inset 0 2px 4px rgba(255,255,255,.35), inset 0 -3px 6px rgba(20,28,50,.55),
              0 3px 9px rgba(0,0,0,.5);
}
.c.peg > i::before {
  content: ''; position: absolute; inset: 18%; border-radius: 50%;
  border: 1px solid rgba(70,85,126,.8);
}
.c.peg > i::after {
  content: ''; position: absolute; inset: 36%; border-radius: 50%;
  background: #6F80A8; transition: background .3s, box-shadow .3s;
}
/* peg sosteniendo tether: punto interior encendido con respiración lenta (§6)
   — MENOS brillante que el tether también en gris (--peg-dot) */
.c.peg.lit > i::after {
  background: var(--peg-dot);
  box-shadow: 0 0 7px rgba(213,222,245,.8);
  animation: pegBreath 2.8s ease-in-out infinite;
}
@keyframes pegBreath { 0%,100% { opacity: .75; } 50% { opacity: 1; } }

/* peg fantasma del ghost (35% — §3) */
.c.ghostpeg > i {
  inset: 12%; border-radius: 50%; opacity: .35;
  border: 2px dashed var(--peg);
}

/* recoil del acto 2 (JS fija --rx/--ry) */
.c.peg.recoil > i { transform: translate(var(--rx, 0), var(--ry, 0)); transition: transform .09s ease-out; }

/* vaporización (corte 120ms: escala 1→1.06→0 §5) */
.c.vapor > i { animation: vaporize .12s ease-in forwards; }
@keyframes vaporize {
  0% { transform: scale(1); opacity: 1; filter: brightness(1.6); }
  45% { transform: scale(1.06); opacity: .95; filter: brightness(2.2); }
  100% { transform: scale(.1); opacity: 0; filter: brightness(2.6); }
}
.c.core.vapor > i { animation: vaporizeCore .3s ease-in forwards; }
@keyframes vaporizeCore {
  0% { transform: rotate(45deg) scale(.78); opacity: 1; filter: brightness(1.4); }
  40% { transform: rotate(45deg) scale(.95); opacity: 1; filter: brightness(2.4); }
  100% { transform: rotate(45deg) scale(.05); opacity: 0; filter: brightness(3); }
}

/* ── slots perimetrales: muescas triangulares hacia adentro (§3) ── */
.slotrow { display: flex; } .slotcol { display: flex; flex-direction: column; }
.slot {
  width: var(--cell); height: var(--slotw); position: relative; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.slotcol .slot { width: var(--slotw); height: var(--cell); }
.slot > i {
  display: block; width: 34%; aspect-ratio: 1;
  background: #35507A;
  transition: background .25s, filter .25s;
}
.slotrow .slot > i { width: 38%; }
.slotcol .slot > i { height: 38%; width: 34%; aspect-ratio: auto; }
#slots-top    .slot > i { clip-path: polygon(0 0, 100% 0, 50% 100%); align-self: end; margin-bottom: 3px; }
#slots-bottom .slot > i { clip-path: polygon(0 100%, 100% 100%, 50% 0); align-self: start; margin-top: 3px; }
#slots-left   .slot > i { clip-path: polygon(0 0, 0 100%, 100% 50%); justify-self: end; margin-left: 12px; }
#slots-right  .slot > i { clip-path: polygon(100% 0, 100% 100%, 0 50%); margin-right: 12px; margin-left: auto; }
/* legal: tenue pulso cian al ritmo de "tu turno" (§6) — por DEBAJO del tether en gris */
.slot.legal > i {
  background: #4E93B8;
  filter: drop-shadow(0 0 4px rgba(92,225,255,.35));
  animation: slotPulse 2.2s ease-in-out infinite;
}
.slot.illegal { cursor: default; }
.slot.illegal > i { background: #1C2740; filter: none; animation: none; }
@keyframes slotPulse {
  0%, 100% { opacity: .55; } 50% { opacity: .95; }
}
/* guía muda del FTUE: slot que late más fuerte */
.slot.hint > i { animation: slotHint 1s ease-in-out infinite; background: #63B8DC; }
@keyframes slotHint {
  0%, 100% { opacity: .5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.35); filter: drop-shadow(0 0 8px rgba(92,225,255,.7)); }
}
.corner { width: var(--slotw); height: var(--slotw); }

/* ── canvas de tethers/partículas: una sola capa (§9) ── */
#fx { position: absolute; inset: 0; pointer-events: none; z-index: var(--z-canvas-tethers); }

/* ── scorepops por carriles --lx (patrón FADE, sin solape) ── */
#pops { position: absolute; inset: 0; pointer-events: none; z-index: var(--z-scorepops); }
.scorepop {
  position: absolute; left: 50%; width: max-content;
  font-family: var(--font-display); font-size: 24px; font-weight: 900;
  color: var(--text-hi); text-shadow: 0 0 12px rgba(92,225,255,.45), 0 2px 4px rgba(0,0,0,.6);
  --lx: 0px;
  animation: spop 1s ease-out forwards;
}
.scorepop.big { font-size: 30px; color: #EAF6FF; }
@keyframes spop {
  0%   { opacity: 0; transform: translate(calc(-50% + var(--lx)), 8px) scale(.7); }
  18%  { opacity: 1; transform: translate(calc(-50% + var(--lx)), 0) scale(1.1); }
  100% { opacity: 0; transform: translate(calc(-50% + var(--lx)), -52px) scale(1); }
}

/* esquirlas del acto 3 */
.shard {
  position: absolute; z-index: var(--z-scorepops); pointer-events: none;
  background: linear-gradient(160deg, #4A5D8C, #232D47);
  border: 1px solid rgba(61,78,120,.8);
  animation: shardFly .7s cubic-bezier(.2,.5,.6,1) forwards;
}
@keyframes shardFly {
  0% { transform: translate(0,0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

/* ── HUD inferior: reserva (puntos) + score display ── */
#hud-bot {
  position: relative; z-index: var(--z-hud);
  padding: 4px 22px 2px; text-align: center;
}
#reserve { display: flex; justify-content: center; gap: 7px; min-height: 8px; margin-bottom: 8px; }
#reserve i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-lo); opacity: .85;
}
#reserve i.spent { opacity: .22; }
#scoreline { border-top: 1px solid var(--grid-line); margin: 0 8px; }
#score {
  font-family: var(--font-display); font-size: 34px; letter-spacing: .1em;
  color: var(--text-hi); text-shadow: 0 0 18px rgba(92,225,255,.28);
  padding-top: 6px; font-variant-numeric: tabular-nums;
}
#mute {
  position: absolute; right: 14px; bottom: 8px;
  background: none; border: none; color: var(--text-lo); cursor: pointer; padding: 6px;
}

/* ── overlay de resultado (mockup D: panel integrado, botones pill) ── */
#overlay {
  position: fixed; inset: 0; z-index: var(--z-overlay);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(7,11,20,.62);
  backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
  animation: overlayIn .4s ease-out;
}
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
#result-panel { text-align: center; padding: 0 26px; max-width: 420px; width: 100%; }
#result-title {
  font-family: var(--font-display); font-size: 30px; letter-spacing: .12em;
  color: var(--text-hi); text-shadow: 0 0 16px rgba(92,225,255,.35);
}
#result-sub { color: var(--text-lo); font-size: 14px; margin: 10px 0 18px; letter-spacing: .06em; }
#minigrid { display: flex; justify-content: center; gap: 7px; margin-bottom: 26px; min-height: 18px; }
/* tiles del share-preview: SOLO familia de la paleta (cian=circuito el héroe,
   acero=corte limpio, ámbar apagado=corte menor, rojo apagado=setup — sin verde
   ajeno ni oro en UI; el oro queda EXCLUSIVO del sello y los núcleos) */
#minigrid i { width: 17px; height: 17px; border-radius: 4px; display: block; }
#minigrid i.q-circuit { background: linear-gradient(135deg, #B5F1FF, var(--tether)); box-shadow: 0 0 8px rgba(92,225,255,.55); }
#minigrid i.q-clean { background: #8E9FC9; }
#minigrid i.q-rough { background: #7A6230; }
#minigrid i.q-setup { background: #8C3040; }
#result-buttons { display: flex; gap: 14px; justify-content: center; }
.pill {
  font-family: var(--font-display); font-size: 15px; letter-spacing: .1em;
  padding: 13px 26px; min-width: 150px; border-radius: 999px; cursor: pointer;
  background: rgba(13,19,34,.85); color: var(--text-hi);
  border: 1.5px solid var(--text-lo);
  transition: filter .2s, transform .1s;
}
.pill:active { transform: scale(.97); }
.pill.primary {
  border-color: var(--tether); color: #EAF9FF;
  box-shadow: 0 0 14px rgba(92,225,255,.35), inset 0 0 10px rgba(92,225,255,.12);
}

/* ── sello de rank: GENIUS es el ÚNICO momento tipográfico grande (§4) ── */
#seal {
  position: fixed; z-index: var(--z-genius);
  top: 12%; left: 50%;
  font-family: var(--font-display); font-size: 64px; letter-spacing: .04em;
  padding: 6px 24px; border-radius: 10px;
  transform: translateX(-50%) rotate(-8deg);
  animation: sealStamp .45s cubic-bezier(.2,.9,.3,1) forwards;
}
#seal.genius {
  /* estampado metálico duro: oro con veta (gradiente en el texto), borde seco,
     glow contenido — no sticker blando (objeción AD vs mockup-resultado) */
  background:
    linear-gradient(168deg, #FFE9A8 0%, var(--gold) 34%, #D89A1E 52%, #FFDf80 68%, #B37712 100%);
  -webkit-background-clip: text; background-clip: text;
  color: transparent;
  border: 5px solid var(--gold);
  border-radius: 8px;
  text-shadow: none;
  filter: drop-shadow(0 2px 2px rgba(60,35,0,.65));
  box-shadow: inset 0 0 14px rgba(255,200,61,.12), 0 0 16px rgba(255,200,61,.18);
}
#seal.plain {
  color: var(--text-hi); border: 4px solid var(--text-hi);
  font-size: 46px; background: rgba(7,11,20,.55);
  text-shadow: 0 0 18px rgba(92,225,255,.3);
}
@keyframes sealStamp {
  0% { opacity: 0; transform: translateX(-50%) rotate(-8deg) scale(1.6); }
  60% { opacity: 1; transform: translateX(-50%) rotate(-8deg) scale(1.15); }
  100% { opacity: 1; transform: translateX(-50%) rotate(-8deg) scale(1); }
}

/* ── endless: tinte danger de las 2 filas superiores (SOLO endless — §2) ── */
#board.danger::after {
  content: ''; position: absolute; left: 0; right: 0; top: 0;
  height: calc(var(--cell) * 2); pointer-events: none;
  background: linear-gradient(180deg, rgba(255,77,94,.16), transparent);
  border-radius: 10px 10px 0 0;
  animation: dangerBreath 1.6s ease-in-out infinite;
}
@keyframes dangerBreath { 0%,100% { opacity: .65; } 50% { opacity: 1; } }

/* feedback efímero del share */
#btn-share.copied { border-color: #7BE3A8; color: #C9F5DC; box-shadow: 0 0 14px rgba(123,227,168,.3); }

/* fundidos usados por el bloque reduced-motion (declarados ANTES: el @media es el cierre) */
@keyframes vaporFade { to { opacity: 0; } }
@keyframes spopFade { 0% { opacity: 0; } 15% { opacity: 1; } 100% { opacity: 0; } }
@keyframes sealFade { from { opacity: 0; } to { opacity: 1; transform: translateX(-50%) rotate(-8deg); } }

/* ═══════════════════════════════════════════════════════════════════════════
   prefers-reduced-motion — SIEMPRE AL FINAL DE LA CASCADA (invariante FADE §5:
   gana por orden; nada se declara después de este bloque).
   shake→0 y recoil→0 los desactiva también el JS; aquí: sin pulsos ni stamps,
   flashes→fundidos. La vibración del canvas pasa a pulso lento de opacidad
   (lo decide ui.js leyendo matchMedia en vivo). ═══════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  .c.core > i { animation: none; }
  .c.peg.lit > i::after { animation: none; opacity: 1; }
  .slot.legal > i, .slot.hint > i { animation: none; opacity: .8; transform: none; }
  .c.peg.recoil > i { transform: none; transition: none; }
  .c.vapor > i { animation: vaporFade .2s ease-out forwards; }
  .c.core.vapor > i { animation: vaporFade .3s ease-out forwards; }
  .scorepop { animation: spopFade 1s ease-out forwards; }
  .shard { animation: none; opacity: 0; }
  #seal { animation: sealFade .45s ease-out forwards; }
  #board.danger::after { animation: none; opacity: .8; }
  #overlay { animation: none; }
}
