:root {
  --fondo: #0a0f14;
  --panel: rgba(12, 16, 22, 0.92);
  --borde: #3a3326;
  --oro: #d8b46a;
  --oro2: #f3dca0;
  --texto: #e8e4da;
  --tenue: #9a9384;
  --azul: #3fa9ff;
  --rojo: #ff4d5a;
  --verde: #58e36f;
  --mana: #4f8dff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--fondo); color: var(--texto); font-family: Inter, system-ui, sans-serif; user-select: none; -webkit-user-select: none; }
canvas#lienzo, canvas#capa { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
canvas#capa { pointer-events: none; }
#vineta { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(4, 8, 6, 0.55) 100%); }
.oculto { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Selección ---------- */
.pantalla { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; padding: 16px; overflow: auto;
  background: radial-gradient(ellipse at 50% 30%, rgba(40, 70, 60, 0.55), rgba(5, 8, 10, 0.96) 70%), #06090c; }
#pausa, #final { background: rgba(4, 6, 9, 0.78); backdrop-filter: blur(4px); }
.sel-caja { width: min(1080px, 100%); display: flex; flex-direction: column; gap: 22px; }
.sel-caja.chica { width: min(560px, 100%); align-items: center; text-align: center; padding: 34px 28px; background: var(--panel); border: 1px solid var(--borde); border-radius: 14px; }
.marca { text-align: center; }
.marca h1 { font-family: Cinzel, serif; font-weight: 800; font-size: clamp(54px, 10vw, 104px); letter-spacing: 0.18em; margin: 0; line-height: 1;
  background: linear-gradient(180deg, #fff3cf, #d8b46a 55%, #8a6a2c); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 30px rgba(216, 180, 106, 0.25)); }
.marca-sub { font-family: Cinzel, serif; letter-spacing: 0.45em; text-transform: uppercase; color: var(--oro); font-size: 13px; }
.marca p { color: var(--tenue); margin: 10px 0 0; }
h2 { font-family: Cinzel, serif; color: var(--oro2); letter-spacing: 0.08em; margin: 0 0 8px; }

.heroes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.heroe { position: relative; border: 1px solid var(--borde); border-radius: 12px; padding: 16px 12px 14px; text-align: left; background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(0,0,0,0.25)); transition: transform .15s, border-color .15s, box-shadow .15s; }
.heroe:hover { transform: translateY(-3px); border-color: #6b5c3c; }
.heroe.activo { border-color: var(--oro); box-shadow: 0 0 0 1px var(--oro), 0 10px 40px rgba(216,180,106,0.18); }
.heroe .emblema { width: 54px; height: 54px; border-radius: 50%; display: grid; place-items: center; font-family: Cinzel, serif; font-weight: 800; font-size: 24px; color: #0b0b0b; margin-bottom: 10px; box-shadow: inset 0 -6px 12px rgba(0,0,0,0.3); }
.heroe b { display: block; font-family: Cinzel, serif; font-size: 18px; color: var(--oro2); }
.heroe small { color: var(--tenue); display: block; }
.heroe .rol { position: absolute; top: 12px; right: 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; padding: 3px 7px; border-radius: 99px; background: rgba(255,255,255,0.06); color: var(--tenue); }
.detalle { min-height: 150px; border: 1px solid var(--borde); border-radius: 12px; padding: 16px 18px; background: var(--panel); display: grid; grid-template-columns: 1.1fr 2fr; gap: 18px; }
.detalle p { margin: 4px 0 0; color: #cfc8b8; }
.detalle .lista-habs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px; }
.detalle .lista-habs div { font-size: 13px; color: #c9c2b2; }
.detalle .lista-habs b { color: var(--oro2); }
.tecla { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 4px; border-radius: 4px; background: #2a251b; border: 1px solid #5a4c30; color: var(--oro2); font-size: 11px; font-weight: 700; margin-right: 6px; }
.sel-pie { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.dificultad { display: flex; align-items: center; gap: 6px; color: var(--tenue); }
.dificultad span { margin-right: 6px; }
.dificultad button, .boton { background: rgba(255,255,255,0.05); border: 1px solid var(--borde); border-radius: 8px; padding: 9px 14px; }
.dificultad button.activo { border-color: var(--oro); color: var(--oro2); background: rgba(216,180,106,0.12); }
.boton-grande { font-family: Cinzel, serif; font-weight: 800; letter-spacing: 0.1em; font-size: 18px; padding: 15px 34px; border-radius: 10px; border: 1px solid #f3dca0;
  background: linear-gradient(180deg, #e8c77f, #a5823f); color: #1a1406; box-shadow: 0 8px 30px rgba(216,180,106,0.25); }
.boton-grande:hover { filter: brightness(1.08); }
.controles { color: var(--tenue); font-size: 14px; }
.controles summary { cursor: pointer; color: var(--oro); }
.controles ul { columns: 2; margin: 10px 0 0; padding-left: 18px; }
.controles b { color: var(--texto); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
#hud > * { pointer-events: auto; }
#hud .arriba, #hud .feed, #hud .anuncio, #hud .aviso, #hud .canal, #hud .muerte { pointer-events: none; }
.arriba { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); }
.marcador { display: flex; align-items: center; gap: 14px; background: var(--panel); border: 1px solid var(--borde); border-radius: 0 0 12px 12px; padding: 6px 18px; font-weight: 800; font-size: 20px; }
.marcador .az { color: var(--azul); } .marcador .ro { color: var(--rojo); }
.marcador .reloj { font-size: 14px; color: var(--tenue); font-variant-numeric: tabular-nums; min-width: 44px; text-align: center; }
.feed { position: absolute; top: 12px; right: 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.feed div { background: rgba(10,14,18,0.82); border: 1px solid #2a2a2a; border-radius: 6px; padding: 4px 10px; font-size: 13px; animation: entra .25s ease-out; }
@keyframes entra { from { transform: translateX(20px); opacity: 0; } }
.anuncio { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); font-family: Cinzel, serif; font-weight: 800; font-size: 34px; letter-spacing: .05em; text-shadow: 0 3px 16px rgba(0,0,0,0.9); white-space: nowrap; transition: opacity .3s; }
.aviso { position: absolute; bottom: 190px; left: 50%; transform: translateX(-50%); color: #ffd0d0; background: rgba(60,10,14,0.75); border: 1px solid #6a2228; padding: 6px 14px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; }

.panel { position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: flex-end; background: var(--panel); border: 1px solid var(--borde); border-radius: 14px; padding: 10px 12px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); }
.retrato { position: relative; width: 84px; height: 84px; border-radius: 50%; border: 2px solid var(--oro); display: grid; place-items: center; font-family: Cinzel, serif; font-size: 34px; font-weight: 800; color: #111; flex: none; }
.retrato #nivel { position: absolute; bottom: -6px; right: -4px; background: #15120c; color: var(--oro2); border: 1px solid var(--oro); border-radius: 50%; width: 28px; height: 28px; display: grid; place-items: center; font-size: 13px; font-family: Inter, sans-serif; }
.retrato .xp { position: absolute; left: 6px; right: 6px; bottom: -10px; height: 4px; background: #222; border-radius: 3px; overflow: hidden; }
.retrato .xp i { display: block; height: 100%; background: #b77dff; width: 0; }
.centro { display: flex; flex-direction: column; gap: 8px; }
.habs { display: flex; gap: 8px; }
.hab { position: relative; width: 60px; height: 60px; border-radius: 10px; border: 1px solid #4b412c; overflow: hidden; display: grid; place-items: center; text-align: center; font-size: 10px; font-weight: 700; line-height: 1.1; color: #fff; text-shadow: 0 1px 2px #000; }
.hab .nom { padding: 0 3px; }
.hab .tk { position: absolute; top: 2px; left: 4px; font-size: 11px; color: var(--oro2); }
.hab .cd { position: absolute; inset: 0; background: rgba(0,0,0,0.68); display: grid; place-items: center; font-size: 18px; font-weight: 800; }
.hab .sinmana { position: absolute; inset: 0; background: rgba(20,40,120,0.55); }
.hab.bloqueada { filter: grayscale(1) brightness(0.45); }
.hab .rangos { position: absolute; bottom: 3px; left: 0; right: 0; display: flex; justify-content: center; gap: 2px; }
.hab .rangos i { width: 6px; height: 3px; background: #444; border-radius: 1px; }
.hab .rangos i.on { background: var(--oro2); }
.hab .mas { position: absolute; top: -1px; right: -1px; width: 20px; height: 20px; border-radius: 0 0 0 8px; background: #e7c66f; color: #221a05; border: none; font-weight: 900; font-size: 15px; line-height: 1; padding: 0; }
.barras { display: flex; flex-direction: column; gap: 4px; }
.b-hp, .b-mana { position: relative; height: 16px; background: #1b1d20; border-radius: 4px; overflow: hidden; border: 1px solid #2c2c2c; }
.b-mana { height: 12px; }
.b-hp i, .b-mana i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(180deg, #6cf083, #2fa548); }
.b-mana i { background: linear-gradient(180deg, #78a5ff, #3361d6); }
.b-hp span, .b-mana span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.b-mana span { font-size: 9px; }
.lado { display: flex; flex-direction: column; gap: 6px; width: 168px; }
.objetos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.objetos div { height: 34px; border-radius: 6px; border: 1px solid #3b3426; background: rgba(255,255,255,0.03); display: grid; place-items: center; font-size: 19px; }
.oro { display: flex; align-items: center; gap: 6px; color: #ffd24a; font-weight: 800; }
.oro b { flex: 1; font-variant-numeric: tabular-nums; }
.oro button { background: linear-gradient(180deg, #e8c77f, #a5823f); color: #1a1406; border: none; border-radius: 6px; padding: 4px 10px; font-weight: 800; font-size: 12px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 6px; font-size: 11px; color: var(--tenue); }
.stats b { color: var(--texto); font-weight: 600; }

.canal { position: absolute; bottom: 200px; left: 50%; transform: translateX(-50%); width: 260px; text-align: center; font-size: 13px; color: #bfe6ff; }
.canal div { height: 8px; background: #111; border: 1px solid #335; border-radius: 4px; margin-top: 4px; overflow: hidden; }
.canal i { display: block; height: 100%; background: linear-gradient(90deg, #4fb4ff, #bfe6ff); }
.muerte { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); text-align: center; font-family: Cinzel, serif; }
.muerte b { display: block; font-size: 40px; color: #ff8b8b; text-shadow: 0 3px 20px #000; }
.muerte span { font-size: 18px; color: #f2d6d6; }
body.muerto canvas#lienzo { filter: grayscale(0.85) brightness(0.8); }

.mini { position: absolute; right: 10px; bottom: 10px; background: var(--panel); border: 1px solid var(--borde); border-radius: 10px; padding: 6px; }
.mini canvas { display: block; width: 220px; height: 220px; border-radius: 6px; cursor: pointer; }
.mini button { position: absolute; top: -28px; right: 0; background: var(--panel); border: 1px solid var(--borde); border-radius: 6px; font-size: 11px; padding: 3px 8px; }

.tooltip { position: fixed; z-index: 30; max-width: 280px; background: rgba(8,10,14,0.97); border: 1px solid var(--oro); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: #d9d3c4; pointer-events: none; }
.tooltip b { color: var(--oro2); display: block; margin-bottom: 4px; }
.tooltip small { color: var(--tenue); display: block; margin-top: 6px; }

/* ---------- Tienda ---------- */
.tienda { position: fixed; z-index: 15; left: 50%; top: 50%; transform: translate(-50%, -55%); width: min(700px, calc(100% - 32px)); max-height: 80vh; overflow: auto; background: rgba(12,15,20,0.97); border: 1px solid var(--oro); border-radius: 14px; padding: 16px 18px 18px; box-shadow: 0 30px 80px rgba(0,0,0,0.7); }
.tienda header { display: flex; align-items: center; gap: 14px; }
.tienda header h2 { margin: 0; flex: 1; }
.tienda header span { color: #ffd24a; font-weight: 800; }
.tienda header button { background: none; border: 1px solid var(--borde); border-radius: 6px; width: 30px; height: 30px; }
.tienda .nota { color: var(--tenue); font-size: 13px; margin: 6px 0 12px; }
.items { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.item { text-align: left; border: 1px solid #3b3426; border-radius: 10px; padding: 10px; background: rgba(255,255,255,0.03); display: grid; grid-template-columns: 34px 1fr; gap: 2px 8px; align-items: center; }
.item:hover { border-color: var(--oro); }
.item .ic { grid-row: span 3; font-size: 26px; }
.item b { font-size: 13px; color: var(--oro2); }
.item small { font-size: 11px; color: var(--tenue); }
.item .precio { font-size: 12px; color: #ffd24a; font-weight: 700; }
.item.caro { opacity: 0.5; }

/* ---------- Marcador (Tab) ---------- */
.tabla { position: fixed; z-index: 14; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(760px, calc(100% - 32px)); background: rgba(10,13,18,0.96); border: 1px solid var(--borde); border-radius: 12px; padding: 14px; }
.tabla table { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabla th { text-align: left; color: var(--tenue); font-weight: 500; padding: 4px 6px; font-size: 12px; }
.tabla td { padding: 5px 6px; border-top: 1px solid #1f2328; }
.tabla .eq0 td:first-child { border-left: 3px solid var(--azul); }
.tabla .eq1 td:first-child { border-left: 3px solid var(--rojo); }
.tabla tr.yo td { background: rgba(216,180,106,0.1); }
.tabla h3 { margin: 10px 0 4px; font-family: Cinzel, serif; }

.cargando { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: #06090c; font-family: Cinzel, serif; font-size: 22px; color: var(--oro); letter-spacing: .1em; }

@media (max-width: 900px) {
  .heroes { grid-template-columns: repeat(2, 1fr); }
  .detalle { grid-template-columns: 1fr; }
  .detalle .lista-habs { grid-template-columns: 1fr; }
  .controles ul { columns: 1; }
  .mini canvas { width: 140px; height: 140px; }
  .lado { display: none; }
}

/* ---------- Celular (controles táctiles, horizontal) ---------- */
body.tactil { touch-action: none; overscroll-behavior: none; -webkit-tap-highlight-color: transparent; }
body.tactil .pantalla { touch-action: pan-y; }
#tactil { position: fixed; inset: 0; z-index: 6; pointer-events: none; }
#tactil > * { pointer-events: auto; }
#tactil button { touch-action: none; -webkit-user-select: none; user-select: none; }
body.tactil .panel, body.tactil .feed, body.tactil #btnCam, body.tactil #tooltip { display: none !important; }
body.tactil .mini { top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); bottom: auto; padding: 4px; }
body.tactil .mini canvas { width: 118px; height: 118px; }
body.tactil .arriba { top: 4px; }
body.tactil .marcador { font-size: 16px; padding: 4px 12px; border-radius: 10px; }
body.tactil .aviso { bottom: auto; top: 58px; font-size: 13px; }
body.tactil .anuncio { font-size: 24px; top: 22%; }
body.tactil .canal { bottom: auto; top: 38%; }
body.tactil .muerte { top: 26%; }
body.tactil .muerte b { font-size: 30px; }
body.tactil .tienda { max-height: 88vh; padding: 12px 14px; top: 50%; transform: translate(-50%, -50%); }
body.tactil .items { grid-template-columns: repeat(4, 1fr); gap: 6px; }
body.tactil .item { padding: 7px; grid-template-columns: 26px 1fr; }
body.tactil .item .ic { font-size: 20px; }
body.tactil .item small { display: none; }
body.tactil .tabla { max-height: 88vh; overflow: auto; padding: 10px; }
body.tactil .tabla table { font-size: 12px; }

.t-estado { position: absolute; top: max(8px, env(safe-area-inset-top)); left: max(8px, env(safe-area-inset-left)); display: flex; gap: 8px; align-items: center; background: var(--panel); border: 1px solid var(--borde); border-radius: 12px; padding: 6px 10px 6px 6px; }
.t-retrato { position: relative; width: 44px; height: 44px; border-radius: 50%; border: 2px solid var(--oro); display: grid; place-items: center; font-family: Cinzel, serif; font-weight: 800; font-size: 20px; color: #111; }
.t-nivel { position: absolute; right: -6px; bottom: -6px; width: 20px; height: 20px; border-radius: 50%; background: #15120c; color: var(--oro2); border: 1px solid var(--oro); display: grid; place-items: center; font: 700 10px Inter, sans-serif; }
.t-barras { width: 150px; display: flex; flex-direction: column; gap: 3px; }
.t-hp, .t-mana { position: relative; height: 12px; background: #1b1d20; border-radius: 4px; overflow: hidden; }
.t-mana { height: 6px; }
.t-hp i, .t-mana i { position: absolute; inset: 0 auto 0 0; background: linear-gradient(180deg, #6cf083, #2fa548); }
.t-mana i { background: linear-gradient(180deg, #78a5ff, #3361d6); }
.t-hp span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 9px; font-weight: 700; text-shadow: 0 1px 2px #000; }
.t-oro { font-size: 12px; color: #ffd24a; font-weight: 800; }
.t-botones { position: absolute; top: calc(max(8px, env(safe-area-inset-top)) + 64px); left: max(8px, env(safe-area-inset-left)); display: flex; gap: 6px; }
.t-botones button { width: 40px; height: 40px; border-radius: 10px; background: var(--panel); border: 1px solid var(--borde); font-size: 18px; }

.t-zona-joy { position: absolute; left: 0; bottom: 0; width: 42vw; height: 62vh; }
.t-joy { position: absolute; left: 110px; top: calc(100% - 110px); width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: radial-gradient(circle, rgba(255,255,255,0.08), rgba(255,255,255,0.03)); border: 2px solid rgba(216,180,106,0.35); opacity: 0.55; transition: opacity .15s; }
.t-joy.activo { opacity: 1; }
.t-palanca { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #f3dca0, #a5823f); box-shadow: 0 4px 14px rgba(0,0,0,0.5); }

.t-acciones { position: absolute; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); width: 250px; height: 200px; }
.t-atq { position: absolute; right: 0; bottom: 0; width: 88px; height: 88px; border-radius: 50%; font-size: 34px; color: #1a1406; border: 2px solid #f3dca0; background: radial-gradient(circle at 40% 35%, #f3dca0, #a5823f); box-shadow: 0 6px 20px rgba(0,0,0,0.5); }
.t-atq:active { transform: scale(0.94); }
.t-hab { position: absolute; width: 62px; height: 62px; border-radius: 50%; border: 2px solid #6b5c3c; color: #fff; font-size: 9px; font-weight: 700; line-height: 1.05; text-shadow: 0 1px 2px #000; padding: 4px; overflow: visible; box-shadow: 0 4px 14px rgba(0,0,0,0.45); }
.t-hab .nom { display: block; pointer-events: none; }
.t-hab.apuntando { border-color: #8fd3ff; transform: scale(1.08); }
.t-hab.bloqueada { filter: grayscale(1) brightness(0.5); }
.t-hab.sinmana { box-shadow: inset 0 0 0 40px rgba(20,40,120,0.5); }
.t-hab .cd { position: absolute; inset: 0; border-radius: 50%; background: rgba(0,0,0,0.65); display: none; place-items: center; font-style: normal; font-size: 18px; font-weight: 800; pointer-events: none; }
.t-hab .cd.on { display: grid; }
.t-hab .mas { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; border-radius: 50%; background: #e7c66f; color: #221a05; font-style: normal; font-size: 18px; font-weight: 900; display: none; place-items: center; border: 2px solid #15120c; }
.t-hab .mas.on { display: grid; }
.t-h0 { right: 104px; bottom: 0; }
.t-h1 { right: 96px; bottom: 80px; }
.t-h2 { right: 22px; bottom: 106px; }
.t-h3 { right: 176px; bottom: 52px; width: 66px; height: 66px; border-color: #d8b46a; }

.girar { display: none; position: fixed; inset: 0; z-index: 50; background: #06090c; place-items: center; text-align: center; color: var(--oro2); }
.girar span { display: block; font-size: 54px; margin-bottom: 10px; }
.girar b { font-family: Cinzel, serif; font-size: 24px; display: block; }
.girar p { color: var(--tenue); }
@media (orientation: portrait) { body.tactil.en-partida .girar { display: grid; } }

/* Selección en pantallas bajas (celular en horizontal). */
@media (max-height: 520px) {
  .pantalla { place-items: start center; padding: 10px 16px; }
  .sel-caja { gap: 10px; }
  .marca h1 { font-size: 40px; }
  .marca-sub { font-size: 10px; }
  .marca p { display: none; }
  .heroes { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .heroe { padding: 8px 6px; text-align: center; }
  .heroe .emblema { width: 34px; height: 34px; font-size: 16px; margin: 0 auto 4px; }
  .heroe b { font-size: 14px; }
  .heroe small, .heroe .rol { display: none; }
  .detalle { min-height: 0; padding: 8px 12px; grid-template-columns: 1fr; }
  .detalle h2 { font-size: 18px; margin: 0; }
  .detalle .lista-habs, .detalle p:last-child { display: none; }
  .detalle p { font-size: 13px; }
  .boton-grande { font-size: 15px; padding: 11px 22px; }
  .dificultad button { padding: 6px 10px; font-size: 13px; }
  .controles { display: none; }
}
