:root {
  --bg: #14111c; --panel: #241f31; --panel2: #2f2940; --line: #4a4160; --ink: #e8e4d0; --dim: #9a93ad;
  --gold: #ffe07a; --hp: #e0403a; --mp: #3a7ae0; --xp: #c084fc; --ok: #4ade80; --bad: #f87171;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: VT323, monospace; font-size: 20px; user-select: none; -webkit-user-select: none; }
body { display: flex; flex-direction: column; overflow: hidden; }
.hidden { display: none !important; }
img, .px, canvas { image-rendering: pixelated; image-rendering: crisp-edges; }
h1, h2, h3, .pix { font-family: 'Press Start 2P', monospace; font-weight: 400; }
button, .btn { font-family: VT323, monospace; font-size: 20px; color: var(--ink); background: var(--panel2); border: 2px solid var(--line); border-bottom-width: 4px; border-radius: 4px; padding: 4px 10px; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.1; }
button:hover, .btn:hover { background: #3a3350; }
button:active, .btn:active { border-bottom-width: 2px; transform: translateY(2px); }
button.sel { border-color: var(--gold); color: var(--gold); }
button.primary, .btn.primary { background: #3d6b3a; border-color: #2a4a28; }
button.primary:hover, .btn.primary:hover { background: #4a8246; }
button.danger { background: #6b3a3a; border-color: #4a2828; }
button:disabled { opacity: .45; cursor: default; }
input[type=text], textarea { font-family: VT323, monospace; font-size: 22px; color: var(--ink); background: #17131f; border: 2px solid var(--line); border-radius: 4px; padding: 3px 8px; width: 100%; user-select: text; -webkit-user-select: text; }
textarea { font-size: 17px; line-height: 1.05; resize: vertical; min-height: 120px; }

/* ---------- Cabecera ---------- */
#top { display: flex; align-items: center; gap: 10px; padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left)); background: #1c1826; border-bottom: 2px solid var(--line); flex-wrap: wrap; }
.logo { margin: 0; font-size: 15px; color: var(--gold); text-shadow: 0 2px 0 #6a3a1a, 0 4px 0 #000; letter-spacing: 1px; }
.logo span { color: var(--ink); text-shadow: 0 2px 0 #3a3350, 0 4px 0 #000; }
#tabs { display: flex; gap: 4px; flex: 1; justify-content: center; }
#tabs button { font-size: 20px; padding: 2px 12px; }

/* ---------- Tres columnas ---------- */
#app { flex: 1; min-height: 0; display: grid; grid-template-columns: 250px 1fr 380px; }
#lista, #ficha { overflow-y: auto; padding: 10px; background: var(--panel); }
#lista { border-right: 2px solid var(--line); }
#ficha { border-left: 2px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
#vista { position: relative; min-width: 0; min-height: 0; display: flex; flex-direction: column; background: #0d0b14; }
#prev { flex: 1; min-height: 0; width: 100%; display: block; }
#vista-ctl { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; padding: 6px; background: #1c1826; border-top: 2px solid var(--line); }
#vista-ctl button { font-size: 18px; padding: 1px 8px; }
#vista-ctl .sep { width: 10px; }

/* ---------- Cajas, filas y huecos (panel de Maraja) ---------- */
.box { background: #1c1826; border: 2px solid var(--line); border-radius: 4px; padding: 8px; }
.box h4 { margin: 0 0 6px; color: var(--gold); font-weight: 400; font-size: 22px; display: flex; align-items: center; gap: 6px; }
.box h4 .g { flex: 1; }
.lbl-row { color: var(--dim); font-size: 17px; margin: 6px 0 2px; }
.row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.row .g { flex: 1; } .dim { color: var(--dim); } .gold { color: var(--gold); } .ok { color: var(--ok); } .bad { color: var(--bad); }
.small { font-size: 17px; line-height: 1.05; }
.opts { display: flex; flex-wrap: wrap; gap: 3px; }
.opts button { font-size: 17px; padding: 0 7px; border-bottom-width: 3px; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.slot { position: relative; width: 44px; height: 44px; background: #17131f; border: 2px solid var(--line); border-radius: 4px; cursor: pointer; padding: 0; flex: none; }
.slot img { width: 32px; height: 32px; margin: 4px; display: block; }
.slot.sel { outline: 2px solid var(--gold); }
.slot .lbl { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; line-height: .9; font-size: 13px; color: var(--dim); }
.slot.off img { opacity: .35; }

/* Muestras de color */
.sw { display: flex; flex-wrap: wrap; gap: 3px; align-items: center; }
.sw button { width: 22px; height: 22px; padding: 0; border: 2px solid #0b0a12; border-radius: 3px; }
.sw button.sel { outline: 2px solid var(--gold); outline-offset: 1px; }
.sw button.none { background: repeating-linear-gradient(45deg, #2f2940 0 4px, #17131f 4px 8px); }
.sw input[type=color] { width: 34px; height: 24px; padding: 0; border: 2px solid var(--line); background: #17131f; border-radius: 3px; cursor: pointer; }

/* Lista de la izquierda */
.lst-head { display: flex; gap: 4px; margin-bottom: 8px; flex-wrap: wrap; }
.it { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border: 2px solid transparent; border-radius: 4px; cursor: pointer; line-height: 1; }
.it:hover { background: #2f2940; }
.it.sel { border-color: var(--gold); background: #2f2940; }
.it img { width: 48px; height: 50px; flex: none; }
.it img.ic { width: 32px; height: 32px; }
.it .g { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.it .g small { display: block; color: var(--dim); font-size: 16px; }
.grp { color: var(--gold); font-size: 17px; margin: 8px 0 2px; border-bottom: 1px solid #3a3350; }

/* Muñeco de equipo: dos columnas de huecos con el personaje en medio */
.doll { display: grid; grid-template-columns: auto 1fr auto; gap: 6px; align-items: center; }
.doll .col { display: flex; flex-direction: column; gap: 6px; }
.doll .mid { display: grid; place-items: center; }
.doll .mid img { width: 96px; height: 100px; }
.hk { display: flex; align-items: center; gap: 4px; }
.doll .col:last-child .hk { flex-direction: row-reverse; text-align: right; }
.hk .nm { font-size: 15px; line-height: .95; color: var(--dim); width: 52px; }
.hk .nm b { display: block; color: var(--ink); font-weight: 400; }
.eye { position: absolute; right: -7px; top: -7px; width: 18px; height: 18px; padding: 0; border-width: 1px; border-radius: 50%; font-size: 13px; line-height: 14px; background: #17131f; z-index: 1; }
.eye.tachado { color: var(--bad); }
.pick { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 6px; }
.pick .it img.ic { width: 32px; height: 32px; }

/* Juegos: marcado = dorado; incluido por dependencia = borde punteado */
.jgrid { display: flex; flex-wrap: wrap; gap: 4px; }
.jgrid .slot:not(.sel):not(.dep) img { opacity: .4; }
.opts button.dep, .slot.dep { border-style: dashed; border-color: var(--gold); color: var(--ink); }
.dep-mk { border: 1px dashed var(--gold); padding: 0 3px; }

/* Exportar */
.sheet { display: block; margin: 6px auto; background: #3e8948; border: 2px solid #0b0a12; max-width: 100%; }
code { font-family: VT323, monospace; color: var(--gold); }

/* Avisos y ventana modal */
#toasts { position: fixed; z-index: 50; left: 50%; top: 58px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 3px; pointer-events: none; width: 92vw; }
.toast { background: #17131fe6; border: 2px solid var(--line); padding: 1px 12px; border-radius: 4px; animation: toast 3s forwards; text-align: center; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 6% { opacity: 1; transform: none; } 85% { opacity: 1; } 100% { opacity: 0; } }
#modal { position: fixed; inset: 0; z-index: 60; background: #0008; display: grid; place-items: center; }
.modal { width: min(380px, 92vw); background: var(--panel); border: 3px solid #0b0a12; outline: 2px solid var(--line); border-radius: 6px; padding: 12px; text-align: center; box-shadow: 0 10px 40px #000a; }
.modal h3 { font-size: 12px; color: var(--gold); margin: 0 0 10px; line-height: 1.4; }
.modal .btns { justify-content: center; margin-top: 10px; }

/* ---------- Móvil: una sola columna (vista arriba, ficha, lista) y la página se desplaza ---------- */
@media (max-width: 860px) {
  body { overflow: auto; height: auto; min-height: 100%; }
  #app { display: flex; flex-direction: column; }
  #vista { order: 1; height: 44vh; min-height: 260px; position: sticky; top: 0; z-index: 2; }
  #ficha { order: 2; border: 0; border-top: 2px solid var(--line); overflow: visible; }
  #lista { order: 3; border: 0; border-top: 2px solid var(--line); overflow: visible; }
  .logo { font-size: 11px; }
  #tabs button { font-size: 18px; padding: 2px 8px; }
}
@media (max-width: 420px) { #tabs { order: 3; width: 100%; } }
