:root {
  --crema: #fffaf2; --borde: #e2d3bf; --naranja: #ff7a59; --morado: #7a3b8f; --tinta: #1d1d22; --suave: #6b5a4e;
  --vida: #4cc463; --vida-e: #e0533d; --energia: #f2c23a; --xp: #a77bff;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #9fd6f0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--tinta);
  -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas { display: block; touch-action: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- entrada ---------- */
#entrada { position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto; background: linear-gradient(#ffb36b, #ff7a59 55%, #7a3b8f); z-index: 30; }
.tarjeta { background: var(--crema); border-radius: 18px; padding: 22px; max-width: 620px; width: 100%; margin: auto 0;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); }
h1 { margin: 0; font-size: 36px; letter-spacing: 4px; }
.sub { margin: 0 0 12px; color: var(--suave); }
label { font-weight: 700; display: block; margin: 12px 0 6px; }
.nota { font-size: 13px; color: var(--suave); font-weight: 400; margin: 6px 0 0; }
input { width: 100%; font-size: 17px; padding: 9px 11px; border-radius: 10px; border: 2px solid var(--borde);
  -webkit-user-select: text; user-select: text; background: #fff; color: var(--tinta); }
.dos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dos label { margin-top: 0; }
.rejilla { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 7px; }
.opcion { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 10px; border: 2px solid var(--borde);
  background: #fff; font-size: 14px; cursor: pointer; text-align: left; line-height: 1.2; }
.opcion small { display: block; color: var(--suave); font-size: 12px; }
.opcion.elegida { border-color: var(--naranja); background: #fff1e8; }
.muestra { width: 22px; height: 22px; border-radius: 50%; border: 4px solid; flex: none; }
.info { background: #fff3e3; border-radius: 10px; padding: 9px 11px; margin-top: 8px; font-size: 14px; line-height: 1.4; }
.info b { color: var(--morado); }
.error { color: #c0392b; font-weight: 700; min-height: 1.2em; margin-top: 10px; }
.entrar { margin-top: 10px; width: 100%; font-size: 19px; font-weight: 800; padding: 12px; border: 0; border-radius: 12px;
  background: var(--naranja); color: #fff; cursor: pointer; }
@media (max-width: 520px) { .dos { grid-template-columns: 1fr; } .rejilla { grid-template-columns: 1fr 1fr; } }

/* ---------- intro ---------- */
#intro { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #3a2a5c, #120c1e); color: #fff; }
.intro-caja { max-width: 560px; width: 100%; text-align: center; }
#intro-dibujo { font-size: 74px; min-height: 100px; line-height: 1.3; }
#intro-texto { font-size: 20px; line-height: 1.5; min-height: 6em; }
.intro-botones { display: flex; gap: 10px; justify-content: center; }
.intro-botones button { border: 0; border-radius: 12px; padding: 11px 20px; font-size: 17px; font-weight: 700; cursor: pointer; }
#intro-seguir { background: var(--naranja); color: #fff; }
#intro-saltar { background: rgba(255,255,255,.15); color: #fff; }

/* ---------- marcos ---------- */
.marco { position: fixed; background: rgba(255,250,242,.92); border-radius: 12px; padding: 8px 10px; width: 230px;
  box-shadow: 0 3px 12px rgba(0,0,0,.18); font-size: 13px; }
#marco-yo { top: max(10px, env(safe-area-inset-top)); left: 10px; }
#marco-obj { top: max(10px, env(safe-area-inset-top)); left: 250px; }
.marco-nombre { font-weight: 800; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nivel { background: var(--morado); color: #fff; border-radius: 6px; padding: 0 5px; font-size: 11px; font-weight: 700; }
.barra { position: relative; height: 14px; background: rgba(0,0,0,.15); border-radius: 7px; overflow: hidden; margin: 3px 0; }
.barra > div { height: 100%; width: 0; transition: width .15s; }
.barra span { position: absolute; inset: 0; text-align: center; font-size: 10px; line-height: 14px; font-weight: 700; color: #1d1d22; }
.vida > div { background: var(--vida); } .vida.enemigo > div { background: var(--vida-e); }
.energia > div { background: var(--energia); } .xp { height: 5px; } .xp > div { background: var(--xp); }
.marco-pie { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; margin-top: 3px; }

.caja { position: fixed; right: 10px; background: rgba(255,250,242,.9); border-radius: 12px; padding: 8px 11px; width: 250px;
  font-size: 13px; line-height: 1.4; box-shadow: 0 3px 12px rgba(0,0,0,.15); }
#mision { top: max(10px, env(safe-area-inset-top)); }
#mision b { color: var(--morado); }
#clan-mini { top: 132px; }
#clan-mini:empty, #mision:empty { display: none; }

#registro { position: fixed; left: 10px; bottom: 110px; width: min(360px, 60vw); font-size: 13px; pointer-events: none;
  display: flex; flex-direction: column; gap: 3px; }
#registro div { background: rgba(0,0,0,.5); color: #fff; padding: 4px 8px; border-radius: 8px; animation: desvanece 9s forwards; }
@keyframes desvanece { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
#aviso-grande { position: fixed; top: 22%; left: 50%; transform: translateX(-50%); text-align: center; pointer-events: none;
  font-size: 22px; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(0,0,0,.6); width: min(640px, 92vw); }
#aviso-grande div { animation: desvanece 6s forwards; margin-bottom: 6px; }
#herida { position: fixed; inset: 0; pointer-events: none; opacity: 0;
  background: radial-gradient(ellipse at center, transparent 45%, rgba(220, 30, 40, .55) 100%); }
#herida.ver { animation: herida .45s ease-out; }
@keyframes herida { 0% { opacity: 1; } 100% { opacity: 0; } }
.corazones { letter-spacing: -1px; font-size: 13px; }
.corazones .lleno { color: #e8384f; text-shadow: 0 1px 0 #7a1020; }
.corazones .vacio { color: #c9bcb0; }
#zona-cartel { position: fixed; top: 12%; left: 50%; transform: translateX(-50%); pointer-events: none; text-align: center;
  font-size: 34px; font-weight: 900; letter-spacing: 1px; color: #fff3d6; white-space: nowrap;
  text-shadow: 0 3px 0 #2a1f2e, 0 -2px 0 #2a1f2e, 2px 0 0 #2a1f2e, -2px 0 0 #2a1f2e, 0 6px 14px rgba(0,0,0,.4); opacity: 0; }
#zona-cartel.ver { animation: zona 3.2s ease forwards; }
#zona-cartel small { display: block; font-size: 15px; font-weight: 700; letter-spacing: 3px; opacity: .9; }
@keyframes zona { 0% { opacity: 0; transform: translate(-50%, 10px) scale(.9); } 12% { opacity: 1; transform: translate(-50%, 0) scale(1); }
  75% { opacity: 1; } 100% { opacity: 0; } }
@media (max-width: 700px) { #zona-cartel { font-size: 24px; top: 30%; } }
#aviso { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); background: var(--morado); color: #fff;
  padding: 8px 14px; border-radius: 10px; font-size: 14px; z-index: 50; max-width: calc(100vw - 32px); text-align: center; }
#aviso:empty { display: none; }

#progreso { position: fixed; left: 50%; bottom: 180px; transform: translateX(-50%); width: 240px; height: 20px;
  background: rgba(0,0,0,.45); border-radius: 10px; overflow: hidden; }
#progreso-barra { height: 100%; width: 0; background: var(--energia); }
#progreso-t { position: absolute; inset: 0; text-align: center; color: #fff; font-size: 12px; line-height: 20px; font-weight: 700; }
#muerto { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px;
  background: rgba(40,20,60,.55); color: #fff; font-size: 22px; font-weight: 800; pointer-events: none; }

/* ---------- botones ---------- */
#botones-menu { position: fixed; right: 10px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 6px; }
#botones-menu button { width: 46px; height: 46px; border-radius: 12px; border: 0; background: rgba(255,250,242,.92); font-size: 22px;
  cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.2); position: relative; }
#botones-menu button.aviso::after { content: ""; position: absolute; top: 5px; right: 5px; width: 10px; height: 10px; border-radius: 50%; background: #e0533d; }
#barra-acciones { position: fixed; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; gap: 8px; }
.hab { position: relative; width: 62px; height: 62px; border-radius: 14px; border: 3px solid #fff; background: #3b2d4a; color: #fff;
  font-size: 28px; cursor: pointer; overflow: hidden; box-shadow: 0 3px 10px rgba(0,0,0,.3); touch-action: manipulation; }
.hab.definitiva { border-color: #ffa53a; }
.hab .tecla { position: absolute; top: 2px; left: 5px; font-size: 11px; font-weight: 800; text-shadow: 0 1px 2px #000; z-index: 2; }
.hab .icono { width: 44px; height: 44px; display: block; margin: auto; filter: drop-shadow(0 2px 0 rgba(0,0,0,.35)); }
.hab { background: radial-gradient(circle at 50% 35%, #5a4570, #2f2340); }
.hab:active { transform: scale(.92); }
.habinfo .ico .icono { width: 34px; height: 34px; }
.habinfo .ico .icono { background: #3b2d4a; border-radius: 8px; }
.hab .cd { position: absolute; inset: 0; background: conic-gradient(rgba(0,0,0,.7) var(--p, 0%), transparent 0); }
.hab .cdt { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 800; }
.hab.sin-energia { filter: grayscale(.8) brightness(.7); }
#minimapa { position: fixed; right: 70px; bottom: 86px; width: 150px; height: 150px; border-radius: 50%;
  border: 4px solid #fffaf2; box-shadow: 0 4px 14px rgba(0,0,0,.35); cursor: pointer; background: #2f8fd0; }
@media (max-width: 700px), (pointer: coarse) { #minimapa { display: none; } }
#mapa-grande { width: 100%; max-width: 560px; aspect-ratio: 1; display: block; margin: 0 auto; border-radius: 14px; background: #2f8fd0; }
.leyenda { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; margin-top: 8px; }
#pociones { position: fixed; left: 12px; bottom: max(14px, env(safe-area-inset-bottom)); display: flex; gap: 6px; }
#pociones button { position: relative; width: 48px; height: 48px; border-radius: 12px; border: 3px solid #fff; cursor: pointer;
  background: radial-gradient(circle at 50% 35%, #4d7a46, #2c4a28); font-size: 22px; box-shadow: 0 3px 10px rgba(0,0,0,.3); touch-action: manipulation; }
#pociones button.leche { background: radial-gradient(circle at 50% 35%, #5a6f8a, #2f3d52); }
#pociones button:disabled { filter: grayscale(.9) brightness(.7); }
#pociones .n { position: absolute; right: 2px; bottom: 0; font-size: 12px; font-weight: 900; color: #fff; text-shadow: 0 1px 2px #000; }
#pociones .tecla { position: absolute; left: 4px; top: 1px; font-size: 10px; font-weight: 800; color: #fff; text-shadow: 0 1px 2px #000; }
#btn-accion { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); border: 0; border-radius: 12px; padding: 10px 16px;
  background: var(--crema); font-weight: 800; font-size: 15px; box-shadow: 0 3px 10px rgba(0,0,0,.25); cursor: pointer; white-space: nowrap; }
#btn-miau { position: fixed; right: 18px; bottom: max(18px, env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--naranja); color: #fff; font-weight: 800; font-size: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.3);
  cursor: pointer; touch-action: manipulation; }
#joystick { display: none; position: fixed; left: 20px; bottom: max(20px, env(safe-area-inset-bottom)); width: 120px; height: 120px;
  border-radius: 50%; background: rgba(255,255,255,.25); border: 2px solid rgba(255,255,255,.6); touch-action: none; }
#pomo { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  background: rgba(255,255,255,.85); pointer-events: none; }

/* ---------- paneles ---------- */
#panel { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(600px, calc(100vw - 20px));
  max-height: calc(100vh - 40px); overflow-y: auto; background: var(--crema); border-radius: 16px; padding: 14px 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,.35); z-index: 20; font-size: 14px; -webkit-user-select: text; user-select: text; }
.panel-cab { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.panel-cab h2 { margin: 0; font-size: 20px; }
#panel-cerrar { border: 0; background: #eee2d2; border-radius: 10px; width: 34px; height: 34px; cursor: pointer; font-size: 16px; }
.tabla { width: 100%; border-collapse: collapse; }
.tabla td { padding: 4px 6px; border-bottom: 1px solid #efe3d3; }
.ranuras { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 8px 0; }
.objeto { border: 2px solid var(--borde); border-radius: 10px; padding: 7px 9px; background: #fff; line-height: 1.35; }
.objeto .nom { font-weight: 800; }
.objeto .mini { font-size: 12px; color: var(--suave); }
.objeto .acciones { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.boton { border: 0; border-radius: 8px; padding: 5px 10px; background: var(--naranja); color: #fff; font-weight: 700; cursor: pointer; font-size: 13px; }
.boton.gris { background: #c9b9a6; }
.boton:disabled { opacity: .45; cursor: default; }
.bolsa { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.mejor { color: #2e9e4a; font-weight: 700; } .peor { color: #c0392b; font-weight: 700; }
.fila-tal { margin: 10px 0 4px; font-weight: 800; color: var(--morado); }
.fila-tal small { color: var(--suave); font-weight: 400; }
.talentos { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.talento { border: 2px solid var(--borde); border-radius: 10px; padding: 8px; background: #fff; }
.talento.bloqueado { opacity: .5; }
.talento .nom { font-weight: 800; }
.talento .rango { float: right; font-weight: 800; color: var(--morado); }
.obra { border: 2px solid var(--borde); border-radius: 10px; padding: 8px 10px; background: #fff; margin-bottom: 7px; }
.obra.hecha { border-color: #4cc463; }
.obra .nom { font-weight: 800; }
.recursos { display: flex; gap: 12px; flex-wrap: wrap; font-weight: 700; margin: 4px 0 10px; }
.deslizador { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; margin: 10px 0; }
.deslizador input { width: 100%; accent-color: var(--naranja); }
.deslizador .acciones { display: flex; gap: 6px; flex-wrap: wrap; }
.casilla { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.casilla input { width: auto; }
.habinfo { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0; }
.habinfo .ico { font-size: 26px; width: 34px; text-align: center; }

/* ---------- diálogo ---------- */
#dialogo { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); width: min(560px, calc(100vw - 20px));
  background: var(--crema); border-radius: 16px; padding: 14px 16px; box-shadow: 0 10px 30px rgba(0,0,0,.35); z-index: 15; }
.dialogo-quien { font-weight: 800; color: var(--morado); margin-bottom: 4px; }
#dialogo p { margin: 0 0 10px; font-size: 16px; line-height: 1.45; }
#dialogo-seguir { border: 0; border-radius: 10px; padding: 8px 14px; background: var(--naranja); color: #fff; font-weight: 800; cursor: pointer; float: right; }

/* ---------- móvil ---------- */
@media (pointer: coarse) {
  #joystick { display: block; }
  #barra-acciones { left: auto; right: 12px; transform: none; display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
    bottom: max(86px, calc(env(safe-area-inset-bottom) + 72px)); }
  .hab { width: 58px; height: 58px; }
  #btn-miau { width: 52px; height: 52px; right: 14px; bottom: max(16px, env(safe-area-inset-bottom)); }
  #pociones { left: 150px; bottom: max(24px, env(safe-area-inset-bottom)); }
  #btn-accion { left: 16px; transform: none; bottom: max(156px, calc(env(safe-area-inset-bottom) + 146px)); }
  #registro { bottom: 220px; }
  #progreso { bottom: 290px; }
}
@media (max-width: 700px) {
  .marco { width: 175px; padding: 6px 8px; }
  #marco-obj { left: auto; right: 10px; top: max(10px, env(safe-area-inset-top)); }
  #mision { top: auto; right: auto; left: 10px; width: 175px; top: 160px; font-size: 12px; }
  #clan-mini { display: none; }
  #botones-menu { top: auto; transform: none; bottom: auto; right: 10px; top: 112px; flex-direction: row; }
  #botones-menu button { width: 40px; height: 40px; font-size: 19px; }
  #registro { width: calc(100vw - 160px); font-size: 12px; }
  #aviso-grande { font-size: 18px; }
  .talentos { grid-template-columns: 1fr; }
}

/* ---------- móvil: pasada del 11-nov-2026 ---------- */
body { touch-action: manipulation; -webkit-touch-callout: none; overscroll-behavior: none; }
#panel { max-height: calc(100dvh - 40px); }
#btn-objetivo { position: fixed; left: calc(50% + 146px); bottom: max(20px, env(safe-area-inset-bottom)); width: 50px; height: 50px;
  border-radius: 50%; border: 3px solid #fff; background: #e8384f; color: #fff; font-size: 24px; line-height: 1;
  box-shadow: 0 3px 10px rgba(0,0,0,.3); cursor: pointer; touch-action: manipulation; }
@media (pointer: coarse) {
  .hab { width: 64px; height: 64px; }
  #barra-acciones { gap: 10px; }
  #btn-objetivo { left: auto; right: 166px; bottom: max(96px, calc(env(safe-area-inset-bottom) + 82px)); width: 58px; height: 58px; font-size: 26px; }
  #botones-menu button { width: 44px; height: 44px; }
  #minimapa { display: block; width: 96px; height: 96px; right: 10px; left: auto; top: 168px; bottom: auto; border-width: 3px; }
}
/* móvil girado (apaisado) */
@media (pointer: coarse) and (orientation: landscape) and (max-height: 520px) {
  .marco { width: 165px; padding: 5px 7px; font-size: 11px; }
  #marco-obj { left: 185px; right: auto; top: max(8px, env(safe-area-inset-top)); }
  #marco-yo { left: max(8px, env(safe-area-inset-left)); top: max(8px, env(safe-area-inset-top)); }
  #botones-menu { flex-direction: row; top: 8px; right: max(8px, env(safe-area-inset-right)); bottom: auto; transform: none; }
  #botones-menu button { width: 38px; height: 38px; font-size: 17px; }
  #mision { top: 54px; right: max(8px, env(safe-area-inset-right)); left: auto; width: 210px; font-size: 11px; }
  #clan-mini { display: none; }
  #minimapa { display: none; }
  #joystick { width: 110px; height: 110px; left: max(16px, env(safe-area-inset-left)); bottom: 12px; }
  #pociones { left: calc(max(16px, env(safe-area-inset-left)) + 122px); bottom: 14px; }
  #barra-acciones { display: flex; right: calc(max(8px, env(safe-area-inset-right)) + 54px); left: auto; bottom: 10px; gap: 8px; }
  .hab { width: 54px; height: 54px; font-size: 22px; }
  .hab .icono { width: 38px; height: 38px; }
  #btn-objetivo { right: calc(max(8px, env(safe-area-inset-right)) + 300px); bottom: 14px; width: 50px; height: 50px; }
  #btn-miau { right: max(6px, env(safe-area-inset-right)); bottom: 10px; width: 46px; height: 46px; font-size: 12px; }
  #btn-accion { left: 50%; transform: translateX(-50%); bottom: 76px; }
  #registro { bottom: 130px; width: 40vw; }
  #aviso-grande { top: 30%; font-size: 16px; }
  #zona-cartel { top: 16%; font-size: 20px; }
  #progreso { bottom: 120px; }
  #dialogo { bottom: 70px; }
}
