:root {
  --bg: #0d0d0c;
  --bg-raise: #151513;
  --bg-2: #1c1c19;
  --fg: #e9e6df;
  --muted: #9c988f;
  --faint: #6b6861;
  --rule: rgba(233, 230, 223, 0.1);
  --rule-strong: rgba(233, 230, 223, 0.22);
  --accent: #e0aa48;
  --accent-ink: #1a1306;
  --good: #8fbf6a;
  --bad: #e07a6a;
  --hp: #c8352b;
  --mp: #3a63c9;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --side-w: 248px;
  --chat-h: 150px;
  --hot-h: 48px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); font: 14px/1.4 var(--sans); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button {
  background: var(--bg-2); border: 1px solid var(--rule-strong); border-radius: 6px; padding: 7px 12px; cursor: pointer;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.on { border-color: var(--accent); color: var(--accent); }
input, select {
  background: var(--bg); border: 1px solid var(--rule-strong); border-radius: 6px; padding: 8px 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

.screen { position: fixed; inset: 0; overflow: auto; padding: 16px; }
.center { display: flex; align-items: center; justify-content: center; }
.card {
  width: min(380px, 100%); background: var(--bg-raise); border: 1px solid var(--rule); border-radius: 12px;
  padding: 24px; display: flex; flex-direction: column; gap: 12px;
}
.card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.brand { font-weight: 800; font-size: 26px; letter-spacing: 0.02em; color: var(--accent); }
.progress { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; border: 1px solid var(--rule); }
#load-bar { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
.msg { min-height: 1.2em; margin: 0; color: var(--bad); font-size: 13px; white-space: pre-line; }
.links { margin: 0; color: var(--faint); }
.row { display: flex; gap: 8px; justify-content: flex-end; }
.char-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; }
.char-list li {
  padding: 10px 12px; border: 1px solid var(--rule-strong); border-radius: 8px; cursor: pointer; display: flex;
  justify-content: space-between;
}
.char-list li.on { border-color: var(--accent); background: rgba(224, 170, 72, 0.08); }
.char-list li span { color: var(--faint); font-size: 12px; }
.motd { white-space: pre-line; margin: 0; }

/* ---------- juego ---------- */
#screen-game {
  position: fixed; inset: 0; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.game {
  height: 100%; display: grid; grid-template-columns: 1fr var(--side-w); grid-template-rows: 1fr var(--hot-h) var(--chat-h);
  grid-template-areas: "view side" "hot side" "chat side"; position: relative;
}
.view { grid-area: view; position: relative; background: #000; min-height: 0; min-width: 0; }
#map { width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }
#map.crosshair { cursor: crosshair; }
.side {
  grid-area: side; background: var(--bg-raise); border-left: 1px solid var(--rule); padding: 8px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px; min-height: 0;
}
.side > * { flex-shrink: 0; }   /* con poco alto, el panel hace scroll en vez de aplastar barras y avisos */
.chat { grid-area: chat; display: flex; flex-direction: column; border-top: 1px solid var(--rule); background: var(--bg); min-height: 0; }

.bars { display: flex; flex-direction: column; gap: 4px; }
.bar { position: relative; height: 18px; background: #000; border: 1px solid var(--rule-strong); border-radius: 4px; overflow: hidden; }
.bar > div { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.2s; }
.bar span { position: relative; display: block; text-align: center; font: 600 11.5px/16px var(--mono); text-shadow: 0 1px 2px #000; }
.bar.hp > div { background: var(--hp); }
.bar.mp > div { background: var(--mp); }
.bar.xp { height: 12px; }
.bar.xp > div { background: var(--good); }
.bar.xp span { font-size: 10px; line-height: 10px; }
.stats { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 8px; color: var(--muted); }
.stats b { color: var(--faint); font-weight: 600; }
.stats span span { color: var(--fg); font-family: var(--mono); }
.icons { display: flex; gap: 4px; flex-wrap: wrap; min-height: 0; }
.icons span { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--rule-strong); }

.tabs { display: flex; gap: 4px; }
.tabs button { flex: 1; padding: 5px 4px; font-size: 12.5px; }
.tab-body { display: flex; flex-direction: column; gap: 8px; min-height: 0; }

.equip {
  display: grid; grid-template-columns: repeat(3, 40px); gap: 4px; justify-content: center;
  grid-template-areas: "s2 s1 s3" "s6 s4 s5" "s9 s7 s10" ". s8 .";
}
.slot {
  width: 40px; height: 40px; background: #0a0a09; border: 1px solid var(--rule-strong); border-radius: 4px; position: relative;
  display: flex; align-items: center; justify-content: center; cursor: pointer; user-select: none; touch-action: none;
}
.slot canvas { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.slot .count { position: absolute; right: 2px; bottom: 0; font: 700 10px var(--mono); text-shadow: 0 0 2px #000, 0 0 2px #000; pointer-events: none; }
.slot .ph { position: absolute; font-size: 9px; color: var(--faint); pointer-events: none; text-align: center; line-height: 1.05; }
.slot.drop { border-color: var(--accent); }
.modes { display: flex; gap: 4px; justify-content: center; }
.modes button { padding: 4px 9px; }

.containers { display: flex; flex-direction: column; gap: 6px; }
.cont { border: 1px solid var(--rule-strong); border-radius: 6px; background: var(--bg); }
.cont-head { display: flex; align-items: center; gap: 4px; padding: 3px 6px; border-bottom: 1px solid var(--rule); font-size: 12px; }
.cont-head .t { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: capitalize; }
.cont-head button { padding: 0 6px; font-size: 11px; line-height: 18px; }
.cont-body { display: grid; grid-template-columns: repeat(auto-fill, 40px); gap: 3px; padding: 5px; justify-content: start; }

.battle { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.battle li { display: flex; flex-direction: column; gap: 2px; padding: 4px 6px; border: 1px solid var(--rule); border-radius: 5px; cursor: pointer; font-size: 12.5px; }
.battle li.target { border-color: #ff3b3b; }
.battle li.follow { border-color: #3bff5e; }
.battle li .hb { height: 4px; background: #000; border-radius: 2px; overflow: hidden; }
.battle li .hb div { height: 100%; }
.battle .empty { color: var(--faint); border: none; cursor: default; }
.skills { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 12.5px; }
.skills span:nth-child(even) { font-family: var(--mono); text-align: right; }
.grid-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.grid-btns button { font-size: 12.5px; padding: 6px; }

.chat-tabs { display: flex; gap: 2px; padding: 3px 6px 0; overflow-x: auto; flex: none; }
.chat-tabs button { padding: 2px 10px; font-size: 12px; border-radius: 6px 6px 0 0; border-bottom: none; white-space: nowrap; }
.chat-tabs button.unread { color: var(--accent); }
.chat-tabs button .x { margin-left: 6px; color: var(--faint); }
.chat-log { flex: 1; overflow-y: auto; padding: 4px 8px; font: 12.5px/1.35 var(--mono); border-top: 1px solid var(--rule); min-height: 0; }
.chat-log div { white-space: pre-wrap; word-break: break-word; }
.chat-log .time { color: var(--faint); }
.chat-input { display: flex; gap: 4px; padding: 4px 6px 6px; flex: none; }
.chat-input input { flex: 1; min-width: 0; padding: 6px 8px; }
.chat-input select { padding: 6px 4px; }
.chat-input button { padding: 6px 10px; }

.hotbar {
  grid-area: hot; display: flex; gap: 4px; padding: 3px 6px; overflow-x: auto; align-items: center;
  background: var(--bg); border-top: 1px solid var(--rule); scrollbar-width: none;
}
.hotbar::-webkit-scrollbar { display: none; }
.hk {
  flex: none; width: 40px; height: 40px; position: relative; padding: 0; border-radius: 6px; background: #0a0a09;
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.hk.empty { border-style: dashed; opacity: 0.55; }
.hk canvas { width: 32px; height: 32px; image-rendering: pixelated; pointer-events: none; }
.hk .k { position: absolute; left: 2px; top: 0; font: 700 9px var(--mono); color: var(--faint); pointer-events: none; }
.hk .tx { font: 700 9.5px/1.05 var(--sans); color: var(--fg); padding: 8px 2px 0; word-break: break-all; pointer-events: none; }
.hk.flash { border-color: var(--accent); }

.pad { display: none; }
.joystick {
  width: 120px; height: 120px; border-radius: 50%; position: relative; touch-action: none; flex: none;
  background: rgba(30, 30, 28, 0.55); border: 2px solid rgba(233, 230, 223, 0.18);
}
.joystick .knob {
  position: absolute; width: 46%; height: 46%; left: 27%; top: 27%; border-radius: 50%; pointer-events: none;
  background: radial-gradient(circle at 35% 35%, #969793, #353633); border: 2px solid #a1a39c;
}
.joystick.active { border-color: rgba(224, 170, 72, 0.6); }
.actions { display: flex; gap: 10px; }
.actions button {
  width: 52px; height: 52px; border-radius: 50%; padding: 0; font-size: 22px; touch-action: manipulation;
  background: rgba(20, 20, 18, 0.8); border: 2px solid rgba(233, 230, 223, 0.35); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.5);
}
.usewith {
  position: absolute; top: 8px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.75);
  padding: 4px 12px; border-radius: 6px; border: 1px solid var(--accent); font-size: 13px; pointer-events: none;
}

.menu {
  position: fixed; z-index: 50; min-width: 170px; background: var(--bg-raise); border: 1px solid var(--rule-strong);
  border-radius: 8px; padding: 4px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.menu button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 7px 10px; border-radius: 5px; }
.menu button:hover { background: var(--bg-2); color: var(--accent); }
.menu hr { border: none; border-top: 1px solid var(--rule); margin: 3px 0; }
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-card {
  width: min(460px, 100%); max-height: 90vh; overflow: auto; background: var(--bg-raise); border: 1px solid var(--rule-strong);
  border-radius: 12px; padding: 18px; display: flex; flex-direction: column; gap: 10px;
}
.modal-card h3 { margin: 0; font-size: 17px; }
.modal-card textarea { width: 100%; min-height: 200px; background: var(--bg); color: var(--fg); border: 1px solid var(--rule-strong); border-radius: 6px; padding: 8px; font: 13px/1.4 var(--mono); resize: vertical; }
.modal-card .row { margin-top: 4px; }
.hk-row { display: grid; grid-template-columns: 38px 1fr auto; gap: 6px; align-items: center; }
.hk-row b { font-family: var(--mono); color: var(--accent); }
.hk-row input { padding: 5px 8px; }
.hk-row label { font-size: 12px; color: var(--muted); display: flex; gap: 4px; align-items: center; white-space: nowrap; }
.help-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.outfit-prev { display: flex; justify-content: center; }
.outfit-prev canvas { width: 128px; height: 128px; image-rendering: pixelated; background: #000; border-radius: 8px; }
.palette { display: grid; grid-template-columns: repeat(19, 1fr); gap: 2px; }
.palette i { aspect-ratio: 1; border-radius: 2px; cursor: pointer; border: 1px solid transparent; }
.palette i.on { border-color: #fff; }
.drag-ghost { position: fixed; z-index: 70; pointer-events: none; transform: translate(-50%, -50%); opacity: 0.85; }
.drag-ghost canvas { width: 40px; height: 40px; image-rendering: pixelated; }

/* ---------- celular y tablet (body.mobile / body.portrait los pone main.js; ?mobile=1 lo fuerza) ---------- */
body.mobile input, body.mobile select, body.mobile textarea { font-size: 16px; }   /* sin zoom de iOS al escribir */
body.mobile .menu button { padding: 12px 14px; font-size: 15px; }
body.mobile .tabs button, body.mobile .grid-btns button { min-height: 40px; }
body.mobile .chat-tabs button { padding: 6px 12px; }
body.mobile .cont-head button { padding: 4px 10px; line-height: 20px; }
body.mobile .hk { width: 44px; height: 44px; }

/* horizontal: mapa grande, chat flotante con 💬 */
body.mobile:not(.portrait) { --side-w: 236px; --hot-h: 50px; }
body.mobile:not(.portrait) .game { grid-template-rows: 1fr var(--hot-h); grid-template-areas: "view side" "hot side"; }
body.mobile:not(.portrait) .pad {
  display: block; position: absolute; left: 0; top: 0; right: var(--side-w); bottom: var(--hot-h); pointer-events: none; z-index: 5;
}
body.mobile:not(.portrait) .joystick { position: absolute; left: 12px; bottom: 12px; pointer-events: auto; }
body.mobile:not(.portrait) .actions { position: absolute; right: 12px; bottom: 12px; flex-direction: column; pointer-events: auto; }
body.mobile:not(.portrait) .chat {
  display: none; position: absolute; left: 0; right: var(--side-w); bottom: var(--hot-h); height: 55%; z-index: 20;
  background: rgba(13, 13, 12, 0.94); border-top: 1px solid var(--rule-strong);
}
body.mobile.chat-open:not(.portrait) .chat { display: flex; }
body.mobile:not(.portrait) .equip { grid-template-columns: repeat(3, 38px); }
body.mobile:not(.portrait) .slot { width: 38px; height: 38px; }

/* vertical: mapa arriba, teclas, joystick a la izquierda del panel, chat abajo */
body.mobile.portrait { --chat-h: 128px; --hot-h: 52px; }
body.mobile.portrait .game {
  grid-template-columns: 136px minmax(0, 1fr); grid-template-rows: auto var(--hot-h) minmax(0, 1fr) var(--chat-h);
  grid-template-areas: "view view" "hot hot" "pad side" "chat chat";
}
body.mobile.portrait .view { aspect-ratio: 15 / 11; width: 100%; }
body.mobile.portrait .side { border-left: none; border-top: 1px solid var(--rule); }
body.mobile.portrait .pad {
  grid-area: pad; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  border-top: 1px solid var(--rule); background: var(--bg); min-height: 0; overflow: hidden;
}
body.mobile.portrait .actions button { width: 40px; height: 40px; font-size: 18px; }
body.mobile.portrait #act-chat { display: none; }
body.mobile.chat-open:not(.portrait) .pad { z-index: 25; }
body.mobile.chat-open:not(.portrait) .joystick { display: none; }
body.mobile.chat-open:not(.portrait) .actions { bottom: auto; top: 10px; flex-direction: row; }

/* entrada: jugar sin cuenta, recordar, cuenta nueva */
.big-btn { padding: 12px 16px; font-size: 16px; }
.center-text { text-align: center; margin: -4px 0 0; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--faint); font-size: 12.5px; margin-top: 4px; }
.sep::before, .sep::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
.stack-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.card label.check, .stack-form label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; }
.check input { width: 16px; height: 16px; }
.hp-field { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.row.left { justify-content: flex-start; }
.link-btn { background: none; border: none; color: var(--muted); padding: 4px; text-decoration: underline; align-self: center; }
.voc-pick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.voc-pick button { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 2px; font-size: 12px; }
.voc-pick canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.acc-box { display: grid; gap: 8px; background: var(--bg); border: 1px solid var(--rule-strong); border-radius: 8px; padding: 12px; }
.acc-box div { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.acc-box b { font-size: 20px; color: var(--accent); letter-spacing: 0.04em; user-select: all; -webkit-user-select: all; }
.mono { font-family: var(--mono); }
.reconnect {
  position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); background: rgba(0, 0, 0, 0.82);
  border: 1px solid var(--accent); border-radius: 8px; padding: 10px 16px; font-size: 14px; z-index: 30; text-align: center;
}
.name-row { display: flex; gap: 6px; }
.name-row input { flex: 1; min-width: 0; font-size: 16px; }
.name-row button { padding: 6px 12px; font-size: 18px; }
