/* =====================================================================
   THE VOLATILE ARENA - tema "tele CRT + RPG pixel"
   Las fuentes van incluidas en /fonts (SIL Open Font License, ver fonts/OFL-*.txt)
   para que el juego funcione tambien abriendo index.html sin conexion.
   ===================================================================== */

@font-face {
  font-family: 'Press Start 2P';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/press-start-2p-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'VT323';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/vt323-latin.woff2') format('woff2');
}

:root {
  --font-pixel: 'Press Start 2P', 'Courier New', monospace;
  --font-crt: 'VT323', 'Courier New', monospace;

  /* Pantalla y marco de la tele */
  --bezel: 7px;
  --screen-r: 18px;
  --bezel-color: #121216;

  /* Paleta 16 bits */
  --bg: #07071a;
  --ink: #08070f;
  --win-1: #3049b6;
  --win-2: #263c9f;
  --win-3: #1d2f86;
  --win-4: #16246d;
  --deep-1: #1b2672;
  --deep-2: #151e5c;
  --deep-3: #10174a;
  --frame: #eef0ff;
  --frame-shade: #8d96d8;
  --well: #0a0f38;
  --text: #f6f3e8;
  --muted: #a9b4f0;
  --accent: #ffd84a;
  --accent-dark: #8a5a00;
  --accent-2: #63f0ff;
  --hp-full: #4be36b;
  --hp-mid: #ffc83d;
  --hp-low: #ff4d4d;
  --black-suit: #17162b;
  --red-suit: #d0202e;
  --coin: #ffd84a;
  --card-face: #f7efd9;
  --card-line: #d6c49a;

  /* Unidad de pixel de los bordes (cada componente la ajusta) */
  --u: 3px;
}

* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  background: var(--bezel-color);
  scrollbar-color: #3a3a4a var(--bezel-color);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-crt);
  font-size: 21px;
  line-height: 1.15;
  background-color: var(--bg);
  /* Suelo de mazmorra muy tenue + resplandor del tubo */
  background-image:
    radial-gradient(ellipse 80% 55% at 50% 0%, rgba(84, 98, 255, 0.18), transparent 70%),
    repeating-conic-gradient(rgba(255, 255, 255, 0.022) 0 25%, transparent 0 50%);
  background-size: auto, 48px 48px;
  background-attachment: fixed;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: grayscale;
}

img.px-sprite { image-rendering: pixelated; image-rendering: crisp-edges; display: inline-block; vertical-align: middle; }
img.px-sprite.px-sm { width: 36px; height: 36px; }
img.px-sprite.px-md { width: 40px; height: 40px; }
img.px-sprite.px-lg { width: 112px; height: 112px; }
.px-emoji { display: inline-block; line-height: 1; vertical-align: middle; }
.px-emoji.px-sm { font-size: 26px; }
.px-emoji.px-md { font-size: 30px; }
.px-emoji.px-lg { font-size: 96px; }

/* Ligera aberracion cromatica del tubo sobre todo el texto */
#app {
  max-width: 1500px; margin: 0 auto;
  padding: calc(var(--bezel) + 10px) calc(var(--bezel) + 12px) calc(var(--bezel) + 48px);
  text-shadow: 0.6px 0 0 rgba(255, 40, 90, 0.28), -0.6px 0 0 rgba(40, 190, 255, 0.28);
}

::selection { background: var(--accent); color: var(--ink); }

/* =====================================================================
   Marcos pixel: contorno con esquinas escalonadas hecho con sombras
   (--fr = marco claro, --ol = contorno oscuro, --u = tamano de pixel)
   ===================================================================== */

.px-window,
#setup-screen, #action-panel, .player-chip, .modal, #log-panel,
#coach-panel, .coach-line, .fx-banner, .fx-stage {
  --fr: var(--frame);
  --ol: var(--ink);
  --in: rgba(4, 6, 30, 0.55);
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--fr),
    0 var(--u) 0 0 var(--fr),
    calc(var(--u) * -1) 0 0 0 var(--fr),
    var(--u) 0 0 0 var(--fr),
    calc(var(--u) * -1) calc(var(--u) * -1) 0 0 var(--ol),
    var(--u) calc(var(--u) * -1) 0 0 var(--ol),
    calc(var(--u) * -1) var(--u) 0 0 var(--ol),
    var(--u) var(--u) 0 0 var(--ol),
    0 calc(var(--u) * -2) 0 0 var(--ol),
    0 calc(var(--u) * 2) 0 0 var(--ol),
    calc(var(--u) * -2) 0 0 0 var(--ol),
    calc(var(--u) * 2) 0 0 0 var(--ol),
    0 calc(var(--u) * 4) 0 0 rgba(0, 0, 0, 0.45),
    inset 0 0 0 var(--u) var(--in);
}

/* Fondo de ventana RPG: degradado en bandas duras, como una paleta de 16 colores */
.px-window, .modal, .player-chip, .fx-banner {
  background: linear-gradient(180deg,
    var(--win-1) 0 18%, var(--win-2) 18% 45%, var(--win-3) 45% 75%, var(--win-4) 75% 100%);
}

/* =====================================================================
   Titulo
   ===================================================================== */

#top-bar { text-align: center; padding: 18px 0 10px; }
#top-bar h1 {
  margin: 0;
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: clamp(15px, 3.2vw, 32px);
  line-height: 1.3;
  letter-spacing: 2px;
  color: var(--accent);
  display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
  text-shadow:
    0 3px 0 var(--accent-dark), 0 6px 0 var(--ink),
    2px 0 0 rgba(255, 40, 90, 0.45), -2px 0 0 rgba(40, 190, 255, 0.45),
    0 0 18px rgba(255, 200, 60, 0.55);
}
.title-text { display: inline-block; animation: title-glow 3.2s steps(2, end) infinite; }
.title-flourish { display: inline-flex; animation: bob-pixel 1.2s steps(2, end) infinite; }
.title-flourish:last-child { animation-delay: 0.6s; }
#top-bar .subtitle {
  display: inline-block; margin-top: 12px;
  color: var(--muted); font-size: 20px; letter-spacing: 3px; text-transform: uppercase;
}
#top-bar::after {
  content: '';
  display: block; height: 6px; width: min(360px, 70%); margin: 12px auto 0;
  background: repeating-linear-gradient(90deg, var(--accent) 0 6px, transparent 6px 12px);
  opacity: 0.75;
}

@keyframes title-glow {
  0%, 92% { filter: none; }
  96% { filter: brightness(1.35); }
}
@keyframes bob-pixel {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* =====================================================================
   Botones: placas pixel con bisel; al pasar el raton aparece el cursor ▶
   ===================================================================== */

.btn {
  --u: 2px;
  --face: #e2e1f4;
  --hi: #ffffff;
  --lo: #9a9bc6;
  --ol: var(--ink);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--face);
  color: var(--ink);
  border: none;
  border-radius: 0;
  padding: 7px 20px 6px;
  font-family: var(--font-crt);
  font-size: 22px;
  line-height: 1;
  letter-spacing: 1px;
  text-transform: uppercase;
  text-shadow: none;
  cursor: pointer;
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--ol),
    0 var(--u) 0 0 var(--ol),
    calc(var(--u) * -1) 0 0 0 var(--ol),
    var(--u) 0 0 0 var(--ol),
    0 calc(var(--u) * 3) 0 0 var(--ink),
    inset var(--u) var(--u) 0 0 var(--hi),
    inset calc(var(--u) * -1) calc(var(--u) * -2) 0 0 var(--lo);
  transition: transform 0.06s steps(1), filter 0.1s;
}
.btn::before {
  content: '';
  position: absolute; left: 6px; top: 50%;
  width: 8px; height: 14px; margin-top: -7px;
  background: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 7' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h1v7H0zM1 1h1v5H1zM2 2h1v3H2zM3 3h1v1H3z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 4 7' shape-rendering='crispEdges'%3E%3Cpath d='M0 0h1v7H0zM1 1h1v5H1zM2 2h1v3H2zM3 3h1v1H3z'/%3E%3C/svg%3E") center / contain no-repeat;
  visibility: hidden;
}
.btn:hover:not(:disabled), .btn:focus-visible { filter: brightness(1.08); }
.btn:hover:not(:disabled)::before, .btn:focus-visible::before { visibility: visible; animation: blink 0.8s steps(1, end) infinite; }
.btn:active:not(:disabled) {
  transform: translateY(var(--u));
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--ol),
    0 var(--u) 0 0 var(--ol),
    calc(var(--u) * -1) 0 0 0 var(--ol),
    var(--u) 0 0 0 var(--ol),
    0 var(--u) 0 0 var(--ink),
    inset var(--u) var(--u) 0 0 var(--lo),
    inset calc(var(--u) * -1) calc(var(--u) * -1) 0 0 var(--hi);
}
.btn:disabled {
  --face: #5c5e7e; --hi: #74779a; --lo: #45475f;
  color: #2a2b3e; cursor: not-allowed;
}
.btn:focus-visible { outline: 2px dashed var(--accent-2); outline-offset: 6px; }
.btn-primary {
  --face: var(--accent); --hi: #fff3b0; --lo: #c98f12;
  color: #3a2400;
}
.btn-danger { --face: #e2444c; --hi: #ff9aa0; --lo: #8e1820; color: #fff; }
.btn-small { padding: 5px 18px 4px; font-size: 19px; }

@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }

/* =====================================================================
   Formularios
   ===================================================================== */

.field-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; flex-wrap: wrap; }
.field-row label { color: var(--muted); min-width: 90px; }
.field-note { color: var(--muted); font-size: 19px; flex: 1 1 220px; }

select, input[type=text] {
  --u: 2px;
  background: var(--well);
  color: var(--text);
  border: none; border-radius: 0;
  padding: 6px 10px 5px;
  font-family: var(--font-crt);
  font-size: 22px;
  line-height: 1;
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--frame-shade),
    0 var(--u) 0 0 var(--frame-shade),
    calc(var(--u) * -1) 0 0 0 var(--frame-shade),
    var(--u) 0 0 0 var(--frame-shade),
    inset var(--u) var(--u) 0 0 rgba(0, 0, 0, 0.6);
}
select {
  -webkit-appearance: none; appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 4' shape-rendering='crispEdges' fill='%23ffd84a'%3E%3Cpath d='M0 0h7v1H0zM1 1h5v1H1zM2 2h3v1H2zM3 3h1v1H3z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px 8px;
  cursor: pointer;
}
select option { background: var(--well); color: var(--text); }
input[type=text]::placeholder { color: #6670b0; }
select:focus, input[type=text]:focus { outline: 2px dashed var(--accent-2); outline-offset: 5px; }

input[type=checkbox] {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; margin: 0 8px 0 2px; vertical-align: -3px;
  background: var(--well);
  box-shadow: 0 0 0 2px var(--frame-shade), inset 2px 2px 0 rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
input[type=checkbox]:checked {
  background:
    linear-gradient(var(--accent), var(--accent)) center / 8px 8px no-repeat,
    var(--well);
}
.check-row { display: inline-flex; align-items: center; color: var(--muted); font-size: 20px; cursor: pointer; margin: 4px 0; }
.check-row-block { display: flex; margin-bottom: 8px; }

/* =====================================================================
   Pantalla de preparacion
   ===================================================================== */

.screen { margin: 0 auto; }
#setup-screen {
  max-width: 720px;
  margin-top: 8px;
  padding: 22px 24px 26px;
  background: linear-gradient(180deg,
    var(--deep-1) 0 20%, var(--deep-2) 20% 60%, var(--deep-3) 60% 100%);
}
#setup-screen h2, #setup-screen h3, .modal h3, .modal h4 {
  font-family: var(--font-pixel);
  font-weight: 400;
  line-height: 1.5;
}
#setup-screen h2 {
  margin: 0 0 6px; font-size: 16px; color: var(--accent);
  text-shadow: 0 3px 0 var(--ink), 0 0 12px rgba(255, 216, 74, 0.45);
}
#setup-screen h3 {
  margin: 4px 0 6px; font-size: 12px; color: var(--accent-2);
  text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(99, 240, 255, 0.4);
}
#game-screen.screen-game { max-width: 1400px; }

#player-forms { display: flex; flex-direction: column; gap: 16px; margin: 16px 0; }
.player-form-row {
  --u: 2px;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: rgba(4, 6, 30, 0.45);
  padding: 10px 12px;
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--frame-shade),
    0 var(--u) 0 0 var(--frame-shade),
    calc(var(--u) * -1) 0 0 0 var(--frame-shade),
    var(--u) 0 0 0 var(--frame-shade);
}
.player-form-row > strong { font-family: var(--font-pixel); font-weight: 400; font-size: 12px; color: var(--accent); }
.player-form-row input[type=text] { flex: 1; min-width: 120px; }
.class-portrait {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  background: var(--well);
  box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px var(--frame-shade);
}
.class-desc { font-size: 19px; color: var(--muted); flex-basis: 100%; }
.hint { color: var(--muted); font-size: 19px; margin-top: 14px; }
.app-version { margin: 16px 0 0; text-align: right; color: var(--muted); font-size: 18px; }
.divider {
  border: none; height: 3px; margin: 22px 0 14px;
  background: repeating-linear-gradient(90deg, var(--frame-shade) 0 6px, transparent 6px 12px);
  opacity: 0.6;
}

.ai-badge {
  display: inline-block;
  background: var(--accent-2); color: var(--ink);
  font-family: var(--font-pixel); font-size: 8px; line-height: 1;
  padding: 3px 4px 2px; margin-left: 4px; vertical-align: 2px;
  box-shadow: 0 0 0 2px var(--ink);
  text-shadow: none;
}
.class-icon { margin-right: 8px; }

/* =====================================================================
   Caja de dialogo del tutor (Modo Tutorial)
   ===================================================================== */

#coach-panel, .coach-line {
  --u: 3px;
  --fr: var(--frame);
  position: relative;
  background: #05061a;
  color: var(--text);
  line-height: 1.2;
}
#coach-panel {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 34px 12px 12px; margin: 6px 0 22px;
  font-size: 21px;
  animation: coach-in 0.25s steps(4, end);
}
#coach-panel::after, .coach-line::after {
  content: '';
  position: absolute; right: 12px; bottom: 9px;
  width: 12px; height: 8px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 25%, 83% 25%, 83% 50%, 67% 50%, 67% 75%, 50% 75%, 50% 100%, 50% 100%, 33% 75%, 33% 75%, 33% 50%, 17% 50%, 17% 25%, 0 25%);
  animation: blink 0.9s steps(1, end) infinite;
}
#coach-panel[hidden] { display: none; }
.coach-icon {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px;
  background: var(--deep-2);
  box-shadow: 0 0 0 2px var(--frame-shade);
}
.coach-line { padding: 10px 30px 12px 12px; font-size: 20px; margin: 10px 0 18px; }
@keyframes coach-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* =====================================================================
   Barra de jugadores: ventanas de estado del grupo
   ===================================================================== */

#players-bar { display: flex; gap: 22px; flex-wrap: wrap; justify-content: center; margin: 22px 0 26px; }
.player-chip {
  --u: 3px;
  padding: 10px 13px 9px;
  min-width: 176px;
  position: relative;
  transition: opacity 0.5s, filter 0.5s;
}
.player-chip::after { content: ''; display: block; clear: both; }
.player-chip.current { --fr: var(--accent); }
/* Cursor ▼ que salta sobre quien tiene el turno */
.player-chip.current::before {
  content: '';
  position: absolute; left: 50%; top: -24px; margin-left: -8px;
  width: 16px; height: 10px;
  background: var(--accent);
  clip-path: polygon(0 0, 100% 0, 100% 20%, 87.5% 20%, 87.5% 40%, 75% 40%, 75% 60%, 62.5% 60%, 62.5% 80%, 50% 80%, 50% 100%, 50% 100%, 37.5% 80%, 37.5% 80%, 37.5% 60%, 25% 60%, 25% 40%, 12.5% 40%, 12.5% 20%, 0 20%);
  filter: drop-shadow(0 2px 0 var(--ink));
  animation: bob-pixel 0.7s steps(2, end) infinite;
}
.player-chip.dead { opacity: 0.5; filter: grayscale(1); }
.player-chip.dead .pname::after {
  content: 'K.O.';
  margin-left: 8px;
  font-family: var(--font-pixel); font-size: 8px; color: var(--hp-low);
  vertical-align: 2px;
}
.player-chip .pname {
  font-family: var(--font-pixel); font-size: 10px; line-height: 1.6;
  padding-top: 2px;
  color: var(--text);
  text-shadow: 0 2px 0 var(--ink);
  white-space: nowrap;
}
.player-chip .class-icon {
  float: left;
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; margin: 0 10px 4px 0;
  background: var(--well);
  box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px var(--frame-shade);
}
.player-chip .pclass { color: var(--muted); font-size: 19px; }

.hp-bar-outer {
  clear: both;
  background: #05051a;
  height: 12px; margin-top: 8px;
  overflow: hidden; position: relative;
  box-shadow: 0 0 0 2px var(--ink), 0 0 0 4px var(--frame-shade);
}
/* Segmentos de la barra, por encima del relleno */
.hp-bar-outer::after {
  content: ''; position: absolute; inset: 0; z-index: 2; pointer-events: none;
  background: repeating-linear-gradient(90deg, transparent 0 7px, rgba(5, 5, 26, 0.85) 7px 9px);
}
.hp-bar-inner {
  position: relative; z-index: 1; height: 100%; background: var(--hp-full);
  box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.35), inset 0 -3px 0 rgba(0, 0, 0, 0.3);
  transition: width 0.4s steps(6, end), background 0.4s steps(1, end);
}
/* Barra "fantasma": se queda un instante en el valor anterior y luego baja, mostrando el trozo de vida perdido. */
.hp-bar-ghost {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: #fff6d0; transition: width 0.6s steps(8, end);
}
.hp-text, .coin-text {
  font-family: var(--font-pixel); font-size: 8px; line-height: 1.4;
  margin-top: 9px; letter-spacing: 1px;
}
.hp-text { color: var(--text); }
.coin-text { color: var(--coin); margin-top: 6px; }
.coin-text::before {
  content: ''; display: inline-block; width: 8px; height: 8px; margin-right: 6px; vertical-align: -1px;
  background: var(--coin); box-shadow: inset -2px -2px 0 #b07a00, 0 0 0 1px var(--ink);
}
.artifact-icons { margin-top: 6px; font-size: 18px; color: var(--accent-2); max-width: 220px; }
.yep-alert { position: absolute; top: -18px; right: -14px; margin: 0; animation: pulse-glow 1s steps(2, end) infinite; }

@keyframes pulse-glow {
  0%, 100% { filter: none; }
  50% { filter: brightness(1.3) drop-shadow(0 0 6px rgba(255, 216, 74, 0.9)); }
}

/* =====================================================================
   Tablero: panel de accion + barra lateral
   ===================================================================== */

#board { display: flex; flex-direction: column; gap: 26px; }

#action-panel {
  --u: 3px;
  background: linear-gradient(180deg,
    var(--deep-1) 0 12%, var(--deep-2) 12% 55%, var(--deep-3) 55% 100%);
  padding: 16px; min-width: 0;
}
#phase-banner {
  font-family: var(--font-pixel); font-size: 10px; line-height: 1.7;
  color: var(--accent); margin-bottom: 12px; min-height: 1.1em;
  text-shadow: 0 2px 0 var(--ink), 0 0 10px rgba(255, 216, 74, 0.4);
}
#phase-banner:not(:empty)::before { content: '\25B6\00A0'; animation: blink 1s steps(1, end) infinite; }

#hand-area { display: flex; flex-wrap: wrap; gap: 14px; margin: 18px 0 20px; padding: 0 4px; min-height: 100px; }

#side-panel { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
#log-panel {
  --u: 3px;
  --fr: var(--frame-shade);
  background: #03040f;
  height: 220px; overflow-y: auto; padding: 10px 12px;
  font-size: 19px; line-height: 1.15; color: #b9f5c4;
  text-shadow: 0 0 6px rgba(120, 255, 160, 0.35);
}
#log-panel::before {
  content: 'REGISTRO DE BATALLA';
  display: block; position: sticky; top: -10px; z-index: 1;
  margin: -10px 0 6px; padding: 10px 0 6px;
  background: #03040f;
  font-family: var(--font-pixel); font-size: 8px; color: var(--muted); letter-spacing: 1px;
  text-shadow: none;
}
#log-list div { padding: 3px 0 3px 14px; text-indent: -14px; border-bottom: 1px solid rgba(120, 255, 160, 0.08); }
#log-list div::before { content: '> '; color: #4be36b; }
#log-list div:last-child { color: #eafff0; }
#log-list div:last-child::after {
  content: ''; display: inline-block; width: 9px; height: 16px; margin-left: 4px; vertical-align: -2px;
  background: #b9f5c4; animation: blink 1s steps(1, end) infinite;
}
.side-buttons { display: flex; gap: 12px; flex-wrap: wrap; }

/* =====================================================================
   Cartas pixel
   ===================================================================== */

.card {
  --u: 3px;
  --sp: 3px;
  --ol: var(--ink);
  --halo: transparent;
  --drop: rgba(0, 0, 0, 0.5);
  width: 66px; height: 94px;
  border: none; border-radius: 0;
  background: var(--card-face);
  color: var(--black-suit);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-pixel); font-weight: 400;
  cursor: pointer; user-select: none; position: relative;
  text-shadow: none;
  box-shadow:
    inset 0 0 0 var(--u) #fffaf0,
    inset 0 0 0 calc(var(--u) * 2) var(--card-line),
    0 calc(var(--u) * -1) 0 0 var(--ol),
    0 var(--u) 0 0 var(--ol),
    calc(var(--u) * -1) 0 0 0 var(--ol),
    var(--u) 0 0 0 var(--ol),
    0 calc(var(--u) * 3) 0 0 var(--drop),
    0 0 0 calc(var(--u) * 2) var(--halo);
  transition: transform 0.08s steps(2, end);
}
.card:hover { transform: translateY(-4px); }
.card.selected { --ol: var(--accent-2); --halo: rgba(99, 240, 255, 0.3); transform: translateY(-10px); }
.card .val { font-size: 22px; line-height: 1; }
.card .suit { line-height: 0; }
.card .px-suit { display: block; width: calc(7 * var(--sp)); height: auto; }
.card.red { color: var(--red-suit); }
.card .corner {
  --sp: 1px;
  position: absolute; display: flex; flex-direction: column; align-items: center;
  font-size: 8px; line-height: 1; gap: 2px;
}
.card .corner-tl { top: 8px; left: 8px; }
.card .corner-br { bottom: 8px; right: 8px; transform: rotate(180deg); }
.card .loose-tag {
  position: absolute; bottom: -12px; left: 50%; transform: translateX(-50%);
  background: var(--coin); color: #3a2400;
  font-size: 8px; padding: 3px 4px 2px;
  box-shadow: 0 0 0 2px var(--ink);
}
.card.disabled { opacity: 0.45; filter: grayscale(0.7); cursor: not-allowed; }
.card.disabled:hover { transform: none; }
.card .group-badge {
  position: absolute; top: -13px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--accent);
  font-size: 8px; line-height: 1; padding: 3px 4px 2px;
  box-shadow: 0 0 0 2px var(--accent);
}

#controls { display: flex; flex-wrap: wrap; gap: 14px 12px; align-items: center; }
#controls .group { display: flex; gap: 14px 12px; flex-wrap: wrap; align-items: center; }
#controls .info, .info { font-size: 19px; color: var(--muted); }
#controls .info { flex-basis: 100%; margin-top: 4px; }

.hand-preview {
  flex-basis: 100%; display: flex; flex-direction: column; gap: 10px;
  margin: 8px 0 8px;
}
.preview-row {
  --u: 2px;
  font-size: 20px; padding: 6px 10px 5px;
  background: rgba(4, 6, 30, 0.6); color: var(--text);
  box-shadow:
    0 calc(var(--u) * -1) 0 0 #3a468f,
    0 var(--u) 0 0 #3a468f,
    calc(var(--u) * -1) 0 0 0 #3a468f,
    var(--u) 0 0 0 #3a468f;
}
.preview-row strong { color: var(--muted); font-weight: 400; }
.preview-row.invalid { color: var(--muted); }
.preview-row.invalid strong { color: var(--muted); }
.preview-row.active {
  background: rgba(255, 216, 74, 0.12);
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--accent),
    0 var(--u) 0 0 var(--accent),
    calc(var(--u) * -1) 0 0 0 var(--accent),
    var(--u) 0 0 0 var(--accent);
}
.preview-row.active strong { color: var(--accent); }

#loot-bar {
  display: flex; gap: 14px 12px; flex-wrap: wrap; margin-top: 16px; padding-top: 14px;
  background: repeating-linear-gradient(90deg, var(--frame-shade) 0 6px, transparent 6px 12px) top / 100% 2px no-repeat;
}
#loot-bar:empty { display: none; }

/* =====================================================================
   Ventanas emergentes
   ===================================================================== */

#overlay-root:empty { display: none; }
/* Pantallas de "pasa/devuelve el dispositivo": tapan del todo lo que hay debajo (manos). */
.overlay.overlay-opaque { background: var(--bg); }
.overlay {
  position: fixed; inset: 0;
  background: rgba(2, 2, 10, 0.78);
  display: flex; align-items: center; justify-content: center;
  padding: calc(var(--bezel) + 14px); z-index: 50;
}
.modal {
  --u: 3px;
  padding: 20px 20px 18px; max-width: 500px; width: 100%; max-height: 82vh; overflow-y: auto;
  scrollbar-color: var(--frame-shade) var(--win-4);
}
.modal h3 {
  margin: 0 0 12px; font-size: 13px; color: var(--accent);
  text-shadow: 0 3px 0 var(--ink), 0 0 10px rgba(255, 216, 74, 0.4);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.modal h4 { margin: 18px 0 10px; font-size: 10px; color: var(--accent-2); text-shadow: 0 2px 0 var(--ink); }
.modal p { margin: 8px 0; }
.modal > .btn { margin: 12px 10px 4px 0; }
.modal #hand-area { margin: 14px 0 18px; }
.shop-item {
  --u: 2px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: rgba(4, 6, 30, 0.55);
  padding: 7px 10px; margin: 0 2px 10px; font-size: 20px;
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--frame-shade),
    0 var(--u) 0 0 var(--frame-shade),
    calc(var(--u) * -1) 0 0 0 var(--frame-shade),
    var(--u) 0 0 0 var(--frame-shade);
}
.shop-item strong { color: var(--accent); font-weight: 400; }
.shop-item .desc { color: var(--muted); font-size: 18px; }
.shop-item .btn { flex-shrink: 0; }
.danger-text { color: #ff6b62; font-weight: 400; }
.error-msg { color: var(--hp-low); font-size: 20px; min-height: 1.1em; margin: 6px 0; flex-basis: 100%; }

/* --- Tutorial "Como Jugar" --- */
.tut-modal { max-width: 600px; }
.tut-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 4px; }
.tut-header h3 { margin-bottom: 4px; }
.tut-step-count { color: var(--muted); font-family: var(--font-pixel); font-size: 8px; text-transform: uppercase; letter-spacing: 1px; white-space: nowrap; }
.tut-body { font-size: 20px; line-height: 1.2; }
.tut-body p { margin: 8px 0; }
.tut-body ul, .tut-body ol { margin: 8px 0; padding-left: 22px; }
.tut-body li { margin: 3px 0; }
.tut-body li::marker { color: var(--accent); }
.tut-body strong { color: var(--accent); font-weight: 400; }
.tut-warn { color: #ffb36b; }
.tut-note { color: var(--muted); font-size: 18px; }
.tut-table-wrap { overflow-x: auto; margin: 12px 2px; padding: 2px; }
.tut-table { border-collapse: collapse; width: 100%; font-size: 19px; background: rgba(4, 6, 30, 0.5); }
.tut-table th, .tut-table td {
  border: 2px solid var(--ink); padding: 4px 8px; text-align: left; white-space: nowrap;
}
.tut-table th {
  background: var(--ink); color: var(--accent);
  font-family: var(--font-pixel); font-weight: 400; font-size: 8px; letter-spacing: 1px;
}
.tut-table tr:nth-child(even) td { background: rgba(255, 255, 255, 0.04); }
.tut-table-classes td, .tut-table-classes th { white-space: normal; }
.tut-dots { display: flex; justify-content: center; gap: 8px; margin: 16px 0 10px; }
.tut-dot {
  width: 10px; height: 10px; background: #3a468f;
  box-shadow: 0 0 0 2px var(--ink);
  cursor: pointer; display: inline-block;
}
.tut-dot.active { background: var(--accent); }
.tut-nav { display: flex; justify-content: space-between; gap: 8px; }

/* --- Compendio --- */
.cmp-modal {
  max-width: 820px; height: min(86vh, 900px); max-height: none;
  display: flex; flex-direction: column; overflow: hidden; padding-bottom: 14px;
}
.cmp-header { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-shrink: 0; }
.cmp-header h3 { margin: 0; font-size: 16px; }
.cmp-tabs {
  flex-shrink: 0;
  display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 12px; padding: 4px 4px 10px;
  background: repeating-linear-gradient(90deg, var(--frame-shade) 0 6px, transparent 6px 12px) bottom / 100% 2px no-repeat;
}
.cmp-tab {
  --u: 2px;
  position: relative;
  background: rgba(4, 6, 30, 0.55); color: var(--muted);
  border: none; padding: 6px 12px 5px 22px;
  font-family: var(--font-crt); font-size: 20px; line-height: 1; text-transform: uppercase; letter-spacing: 1px;
  cursor: pointer;
  box-shadow:
    0 calc(var(--u) * -1) 0 0 #3a468f, 0 var(--u) 0 0 #3a468f,
    calc(var(--u) * -1) 0 0 0 #3a468f, var(--u) 0 0 0 #3a468f;
}
.cmp-tab::before {
  content: ''; position: absolute; left: 7px; top: 50%; width: 8px; height: 12px; margin-top: -6px;
  background: currentColor; visibility: hidden;
  clip-path: polygon(0 0, 25% 0, 25% 14%, 50% 14%, 50% 28%, 75% 28%, 75% 43%, 100% 43%, 100% 57%, 75% 57%, 75% 72%, 50% 72%, 50% 86%, 25% 86%, 25% 100%, 0 100%);
}
.cmp-tab:hover { color: var(--text); }
.cmp-tab.active {
  color: var(--ink); background: var(--accent);
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--ink), 0 var(--u) 0 0 var(--ink),
    calc(var(--u) * -1) 0 0 0 var(--ink), var(--u) 0 0 0 var(--ink);
}
.cmp-tab.active::before, .cmp-tab:focus-visible::before { visibility: visible; }
.cmp-tab:focus-visible { outline: 2px dashed var(--accent-2); outline-offset: 5px; }
.cmp-body {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px 6px 10px 4px;
  font-size: 20px; line-height: 1.2;
  scrollbar-color: var(--frame-shade) var(--win-4);
}
.cmp-body:focus-visible { outline: 2px dashed var(--accent-2); outline-offset: -2px; }
.cmp-intro, .cmp-duration { margin: 4px 0 14px; color: var(--muted); }
.cmp-duration strong { color: var(--accent); font-weight: 400; }
.cmp-muted { color: var(--muted); }
.cmp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 18px; margin: 4px 0 18px; }
.cmp-entry {
  --u: 2px;
  background: rgba(4, 6, 30, 0.55); padding: 12px 12px 10px;
  box-shadow:
    0 calc(var(--u) * -1) 0 0 var(--frame-shade), 0 var(--u) 0 0 var(--frame-shade),
    calc(var(--u) * -1) 0 0 0 var(--frame-shade), var(--u) 0 0 0 var(--frame-shade);
}
.cmp-entry-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.cmp-entry h4, .cmp-box h4 {
  margin: 0; font-family: var(--font-pixel); font-weight: 400; font-size: 10px; line-height: 1.6;
  color: var(--accent); text-shadow: 0 2px 0 var(--ink);
}
.cmp-sub { color: var(--coin); font-size: 18px; margin-top: 2px; }
.cmp-portrait {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px; background: var(--well);
  box-shadow: 0 0 0 2px var(--ink), inset 0 0 0 2px var(--frame-shade);
}
.cmp-stats { margin: 0; display: grid; gap: 6px; }
.cmp-stats > div { display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.cmp-stats dt { color: var(--accent-2); font-size: 18px; }
.cmp-stats dd { margin: 0; }
.cmp-stats strong { color: var(--text); font-weight: 400; font-family: var(--font-pixel); font-size: 12px; }
.cmp-text p { margin: 8px 0 0; }
.cmp-box { margin: 6px 0 18px; }
.cmp-box h4 { margin-bottom: 8px; color: var(--accent-2); }
.cmp-box ul, .cmp-box ol { margin: 0; padding-left: 22px; }
.cmp-box li { margin: 4px 0; }
.cmp-box li::marker { color: var(--accent); }
.cmp-box strong, .cmp-text strong { color: var(--accent); font-weight: 400; }
.cmp-hands td { vertical-align: middle; white-space: normal; min-width: 70px; }
.cmp-hands td:nth-child(2) { white-space: nowrap; }
.cmp-link { margin-top: 14px; }
.cmp-cards { display: inline-flex; gap: 3px; }
.mini-card {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 20px; height: 28px; background: var(--card-face); color: var(--black-suit);
  box-shadow: 0 0 0 2px var(--ink);
}
.mini-card.red { color: var(--red-suit); }
.mini-card b { font-family: var(--font-pixel); font-weight: 400; font-size: 8px; line-height: 1; }
.mini-card .px-suit { display: block; width: 7px; height: auto; }

@media (max-width: 480px) {
  .cmp-modal { height: 88vh; }
  .cmp-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .cmp-tabs::-webkit-scrollbar { display: none; }
  .cmp-tab { flex-shrink: 0; font-size: 18px; }
  .cmp-stats > div { grid-template-columns: 1fr; gap: 0; }
  /* La tabla de manos pasa a una ficha por fila */
  .cmp-hands, .cmp-hands tbody, .cmp-hands tr, .cmp-hands td { display: block; width: 100%; }
  .cmp-hands { background: none; }
  .cmp-hands tr.cmp-head-row { display: none; }
  .cmp-hands tr { margin-bottom: 12px; background: rgba(4, 6, 30, 0.55); box-shadow: 0 0 0 2px var(--frame-shade); }
  .cmp-hands td { border: none; display: flex; align-items: center; gap: 10px; padding: 3px 10px; }
  .cmp-hands td::before { content: attr(data-label); flex: 0 0 78px; color: var(--accent-2); font-size: 18px; }
  .cmp-hands td:first-child { padding-top: 8px; }
  .cmp-hands td:first-child::before { content: none; }
  .cmp-hands td:last-child { padding-bottom: 8px; }
}

/* =====================================================================
   Tele CRT: lineas de barrido, vineta, marco y parpadeo (encima de todo,
   sin capturar clics)
   ===================================================================== */

#crt { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }
#crt > div { position: absolute; pointer-events: none; }

.crt-scanlines {
  inset: 0;
  background:
    repeating-linear-gradient(180deg, transparent 0 2px, rgba(0, 0, 0, 0.26) 2px 3px),
    repeating-linear-gradient(90deg, rgba(255, 0, 60, 0.035) 0 1px, rgba(0, 255, 120, 0.025) 1px 2px, rgba(40, 90, 255, 0.035) 2px 3px);
  animation: crt-flicker 5s steps(1, end) infinite;
}
/* Banda clara que recorre la pantalla de arriba abajo, como en los tubos viejos */
.crt-roll {
  left: 0; right: 0; top: 0; height: 22vh;
  background: linear-gradient(180deg, transparent, rgba(190, 210, 255, 0.045) 50%, transparent);
  animation: crt-roll 9s linear infinite;
}
.crt-glass {
  inset: var(--bezel);
  border-radius: var(--screen-r);
  background:
    radial-gradient(ellipse 70% 40% at 28% 6%, rgba(255, 255, 255, 0.055), transparent 70%);
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.7),
    inset 0 0 28px 8px rgba(0, 0, 0, 0.55),
    inset 0 0 140px 30px rgba(0, 0, 0, 0.32),
    0 0 0 2px #26262e,
    0 0 0 calc(var(--bezel) + 2px) var(--bezel-color);
}
/* Marco de plastico: tapa los bordes con esquinas exteriores rectas; la sombra del cristal
   redondea las interiores. Medido contra la ventana, asi nunca tapa contenido si cambia
   el alto visible (barra del navegador en el movil). */
#crt::before {
  content: '';
  position: absolute; inset: 0;
  border: var(--bezel) solid var(--bezel-color);
}
/* Piloto de encendido en el marco (solo cuando el marco es lo bastante grueso) */
#crt::after {
  content: ''; display: none;
  position: absolute; right: calc(var(--bezel) + 26px); bottom: calc(var(--bezel) / 2 - 3px);
  width: 6px; height: 6px;
  background: #5dff8a; box-shadow: 0 0 6px 2px rgba(93, 255, 138, 0.6);
}

/* Encendido de la tele al cargar: linea blanca que se abre y revela la imagen */
.crt-power {
  inset: 0;
  background: #000;
  animation: crt-power-on 1.1s ease-out forwards;
}
.crt-power::after {
  content: '';
  position: absolute; left: 0; right: 0; top: 50%; height: 2px; margin-top: -1px;
  background: #fff;
  box-shadow: 0 0 14px 4px rgba(200, 220, 255, 0.85);
  transform: scaleX(0);
  animation: crt-line 1.1s ease-out forwards;
}
/* Interferencia al cambiar de pantalla */
#crt.crt-switching .crt-power {
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    #222;
  animation: crt-static 0.6s steps(6, end) forwards;
}
#crt.crt-switching .crt-power::after { animation: none; transform: scaleX(0); }

@keyframes crt-flicker {
  0%, 100% { opacity: 1; }
  41% { opacity: 0.86; }
  42% { opacity: 1; }
  77% { opacity: 0.92; }
  78% { opacity: 1; }
}
@keyframes crt-roll {
  from { transform: translateY(-25vh); }
  to { transform: translateY(105vh); }
}
@keyframes crt-power-on {
  0%, 40% { opacity: 1; visibility: visible; }
  100% { opacity: 0; visibility: hidden; }
}
@keyframes crt-line {
  0% { transform: scale(0, 1); opacity: 1; }
  28% { transform: scale(1, 1); opacity: 1; }
  52% { transform: scale(1, 220); opacity: 0.9; }
  80% { transform: scale(1, 400); opacity: 0; }
  100% { transform: scale(1, 400); opacity: 0; }
}
@keyframes crt-static {
  0% { opacity: 0.95; visibility: visible; background-position: 0 0, 0 0; }
  20% { background-position: 37px 91px, 0 0; }
  40% { opacity: 0.85; background-position: 113px 23px, 0 0; }
  60% { background-position: 61px 140px, 0 0; }
  80% { opacity: 0.5; background-position: 9px 57px, 0 0; }
  100% { opacity: 0; visibility: hidden; background-position: 88px 5px, 0 0; }
}

/* ================= Responsive ================= */

@media (min-width: 620px) {
  :root { --bezel: 12px; --screen-r: 26px; }
  .card { width: 74px; height: 104px; }
  .card .val { font-size: 24px; }
  .modal { padding: 24px 24px 20px; }
  .modal h3 { font-size: 14px; }
  #setup-screen h2 { font-size: 18px; }
  #setup-screen h3 { font-size: 13px; }
}

/* Escritorio: el tablero pasa a dos columnas (accion + barra lateral). Ambas se
   estiran a la misma altura para que el panel del log aproveche todo el alto real
   del panel de accion en vez de quedar corto y con hueco vacio debajo. */
@media (min-width: 900px) {
  :root { --bezel: 18px; --screen-r: 34px; }
  #crt::after { display: block; }
  #board { display: grid; grid-template-columns: minmax(0, 1fr) 320px; align-items: stretch; }
  #side-panel { position: sticky; top: calc(var(--bezel) + 16px); }
  #log-panel { flex: 1 1 auto; min-height: 240px; max-height: calc(100vh - 240px); }
  #action-panel { padding: 22px 24px; }
  #phase-banner { font-size: 11px; }
  .card { width: 82px; height: 116px; --sp: 4px; }
  .card .val { font-size: 26px; }
  .card .corner { font-size: 8px; }
  .player-chip { min-width: 196px; padding: 12px 16px 11px; }
  .player-chip .pname { font-size: 11px; }
  body { font-size: 22px; }
}

/* Pantallas muy anchas: todavia un poco mas de aire y cartas mas grandes */
@media (min-width: 1300px) {
  #board { grid-template-columns: minmax(0, 1fr) 360px; gap: 30px; }
  .card { width: 90px; height: 126px; }
  .card .val { font-size: 30px; }
}

@media (max-width: 480px) {
  body { font-size: 20px; }
  #top-bar { padding-top: 12px; }
  #top-bar h1 { letter-spacing: 1px; gap: 8px; }
  #top-bar .subtitle { font-size: 17px; letter-spacing: 1px; }
  .title-flourish { display: none; }
  .card { --u: 2px; --sp: 2px; width: 54px; height: 78px; gap: 4px; }
  .card .val { font-size: 16px; }
  .card .corner { display: none; }
  #hand-area { gap: 12px; }
  .player-chip { min-width: 0; flex: 1 1 140px; padding: 8px 10px; }
  .player-chip .pname { font-size: 8px; white-space: normal; }
  .player-chip .class-icon { width: 38px; height: 38px; margin-right: 8px; }
  img.px-sprite.px-sm { width: 32px; height: 32px; }
  img.px-sprite.px-lg { width: 84px; height: 84px; }
  #players-bar { gap: 18px; }
  .tut-table { font-size: 17px; }
  #setup-screen { padding: 16px 14px 20px; }
  #action-panel { padding: 14px 12px; }
  .btn { font-size: 20px; padding: 7px 18px 6px; }
  .btn-small { font-size: 18px; }
  .modal { padding: 16px 14px 14px; }
}

/* ================= Animaciones y efectos ================= */

:root { --join: 34px; }
@media (min-width: 900px) { :root { --join: 40px; } }
@media (min-width: 1300px) { :root { --join: 44px; } }
@media (max-width: 480px) { :root { --join: 26px; } }

#fx-layer { position: fixed; inset: 0; pointer-events: none; z-index: 70; overflow: hidden; }

.player-chip.fx-dying { animation: fx-dying 0.8s steps(6, end); }

/* --- Cartas: reparto, union en combinaciones --- */
.card.deal-in { animation: fx-deal 0.42s steps(7, end) backwards; }
.card.linked { --ol: var(--accent); --halo: rgba(255, 216, 74, 0.35); }
.card.linked.selected { --ol: var(--accent); }
.card.linked-join { margin-left: calc(var(--join) * -1); }
.card.link-in { animation: fx-link-glow 0.45s steps(4, end); }
.card.linked-join.link-in { animation: fx-link-snap 0.3s steps(4, end), fx-link-glow 0.45s steps(4, end); }

@keyframes fx-deal {
  from { opacity: 0; transform: translate(48px, -36px) rotate(10deg); }
  to { opacity: 1; transform: none; }
}
@keyframes fx-link-snap {
  from { margin-left: 0; }
  to { margin-left: calc(var(--join) * -1); }
}
@keyframes fx-link-glow {
  0% { filter: brightness(1.7) drop-shadow(0 0 10px rgba(255, 216, 74, 0.95)); }
  100% { filter: none; }
}

.fx-card-clone { position: absolute !important; margin: 0 !important; transition: none !important; animation: none !important; }

/* --- Sacudidas --- */
.fx-shake { animation: fx-shake 0.36s steps(6, end); }
.fx-shake-big { animation: fx-shake-big 0.5s steps(8, end); }
@keyframes fx-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-3px); }
  80% { transform: translateX(3px); }
}
@keyframes fx-shake-big {
  0%, 100% { transform: translate(0, 0); }
  15% { transform: translate(-9px, 3px); }
  30% { transform: translate(9px, -3px); }
  45% { transform: translate(-6px, 3px); }
  60% { transform: translate(6px, -3px); }
  80% { transform: translate(-3px, 0); }
}
@keyframes fx-dying {
  0% { transform: none; }
  30% { transform: translate(-4px, -4px); }
  60% { transform: translate(4px, 0); }
  100% { transform: none; }
}

/* --- Numeros flotantes (estilo RPG: fuente pixel con contorno negro) --- */
.fx-float {
  position: absolute; transform: translate(-50%, -50%);
  font-family: var(--font-pixel); font-size: 20px; white-space: nowrap;
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink),
    0 6px 0 var(--ink);
  animation: fx-rise 1.3s ease-out forwards;
}
.fx-float.fx-dmg { color: #ff5a4e; font-size: 26px; }
.fx-float.fx-heal { color: #7dff95; }
.fx-float.fx-coin { color: var(--coin); font-size: 13px; }
.fx-float.fx-gold { color: #ffd36b; font-size: 14px; }
.fx-float.fx-skull { font-family: inherit; font-size: 2.2rem; text-shadow: none; }
@keyframes fx-rise {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  12% { opacity: 1; transform: translate(-50%, -80%) scale(1.2); }
  22% { transform: translate(-50%, -55%) scale(1); }
  32% { transform: translate(-50%, -70%); }
  100% { opacity: 0; transform: translate(-50%, -200%); }
}

/* --- Orbes (ataque, curacion, reflejo): bolas pixel --- */
.fx-orb {
  position: absolute; left: 0; top: 0; width: 24px; height: 24px; will-change: transform;
  background: center / 100% 100% no-repeat;
  image-rendering: pixelated;
}
.fx-orb.fx-attack {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath fill='%23d81f2a' d='M2 0h4v1h1v1h1v4h-1v1h-1v1H2v-1H1v-1H0V2h1V1h1z'/%3E%3Cpath fill='%23ff8a1e' d='M2 1h4v1h1v4h-1v1H2v-1H1V2h1z'/%3E%3Cpath fill='%23ffe066' d='M2 2h3v1h1v2H5v1H3V5H2z'/%3E%3Cpath fill='%23fff' d='M2 2h2v2H2z'/%3E%3C/svg%3E");
  filter: drop-shadow(0 0 6px rgba(255, 120, 40, 0.9));
}
.fx-orb.fx-heal {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath fill='%231f9a3a' d='M2 0h4v1h1v1h1v4h-1v1h-1v1H2v-1H1v-1H0V2h1V1h1z'/%3E%3Cpath fill='%234be36b' d='M2 1h4v1h1v4h-1v1H2v-1H1V2h1z'/%3E%3Cpath fill='%23b8ffc4' d='M2 2h3v1h1v2H5v1H3V5H2z'/%3E%3Cpath fill='%23fff' d='M2 2h2v2H2z'/%3E%3C/svg%3E");
  filter: drop-shadow(0 0 6px rgba(80, 230, 110, 0.9));
}
.fx-orb.fx-reflect {
  width: 18px; height: 18px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath fill='%235a2fd6' d='M3 0h2v1h1v1h1v1h1v2H7v1H6v1H5v1H3V7H2V6H1V5H0V3h1V2h1V1h1z'/%3E%3Cpath fill='%23b69cff' d='M3 1h2v1h1v1h1v2H6v1H5v1H3V6H2V5H1V3h1V2h1z'/%3E%3Cpath fill='%23fff' d='M3 2h2v2H3z'/%3E%3C/svg%3E");
  filter: drop-shadow(0 0 6px rgba(140, 100, 255, 0.9));
}
.fx-orb.fx-trail { width: 14px; height: 14px; filter: none; }

/* --- Estallidos, chispas, destellos --- */
.fx-ring {
  position: absolute; width: 18px; height: 18px; border: 3px solid #ff8a1e;
  transform: translate(-50%, -50%) rotate(45deg); animation: fx-ring 0.55s steps(6, end) forwards;
}
.fx-ring.fx-heal { border-color: #4be36b; }
.fx-ring.fx-reflect { border-color: #b69cff; }
.fx-ring.fx-gold { border-color: var(--accent); }
.fx-ring.fx-fire { border-color: #ff9d2e; }
@keyframes fx-ring {
  from { opacity: 1; transform: translate(-50%, -50%) rotate(45deg) scale(0.3); }
  to { opacity: 0; transform: translate(-50%, -50%) rotate(45deg) scale(5); }
}
.fx-particle { position: absolute; width: 8px; height: 8px; background: #ffb347; box-shadow: 0 0 0 2px rgba(120, 20, 0, 0.6); }
.fx-particle.fx-heal { background: #7dff95; box-shadow: 0 0 0 2px rgba(0, 80, 20, 0.6); }
.fx-particle.fx-reflect { background: #b69cff; box-shadow: 0 0 0 2px rgba(40, 10, 120, 0.6); }
.fx-particle.fx-gold { background: var(--accent); box-shadow: 0 0 0 2px rgba(110, 70, 0, 0.6); }
.fx-particle.fx-fire { background: #ff9d2e; box-shadow: 0 0 0 2px rgba(130, 30, 0, 0.6); }
.fx-spark {
  position: absolute; font-family: var(--font-pixel); font-size: 14px; color: #7dff95;
  text-shadow: 2px 2px 0 var(--ink), 0 0 8px rgba(125, 255, 149, 0.8);
}
.fx-core {
  position: absolute; width: 48px; height: 48px;
  transform: translate(-50%, -50%); animation: fx-core 0.5s steps(5, end) forwards;
  background: radial-gradient(circle, #fff 0 22%, #ffe066 22% 40%, #ff8a1e 40% 56%, transparent 57%);
}
.fx-core.fx-heal { background: radial-gradient(circle, #fff 0 22%, #b8ffc4 22% 40%, #4be36b 40% 56%, transparent 57%); }
@keyframes fx-core {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.3); }
  30% { opacity: 1; transform: translate(-50%, -50%) scale(1.5); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(2.2); }
}
.fx-flash { position: absolute; animation: fx-flash 0.5s steps(4, end) forwards; }
.fx-flash.fx-dmg { background: rgba(255, 60, 60, 0.6); }
.fx-flash.fx-heal { background: rgba(75, 227, 107, 0.45); }
.fx-vignette { position: absolute; width: 100%; height: 100%; animation: fx-flash 0.7s steps(5, end) forwards; }
.fx-vignette.fx-dmg { background: radial-gradient(ellipse at center, transparent 45%, rgba(230, 30, 30, 0.5) 100%); }
@keyframes fx-flash { from { opacity: 1; } to { opacity: 0; } }

/* --- Nombre de la jugada que salta --- */
.fx-combo {
  position: absolute; transform: translate(-50%, -100%); text-align: center; white-space: nowrap;
  animation: fx-combo 1.25s ease-out forwards;
}
.fx-combo-main {
  display: block; font-family: var(--font-pixel); font-size: 18px; letter-spacing: 1px;
  color: var(--accent);
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink),
    0 6px 0 var(--accent-dark), 0 0 16px rgba(255, 200, 60, 0.7);
}
.fx-combo.fx-heal .fx-combo-main {
  color: #9dffb0;
  text-shadow:
    3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink),
    3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink),
    0 6px 0 #145c24, 0 0 16px rgba(75, 227, 107, 0.7);
}
.fx-combo-sub {
  display: block; margin-top: 8px; font-size: 22px; color: var(--text);
  text-shadow: 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 2px 0 var(--ink), 0 -2px 0 var(--ink);
}
@keyframes fx-combo {
  0% { opacity: 0; transform: translate(-50%, -100%) scale(0.4); }
  18% { opacity: 1; transform: translate(-50%, -100%) scale(1.18); }
  30% { transform: translate(-50%, -100%) scale(1); }
  75% { opacity: 1; transform: translate(-50%, -125%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -150%) scale(0.95); }
}

/* --- Carteles (sucesos, monstruo derrotado, eliminaciones) --- */
#fx-banners {
  position: absolute; top: calc(var(--bezel) + 16px); left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 16px; width: min(88vw, 540px);
}
.fx-banner {
  --u: 3px;
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 10px 14px; font-size: 21px; color: var(--text);
  animation-name: fx-banner; animation-timing-function: ease; animation-fill-mode: both;
}
.fx-banner strong { font-weight: 400; color: var(--accent); }
.fx-banner small { display: block; color: var(--muted); font-size: 19px; margin-top: 2px; }
.fx-banner-icon { flex-shrink: 0; line-height: 0; }
.fx-banner.fx-event { --fr: var(--accent-2); }
.fx-banner.fx-gold { --fr: var(--accent); }
.fx-banner.fx-dmg { --fr: var(--hp-low); }
@keyframes fx-banner {
  0% { opacity: 0; transform: translateY(-24px); }
  8% { opacity: 1; transform: none; }
  88% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-12px); }
}

/* --- Monstruo en el centro durante el combate --- */
.fx-stage {
  --u: 3px;
  --fr: var(--hp-low);
  position: absolute; left: 50% !important; top: 40% !important; transform: translate(-50%, -50%);
  text-align: center; padding: 22px 36px 20px; min-width: 260px;
  background:
    repeating-linear-gradient(180deg, transparent 0 6px, rgba(255, 255, 255, 0.025) 6px 12px),
    rgba(6, 6, 22, 0.95);
  animation: fx-stage-in 0.35s steps(5, end) both;
}
/* Oscurece el tablero alrededor de la ventana de combate */
.fx-stage::before {
  content: ''; position: absolute; inset: -80px -120px; z-index: -1;
  background: radial-gradient(ellipse closest-side, rgba(2, 2, 10, 0.6) 0 60%, rgba(2, 2, 10, 0.3) 60% 80%, transparent 80%);
}
.fx-stage-icon {
  display: inline-block; line-height: 0;
  filter: drop-shadow(0 8px 0 rgba(0, 0, 0, 0.5)); animation: fx-bob 1s steps(2, end) infinite;
}
.fx-stage-name {
  margin-top: 14px; font-family: var(--font-pixel); font-size: 12px; color: var(--text);
  text-shadow: 0 3px 0 var(--ink);
}
.fx-stage-label {
  margin-top: 12px; font-family: var(--font-pixel); font-size: 18px; letter-spacing: 1px; opacity: 0;
  text-shadow: 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink), 0 6px 0 var(--ink);
}
.fx-stage-label.show { animation: fx-label-pop 0.4s steps(4, end) forwards; }
.fx-stage-label.fx-gold { color: var(--accent); }
.fx-stage-label.fx-dmg { color: #ff5a4e; }
.fx-stage-label.fx-info { color: var(--muted); }
.fx-stage-icon.fx-shake-big { animation: fx-shake-big 0.5s steps(8, end); }
.fx-stage-icon.fx-stage-defeat { animation: fx-defeat 0.7s steps(7, end) forwards; }
.fx-stage-icon.fx-stage-resist { animation: fx-resist 0.6s steps(6, end); }
.fx-stage.fx-stage-out { animation: fx-stage-out 0.35s steps(4, end) forwards; }
@keyframes fx-stage-in {
  from { opacity: 0; transform: translate(-50%, -50%) scale(0.4); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
@keyframes fx-stage-out { to { opacity: 0; transform: translate(-50%, -50%) scale(0.85); } }
@keyframes fx-bob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes fx-defeat {
  0% { transform: scale(1); opacity: 1; filter: brightness(1); }
  40% { transform: scale(1.25); filter: brightness(3); }
  100% { transform: scale(0.1); opacity: 0; filter: brightness(3); }
}
@keyframes fx-resist {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-10px); }
  50% { transform: translateX(10px); }
  75% { transform: translateX(-5px); }
}
@keyframes fx-label-pop { from { opacity: 0; transform: scale(0.5); } to { opacity: 1; transform: scale(1); } }

/* --- Entrada de ventanas (solo cuando cambian, no en cada re-render) --- */
.overlay.enter { animation: fx-fade-in 0.2s steps(3, end); }
.overlay.enter .modal { animation: fx-modal-in 0.28s steps(4, end); }
.monster-icon { display: inline-flex; line-height: 0; animation: fx-bob 1s steps(2, end) infinite; }
@keyframes fx-fade-in { from { opacity: 0; } to { opacity: 1; } }
/* Las ventanas se "despliegan" de arriba abajo como en los RPG de 16 bits */
@keyframes fx-modal-in {
  from { opacity: 0; clip-path: inset(-16px -16px 100% -16px); }
  to { opacity: 1; clip-path: inset(-16px); }
}

/* --- Gusano Suplicante (criatura errante) --- */
.modal.wanderer-modal { text-align: center; --fr: #f0a6ae; max-width: 560px; }
.wanderer-modal h3 { color: #f0a6ae; }
.wanderer-art { display: flex; justify-content: center; margin: -6px 0 2px; }
.wanderer-art .worm { width: 150px; height: auto; overflow: visible; }
.worm-speech {
  position: relative; display: inline-block; margin: 0 auto 10px; padding: 8px 14px;
  background: #f6ead9; color: #3b2420; border-radius: 14px; font-weight: 700; font-style: italic; font-size: 0.9rem;
}
.worm-speech::after {
  content: ''; position: absolute; left: 50%; bottom: -8px; transform: translateX(-50%);
  border: 8px solid transparent; border-top-color: #f6ead9; border-bottom: 0;
}
.wanderer-modal .wanderer-options { display: grid; gap: 6px; text-align: left; font-size: 0.82rem; margin: 6px 0 10px; }
.wanderer-modal .wanderer-options div { background: var(--well); border: 2px solid var(--deep-1); padding: 7px 10px; }
.wanderer-modal .wanderer-options strong.good { color: var(--hp-full); }
.wanderer-modal .wanderer-options strong.bad { color: var(--hp-low); }
.wanderer-modal #hand-area { justify-content: center; }
.feed-meter { height: 12px; background: var(--well); border: 2px solid var(--frame-shade); overflow: hidden; margin: 8px auto 4px; max-width: 320px; }
.feed-meter > div { height: 100%; background: var(--hp-mid); transition: width 0.25s steps(4, end); }
.feed-meter.full > div { background: var(--hp-full); }
.fx-stage-icon .worm { width: 190px; height: auto; overflow: visible; }
/* El gusano es mas alto que un emoji: se baja para no tapar las fichas de los jugadores. Marco
   rosado en vez del rojo de combate: no es una pelea. */
.fx-stage.fx-stage-creature { top: 58% !important; --fr: #f0a6ae; }
.fx-stage-icon.fx-stage-lunge { animation: worm-lunge 0.5s ease-in-out; }
.fx-coin-fly { position: absolute; left: 0; top: 0; font-size: 1.7rem; will-change: transform; filter: drop-shadow(0 0 6px rgba(255,200,60,0.85)); }

.worm .w-outline { stroke: #0c0a18; }
.worm .w-outline-fill { fill: #0c0a18; }
.worm .w-body { stroke: #d98c8f; transition: stroke 0.3s; }
.worm .w-rings { stroke: #a8585f; opacity: 0.45; }
.worm .w-sheen { stroke: #f6c9c6; opacity: 0.5; }
.worm .w-skin { fill: #eeb4a2; stroke: #0c0a18; stroke-width: 2; transition: fill 0.3s; }
.worm .w-limb { stroke: #e3a796; }
.worm .w-finger { stroke: #a56a5e; }
.worm .w-hair { stroke: #3d2f2b; }
.worm .w-wrinkle { stroke: #b07a6c; opacity: 0.6; }
.worm .w-eye { fill: #fbf6ef; stroke: #6b4a40; stroke-width: 1; }
.worm .w-pupil { fill: #2a1d1a; transform-box: fill-box; transform-origin: center; transition: transform 0.2s, fill 0.2s; }
.worm .w-glint { fill: #fff; }
.worm .w-eyes-happy { stroke: #3a2622; }
.worm .w-brow { stroke: #4a3530; }
.worm .w-nose { stroke: #b47565; }
.worm .w-blush { fill: #ff8fa0; opacity: 0.45; }
.worm .w-mouth { fill: #4a1c22; }
.worm .w-tongue { fill: #e46a7a; }
.worm .w-teeth { fill: #f8f1e6; }
.worm .w-tear { fill: #8fd3ff; opacity: 0.9; }
.worm .w-mound { fill: #4a3426; }
.worm .w-mound-top { fill: #241810; }
.worm .w-dirt circle { fill: #6a4c36; }
.worm .w-hearts path { fill: #ff6b8a; }
.worm .w-steam circle { fill: #f1ece6; opacity: 0.85; }
.worm .w-vein { stroke: #c0182a; }

/* Una sola ilustracion, tres expresiones */
.worm .w-only-beg, .worm .w-only-happy, .worm .w-only-angry,
.worm .w-eyes-happy, .worm .w-tear, .worm .w-hearts, .worm .w-steam { display: none; }
.worm.beg .w-only-beg, .worm.beg .w-tear { display: inline; }
.worm.happy .w-only-happy, .worm.happy .w-eyes-happy, .worm.happy .w-hearts { display: inline; }
.worm.happy .w-eyes-open, .worm.happy .w-wrinkle { display: none; }
.worm.angry .w-only-angry, .worm.angry .w-steam { display: inline; }
.worm.angry .w-skin { fill: #ef8f7c; }
.worm.angry .w-body { stroke: #d2706f; }
.worm.angry .w-eye { fill: #ffe0d8; }
.worm.angry .w-pupil { fill: #9b1020; transform: scale(0.6); }

/* Movimiento: se retuerce siempre; suplica con los bracitos, llora, salta de alegria o tiembla de rabia */
.worm .w-upper { transform-origin: 100px 214px; animation: worm-writhe 2.2s ease-in-out infinite; }
.worm .w-arm-l { transform-origin: 86px 128px; }
.worm .w-arm-r { transform-origin: 114px 128px; }
.worm.beg .w-arm-l { animation: worm-grab-l 0.7s ease-in-out infinite alternate; }
.worm.beg .w-arm-r { animation: worm-grab-r 0.7s ease-in-out 0.35s infinite alternate; }
.worm.beg .w-head { transform-origin: 100px 112px; animation: worm-sob 0.55s ease-in-out infinite; }
.worm.beg .w-tear-l { animation: worm-tear 1.3s ease-in infinite; }
.worm.beg .w-tear-r { animation: worm-tear 1.3s ease-in 0.65s infinite; }
.worm.happy .w-upper { animation: worm-happy 0.6s ease-in-out infinite; }
.worm.happy .w-arm-l { animation: worm-wave-l 0.4s ease-in-out infinite alternate; }
.worm.happy .w-arm-r { animation: worm-wave-r 0.4s ease-in-out 0.2s infinite alternate; }
.worm.happy .w-hearts path { transform-box: fill-box; transform-origin: center; animation: worm-heart 1.4s ease-out infinite; }
.worm.happy .w-hearts path:nth-child(2) { animation-delay: 0.6s; }
.worm.angry .w-upper { animation: worm-rage 0.16s linear infinite; }
.worm.angry .w-arm-l { animation: worm-fist-l 0.22s ease-in-out infinite alternate; }
.worm.angry .w-arm-r { animation: worm-fist-r 0.22s ease-in-out 0.11s infinite alternate; }
.worm.angry .w-steam circle { transform-box: fill-box; transform-origin: center; animation: worm-steam 0.9s ease-out infinite; }
.worm.angry .w-steam circle:nth-child(2n) { animation-delay: 0.45s; }
.worm.emerge .w-rise { animation: worm-emerge 1.1s cubic-bezier(.25,.9,.35,1.15) both; }

@keyframes worm-writhe { 0%, 100% { transform: rotate(-4deg); } 50% { transform: rotate(4deg); } }
@keyframes worm-grab-l { from { transform: rotate(14deg); } to { transform: rotate(-28deg); } }
@keyframes worm-grab-r { from { transform: rotate(-14deg); } to { transform: rotate(28deg); } }
@keyframes worm-sob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(1.6px) rotate(-1deg); } }
@keyframes worm-tear { 0% { transform: translateY(0); opacity: 0; } 15% { opacity: 0.95; } 100% { transform: translateY(30px); opacity: 0; } }
@keyframes worm-happy { 0%, 100% { transform: translateY(0) rotate(-3deg); } 50% { transform: translateY(-9px) rotate(3deg); } }
@keyframes worm-wave-l { from { transform: rotate(-20deg); } to { transform: rotate(-55deg); } }
@keyframes worm-wave-r { from { transform: rotate(20deg); } to { transform: rotate(55deg); } }
@keyframes worm-heart {
  0% { transform: translateY(10px) scale(0.5); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(-22px) scale(1.1); opacity: 0; }
}
@keyframes worm-rage { 0%, 100% { transform: translate(-2px, 0) rotate(-1.5deg); } 50% { transform: translate(2px, -1px) rotate(1.5deg); } }
@keyframes worm-fist-l { from { transform: rotate(-10deg); } to { transform: rotate(-48deg); } }
@keyframes worm-fist-r { from { transform: rotate(10deg); } to { transform: rotate(48deg); } }
@keyframes worm-steam { 0% { transform: translateY(6px) scale(0.4); opacity: 0; } 40% { opacity: 0.9; } 100% { transform: translateY(-14px) scale(1.3); opacity: 0; } }
@keyframes worm-emerge {
  0% { transform: translateY(175px); }
  55% { transform: translateY(-8px); }
  75% { transform: translateY(4px); }
  100% { transform: translateY(0); }
}
@keyframes worm-lunge {
  0%, 100% { transform: scale(1) translateY(0); }
  40% { transform: scale(1.35) translateY(-24px); }
  60% { transform: scale(1.3) translateY(-18px); }
}

/* Quien pidio reducir movimiento en su sistema ve los mismos avisos, pero sin desplazamientos
   ni parpadeos de la tele. */
@media (prefers-reduced-motion: reduce) {
  .card.deal-in, .card.link-in, .card.linked-join.link-in, .fx-shake, .fx-shake-big,
  .player-chip.fx-dying, .overlay.enter, .overlay.enter .modal, .fx-stage, .fx-stage-icon,
  .fx-stage-icon.fx-stage-defeat, .fx-stage-icon.fx-stage-resist, .monster-icon,
  .title-text, .title-flourish, .player-chip.current::before, #coach-panel,
  .crt-scanlines, .yep-alert { animation: none !important; }
  .crt-roll, .crt-power { display: none; }
  .btn:hover:not(:disabled)::before, .btn:focus-visible::before,
  #phase-banner:not(:empty)::before, #log-list div:last-child::after,
  #coach-panel::after, .coach-line::after { animation: none; }
  .fx-stage-label.show { animation: none; opacity: 1; }
  .worm *, .fx-stage-icon.fx-stage-lunge { animation: none !important; }
  .fx-float, .fx-combo { animation: fx-fade-only 1.2s ease-out forwards; }
  .fx-banner { animation-name: fx-fade-only; }
  .hp-bar-inner, .hp-bar-ghost { transition: none; }
}
@keyframes fx-fade-only { 0% { opacity: 0; } 15% { opacity: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

/* =====================================================================
   iPhone y pantallas tactiles
   ===================================================================== */

/* Safari en iPhone agranda el texto al girar a horizontal si no se le indica lo contrario. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
/* Sin zoom por doble toque (que ademas retrasa cada toque) en lo que se pulsa. */
button, select, input, .card, .cmp-tab, .tut-dot { touch-action: manipulation; }
/* En pantallas tactiles el "hover" se queda pegado tras tocar: sin levantar cartas por hover. */
@media (hover: none) {
  .card:hover { transform: none; }
  .card.selected, .card.selected:hover { transform: translateY(-10px); }
}

.modal-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 12px; margin-top: 14px; padding-bottom: 6px; }
.modal-actions .btn { margin: 0; }
.wanderer-modal .modal-actions { justify-content: center; }

/* Aviso "gira el telefono": solo en la app agregada a la pantalla de inicio, en vertical. */
#rotate-hint { display: none; }
@media (orientation: portrait) and (max-width: 600px) {
  html.standalone #rotate-hint {
    position: fixed; inset: 0; z-index: 900;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    padding: 24px; text-align: center; background: var(--bg);
  }
  html.standalone #app { visibility: hidden; }
}
@media (display-mode: standalone) and (orientation: portrait) and (max-width: 600px) {
  #rotate-hint {
    position: fixed; inset: 0; z-index: 900;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    padding: 24px; text-align: center; background: var(--bg);
  }
  #app { visibility: hidden; }
}
#rotate-hint p { margin: 0; font-family: var(--font-pixel); font-size: 13px; line-height: 1.6; color: var(--accent); text-shadow: 0 3px 0 var(--ink); }
#rotate-hint small { color: var(--muted); font-size: 20px; }
.rotate-phone {
  width: 44px; height: 76px; border: 4px solid var(--frame); background: var(--win-3);
  box-shadow: 0 0 0 3px var(--ink), inset 0 -10px 0 var(--win-4);
  animation: rotate-phone 2.4s steps(6, end) infinite;
}
@keyframes rotate-phone {
  0%, 30% { transform: rotate(0deg); }
  60%, 100% { transform: rotate(-90deg); }
}

/* =====================================================================
   Telefono en horizontal (iPhone girado: 320-430 px de alto).
   Todo el juego cabe en una pantalla, sin desplazar la pagina:
   jugadores a la izquierda, mano y controles al centro, registro a la derecha.
   Las muescas/isla del iPhone quedan a los lados: se respetan con safe-area.
   ===================================================================== */
@media (orientation: landscape) and (max-height: 500px) {
  :root { --bezel: 5px; --screen-r: 14px; --join: 22px; }
  html, body { overscroll-behavior: none; }
  body { font-size: 18px; min-height: 0; }
  #app {
    max-width: none;
    padding:
      calc(var(--bezel) + 6px)
      max(calc(var(--bezel) + 8px), env(safe-area-inset-right))
      max(calc(var(--bezel) + 6px), env(safe-area-inset-bottom))
      max(calc(var(--bezel) + 8px), env(safe-area-inset-left));
  }

  /* Titulo: una linea en la preparacion; durante la partida no ocupa lugar */
  #top-bar { padding: 2px 0 4px; }
  #top-bar h1 { font-size: 13px; }
  #top-bar .subtitle, #top-bar::after, .title-flourish { display: none; }
  body.in-game #top-bar { display: none; }

  /* --- Preparacion --- */
  #setup-screen { max-width: 980px; margin-top: 2px; padding: 12px 16px 14px; }
  #setup-screen h2 { font-size: 12px; margin-bottom: 2px; }
  #setup-screen h3 { font-size: 10px; }
  .field-row { margin: 6px 0; gap: 10px; }
  .field-note { font-size: 16px; }
  #player-forms { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 10px 0; }
  .player-form-row { padding: 6px 8px; gap: 8px; }
  .class-desc { font-size: 15px; }
  .class-portrait { width: 36px; height: 36px; }
  #setup-screen .hint { font-size: 16px; margin-top: 6px; }
  .app-version { margin-top: 6px; font-size: 16px; }
  .divider { margin: 10px 0 8px; }

  /* --- Partida: tres columnas a pantalla completa --- */
  #game-screen.screen-game {
    display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 12px;
    max-width: none;
    height: calc(100vh - 2 * (var(--bezel) + 6px));
    height: calc(100dvh - (var(--bezel) + 6px) - max(calc(var(--bezel) + 6px), env(safe-area-inset-bottom)));
  }
  #game-screen.screen-game[hidden] { display: none; }
  #game-screen.screen-game { grid-template-rows: minmax(0, 1fr); }
  /* Sus ventanas son position:fixed; fuera del grid, para no crear una fila extra que achique
     el tablero mientras estan abiertas. */
  #game-screen.screen-game > #overlay-root { position: absolute; }

  #players-bar {
    flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; align-items: stretch;
    gap: 12px; margin: 0; padding: 4px 4px 6px; min-height: 0; overflow-y: auto;
    scrollbar-width: none;
  }
  #players-bar::-webkit-scrollbar { display: none; }
  .player-chip { min-width: 0; padding: 6px 8px 5px; }
  .player-chip.current::before { display: none; }
  .player-chip .class-icon { width: 28px; height: 28px; margin: 0 6px 2px 0; }
  .player-chip .class-icon img.px-sprite { width: 22px; height: 22px; }
  .player-chip .pname { font-size: 8px; line-height: 1.5; white-space: normal; overflow-wrap: anywhere; }
  .player-chip .pclass { display: none; }
  .player-chip .hp-bar-outer { height: 8px; margin-top: 5px; }
  .player-chip .hp-text, .player-chip .coin-text { display: inline-block; font-size: 7px; margin-top: 7px; letter-spacing: 0; white-space: nowrap; }
  .player-chip .coin-text { margin-left: 8px; }
  .player-chip .coin-text::before { margin-right: 4px; }
  .player-chip .coin-label { display: none; }
  .player-chip .artifact-icons { font-size: 14px; max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .yep-alert { top: -10px; right: -8px; }
  /* Con 5 o 6 jugadores, fichas sin retrato para que entren todas */
  #players-bar:has(> .player-chip:nth-child(5)) { gap: 8px; padding-top: 3px; }
  #players-bar:has(> .player-chip:nth-child(5)) .player-chip { --u: 2px; padding: 3px 7px 3px; }
  #players-bar:has(> .player-chip:nth-child(5)) .hp-bar-outer { margin-top: 3px; height: 7px; }
  #players-bar:has(> .player-chip:nth-child(5)) .class-icon,
  #players-bar:has(> .player-chip:nth-child(5)) .artifact-icons { display: none; }
  #players-bar:has(> .player-chip:nth-child(5)) .pname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-top: 0; }
  #players-bar:has(> .player-chip:nth-child(5)) .hp-text,
  #players-bar:has(> .player-chip:nth-child(5)) .coin-text { margin-top: 4px; }

  #board { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 12px; min-height: 0; }
  #action-panel { padding: 8px 10px 10px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
  #phase-banner { font-size: 8px; margin-bottom: 2px; }
  #coach-panel { font-size: 16px; padding: 6px 26px 6px 8px; margin: 2px 0 6px; gap: 8px; }
  .coach-icon { width: 30px; height: 30px; }
  .coach-line { font-size: 16px; padding: 6px 26px 6px 8px; margin: 6px 0 8px; }

  /* La mano en una sola fila (se desliza de lado si hay muchas cartas) */
  #hand-area {
    flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; gap: 8px;
    margin: 0 0 4px; padding: 16px 6px 10px; min-height: 0;
    scrollbar-width: none;
  }
  #hand-area::-webkit-scrollbar { display: none; }
  .card { --u: 2px; --sp: 2px; width: 50px; height: 72px; flex-shrink: 0; gap: 4px; }
  .card .val { font-size: 16px; }
  .card .corner { display: none; }
  .card .group-badge { top: -12px; }

  #controls { gap: 10px 8px; }
  #controls .group { gap: 10px 8px; }
  #controls .info, .info { font-size: 16px; }
  .btn { font-size: 17px; padding: 6px 12px 5px; }
  .btn-small { font-size: 15px; padding: 5px 10px 4px; }
  .hand-preview { gap: 6px; margin: 2px 0 4px; }
  .preview-row { font-size: 16px; padding: 4px 8px 3px; }
  #loot-bar { margin-top: 8px; padding-top: 8px; gap: 10px 8px; }

  #side-panel { min-height: 0; gap: 8px; position: static; }
  #log-panel { flex: 1 1 auto; height: auto; min-height: 0; max-height: none; font-size: 15px; padding: 6px 8px; }
  #log-panel::before { font-size: 7px; top: -6px; margin: -6px 0 4px; padding: 6px 0 4px; }
  .side-buttons { flex-wrap: nowrap; gap: 8px; }
  .side-buttons .btn { flex: 1 1 0; padding: 5px 4px 4px; font-size: 14px; }

  /* --- Ventanas: ocupan el alto disponible; los botones quedan fijos al pie --- */
  .overlay {
    padding:
      calc(var(--bezel) + 6px)
      max(calc(var(--bezel) + 10px), env(safe-area-inset-right))
      max(calc(var(--bezel) + 6px), env(safe-area-inset-bottom))
      max(calc(var(--bezel) + 10px), env(safe-area-inset-left));
  }
  /* Sin relleno inferior: asi la barra fija de botones queda pegada al borde en cualquier
     navegador (Chrome y Safari no tratan igual el relleno de un contenedor con scroll). */
  .modal { max-width: min(760px, 100%); max-height: 100%; padding: 12px 16px 0; font-size: 18px; }
  .modal > :last-child:not(.modal-actions):not(.tut-nav) { margin-bottom: 12px; }
  .modal h3 { font-size: 11px; margin-bottom: 6px; }
  .modal h4 { font-size: 9px; margin: 10px 0 6px; }
  .modal p { margin: 4px 0; }
  .modal #hand-area { margin: 6px 0 4px; padding-top: 14px; }
  .modal-actions, .tut-nav {
    position: sticky; bottom: 0; z-index: 3;
    margin-top: 8px; padding: 8px 0 12px;
    background: var(--win-4);
  }
  .modal-actions .btn-small.cmp-link { margin-left: auto; }

  /* Tienda: articulos en dos columnas */
  .shop-modal { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 12px; align-content: start; }
  .shop-modal > :not(.shop-item) { grid-column: 1 / -1; }
  .shop-modal > .cmp-link { justify-self: start; }
  .shop-item { font-size: 17px; padding: 5px 8px; margin: 0 2px 8px; }
  .shop-item .desc { font-size: 15px; }

  /* Gusano: dibujo a la izquierda, decision a la derecha */
  .modal.wanderer-modal {
    display: grid; grid-template-columns: 150px minmax(0, 1fr); column-gap: 16px; align-content: start;
    text-align: left; max-width: 760px;
  }
  .wanderer-modal > * { grid-column: 2; }
  .wanderer-modal > h3 { grid-column: 1 / -1; }
  .wanderer-modal > .wanderer-side { grid-column: 1; grid-row: 2 / span 6; align-self: start; text-align: center; }
  .wanderer-art .worm { width: 112px; }
  .worm-speech { font-size: 15px; padding: 6px 8px; margin: 2px 0 0; }
  .worm-speech::after { top: -8px; bottom: auto; border-top: 0; border-bottom: 8px solid #f6ead9; }
  .wanderer-modal .wanderer-options { font-size: 15px; gap: 6px; margin: 0 0 4px; }
  .wanderer-modal .wanderer-options div { padding: 5px 8px; }
  .wanderer-modal #hand-area { justify-content: flex-start; }
  .wanderer-modal .modal-actions { justify-content: flex-start; }
  .feed-meter { margin: 4px 0 2px; max-width: none; }

  /* Como jugar y Compendio */
  .tut-modal { max-width: 760px; }
  .tut-body { font-size: 17px; }
  .tut-dots { margin: 8px 0 4px; }
  .cmp-modal { height: 100%; max-width: 900px; padding-bottom: 8px; }
  .cmp-header h3 { font-size: 12px; }
  .cmp-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 8px 0 6px; padding-bottom: 8px; }
  .cmp-tabs::-webkit-scrollbar { display: none; }
  .cmp-tab { flex-shrink: 0; font-size: 16px; }
  .cmp-body { font-size: 17px; }

  /* Efectos centrales mas chicos: la pantalla es baja */
  img.px-sprite.px-lg { width: 72px; height: 72px; }
  .fx-stage { padding: 12px 22px 12px; min-width: 200px; }
  .fx-stage.fx-stage-creature { top: 50% !important; }
  .fx-stage-icon .worm { width: 104px; }
  .fx-stage-label { font-size: 13px; margin-top: 6px; }
  #fx-banners { top: calc(var(--bezel) + 6px); width: min(70vw, 520px); }
}

/* iPhone SE y similares (667 px de ancho): columnas laterales un poco mas angostas */
@media (orientation: landscape) and (max-height: 500px) and (max-width: 700px) {
  #game-screen.screen-game { grid-template-columns: 138px minmax(0, 1fr); gap: 8px; }
  #board { grid-template-columns: minmax(0, 1fr) 150px; gap: 8px; }
  #action-panel { padding: 6px 8px 8px; }
  .card { width: 46px; height: 66px; }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-phone { animation: none; transform: rotate(-90deg); }
}
