:root {
  --ink: #17131a;
  --panel: rgba(26, 21, 20, 0.9);
  --panel-solid: #1f1a18;
  --edge: #4a3f34;
  --gold: #d9a13b;
  --hp: #b8453a;
  --mp: #6f8a5a;
  --text: #e6ddd0;
  --dim: #9a8f80;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--ink);
  color: var(--text);
  font-family: ui-monospace, "Courier New", monospace;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: none;
}

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ---------- Canvas del juego: baja resolución escalada ---------- */
#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* ---------- HUD comun ---------- */
.hud-bar {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel);
  backdrop-filter: blur(2px);
  pointer-events: none;
}
.hud-bar button { pointer-events: auto; }

/* div 2 — superior */
#hud-top {
  top: 0;
  padding: calc(6px + var(--safe-top)) 10px 6px;
  height: calc(52px + var(--safe-top));
  border-bottom: 2px solid var(--edge);
}

.portrait {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  background: #241b33;
  border: 2px solid var(--edge);
  border-radius: 3px;
}
#portrait-canvas {
  width: 28px;
  height: 28px;
  image-rendering: pixelated;
}

.vitals { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.name-row { display: flex; align-items: center; gap: 6px; font-size: 11px; letter-spacing: .5px; }
.name-row .tag { color: var(--dim); font-size: 9px; text-transform: uppercase; }

.bar {
  height: 6px;
  background: #2a2038;
  border: 1px solid #0a0810;
  overflow: hidden;
}
.bar i { display: block; height: 100%; width: 100%; transition: width .18s linear; }
.bar.hp i { background: linear-gradient(180deg, #ff6a5e, var(--hp)); }
.bar.mp { height: 4px; }
.bar.mp i { background: linear-gradient(180deg, #6fb6ff, var(--mp)); }

.coins { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--gold); }
.coin-icon {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--gold);
  box-shadow: inset -2px -2px 0 #a97c14;
}

/* div 3 — esquina superior derecha, transparente */
#hud-corner {
  position: absolute;
  right: 8px;
  top: calc(60px + var(--safe-top));
  z-index: 9;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
}
#minimap {
  width: 72px;
  height: 72px;
  image-rendering: pixelated;
  border: 2px solid rgba(59, 47, 82, 0.75);
  border-radius: 2px;
  background: rgba(10, 8, 16, 0.35);
}
#hud-coords {
  font-size: 9px;
  color: rgba(232, 226, 240, 0.65);
  text-shadow: 0 1px 0 #000;
}

#hud-district {
  font-size: 10px;
  letter-spacing: .5px;
  color: var(--gold);
  text-shadow: 0 1px 0 #000, 0 0 6px rgba(0, 0, 0, .6);
}

/* ---------- Transicion entre barrios ---------- */
#transition {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: #0e0a08;
  display: grid;
  place-items: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
#transition.show {
  opacity: 1;
  pointer-events: auto;
}
#transition .t-label {
  font-size: 14px;
  letter-spacing: 1px;
  color: var(--gold);
  text-align: center;
  padding: 0 20px;
}
#transition .t-label::after {
  content: '';
  display: inline-block;
  width: 3ch;
  text-align: left;
  animation: t-dots 1.2s steps(1) infinite;
}
@keyframes t-dots {
  0% { content: ''; }
  25% { content: '.'; }
  50% { content: '..'; }
  75% { content: '...'; }
}

/* div 1 — inferior */
#hud-bottom {
  bottom: 0;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  height: calc(76px + var(--safe-bottom));
  border-top: 2px solid var(--edge);
  justify-content: space-between;
}

.slots { display: flex; gap: 8px; }
.slot {
  width: 42px; height: 42px;
  background: #241b33;
  border: 2px solid var(--edge);
  border-radius: 3px;
  color: var(--dim);
  font: inherit;
  font-size: 11px;
  display: grid;
  place-items: center;
}
.slot:active { background: #322546; }

.actions { display: flex; align-items: center; gap: 10px; }
.act {
  border-radius: 50%;
  border: 2px solid #0a0810;
  font: inherit;
  font-size: 15px;
  font-weight: bold;
  color: #1a1220;
}
.act-a { width: 54px; height: 54px; background: radial-gradient(circle at 35% 30%, #ffe07a, var(--gold)); }
.act-b { width: 44px; height: 44px; background: radial-gradient(circle at 35% 30%, #a8b6d8, #6f7fa8); }
.act:active { transform: translateY(2px); }

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 20;
  padding: 5px 12px;
  font-size: 11px;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 2px;
  opacity: 0;
  transition: opacity .25s;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { opacity: 1; }

/* ---------- Seleccion de personaje ---------- */
#char-select {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: radial-gradient(circle at 50% 30%, #241b3a, var(--ink) 70%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(20px + var(--safe-top)) 16px calc(20px + var(--safe-bottom));
}
#char-select.hidden { display: none; }
#char-select h1 { font-size: 17px; letter-spacing: 1px; }
#char-select .subtitle { font-size: 10px; color: var(--dim); text-align: center; }

#char-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: 100%;
  max-width: 360px;
}

.card {
  flex: 0 0 105px;
  background: #221c1a;
  border: 2px solid var(--edge);
  border-radius: 4px;
  padding: 7px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}
.card.selected {
  border-color: var(--gold);
  background: #33291f;
  box-shadow: 0 0 0 1px var(--gold) inset;
}
.card canvas {
  width: 60px;   /* 20 x 3 */
  height: 84px;  /* 28 x 3 */
  image-rendering: pixelated;
}
.card .cname { font-size: 11px; }
.card .cdesc { font-size: 7.5px; color: var(--dim); text-align: center; line-height: 1.35; }
.card .cstats { font-size: 8px; color: var(--gold); }

#start-btn {
  margin-top: 4px;
  padding: 11px 34px;
  font: inherit;
  font-size: 13px;
  letter-spacing: 1px;
  color: #1a1220;
  background: linear-gradient(180deg, #ffe07a, var(--gold));
  border: 2px solid #0a0810;
  border-radius: 3px;
}
#start-btn:disabled { background: #3b2f52; color: #6d6382; }

@media (min-height: 760px) {
  .card { flex: 0 0 112px; }
  .card canvas { width: 80px; height: 112px; }
}
