:root {
    --bg: #110d09; --stone: rgba(20, 15, 11, 0.82); --line: #3a2c1c; --gold: #d4a24c; --gold-light: #efcf8a;
    --parch: #eadcb8; --ink: #2a1d10; --ink-muted: #5c4630; --red: #8e2a1f; --text: #efe4cc;
    --t: #ff8a6b; --ct: #8fc3ff;
    --f-display: 'Cinzel Decorative', Georgia, serif; --f-title: 'Cinzel', Georgia, serif; --f-body: 'EB Garamond', Georgia, serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--f-body);
    touch-action: none; overscroll-behavior: none; user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---------- Entrada ---------- */
.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
    background: rgba(12, 9, 7, 0.8); z-index: 30; overflow-y: auto; }
.parch { width: 100%; max-width: 460px; margin: auto; padding: 24px 24px 20px; display: flex; flex-direction: column; align-items: center;
    gap: 9px; text-align: center; background: var(--parch); color: var(--ink); border: 1px solid #b8955a;
    outline: 1px solid rgba(92, 70, 48, 0.35); outline-offset: -7px; }
.parch h1 { margin: 0; font-family: var(--f-display); font-size: 34px; color: var(--red); }
.parch p { margin: 0; color: var(--ink-muted); font-size: 16px; }
.parch .sub { margin-top: -6px; }
.kicker { font-family: var(--f-title); font-size: 11px !important; font-weight: 700; letter-spacing: 3px; text-transform: uppercase; color: var(--red) !important; }
.parch > label, .grupo-titulo { align-self: stretch; text-align: left; margin-top: 4px; font-family: var(--f-title); font-size: 12px !important;
    font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--ink-muted) !important; }
.parch input[type=text] { align-self: stretch; height: 48px; padding: 0 14px; background: #f5ecd6; border: 1px solid #9c7b4a; color: var(--ink);
    font-family: var(--f-body); font-size: 20px; outline: none; user-select: text; -webkit-user-select: text; }
.parch input[type=text]:focus { border-color: var(--red); }
.opciones { align-self: stretch; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opcion, .eq { position: relative; cursor: pointer; }
.opcion input, .eq input { position: absolute; opacity: 0; }
.opcion span { display: flex; flex-direction: column; gap: 3px; height: 100%; padding: 10px; text-align: left; background: #f5ecd6; border: 1px solid #b8955a; }
.opcion b { font-family: var(--f-title); font-size: 15px; }
.opcion small { font-size: 13px; line-height: 1.25; color: var(--ink-muted); }
.opcion em { font-size: 12px; font-style: normal; color: var(--red); font-weight: 600; }
.opcion input:checked + span { border: 2px solid var(--red); background: #fff6e2; }
.opcion input:focus-visible + span, .eq input:focus-visible + span { outline: 2px solid var(--red); outline-offset: 2px; }
.equipos { align-self: stretch; display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.eq span { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 50px; padding: 6px;
    font-family: var(--f-title); font-weight: 700; font-size: 14px; border: 1px solid #b8955a; background: #f5ecd6; }
.eq small { font-family: var(--f-body); font-weight: 400; font-size: 12px; color: var(--ink-muted); }
.eq-t input:checked + span { background: #6b1f16; color: #ffe1d6; border-color: var(--t); }
.eq-ct input:checked + span { background: #1f3566; color: #dce9ff; border-color: var(--ct); }
.eq-auto input:checked + span { background: #5c4630; color: #f5ecd6; }
.eq input:checked + span small { color: inherit; opacity: 0.8; }
.error { min-height: 20px; color: var(--red) !important; font-weight: 600; }
.hint { font-size: 13px !important; line-height: 1.45; }
.btn-red { align-self: stretch; min-height: 50px; padding: 0 22px; background: var(--red); color: #f6ead0; border: 1px solid var(--gold);
    outline: 1px solid rgba(212, 162, 76, 0.4); outline-offset: 3px; font-family: var(--f-title); font-size: 15px; font-weight: 700;
    letter-spacing: 1.5px; text-transform: uppercase; cursor: pointer; }
.btn-red:disabled { opacity: 0.6; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud button, #hud input, #hud form, #hud .marcador, #hud .arsenal { pointer-events: auto; }

.radar { position: absolute; left: max(8px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top)); width: 150px; height: 150px;
    border: 1px solid rgba(212, 162, 76, 0.5); background: rgba(0, 0, 0, 0.4); }

.marcador { position: absolute; left: 50%; top: max(8px, env(safe-area-inset-top)); transform: translateX(-50%); display: flex; align-items: stretch;
    background: var(--stone); border: 1px solid rgba(212, 162, 76, 0.45); cursor: pointer; }
.marcador > span { min-width: 52px; display: flex; align-items: center; justify-content: center; font-family: var(--f-title); font-size: 24px; font-weight: 700; }
.m-t { color: var(--t); background: rgba(142, 42, 31, 0.35); }
.m-ct { color: var(--ct); background: rgba(31, 53, 102, 0.45); }
.m-centro { display: flex; flex-direction: column; align-items: center; padding: 4px 14px; min-width: 110px; }
.m-reloj { font-family: var(--f-title); font-size: 22px; font-weight: 700; color: var(--gold-light); font-variant-numeric: tabular-nums; }
.m-reloj.bomba { color: #ff6b5e; }
.m-info { font-size: 12px; color: #cbb993; white-space: nowrap; }

.killfeed { position: absolute; right: max(8px, env(safe-area-inset-right)); top: max(8px, env(safe-area-inset-top)); display: flex; flex-direction: column;
    align-items: flex-end; gap: 3px; max-width: 46vw; }
.kf { display: flex; align-items: center; gap: 6px; padding: 3px 8px; background: rgba(12, 9, 7, 0.75); border: 1px solid rgba(255, 255, 255, 0.08);
    font-family: var(--f-title); font-size: 13px; font-weight: 700; white-space: nowrap; transition: opacity 0.5s; }
.kf.mio { border-color: var(--gold); }
.kf .t { color: var(--t); } .kf .ct { color: var(--ct); }
.kf canvas { width: 24px; height: 24px; image-rendering: pixelated; }
.kf i { font-style: normal; color: #e7c86a; font-family: var(--f-body); font-size: 13px; }

.chat-log { position: absolute; left: max(8px, env(safe-area-inset-left)); top: 168px; width: min(400px, calc(100vw - 180px)); max-height: 26vh;
    overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; font-size: 15px; line-height: 1.3;
    text-shadow: 0 1px 2px #000, 0 0 3px #000; }
.chat-log .who.t { color: var(--t); } .chat-log .who.ct { color: var(--ct); } .chat-log .who { font-weight: 600; }
.chat-log .sys { color: #e7c86a; font-style: italic; }

.banner { position: absolute; left: 50%; top: 22%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 4px;
    text-align: center; text-shadow: 0 2px 6px #000, 0 0 2px #000; animation: aparecer 0.35s ease-out; width: max-content; max-width: 94vw; }
.banner b { font-family: var(--f-display); font-size: clamp(24px, 5vw, 44px); }
.banner span { font-size: 18px; color: #efe4cc; }
@keyframes aparecer { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

.progreso { position: absolute; left: 50%; bottom: 32%; transform: translateX(-50%); width: min(320px, 70vw); text-align: center;
    font-family: var(--f-title); font-size: 14px; font-weight: 700; color: var(--gold-light); text-shadow: 0 1px 3px #000; }
.progreso div { margin-top: 5px; height: 10px; background: rgba(0, 0, 0, 0.6); border: 1px solid var(--gold); }
.progreso i { display: block; height: 100%; width: 0; background: #e0a33c; }
.espectador { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); padding: 6px 16px; background: var(--stone);
    border: 1px solid rgba(212, 162, 76, 0.4); font-size: 16px; white-space: nowrap; }

.estado { position: absolute; left: max(8px, env(safe-area-inset-left)); bottom: max(8px, env(safe-area-inset-bottom)); width: min(250px, 40vw);
    padding: 8px 12px; background: var(--stone); border: 1px solid rgba(212, 162, 76, 0.35); display: flex; flex-direction: column; gap: 5px; }
.est-fila { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.est-nombre { font-family: var(--f-title); font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.est-nombre.t { color: var(--t); } .est-nombre.ct { color: var(--ct); }
.est-plata { font-family: var(--f-title); font-size: 18px; font-weight: 700; color: #7ddc6a; }
.est-extra { font-size: 13px; color: #cbb993; min-height: 16px; }
.bar { position: relative; height: 15px; background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 255, 255, 0.12); overflow: hidden; }
.bar > div { height: 100%; width: 100%; transition: width 0.2s; }
.bar-hp > div { background: #b8352a; } .bar-mana > div { background: #2f63c9; }
.bar span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; text-shadow: 0 1px 2px #000; }

.arsenal { position: absolute; left: 50%; bottom: max(8px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; gap: 4px; }
.ars { position: relative; width: 46px; height: 46px; padding: 0; display: flex; align-items: center; justify-content: center;
    background: var(--stone); border: 1px solid rgba(212, 162, 76, 0.3); color: var(--text); cursor: pointer; }
.ars canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.ars .tecla { position: absolute; left: 2px; top: 0; font-size: 10px; font-weight: 700; color: #cbb993; }
.ars .cnt { position: absolute; right: 2px; bottom: 0; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 1px 2px #000; }
.ars.on { border: 2px solid var(--gold); background: rgba(212, 162, 76, 0.2); }
.ars.sel { border: 2px solid #9cc7ff; background: rgba(44, 63, 122, 0.6); }
.ars.vacio { opacity: 0.35; }
.ars .glifo { font-family: var(--f-title); font-weight: 700; font-size: 17px; }
.ars.sep { margin-left: 8px; }

.round-btn { width: 50px; height: 50px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--stone);
    color: var(--gold-light); border: 1px solid var(--gold); cursor: pointer; touch-action: manipulation; font-family: var(--f-title); font-size: 20px; font-weight: 700; }
.acciones { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: calc(max(20px, env(safe-area-inset-bottom)) + 100px);
    display: flex; flex-direction: column; gap: 10px; }
.attack-btn { position: absolute; right: max(20px, env(safe-area-inset-right)); bottom: max(20px, env(safe-area-inset-bottom)); width: 86px; height: 86px;
    border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    background: rgba(142, 42, 31, 0.92); color: #f6ead0; border: 2px solid var(--gold); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.6);
    font-family: var(--f-title); font-size: 11px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; cursor: pointer; touch-action: manipulation; }
.attack-btn:active { transform: scale(0.94); }
.accion-btn { position: absolute; right: calc(max(20px, env(safe-area-inset-right)) + 100px); bottom: max(28px, env(safe-area-inset-bottom));
    min-height: 56px; padding: 0 18px; background: #6b4a12; color: #fff1cf; border: 2px solid var(--gold); font-family: var(--f-title);
    font-size: 14px; font-weight: 700; letter-spacing: 1px; text-transform: uppercase; cursor: pointer; touch-action: manipulation; }
@media (hover: hover) and (pointer: fine) {
    .attack-btn, .acciones { display: none; }
    .accion-btn { right: 20px; bottom: 20px; }
}
@media (max-height: 500px) {
    .radar { width: 104px; height: 104px; }
    .chat-log { top: 118px; max-height: 20vh; font-size: 13px; }
    .acciones { flex-direction: row; bottom: max(20px, env(safe-area-inset-bottom)); right: calc(max(20px, env(safe-area-inset-right)) + 96px); }
    .accion-btn { bottom: 84px; right: max(20px, env(safe-area-inset-right)); }
    .arsenal { bottom: auto; top: max(62px, env(safe-area-inset-top)); left: auto; right: max(8px, env(safe-area-inset-right)); transform: none;
        flex-direction: column; flex-wrap: wrap; max-height: 44vh; }
    .ars { width: 38px; height: 38px; } .ars canvas { width: 26px; height: 26px; } .ars.sep { margin-left: 0; margin-top: 4px; }
    .killfeed { top: max(58px, env(safe-area-inset-top)); right: 60px; }
    .estado { width: min(220px, 36vw); padding: 6px 10px; }
    .marcador > span { min-width: 40px; font-size: 20px; } .m-reloj { font-size: 18px; }
    .banner b { font-size: 26px; } .banner span { font-size: 14px; } .banner { top: 26%; }
}

.joy { position: absolute; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; background: rgba(12, 9, 7, 0.35);
    border: 2px solid rgba(239, 228, 204, 0.3); display: none; }
.joy.on { display: block; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 50px; height: 50px; margin: -25px 0 0 -25px; border-radius: 50%;
    background: rgba(239, 228, 204, 0.85); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5); }
.ciego { position: absolute; inset: 0; background: #fff; opacity: 0; transition: opacity 0.2s; }

.chat-form { position: absolute; left: 50%; bottom: 70px; transform: translateX(-50%); width: min(520px, calc(100vw - 20px)); display: flex; gap: 8px;
    padding: 6px; background: var(--stone); border: 1px solid var(--gold); z-index: 12; }
.chat-form input { flex-grow: 1; min-width: 0; height: 44px; padding: 0 12px; background: transparent; border: 0; color: var(--text);
    font-family: var(--f-body); font-size: 18px; outline: none; user-select: text; -webkit-user-select: text; }
.chat-form .btn-red { align-self: auto; min-height: 44px; outline: none; font-size: 13px; }
.target-banner { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); display: flex; align-items: center; gap: 12px;
    padding: 6px 6px 6px 16px; background: rgba(44, 63, 122, 0.95); border: 1px solid #9cc7ff; color: #e8f0ff; font-size: 16px; max-width: calc(100vw - 20px); }
.target-banner button { min-height: 40px; padding: 0 12px; background: transparent; color: #e8f0ff; border: 1px solid #9cc7ff;
    font-family: var(--f-title); font-size: 12px; cursor: pointer; }

/* ---------- Tienda ---------- */
.tienda { position: fixed; top: 0; right: 0; bottom: 0; width: min(430px, 100vw); display: flex; flex-direction: column; gap: 10px;
    background: rgba(20, 16, 12, 0.97); border-left: 2px solid var(--gold); z-index: 20;
    padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 12px 12px; overflow-y: auto; }
.tienda-head { display: flex; align-items: center; gap: 10px; }
.tienda-head > div { flex-grow: 1; display: flex; flex-direction: column; }
.tienda-head b { font-family: var(--f-title); font-size: 18px; color: var(--gold-light); }
.tienda-head span { font-size: 13px; color: #cbb993; }
.tienda-plata { font-family: var(--f-title); font-size: 20px !important; font-weight: 700; color: #7ddc6a !important; }
.menu-close { width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; background: transparent; color: var(--gold-light);
    border: 1px solid var(--line); cursor: pointer; }
.tienda-lista h4 { margin: 10px 0 6px; font-family: var(--f-title); font-size: 12px; letter-spacing: 2px; text-transform: uppercase; color: #cbb993; }
.items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.item { display: flex; align-items: center; gap: 8px; min-height: 54px; padding: 6px 8px; text-align: left; background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(212, 162, 76, 0.25); color: var(--text); cursor: pointer; font-family: var(--f-body); }
.item:hover:not(:disabled) { border-color: var(--gold); background: rgba(212, 162, 76, 0.12); }
.item:disabled { opacity: 0.4; cursor: default; }
.item.tiene { border-color: #6fbf5a; }
.item canvas { width: 32px; height: 32px; flex-shrink: 0; image-rendering: pixelated; }
.item div { display: flex; flex-direction: column; min-width: 0; }
.item b { font-size: 14px; line-height: 1.15; }
.item small { font-size: 12px; color: #cbb993; line-height: 1.2; }
.item em { font-style: normal; font-family: var(--f-title); font-weight: 700; font-size: 13px; color: #7ddc6a; }

/* ---------- Tabla ---------- */
.tabla { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; z-index: 18; background: rgba(0, 0, 0, 0.35); }
.tabla-caja { width: min(760px, 100%); max-height: 100%; overflow-y: auto; padding: 14px; background: rgba(20, 16, 12, 0.96); border: 1px solid var(--gold); }
.tabla-titulo { display: flex; justify-content: space-between; gap: 10px; font-family: var(--f-title); color: var(--gold-light); margin-bottom: 8px; }
.tabla-equipos { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tabla h3 { margin: 0 0 6px; font-family: var(--f-title); font-size: 14px; }
.tabla h3.t { color: var(--t); } .tabla h3.ct { color: var(--ct); }
.tabla table { width: 100%; border-collapse: collapse; font-size: 15px; }
.tabla td { padding: 3px 4px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.tabla td.n { text-align: right; width: 34px; font-variant-numeric: tabular-nums; }
.tabla tr.muerto td { opacity: 0.45; }
.tabla tr.yo td { color: var(--gold-light); font-weight: 600; }
.tabla .bot { font-size: 11px; color: #9a8a6a; margin-left: 4px; }
.tabla-hint { margin: 10px 0 0; font-size: 13px; color: #9a8a6a; text-align: center; }
@media (max-width: 560px) { .tabla-equipos { grid-template-columns: 1fr; } .opciones { grid-template-columns: 1fr; } }

.cargando { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); padding: 10px 22px; background: rgba(12, 9, 7, 0.85);
    border: 1px solid var(--gold); font-family: var(--f-title); font-size: 14px; color: var(--gold-light); z-index: 25; }
