:root {
  --panel: #1e1a2b;
  --panel-hi: #2a2340;
  --border: #3a3150;
  --gold: #e8b85a;
  --gold-hi: #ffd27a;
  --text: #efe6d6;
  --muted: #a99fbd;
  --night: #1b1424;
  --shadow: 0 10px 28px rgba(18, 10, 28, 0.65), 0 2px 6px rgba(18, 10, 28, 0.5);
  --bevel: inset 0 1px 0 rgba(255, 241, 193, 0.07), inset 0 -2px 0 rgba(0, 0, 0, 0.28);
  --serif: Georgia, 'Palatino Linotype', 'Book Antiqua', serif;
  --sans: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #2a1f3d, #1b1424 70%); color: var(--text); font-family: var(--sans); }
#scene { position: fixed; left: 0; top: 0; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
#hud { position: fixed; inset: 0; pointer-events: none; padding: 14px 16px; display: flex; flex-direction: column; justify-content: space-between; }
#hud > * { pointer-events: auto; }

/* ---------- Barra superior ---------- */
.top { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.back { color: var(--text); text-decoration: none; font-size: 13px; padding: 8px 12px; border-radius: 10px; background: linear-gradient(180deg, var(--panel-hi), var(--panel)); border: 1px solid var(--border); box-shadow: var(--shadow), var(--bevel); white-space: nowrap; }
.back:hover, .back:focus-visible { border-color: var(--gold); color: var(--gold-hi); outline: none; }
.title { padding: 6px 16px 8px; border-radius: 12px; background: linear-gradient(180deg, rgba(42, 35, 64, 0.92), rgba(30, 26, 43, 0.92)); border: 1px solid var(--border); box-shadow: var(--shadow), var(--bevel); }
.kicker { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.kicker b { color: var(--gold); font-weight: 600; }
h1 { margin: 2px 0 0; font: 600 20px/1.15 var(--serif); color: var(--text); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.4), 0 0 18px rgba(232, 184, 90, 0.18); }
.controls { margin-left: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; padding: 6px; border-radius: 14px; background: rgba(30, 26, 43, 0.85); border: 1px solid var(--border); box-shadow: var(--shadow), var(--bevel); }
.btn, .seg button { font: 600 13px var(--sans); color: var(--text); background: linear-gradient(180deg, #3a3150, #2a2340); border: 1px solid #4a4060; border-radius: 9px; padding: 8px 12px; cursor: pointer; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 241, 193, 0.1); transition: transform 0.08s, border-color 0.15s, background 0.15s; min-height: 36px; }
.btn:hover, .seg button:hover { border-color: var(--gold); }
.btn:active, .seg button:active { transform: translateY(1px); }
.btn:focus-visible, .seg button:focus-visible, .seed:focus-visible { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.btn.primary { background: linear-gradient(180deg, #f0c56a, #c98d4f); color: #2a1d14; border-color: #ffd27a; text-shadow: 0 1px 0 rgba(255, 241, 193, 0.5); box-shadow: 0 2px 0 #6b3f2a, 0 6px 16px rgba(232, 184, 90, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.4); }
.btn.icon { width: 38px; padding: 8px 0; display: inline-grid; place-items: center; }
.btn.icon.on { background: linear-gradient(180deg, #4a3e6a, #3a3150); border-color: var(--gold); color: var(--gold-hi); }
.seg { display: inline-flex; border-radius: 10px; overflow: hidden; border: 1px solid #4a4060; }
.seg button { border: 0; border-radius: 0; box-shadow: none; padding: 8px 11px; background: #2a2340; }
.seg button + button { border-left: 1px solid #4a4060; }
.seg button.on { background: linear-gradient(180deg, #e8b85a, #b8925a); color: #2a1d14; }
.seed { font: 12px ui-monospace, Consolas, monospace; color: var(--muted); padding: 4px 8px; border-radius: 8px; cursor: help; }

/* ---------- Tooltips (hover, foco y toque) ---------- */
[data-tip] { position: relative; }
[data-tip]::after { content: attr(data-tip); position: absolute; top: calc(100% + 10px); right: 0; width: max-content; max-width: 240px; padding: 8px 10px; border-radius: 9px; font: 500 12px/1.35 var(--sans); color: var(--text); background: #120d19f2; border: 1px solid var(--border); box-shadow: var(--shadow); opacity: 0; transform: translateY(-4px); transition: opacity 0.15s, transform 0.15s; pointer-events: none; z-index: 20; text-align: left; letter-spacing: 0; white-space: normal; }
[data-tip]:hover::after, [data-tip]:focus-visible::after, [data-tip].tip-open::after { opacity: 1; transform: none; }

/* ---------- Barra del jefe ---------- */
#bossbar { position: absolute; left: 50%; top: 84px; transform: translateX(-50%); width: min(420px, 60vw); text-align: center; pointer-events: none; }
#bossbar .bname { font: 600 13px var(--serif); letter-spacing: 0.18em; text-transform: uppercase; color: #ffd6f5; text-shadow: 0 0 12px rgba(255, 122, 217, 0.6), 0 2px 0 #1b1424; }
#bossbar .bar { margin-top: 5px; height: 10px; border-radius: 6px; background: #1b1424; border: 1px solid #5a2a6a; position: relative; overflow: hidden; box-shadow: 0 0 18px rgba(255, 122, 217, 0.25), 0 4px 10px rgba(18, 10, 28, 0.6); }
#bossbar i { position: absolute; left: 0; top: 0; bottom: 0; }
#bossbar .ghost { background: #fff1c1; opacity: 0.8; }
#bossbar .fill { background: linear-gradient(180deg, #ff9ae3, #b048a0); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35); }

/* ---------- Pie: party y crónica ---------- */
footer { display: flex; align-items: flex-end; gap: 14px; }
#party { display: flex; gap: 10px; flex-wrap: wrap; }
.card { position: relative; display: flex; gap: 10px; align-items: center; width: 218px; padding: 8px 10px 8px 8px; border-radius: 14px; background: linear-gradient(180deg, rgba(42, 35, 64, 0.94), rgba(30, 26, 43, 0.94)); border: 1px solid var(--border); box-shadow: var(--shadow), var(--bevel); transition: filter 0.6s, transform 0.2s; }
.card .pt-wrap { position: relative; width: 54px; height: 54px; flex: none; border-radius: 11px; overflow: hidden; border: 1px solid #4a4060; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.4), 0 3px 8px rgba(18, 10, 28, 0.6); }
.card canvas.pt { width: 54px; height: 54px; image-rendering: pixelated; display: block; }
.card[data-cls='warrior'] .pt-wrap { background: radial-gradient(circle at 40% 35%, #b5523b, #3d1f2a); }
.card[data-cls='mage'] .pt-wrap { background: radial-gradient(circle at 40% 35%, #7a5cc0, #2a1f3d); }
.card[data-cls='archer'] .pt-wrap { background: radial-gradient(circle at 40% 35%, #4a8a4a, #1f3d2e); }
.card[data-cls='priest'] .pt-wrap { background: radial-gradient(circle at 40% 35%, #e8b85a, #6b3f2a); }
.card .info { flex: 1; min-width: 0; }
.card .nm { font: 600 14px var(--serif); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .nm small { font: 500 11px var(--sans); color: var(--muted); margin-left: 4px; }
.bar { position: relative; height: 10px; border-radius: 5px; background: #120d19; border: 1px solid #3a3150; overflow: hidden; margin-top: 5px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; transition: width 0.12s linear; }
.bar .ghost { background: #fff1c1; opacity: 0.75; transition: none; }
.bar.hp .fill { background: linear-gradient(180deg, #b8d86b, #4a8a4a); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3); }
.bar.hp.mid .fill { background: linear-gradient(180deg, #ffd27a, #c98d4f); }
.bar.hp.low .fill { background: linear-gradient(180deg, #ff9d4a, #c2410c); }
.bar .val { position: absolute; right: 5px; top: -2px; font: 700 10px/14px var(--sans); color: #fff; text-shadow: 0 1px 0 #1b1424, 0 0 3px #1b1424; }
.bar.mp { height: 5px; margin-top: 3px; }
.bar.mp .fill { background: linear-gradient(180deg, #79c3e0, #2b4f7a); }
.card .badge { position: absolute; right: 8px; top: 6px; width: 20px; height: 18px; image-rendering: pixelated; opacity: 0; transition: opacity 0.6s; }
.card.fallen { filter: grayscale(0.85) brightness(0.8); }
.card.fallen .badge { opacity: 1; filter: none; }
.card.fallen .nm::after { content: 'Cayó'; font: 600 10px var(--sans); color: #ffb3ec; margin-left: 6px; letter-spacing: 0.08em; text-transform: uppercase; }
.card.hurt { animation: hurt 0.25s; }
@keyframes hurt { 30% { transform: translateX(-3px); } 60% { transform: translateX(2px); } }

#chron { margin-left: auto; width: 340px; padding: 10px 14px 10px; border-radius: 14px; background: linear-gradient(180deg, rgba(42, 35, 64, 0.9), rgba(30, 26, 43, 0.94)); border: 1px solid var(--border); box-shadow: var(--shadow), var(--bevel); }
#chron h2 { margin: 0 0 6px; font: 600 12px var(--sans); letter-spacing: 0.16em; text-transform: uppercase; color: var(--gold); display: flex; justify-content: space-between; }
#chron h2 span { color: var(--muted); font-family: ui-monospace, Consolas, monospace; letter-spacing: 0; }
#log { list-style: none; margin: 0; padding: 0; font: 13px/1.4 var(--serif); min-height: 108px; display: flex; flex-direction: column; justify-content: flex-end; }
#log li { padding: 1px 0; animation: logIn 0.35s ease-out; color: var(--text); }
#log li:nth-last-child(n + 4) { opacity: 0.55; }
#log li:nth-last-child(n + 6) { opacity: 0.3; }
#log li.hero { color: #a9dcf0; }
#log li.mon { color: #ffb889; }
#log li.heal { color: #cfe79a; }
#log li.gold { color: var(--gold-hi); }
#log li.bad { color: #ffb3ec; font-style: italic; }
#log li.muted { color: var(--muted); font-style: italic; }
@keyframes logIn { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Cartel final ---------- */
#end { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(ellipse at center, rgba(27, 20, 36, 0.35), rgba(27, 20, 36, 0.75)); animation: fade 0.5s; z-index: 10; }
#end[hidden] { display: none; }
.end-card { width: min(420px, calc(100vw - 32px)); padding: 22px 24px 20px; border-radius: 18px; text-align: center; background: linear-gradient(180deg, #f3e3c3, #e0c497); color: #2a1d14; border: 2px solid #b8925a; box-shadow: 0 20px 60px rgba(18, 10, 28, 0.8), 0 0 0 6px rgba(30, 26, 43, 0.85), 0 0 40px 8px rgba(232, 184, 90, 0.25), inset 0 2px 0 rgba(255, 255, 255, 0.5), inset 0 -4px 0 rgba(184, 146, 90, 0.5); animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); position: relative; }
.end-card::before { content: ''; position: absolute; inset: 8px; border: 1px dashed rgba(107, 63, 42, 0.35); border-radius: 12px; pointer-events: none; }
.end-kicker { font: 600 11px var(--sans); letter-spacing: 0.2em; text-transform: uppercase; color: #8a5a2a; }
#end-title { margin: 4px 0 2px; font: 700 38px/1 var(--serif); color: #6b3f2a; text-shadow: 0 2px 0 #fff1c1; }
#end.defeat #end-title { color: #5a2a6a; }
#end-sub { margin: 4px 0 12px; font: italic 14px var(--serif); color: #4a2a1d; }
#loot { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
#loot li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 10px; background: rgba(255, 241, 193, 0.55); border: 1px solid rgba(184, 146, 90, 0.6); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6); text-align: left; font: 14px var(--serif); animation: logIn 0.4s backwards; }
#loot li canvas { width: 28px; height: 28px; image-rendering: pixelated; flex: none; }
#loot li b { margin-left: auto; font-family: var(--sans); color: #6b3f2a; }
#loot li.rare { background: linear-gradient(90deg, rgba(180, 140, 255, 0.35), rgba(255, 241, 193, 0.55)); border-color: #b48cff; }
#loot li.rare span::after { content: ' · raro'; font: 600 10px var(--sans); color: #6a4aa8; text-transform: uppercase; letter-spacing: 0.1em; }
#end-fallen { font: italic 13px var(--serif); color: #5a2a6a; margin-bottom: 12px; }
#end-fallen:empty { display: none; }
.end-actions { display: flex; gap: 10px; justify-content: center; }
.end-card .btn:not(.primary) { background: linear-gradient(180deg, #4a3e6a, #2a2340); }
@keyframes pop { from { transform: scale(0.85) translateY(10px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

body.noanim *, body.noanim *::before, body.noanim *::after { animation: none !important; transition: none !important; }
#err { position: fixed; left: 10px; top: 10px; max-width: 70vw; white-space: pre-wrap; background: #5a1020ee; color: #fff; font: 12px monospace; padding: 10px; border-radius: 8px; z-index: 99; }
#err[hidden] { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .card { width: 180px; }
  .card .pt-wrap, .card canvas.pt { width: 44px; height: 44px; }
  #chron { width: 280px; }
}
@media (max-width: 860px) {
  #hud { padding: 10px; }
  footer { flex-direction: column; align-items: stretch; gap: 8px; }
  #party { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { width: auto; }
  #chron { width: auto; margin-left: 0; }
  #log { min-height: 0; }
  #log li:nth-last-child(n + 4) { display: none; }
  #bossbar { top: auto; bottom: calc(100% - 128px); }
}
@media (max-width: 560px) {
  .top { gap: 8px; }
  .title { flex: 1; padding: 4px 10px 6px; }
  h1 { font-size: 16px; }
  .controls { margin-left: 0; width: 100%; justify-content: space-between; gap: 6px; padding: 5px; }
  .btn, .seg button { padding: 7px 9px; font-size: 12px; }
  .btn .long { display: none; }
  #party { width: 100%; }
  .card, .card .info { min-width: 0; }
  .bar .val { font-size: 9px; }
  .seed { display: none; }
  .card { padding: 6px; gap: 6px; }
  .card .pt-wrap, .card canvas.pt { width: 36px; height: 36px; }
  .card .nm small { display: none; }
  #bossbar { width: 80vw; top: 150px; bottom: auto; }
  [data-tip]::after { right: auto; left: 0; }
}
