:root {
  --gold: #e8c46a;
  --gold-dark: #8a6a2a;
  --panel: rgba(18, 11, 6, 0.86);
  --celeste: #74acdf;
  --text: #f1e6cc;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #0d0805;
  color: var(--text);
  font-family: Georgia, 'Times New Roman', serif;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

#game, #game canvas { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }

[hidden] { display: none !important; }

/* ---------- Pantalla de inicio ---------- */
#start {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 16px;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0.15), rgba(0,0,0,0.65));
}
.panel {
  width: min(420px, 100%);
  padding: 24px 20px;
  background: var(--panel);
  border: 2px solid var(--gold-dark);
  border-radius: 10px;
  box-shadow: 0 0 0 1px #000, 0 10px 40px rgba(0,0,0,0.6), inset 0 0 30px rgba(232,196,106,0.08);
  text-align: center;
}
h1 { margin: 0; line-height: 1; display: flex; flex-direction: column; gap: 4px; }
h1 .mu {
  font-size: 64px; letter-spacing: 6px;
  background: linear-gradient(#fff6c8, var(--gold) 45%, #8a5a14);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 3px 0 #2a1a08);
}
h1 .ar {
  font-size: 22px; letter-spacing: 8px; color: #fff;
  background: linear-gradient(var(--celeste) 0 33%, #fff 33% 66%, var(--celeste) 66%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 #0a2a4a);
}
.sub { margin: 10px 0 18px; font-size: 13px; color: #b9a57a; font-style: italic; }
label { display: block; font-size: 13px; color: var(--gold); margin-bottom: 6px; text-align: left; }
input {
  width: 100%; padding: 12px; font: inherit; font-size: 18px;
  background: #0d0805; color: var(--text);
  border: 1px solid var(--gold-dark); border-radius: 6px; outline: none;
}
input:focus { border-color: var(--gold); }
.class-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 16px 0; }
.class {
  padding: 10px 4px; border: 1px solid #3a2a18; border-radius: 6px; font-size: 22px;
  display: flex; flex-direction: column; gap: 2px; background: rgba(0,0,0,0.3);
}
.class b { font-size: 12px; color: var(--text); }
.class small { font-size: 10px; color: #8d7c5a; }
.class.selected { border-color: var(--gold); box-shadow: inset 0 0 12px rgba(232,196,106,0.25); }
button.class { font: inherit; font-size: 22px; color: inherit; cursor: pointer; }
.class-pick { margin-bottom: 4px; }
.class-hint { margin: 0 0 14px; font-size: 11px; color: #8d7c5a; }
.class.locked { opacity: 0.45; filter: grayscale(1); }
button[type=submit] {
  width: 100%; padding: 14px; font: inherit; font-size: 18px; font-weight: bold; cursor: pointer;
  color: #1a0f08; border: 1px solid #fff2b0; border-radius: 6px;
  background: linear-gradient(#ffe9a0, var(--gold) 50%, #b8892e);
  box-shadow: 0 3px 0 #5a3e12;
}
button[type=submit]:active { transform: translateY(2px); box-shadow: 0 1px 0 #5a3e12; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
#topbar {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px; right: 8px;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
#topbar > * { pointer-events: auto; }
#mapinfo {
  padding: 6px 12px; background: var(--panel); border: 1px solid var(--gold-dark); border-radius: 6px;
  font-size: 14px; text-shadow: 0 1px 2px #000;
}
#mapname { color: var(--gold); font-weight: bold; }
#coords { color: #cfc2a0; font-variant-numeric: tabular-nums; }
#btn-fs {
  width: 40px; height: 40px; font-size: 20px; color: var(--gold); cursor: pointer;
  background: var(--panel); border: 1px solid var(--gold-dark); border-radius: 6px;
}
#fps { position: absolute; top: 56px; left: 8px; font: 12px monospace; color: #9f9; text-shadow: 0 1px 2px #000; }

#bottombar {
  position: absolute; left: 50%; bottom: max(6px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(560px, calc(100% - 12px));
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px 8px;
  background: linear-gradient(rgba(40,26,14,0.92), rgba(15,9,4,0.95));
  border: 2px solid var(--gold-dark); border-radius: 40px 40px 10px 10px;
  box-shadow: 0 0 0 1px #000, 0 -4px 20px rgba(0,0,0,0.5);
}
.orb {
  position: relative; flex: 0 0 auto; width: 72px; height: 72px; border-radius: 50%; overflow: hidden;
  background: #120a06; border: 3px solid var(--gold-dark);
  box-shadow: inset 0 0 12px #000, 0 0 0 1px #000;
  display: grid; place-items: center;
}
.orb .liquid { position: absolute; left: 0; right: 0; bottom: 0; height: 100%; transition: height 0.2s; }
.orb.hp .liquid { background: radial-gradient(circle at 35% 30%, #ff7a6a, #b3110f 55%, #4a0405); }
.orb.mp .liquid { background: radial-gradient(circle at 35% 30%, #7ab8ff, #1747b3 55%, #06164a); }
.orb::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle at 32% 25%, rgba(255,255,255,0.45), transparent 35%);
}
.orb span { position: relative; z-index: 1; font: bold 12px sans-serif; text-shadow: 0 1px 2px #000, 0 0 4px #000; }
.center { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; padding-bottom: 2px; }
#level { text-align: center; font-size: 13px; color: var(--gold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.xp { height: 7px; background: #120a06; border: 1px solid #3a2a18; border-radius: 4px; overflow: hidden; }
#xp-fill { height: 100%; width: 0; background: linear-gradient(90deg, #8a6a2a, var(--gold)); transition: width 0.3s; }
.slots { display: flex; gap: 6px; justify-content: center; }
.slot {
  width: 42px; height: 42px; border-radius: 6px; display: grid; place-items: center;
  background: #120a06; border: 1px solid var(--gold-dark); color: #5d4c30; font-size: 14px;
}
.slot.potion { font-size: 20px; }

#dialog {
  position: absolute; left: 50%; bottom: 110px; transform: translateX(-50%);
  width: min(460px, calc(100% - 24px));
  padding: 14px 16px 10px;
  background: var(--panel); border: 2px solid var(--gold-dark); border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.6);
  cursor: pointer;
}
#dialog b { color: var(--gold); }
#dialog p { margin: 6px 0; line-height: 1.4; }
#dialog small { display: block; text-align: right; color: #8d7c5a; font-size: 11px; }

/* ---------- Login y desconexión ---------- */
#start label + input { margin-bottom: 10px; }
#login-error { margin: 0 0 12px; padding: 8px; border-radius: 6px; background: rgba(160, 20, 20, 0.35); color: #ffb4a8; font-size: 14px; }
button[type=submit]:disabled { opacity: 0.6; }
#disconnected { position: fixed; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,0.6); z-index: 50; padding: 16px; }
.gold-btn {
  padding: 12px 24px; font: inherit; font-weight: bold; cursor: pointer; color: #1a0f08;
  border: 1px solid #fff2b0; border-radius: 6px; background: linear-gradient(#ffe9a0, var(--gold) 50%, #b8892e);
}

/* ---------- Botones superiores ---------- */
.top-buttons { display: flex; gap: 6px; }
.round {
  position: relative; width: 40px; height: 40px; font: bold 18px Georgia, serif; color: var(--gold); cursor: pointer;
  background: var(--panel); border: 1px solid var(--gold-dark); border-radius: 6px;
}
.round.small-text { width: auto; min-width: 40px; padding: 0 6px; font: bold 11px sans-serif; }
#points-badge {
  position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: #c9271a; color: #fff; font: bold 11px/18px sans-serif;
}
button.slot { cursor: pointer; font-size: 18px; color: var(--text); padding: 0; }
.slot.locked { opacity: 0.35; font-size: 16px; }
.slot.potion { position: relative; }
.slot.skill { position: relative; overflow: hidden; }
.slot.skill.locked { opacity: 0.35; filter: grayscale(1); }
.slot.skill.selected { border: 2px solid var(--gold); box-shadow: 0 0 8px rgba(232,196,106,0.7), inset 0 0 10px rgba(232,196,106,0.35); }
.slot.skill.queued { border-color: #fff2b0; box-shadow: 0 0 14px #fff2b0; }
.slot.skill em { position: absolute; left: 0; right: 0; bottom: 0; font: bold 9px sans-serif; font-style: normal; color: #fff; text-shadow: 0 1px 2px #000; }
.slot .cd { position: absolute; inset: 0; background: rgba(0,0,0,0.65); transform-origin: bottom; transform: scaleY(0); pointer-events: none; }
.slot .cd.run { animation: cd var(--cd, 1s) linear; }
@keyframes cd { from { transform: scaleY(1); } to { transform: scaleY(0); } }
#mana-count { position: absolute; right: 2px; bottom: 0; font: bold 11px sans-serif; color: #fff; text-shadow: 0 1px 2px #000; }
#potion-count { position: absolute; right: 2px; bottom: 0; font: bold 11px sans-serif; color: #fff; text-shadow: 0 1px 2px #000; }

/* ---------- Números flotantes ---------- */
#floaters { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 5; }
.floater {
  position: absolute; left: 0; top: 0; font: bold 22px Georgia, serif; white-space: nowrap;
  text-shadow: 0 0 3px #000, 0 2px 2px #000;
}
.floater.dmg { color: #fff; }
.floater.dmg.other { color: #ddd; font-size: 16px; }
.floater.crit { color: #5ab8ff; font-size: 28px; }
.floater.miss { color: #c8c8c8; font-size: 16px; font-style: italic; }
.floater.hurt { color: #ff4a3a; }
.floater.hurt.other { font-size: 16px; }
.floater.exp { color: #ffd24a; font-size: 15px; }

#hurt { position: fixed; inset: 0; pointer-events: none; z-index: 4; box-shadow: inset 0 0 80px rgba(200, 0, 0, 0.7); opacity: 0; }
#hurt.on { animation: hurt 0.4s ease-out; }
@keyframes hurt { from { opacity: 1; } to { opacity: 0; } }

#notice {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 24px);
  padding: 8px 16px; background: var(--panel); border: 1px solid var(--gold); border-radius: 6px;
  color: var(--gold); font-size: 14px; text-align: center; pointer-events: none;
  animation: notice-in 0.25s ease-out;
}
@keyframes notice-in { from { opacity: 0; transform: translate(-50%, -8px); } }

/* ---------- Chat ---------- */
#chat { position: absolute; left: 8px; bottom: 112px; width: min(360px, calc(100% - 16px)); pointer-events: none; }
#chat-log { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
#chat-log > div {
  align-self: flex-start; max-width: 100%; padding: 2px 8px; border-radius: 4px; background: rgba(0,0,0,0.45);
  text-shadow: 0 1px 2px #000; transition: opacity 1s;
}
#chat-log > div.sys { color: #ffd98a; }
#chat-log > div.old { opacity: 0.35; }
#chat-log b { color: #9fe8ff; }
#chat-form { margin-top: 6px; pointer-events: auto; }
#chat-input { padding: 8px 10px; font-size: 15px; }

/* ---------- Ventanas ---------- */
.window {
  position: absolute; top: 56px; right: 8px; width: min(320px, calc(100% - 16px)); max-height: calc(100% - 180px); overflow-y: auto;
  background: var(--panel); border: 2px solid var(--gold-dark); border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,0.6);
  padding: 0 12px 12px; z-index: 10;
}
#win-inv { top: 56px; left: 8px; right: auto; }
.win-title {
  position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0 8px; margin-bottom: 8px; border-bottom: 1px solid #3a2a18; background: inherit;
  color: var(--gold); font-weight: bold;
}
.win-title button { background: none; border: 0; color: var(--text); font-size: 18px; cursor: pointer; }
.stat-head { color: var(--gold); font-weight: bold; }
.stat-sub { font-size: 12px; color: #b9a57a; margin: 2px 0 10px; }
.stat-row { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.stat-row span { flex: 1; }
.stat-row b { min-width: 36px; text-align: right; }
.stat-row button, .inv-row button {
  padding: 4px 10px; font: bold 13px Georgia, serif; cursor: pointer; color: #1a0f08;
  border: 1px solid #fff2b0; border-radius: 4px; background: linear-gradient(#ffe9a0, var(--gold) 50%, #b8892e);
}
.stat-points { margin: 10px 0; color: var(--gold); }
.stat-derived { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; font-size: 13px; color: #cfc2a0; }
.stat-derived b { color: var(--text); text-align: right; }
.zen { padding: 6px 0 10px; color: var(--gold); font-weight: bold; }
.inv-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid rgba(255,255,255,0.05); }
.inv-row span:nth-child(2) { flex: 1; }
.inv-row .icon { font-size: 22px; }
.empty { color: #8d7c5a; font-style: italic; }

/* ---------- Party y avisos con botones ---------- */
#party {
  position: absolute; top: 54px; left: 8px; width: 150px; padding: 6px 8px;
  background: var(--panel); border: 1px solid var(--gold-dark); border-radius: 6px; font-size: 12px;
}
#party .pm { margin-bottom: 5px; }
#party .pm b { color: #9fe8ff; }
#party .pm.me b { color: var(--gold); }
#party .bar { height: 5px; margin-top: 2px; background: #120a06; border-radius: 3px; overflow: hidden; }
#party .bar i { display: block; height: 100%; background: linear-gradient(90deg, #8a1010, #e0302a); }
#party button { width: 100%; margin-top: 2px; padding: 4px; font: 11px Georgia, serif; color: var(--text); background: #2a1d10; border: 1px solid var(--gold-dark); border-radius: 4px; cursor: pointer; }
#prompt {
  position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); width: min(340px, calc(100% - 32px));
  padding: 16px; z-index: 20; text-align: center;
}
#prompt p { margin: 0 0 14px; line-height: 1.4; }
.prompt-btns { display: flex; gap: 10px; justify-content: center; }
.gold-btn.dark { background: #2a1d10; color: var(--text); border-color: var(--gold-dark); }

/* ---------- Equipo e inventario ---------- */
.equip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; margin-bottom: 10px; }
.ico-svg { width: 82%; height: 82%; display: block; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.6)); }
.empty-slot .ico-svg { opacity: 0.35; }
.inv-row .icon { width: 32px; height: 32px; display: grid; place-items: center; }
.inv-row .icon .ico-svg { width: 100%; height: 100%; }
.chaos-rate { margin: 10px 0; font-size: 14px; }
.chaos-in { min-height: 48px; padding: 4px; border: 1px dashed #6a3a8a; border-radius: 6px; background: rgba(90, 30, 120, 0.15); }
#chaos-go { width: 100%; }
#chaos-go:disabled { opacity: 0.45; cursor: default; }
#win-chaos, #win-quest { left: 50%; right: auto; transform: translateX(-50%); }
#quest-body p { line-height: 1.5; margin: 0 0 10px; }
#quest-body .gold-btn { width: 100%; }
.slot.skill.evo { border-color: #d8b040; box-shadow: inset 0 0 8px rgba(255,210,74,0.35); }
@media (max-width: 420px) {
  .slots:has(.evo:not([hidden])) .slot { width: 32px; height: 32px; font-size: 14px; }
  .slots:has(.evo:not([hidden])) { gap: 3px; }
}

/* Botón de correr: arriba del orbe de maná, al alcance del pulgar */
#btn-run {
  position: absolute; right: 14px; bottom: calc(max(6px, env(safe-area-inset-bottom)) + 96px);
  width: 54px; height: 54px; border-radius: 50%; font-size: 26px; cursor: pointer;
  background: radial-gradient(circle at 35% 30%, #4a3520, #1a0f08); border: 2px solid var(--gold-dark);
  box-shadow: 0 2px 10px rgba(0,0,0,0.6);
}
#btn-run.on { border-color: #fff2b0; box-shadow: 0 0 14px var(--gold); background: radial-gradient(circle at 35% 30%, #8a6a2a, #3a2410); }
#btn-run.locked { opacity: 0.4; filter: grayscale(1); }
.eslot { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 4px; border: 1px solid #3a2a18; border-radius: 6px; background: rgba(0,0,0,0.25); }
.eslot small { font-size: 10px; color: #8d7c5a; }
.empty-slot { width: 44px; height: 44px; display: grid; place-items: center; font-size: 20px; opacity: 0.25; filter: grayscale(1); }
.bag-title { margin: 10px 0 6px; color: var(--gold); font-size: 13px; display: flex; justify-content: space-between; }
.bag { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; }
.bag .empty { grid-column: 1 / -1; margin: 0; font-size: 13px; }
.cell {
  position: relative; width: 44px; height: 44px; justify-self: center; display: grid; place-items: center; font-size: 22px; cursor: pointer;
  background: radial-gradient(circle, #2a1d10, #120a06); border: 1px solid #4a3620; border-radius: 6px; padding: 0;
}
.cell b { position: absolute; right: 2px; bottom: 0; font: bold 10px sans-serif; color: #ffd24a; text-shadow: 0 1px 2px #000; }
.cell.exc { border-color: #3aff7a; box-shadow: inset 0 0 8px rgba(58,255,122,0.4); }
.cell.gold { border-color: #d8b040; box-shadow: inset 0 0 8px rgba(255,210,74,0.35); }
.cell.sel { outline: 2px solid #fff2b0; }
.cell.jm { animation: pulse 0.8s infinite alternate; }
@keyframes pulse { to { box-shadow: 0 0 12px #9ad8ff; } }
.detail { margin: 6px 0; padding: 8px 10px; border: 1px solid var(--gold-dark); border-radius: 6px; background: rgba(0,0,0,0.35); font-size: 13px; line-height: 1.5; }
.detail > b { display: block; margin-bottom: 2px; }
.detail .bad { color: #ff6a5a; }
.exc { color: #5aff8a; }
.gold { color: #ffd24a; }
.detail-btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.detail-btns button {
  padding: 6px 12px; font: bold 13px Georgia, serif; cursor: pointer; color: #1a0f08;
  border: 1px solid #fff2b0; border-radius: 4px; background: linear-gradient(#ffe9a0, var(--gold) 50%, #b8892e);
}
.shop-hint { font-size: 12px; color: #b9a57a; margin: 0 0 8px; }
.inv-row small { color: #b9a57a; }

@media (max-width: 420px) {
  .orb { width: 60px; height: 60px; }
  .slot { width: 36px; height: 36px; font-size: 16px; }
  .slots { gap: 4px; }
  #bottombar { gap: 4px; padding: 5px 6px; }
  .round { width: 34px; height: 34px; font-size: 15px; }
  .top-buttons { gap: 4px; }
  #mapinfo { font-size: 12px; padding: 5px 8px; }
}

/* Celular acostado (pantalla baja): barra inferior, botones y chat más chicos para ver más mapa. */
@media (max-height: 500px) {
  #bottombar { transform: translateX(-50%) scale(0.62); transform-origin: bottom center; bottom: 2px; }
  #topbar { transform: scale(0.75); transform-origin: top left; width: 133%; }
  #btn-run { transform: scale(0.7); transform-origin: bottom right; }
  #chat-log { font-size: 11px; max-width: 40%; }
}
