:root {
  --ink: #14111c; --panel: rgba(30, 24, 44, .92); --panel-2: #2b2340; --brass: #c9a24b; --brass-d: #7d6228;
  --text: #f3e9d2; --dim: #a79d86; --hp: #d8524a; --mp: #4f8fe0; --xp: #e8c25a; --ok: #6fd08c; --err: #ff8a7a;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px); --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--ink); color: var(--text); overflow: hidden; overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; background: #0b0a10; }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
button { font: inherit; color: var(--text); cursor: pointer; }
.panel { background: var(--panel); border: 2px solid var(--brass-d); border-radius: 6px; box-shadow: 0 0 0 1px #000, inset 0 0 0 1px rgba(255, 230, 160, .12), 0 6px 18px rgba(0, 0, 0, .45); }
#hud > * { position: fixed; }

/* bars */
.bar { position: relative; height: 12px; background: #120e1a; border: 1px solid #000; border-radius: 3px; overflow: hidden; margin-top: 3px; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 0; transition: width .15s linear; }
.bar.hp i { background: linear-gradient(#f0776e, var(--hp)); } .bar.mp i { background: linear-gradient(#78aef2, var(--mp)); } .bar.xp i { background: linear-gradient(#f4d67e, var(--xp)); }
.bar.xp { height: 7px; } .bar.xp span { display: none; }
.bar span { position: absolute; inset: 0; text-align: center; font: 700 10px/12px ui-monospace, monospace; text-shadow: 0 1px 1px #000; }

#plate { top: calc(8px + var(--safe-t)); left: calc(8px + var(--safe-l)); width: 210px; display: flex; gap: 8px; padding: 7px; }
#portrait { width: 44px; height: 44px; image-rendering: pixelated; background: #0d0a14; border: 2px solid var(--brass-d); border-radius: 4px; align-self: flex-start; }
.plate-body { flex: 1; min-width: 0; }
.plate-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; }
.plate-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.lvl { color: var(--xp); font: 700 12px ui-monospace, monospace; }
#targetPlate { top: calc(8px + var(--safe-t)); left: 50%; transform: translateX(-50%); width: 190px; padding: 6px 8px; text-align: center; font-size: 13px; }

#mini { top: calc(8px + var(--safe-t)); right: calc(8px + var(--safe-r)); padding: 6px; width: 120px; }
#minimap { width: 106px; height: 106px; display: block; image-rendering: pixelated; background: #0d0a14; border-radius: 3px; }
.mini-info { display: flex; flex-direction: column; font-size: 11px; margin: 4px 0; line-height: 1.25; }
.mini-btns { display: flex; flex-direction: column; gap: 3px; }
.mini-btns button, .win button.x, #dlgActions button, #menu button, .primary, .ghost, .tabs button { background: var(--panel-2); border: 1px solid var(--brass-d); border-radius: 4px; padding: 5px 8px; font-size: 12px; }
.mini-btns button:hover, #menu button:hover, #dlgActions button:hover { background: #3a2f57; border-color: var(--brass); }

#tracker { top: 118px; left: calc(8px + var(--safe-l)); width: 210px; padding: 7px 9px; font-size: 12px; pointer-events: none; }
#tracker h4 { margin: 0 0 3px; color: var(--xp); font-size: 12px; } .q-ready { color: var(--ok); }

#chat { left: calc(8px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); width: min(360px, 46vw); padding: 5px; background: rgba(20, 16, 30, .72); }
#chatLog { height: 96px; overflow-y: auto; font-size: 12px; line-height: 1.35; padding: 2px 4px; user-select: text; -webkit-user-select: text; touch-action: pan-y; }
#chatLog p { margin: 0; word-break: break-word; } #chatLog .n { color: var(--brass); } #chatLog .sys { color: #9fd0ff; } #chatLog .ann { color: var(--xp); font-weight: 700; } #chatLog .bad { color: var(--err); }
#chatInput { width: 100%; margin-top: 4px; background: #0f0b17; border: 1px solid var(--brass-d); border-radius: 4px; color: var(--text); padding: 5px 7px; font-size: 13px; }

#skillbar { bottom: calc(8px + var(--safe-b)); left: 50%; transform: translateX(-50%); display: flex; gap: 12px; align-items: flex-end; }
#skills, #quick { display: flex; gap: 6px; }
.slot { position: relative; width: 48px; height: 48px; background: var(--panel); border: 2px solid var(--brass-d); border-radius: 6px; display: grid; place-items: center; overflow: hidden; }
.slot canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.slot .key { position: absolute; top: 1px; left: 3px; font: 700 10px ui-monospace, monospace; color: var(--xp); text-shadow: 0 1px 0 #000; }
.slot .qty { position: absolute; right: 3px; bottom: 1px; font: 700 11px ui-monospace, monospace; text-shadow: 0 1px 1px #000; }
.slot .cd { position: absolute; inset: 0; background: rgba(0, 0, 0, .65); transform-origin: bottom; transform: scaleY(0); }
.slot.off { opacity: .45; }
#skills .slot { cursor: pointer; }

#toasts { top: calc(120px + var(--safe-t)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; width: min(420px, 90vw); }
.toast { background: rgba(20, 16, 30, .92); border: 1px solid var(--brass-d); border-radius: 4px; padding: 5px 10px; font-size: 13px; animation: toast 3.2s forwards; }
.toast.good { border-color: var(--ok); } .toast.bad { border-color: var(--err); } .toast.announce { border-color: var(--xp); color: var(--xp); }
@keyframes toast { 0% { opacity: 0; transform: translateY(-6px); } 8% { opacity: 1; transform: none; } 80% { opacity: 1; } 100% { opacity: 0; } }

#dialog { left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); width: min(560px, 94vw); padding: 12px 14px; }
#dlgName { color: var(--xp); font-weight: 700; margin-bottom: 4px; } #dlgText { min-height: 44px; font-size: 14px; line-height: 1.45; }
#dlgActions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; } #dlgActions button { padding: 7px 12px; font-size: 13px; }

.win { top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(420px, 94vw); max-height: 86vh; overflow: auto; padding: 10px; touch-action: pan-y; }
.win-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; } .win-head b { flex: 1; font-size: 15px; color: var(--xp); } .win-head span { font: 700 12px ui-monospace, monospace; color: var(--xp); }
#invGrid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
#invGrid .slot { width: auto; aspect-ratio: 1; height: auto; background: #1a1428; cursor: pointer; }
#equipGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
#equipGrid .es { text-align: center; font-size: 10px; color: var(--dim); } #equipGrid .slot { width: 100%; height: 56px; margin-bottom: 2px; cursor: pointer; }
#statList { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; font-size: 13px; } #statList div { display: flex; justify-content: space-between; border-bottom: 1px dotted #4a3f66; }
.hint { font-size: 11px; margin-top: 8px; }
#questList .q { margin-bottom: 10px; font-size: 13px; } #questList h4 { margin: 0 0 3px; color: var(--xp); }

.popover { z-index: 50; padding: 6px; font-size: 12px; max-width: 240px; }
#menu { display: flex; flex-direction: column; gap: 4px; min-width: 130px; } #tip { pointer-events: none; line-height: 1.4; } #tip b { color: var(--xp); } #tip .g { color: var(--ok); }

#dead { inset: 0; background: rgba(60, 0, 0, .45); display: grid; place-items: center; text-align: center; pointer-events: none; z-index: 40; } #dead h2 { font-size: 34px; margin: 0; color: #ffb3aa; text-shadow: 0 2px 0 #000; }

/* touch controls */
#touch { inset: 0; pointer-events: none; z-index: 20; }
#touch > * { pointer-events: auto; position: absolute; }
#stick { left: calc(22px + var(--safe-l)); bottom: calc(26px + var(--safe-b)); width: 128px; height: 128px; border-radius: 50%; background: rgba(255, 255, 255, .08); border: 2px solid rgba(201, 162, 75, .45); touch-action: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(201, 162, 75, .55); border: 2px solid var(--brass); }
#tbtns { right: calc(14px + var(--safe-r)); bottom: calc(22px + var(--safe-b)); width: 190px; height: 150px; }
#tbtns button { position: absolute; width: 54px; height: 54px; border-radius: 50%; background: rgba(43, 35, 64, .82); border: 2px solid var(--brass); font-size: 20px; touch-action: none; }
#tbtns .big { width: 78px; height: 78px; right: 0; bottom: 0; font-size: 30px; } #tSkill1 { right: 88px; bottom: 6px; } #tSkill2 { right: 66px; bottom: 68px; } #tAct { right: 0; bottom: 92px; }
.chat-toggle { left: calc(160px + var(--safe-l)); bottom: calc(8px + var(--safe-b)); width: 42px; height: 42px; border-radius: 50%; background: rgba(43, 35, 64, .82); border: 2px solid var(--brass-d); }
body.touch #chat { bottom: auto; top: 176px; width: min(300px, 50vw); opacity: .85; } body.touch #chatLog { height: 70px; } body.touch #chat.collapsed { display: none; }
body.touch #skillbar { bottom: calc(170px + var(--safe-b)); left: auto; right: calc(8px + var(--safe-r)); transform: none; flex-direction: column-reverse; align-items: flex-end; }
body.touch #skills { display: none; } body.touch #dialog { bottom: calc(150px + var(--safe-b)); }
@media (max-height: 520px) { #tracker { display: none; } #mini { width: 96px; } #minimap { width: 82px; height: 82px; } #chatLog { height: 60px; } }

/* auth */
.overlay { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 16px; touch-action: auto; background: radial-gradient(ellipse at 50% 30%, #2d2450 0%, #14111c 70%); }
#authForm, #disc .panel { width: min(380px, 100%); padding: 22px; } #authForm h1 { margin: 0; font-size: 28px; letter-spacing: 3px; color: var(--xp); text-align: center; text-shadow: 0 2px 0 #000; } .sub { text-align: center; font-size: 12px; margin: 6px 0 14px; }
label { display: block; font-size: 12px; color: var(--dim); margin-bottom: 9px; user-select: auto; }
label input { display: block; width: 100%; margin-top: 3px; background: #0f0b17; color: var(--text); border: 1px solid var(--brass-d); border-radius: 4px; padding: 9px; font-size: 16px; }
label input:focus, #chatInput:focus { outline: 2px solid var(--brass); }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; } .tabs button { flex: 1; padding: 8px; } .tabs .on { background: var(--brass-d); color: #fff; }
.primary { width: 100%; padding: 11px; font-size: 15px; font-weight: 700; background: linear-gradient(#d9b45c, #a8822f); color: #1c1305; border: 1px solid #000; } .ghost { width: 100%; margin-top: 8px; }
.err { color: var(--err); font-size: 13px; min-height: 18px; margin-bottom: 8px; } #online { text-align: center; font-size: 11px; margin-top: 10px; }
.swatches { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 10px; } .swatches button { width: 28px; height: 28px; border-radius: 50%; border: 2px solid #000; } .swatches .on { outline: 2px solid var(--xp); outline-offset: 2px; }
#disc { z-index: 200; background: rgba(10, 8, 16, .82); } #disc .panel { text-align: center; }

/* =====================================================
   CÓDICE - CARTAS
   ===================================================== */

.codex-card {
  width: 180px;
  height: 260px;
  margin: 12px auto;
  perspective: 900px;
  cursor: pointer;
}

.codex-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.55s ease;
}

.codex-card.revealed .codex-card-inner {
  transform: rotateY(180deg);
}

.codex-card-front,
.codex-card-back {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  border: 2px solid rgba(255,255,255,.25);
  box-sizing: border-box;
  overflow: hidden;
}

.codex-card-back {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at center, rgba(255,255,255,.12), transparent 45%),
    repeating-linear-gradient(
      45deg,
      rgba(255,255,255,.035) 0,
      rgba(255,255,255,.035) 2px,
      transparent 2px,
      transparent 8px
    ),
    #171b29;
}

.codex-card-back::before {
  content: "C";
  width: 82px;
  height: 82px;
  border: 2px solid rgba(255,255,255,.35);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  font-weight: 800;
  color: rgba(255,255,255,.7);
  box-shadow: 0 0 22px rgba(255,255,255,.08);
}

.codex-card-front {
  transform: rotateY(180deg);
  padding: 10px;
  background: linear-gradient(#252b3d, #111522);
  display: flex;
  flex-direction: column;
}

.codex-card-art {
  flex: 1;
  min-height: 120px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.18);
  background:
    radial-gradient(circle at 50% 50%, rgba(255,255,255,.14), transparent 35%),
    #0d111c;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
}

.codex-card-name {
  margin-top: 8px;
  text-align: center;
  font-weight: 800;
  font-size: 18px;
}

.codex-card-lore {
  margin-top: 5px;
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
  color: rgba(255,255,255,.68);
}

.codex-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.codex-card {
  width: 125px;
  height: 170px;
  margin: 4px;
  padding: 8px;
  perspective: none;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid rgba(255,255,255,.2);
  box-sizing: border-box;
  background: linear-gradient(#252b3d, #111522);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.codex-card:hover {
  transform: translateY(-2px);
}

.codex-card.selected {
  border-color: rgba(255,220,90,.85);
  box-shadow: 0 0 10px rgba(255,220,90,.18);
}

.codex-card-inner,
.codex-card-front,
.codex-card-back {
  position: static;
  transform: none;
  width: auto;
  height: auto;
  border: 0;
  background: none;
  overflow: visible;
}

.codex-card-art {
  height: 70px;
  min-height: 0;
  font-size: 32px;
  border-radius: 6px;
}

.codex-card-name {
  margin-top: 6px;
  font-size: 15px;
}

.codex-card-lore {
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.25;
}

.codex-card-status {
  margin-top: 6px;
  text-align: center;
  font-size: 9px;
  font-weight: 700;
  opacity: .7;
}

.codex-card.selected .codex-card-status {
  color: #ffd95a;
  opacity: 1;
}
