:root {
  --bg: #12131a;
  --panel: #1c1e29;
  --panel2: #252838;
  --text: #e8e9f0;
  --muted: #8b8fa3;
  --accent: #6c8cff;
  --star1: #9aa0b4;
  --star2: #4fc3f7;
  --star3: #ffca28;
  --rank-bronze: #cd7f32;
  --rank-silver: #cfd8e3;
  --rank-gold: #ffca28;
  --rank-red: #ff4d5a;
  --danger: #ff6b6b;
  --good: #6bd68a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}

[hidden] { display: none !important; }

h1, h3 { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: var(--danger); min-height: 1.2em; }

.card {
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
  margin: 12px 0;
}
.card.highlight { border: 1px solid var(--star3); }

.auth-card {
  width: 100%; max-width: 380px; margin: 0;
  background: rgba(20, 22, 32, 0.82);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 202, 40, 0.18);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
}

label { display: block; margin: 12px 0; font-size: 0.9rem; color: var(--muted); }
input[type="text"], input[type="password"], input:not([type]) {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--panel2);
  background: var(--panel2);
  color: var(--text);
  font-size: 1rem;
}

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 1rem;
  cursor: pointer;
}
button.secondary { background: var(--panel2); }
button.danger { background: #b23b3b; }
button.small { padding: 6px 10px; font-size: 0.85rem; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 5;
}
.currency { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.hd-identity {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.hd-world {
  color: var(--muted);
  font-size: 0.85rem;
}

#tabs {
  display: flex;
  gap: 6px;
  padding: 8px 16px 0;
  overflow-x: auto;
}
#tabs button {
  flex: 0 0 auto;
  background: var(--panel);
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  padding: 10px 14px;
}
#tabs button.active { background: var(--panel2); color: var(--text); }

main { padding: 0 16px 40px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.hero {
  background: var(--panel2);
  border-radius: 10px;
  padding: 10px;
  border-left: 4px solid var(--rank-bronze);
  font-size: 0.85rem;
}
.hero.s1, .hero.s2 { border-left-color: var(--rank-bronze); }
.hero.s3, .hero.s4 { border-left-color: var(--rank-silver); box-shadow: 0 0 12px rgba(207, 216, 227, 0.22); }
.hero.s5, .hero.s6 { border-left-color: var(--rank-gold); box-shadow: 0 0 12px rgba(255, 202, 40, 0.35); }
.hero.s7 { border-left-color: var(--rank-red); box-shadow: 0 0 14px rgba(255, 77, 90, 0.45); }

.hero .name { font-weight: 700; font-size: 1rem; }
.hero .stars { letter-spacing: 1px; }
.hero.s1 .stars, .hero.s2 .stars { color: var(--rank-bronze); }
.hero.s3 .stars, .hero.s4 .stars { color: var(--rank-silver); }
.hero.s5 .stars, .hero.s6 .stars { color: var(--rank-gold); }
.hero.s7 .stars { color: var(--rank-red); }

.hero .stats { margin: 6px 0; color: var(--muted); }
.hero .tags span, .sheet .tags span {
  display: inline-block;
  background: var(--bg);
  border-radius: 20px;
  padding: 1px 8px;
  margin: 2px 2px 0 0;
  font-size: 0.75rem;
}

/* Filas compactas de héroe (equipos y torre) */
.hrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel2);
  border-radius: 10px;
  border-left: 4px solid var(--star1);
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 0.85rem;
}
.hrow.s2 { border-left-color: var(--star2); }
.hrow.s3 { border-left-color: var(--star3); }
.hrow .info { min-width: 0; flex: 1; }
.hrow .nm { font-weight: 700; }
.hrow.dim { opacity: 0.5; }
.stars1 { color: var(--star1); }
.stars2 { color: var(--star2); }
.stars3 { color: var(--star3); }
.hrow .tags span {
  display: inline-block;
  background: var(--bg);
  border-radius: 20px;
  padding: 0 7px;
  margin: 2px 2px 0 0;
  font-size: 0.7rem;
}
.hrow .acts { display: flex; gap: 6px; flex-shrink: 0; }

.bar {
  height: 6px;
  background: var(--bg);
  border-radius: 4px;
  overflow: hidden;
  margin: 3px 0;
}
.bar i { display: block; height: 100%; background: var(--good); }
.bar.mp i { background: var(--accent); }

/* Selector de grupos */
.slots { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.slot { background: var(--panel2); padding: 8px 12px; font-size: 0.9rem; }
.slot small { display: block; color: var(--muted); font-size: 0.7rem; }
.slot.sel { background: var(--accent); }
.slot.sel small { color: #dfe6ff; }
.slot.act { outline: 2px solid var(--star3); }

/* Registro de combate */
.log {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  max-height: 380px;
  overflow-y: auto;
  font-size: 0.85rem;
}
.lg { padding: 1px 0; }
.lg.r { color: var(--accent); font-weight: 700; margin-top: 8px; border-top: 1px solid var(--panel2); padding-top: 6px; }
.lg.a { color: var(--muted); }
.lg.s { color: var(--star2); }
.lg.q { color: #d8a8ff; }
.lg.f { color: #ffb86b; }
.lg.d { color: var(--danger); font-weight: 600; }
.lg.k { color: var(--good); }
.lg.i { font-weight: 700; margin-top: 8px; }
.logtoggle { display: flex; align-items: center; gap: 8px; margin: 10px 0 6px; }

#feed-list { list-style: none; padding: 0; margin: 0; }
#feed-list li {
  background: var(--panel);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-left: 4px solid var(--star2);
}
#feed-list li.s3 { border-left-color: var(--star3); }

.result-box {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--panel2);
  margin: 10px 0;
}

#toasts {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 420px);
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--panel2);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}
.toast.s2 { border-left-color: var(--star2); }
.toast.s3 { border-left-color: var(--star3); }
.toast.err { border-left-color: var(--danger); }

/* ---------- Lobby ---------- */
.lobby { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 16px; }
.lobby-tile {
  background: var(--panel); color: var(--text); padding: 18px 12px; text-align: left;
  border-radius: 12px; display: flex; flex-direction: column; gap: 6px; font-size: 1.05rem;
}
.lobby-tile small { color: var(--muted); font-size: 0.78rem; font-weight: 400; min-height: 1em; }
.debug-link { padding: 0 16px 16px; text-align: right; }
.section-bar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; }
.tab[hidden], .lobby[hidden], .section-bar[hidden] { display: none; }

/* ---------- Equipos ---------- */
.sel-bar { border: 1px solid var(--accent); }
.team.complete { border: 1px solid var(--good); }
.team-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.team-slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.tile {
  background: var(--panel2); border-radius: 8px; padding: 6px 4px; min-height: 64px;
  font-size: 0.72rem; text-align: center; border: 2px solid transparent; color: var(--text);
  overflow: hidden; word-break: break-word; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
}
.tile.s2 { border-bottom-color: var(--star2); }
.tile.s3 { border-bottom-color: var(--star3); }
.tile.empty { background: transparent; border: 2px dashed var(--panel2); color: var(--muted); }
.tile.sel { border-color: var(--accent); background: #2f3560; }
.pool { display: grid; grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); gap: 6px; }

#boot-error { margin: 16px; padding: 14px; background: #3a1d1d; border: 1px solid var(--danger); border-radius: 10px; line-height: 1.5; }
#boot-error[hidden] { display: none; }

/* ---------- Cartas con imagen ---------- */
.grid { grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); }
.hcard {
  position: relative; aspect-ratio: 535 / 896; border-radius: 10px; overflow: hidden;
  cursor: pointer; container-type: inline-size; background: #000;
  border: 2px solid transparent;
  transition: transform 0.16s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.hcard:hover,
.hcard:focus-visible {
  transform: translateY(-3px);
  outline: none;
}
.hcard img { width: 100%; height: 100%; display: block; object-fit: cover; user-select: none; -webkit-user-drag: none; }
/* El banner negro de los marcos ocupa aprox. del 82% al 94% de la altura. */
.cname {
  position: absolute; left: 17%; right: 17%; top: 83.5%; height: 9.5%;
  display: flex; align-items: center; justify-content: center; text-align: center;
  white-space: nowrap; overflow: hidden; color: #f4ead2; font-weight: 700;
  font-size: 11cqw; text-shadow: 0 1px 2px #000;
}
.clv {
  position: absolute; top: 3%; left: 6%; background: rgba(0,0,0,.65); color: #fff;
  font-size: 0.7rem; padding: 1px 6px; border-radius: 8px;
}
.hcard.small { width: 120px; flex-shrink: 0; cursor: default; }

/* Rarezas: 1-2 bronce, 3-4 plata, 5-6 oro, 7 rojo */
.hcard.r-bronze {
  border-color: rgba(205, 127, 50, 0.72);
  box-shadow: 0 4px 12px rgba(205, 127, 50, 0.16);
}
.hcard.r-bronze:hover { box-shadow: 0 8px 18px rgba(205, 127, 50, 0.34); }

.hcard.r-silver {
  border-color: rgba(207, 216, 227, 0.85);
  box-shadow: 0 4px 14px rgba(207, 216, 227, 0.22);
}
.hcard.r-silver:hover { box-shadow: 0 8px 20px rgba(207, 216, 227, 0.42); }

.hcard.r-gold {
  border-color: rgba(255, 202, 40, 0.92);
  box-shadow: 0 4px 16px rgba(255, 202, 40, 0.28);
}
.hcard.r-gold:hover { box-shadow: 0 8px 22px rgba(255, 202, 40, 0.5); }

.hcard.r-red {
  border-color: rgba(255, 77, 90, 0.95);
  box-shadow: 0 4px 18px rgba(255, 77, 90, 0.35);
}
.hcard.r-red:hover { box-shadow: 0 8px 24px rgba(255, 77, 90, 0.58); }

/* Entrada suave para cartas del gacha */
@keyframes cardPop {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.hcard.card-pop {
  animation: cardPop 0.26s ease both;
  animation-delay: calc(var(--i, 0) * 45ms);
}

.tile img { width: 100%; border-radius: 6px; display: block; aspect-ratio: 535 / 896; object-fit: cover; }
.tile { padding: 4px; gap: 2px; justify-content: flex-start; }
.tile b { font-size: 0.68rem; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile small { color: var(--muted); font-size: 0.62rem; }
.tile.empty { min-height: 90px; justify-content: center; font-size: 1.4rem; }

/* ---------- Ficha ---------- */
.sheet {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.sheet[hidden] { display: none; }
.sheet-card {
  position: relative; background: var(--panel); border-radius: 14px; padding: 16px;
  width: 100%; max-width: 420px; max-height: 90vh; overflow-y: auto;
}
#sheet-close { position: absolute; top: 10px; right: 10px; }
.sheet-top { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 10px; }
.sheet-info h3 { margin-bottom: 4px; }
.sheet-info p { margin: 4px 0; }
.sheet-stats { width: 100%; border-collapse: collapse; margin: 6px 0; }
.sheet-stats td { padding: 5px 2px; border-bottom: 1px solid var(--panel2); }
.sheet-stats td:last-child { text-align: right; }
.hrow .info[data-sheet] { cursor: pointer; }

/* ---------- Arrastrar y soltar ---------- */
.tile { touch-action: pan-y; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: grab; }
.tile.empty { cursor: pointer; }
.tile.dragging { opacity: 0.35; }
.tile.drop-ok, .pool-card.drop-ok { outline: 2px solid var(--good); background: #24402f; }
.drag-ghost {
  position: fixed; z-index: 100; width: 64px; pointer-events: none;
  transform: translate(-50%, -60%) rotate(4deg); opacity: 0.92; filter: drop-shadow(0 6px 10px #000);
}
.drag-ghost img { width: 100%; border-radius: 6px; display: block; }

/* ---------- Pantalla de acceso ---------- */
#auth-screen {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 20px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background:
    linear-gradient(rgba(9, 11, 17, 0.52), rgba(9, 11, 17, 0.68)),
    url("bg-login.jpeg") 50% 40% / cover no-repeat,
    var(--bg);
}
#auth-screen[hidden] { display: none; }

.ig-auth-header {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  margin-bottom: 14px; background: transparent; padding: 0; position: static;
}
.ig-title {
  margin: 0; text-align: center;
  font-size: clamp(1.85rem, 6.5vw, 2.35rem);
  line-height: 1.04; font-weight: 900; letter-spacing: 0.04em; text-transform: uppercase;
  background: linear-gradient(180deg, #fff6dc 0%, var(--star3) 52%, #9e7316 100%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 12px rgba(255, 202, 40, 0.2));
}
.ig-auth-header .muted { margin: 6px 0 0; }
#auth-msg:empty { display: none; }

/* ---------- Mazmorras, síntesis y talleres ---------- */
.dcard { display: flex; gap: 12px; align-items: flex-start; }
.dcard .dimg { width: 96px; flex-shrink: 0; border-radius: 10px; }
.dcard .dtxt { flex: 1; min-width: 0; }
.dcard .dtxt h3 { margin-top: 0; }
.dcard.closed { opacity: 0.55; filter: grayscale(0.5); }
.dcard details { margin-top: 10px; }
.dcard summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; }
@media (min-width: 700px) { .dcard .dimg { width: 140px; } }

.pool.one { grid-template-columns: 86px; }
.tile.sacrifice { border-color: var(--danger); background: #3a2024; }
.mats { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 8px; }

/* ---------- Entrega A ---------- */
.sunday-banner{margin-bottom:10px;text-align:center}
.sunday-banner img{width:100%;max-width:520px;border-radius:14px;display:block;margin:0 auto}
.sunday-banner p{margin:6px 0 0}
.week-strip{display:flex;flex-wrap:wrap;gap:6px;justify-content:center}
.week-strip .wd{flex:1 1 40px;min-width:40px;text-align:center;padding:6px 2px;border-radius:8px;background:rgba(255,255,255,.05)}
.week-strip .wd.today{outline:2px solid var(--accent,#c9a14a)}
.week-strip .wd b{display:block;font-size:12px}
.week-strip .wd span{font-size:15px}
.week-strip p{flex-basis:100%;margin:2px 0 0;text-align:center}
.synth-strip{position:sticky;top:0;z-index:5;background:var(--card,#1d1b2a);border-radius:12px;padding:8px;margin-bottom:10px;box-shadow:0 4px 12px rgba(0,0,0,.4)}
.synth-row{display:flex;align-items:center;gap:6px}
.synth-row .plus{font-size:20px;opacity:.8}
.synth-main,.slot-mini{width:64px;height:84px;border-radius:10px;border:2px dashed rgba(255,255,255,.25);display:flex;align-items:center;justify-content:center;flex:0 0 auto;padding:0;background:transparent;color:inherit;overflow:hidden}
.synth-main{width:76px;height:100px}
.synth-main.filled,.slot-mini.filled{border-style:solid}
.slot-mini{width:52px;height:72px;font-size:11px}
.synth-slots{display:flex;gap:5px;flex:1;min-width:0}
.synth-strip .tile{width:100%;height:100%;padding:0;margin:0}
.synth-strip .tile img{width:100%}
.synth-go{width:100%;margin-top:8px}
.pool.small-tiles{display:grid;grid-template-columns:repeat(5,1fr);gap:5px}
.pool.small-tiles .tile{width:auto;padding:2px;font-size:10px}
.pool.small-tiles .tile b{font-size:10px}
.pool.small-tiles .tile small{font-size:9px}
.pick-list{display:grid;grid-template-columns:repeat(4,1fr);gap:6px;max-height:60vh;overflow:auto}
@media(max-width:420px){.pool.small-tiles,.pick-list{grid-template-columns:repeat(4,1fr)}}
.afin{font-size:12px}
.synth-strip .tile small{display:none}
.synth-strip .tile b{font-size:9px}
.synth-main,.slot-mini{flex-direction:column;justify-content:flex-start;background:var(--panel2,#262a45)!important;border-color:var(--panel2,#262a45)}
.synth-main.filled,.slot-mini.filled{background:transparent!important}
.synth-main img,.slot-mini img{width:100%;height:auto;display:block}
.synth-main b,.slot-mini b{display:block;font-size:9px;line-height:1.1;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:#fff}
.synth-main small,.slot-mini small{display:none}
.synth-main,.slot-mini{height:auto;min-height:72px;align-self:flex-start}
.synth-main:not(.filled),.slot-mini:not(.filled){height:72px;font-size:18px;opacity:.5}

.pin-wrap {
  position: relative;
  display: block;
  margin-top: 4px;
}

.pin-wrap input {
  margin-top: 0;
  padding-right: 42px;
}

.pin-eye {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  color: var(--muted);
  padding: 4px;
  line-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.pin-eye:hover,
.pin-eye:focus-visible {
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  outline: none;
}

.pin-eye svg[hidden] {
  display: none;
}

.pin-eye:hover {
  color: var(--text);
}

.auth-main-row button {
  width: 100%;
}

.auth-reg-wrap {
  margin-top: 10px;
  text-align: center;
}

.res-tip {
  position: relative;
  cursor: pointer;
  outline: none;
}

.res-tip::after {
  content: attr(data-tip);
  position: absolute;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%) translateY(-4px);
  background: var(--panel2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  white-space: nowrap;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease, transform 0.15s ease;
  z-index: 60;
}

.res-tip:hover::after,
.res-tip.show-tip::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.gacha-panel {
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.gacha-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.gacha-pill {
  background: var(--panel2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.8rem;
  color: var(--text);
}

.gacha-actions .btn-main-pull {
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(108, 140, 255, 0.28);
}

.gacha-divider {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  margin: 16px 0 14px;
}

.results-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.results-head h3 {
  margin: 0;
}

.results-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* En los resultados del gacha no hace falta mostrar Nv 1 */
#results-list .clv {
  display: none;
}

/* Efecto celeste al pasar el cursor o presionar en Gacha */
.gacha-actions button,
.gacha-panel .row button {
  transition: transform 0.14s ease, box-shadow 0.18s ease, border-color 0.18s ease, background 0.18s ease;
}

.gacha-actions button:hover:not(:disabled),
.gacha-panel .row button:hover:not(:disabled) {
  box-shadow: 0 0 0 2px rgba(79, 195, 247, 0.55), 0 6px 18px rgba(79, 195, 247, 0.28);
}

.gacha-actions button:active:not(:disabled),
.gacha-panel .row button:active:not(:disabled) {
  transform: scale(0.97);
  box-shadow: 0 0 0 2px rgba(129, 212, 250, 0.85), 0 0 22px rgba(79, 195, 247, 0.45);
}

/* Revelación progresiva estilo gacha */
@keyframes gachaReveal {
  0% {
    opacity: 0;
    transform: translateY(10px) scale(0.92);
    filter: brightness(1.8);
  }
  65% {
    opacity: 1;
    filter: brightness(1.18);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: brightness(1);
  }
}

.hcard.gacha-reveal {
  animation: gachaReveal 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}