:root {
  --bg: #050505; --panel: #0a0a0a; --border: #4a4538;
  --text: #b8b09c; --yellow: #e6b800; --blood: #a81c1c;
  --sanity: #8a2be2; --heal: #2e8b57; --dim: #333028;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background-color: var(--bg); color: var(--text);
  font-family: 'Courier New', Courier, monospace; font-size: 14px;
  line-height: 1.3; overflow: hidden; height: 100vh;
  display: flex; flex-direction: column; user-select: none;
}
@keyframes madnessShake {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-1px, 1px); filter: hue-rotate(15deg); }
  50% { transform: translate(1px, -1px); }
  75% { transform: translate(-1px, -1px); filter: hue-rotate(-15deg); }
  100% { transform: translate(0, 0); }
}
.insane-ui { animation: madnessShake 0.4s infinite; border-color: var(--sanity) !important; }

#lobby-screen, #end-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; padding: 15px; text-align: center;
}
#end-screen { display: none; overflow-y: auto; }
.ascii-title {
  color: var(--yellow); font-weight: bold; white-space: pre;
  font-size: 12px; margin-bottom: 12px; text-shadow: 0 0 8px rgba(230, 184, 0, 0.4);
}
.lobby-box {
  border: 1px solid var(--yellow); background: var(--panel);
  padding: 18px; width: 100%; max-width: 720px; max-height: 85vh; overflow-y: auto;
}
.form-group { margin-bottom: 10px; text-align: left; }
label { display: block; color: var(--yellow); margin-bottom: 4px; font-weight: bold; font-size: 12px; }
input, select, button {
  background: #111; color: var(--text); border: 1px solid var(--border);
  padding: 7px; font-family: inherit; font-size: 13px; width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--yellow); }
button {
  cursor: pointer; font-weight: bold; color: var(--yellow);
  border-color: var(--yellow); transition: 0.15s; margin-top: 5px;
}
button:hover:not(:disabled) { background: var(--yellow); color: #000; }
.class-desc {
  font-size: 12px; color: #8c8573; margin-top: 5px; padding: 7px;
  border-left: 2px solid var(--yellow); background: #0d0d0d; text-align: left;
}

#game-screen {
  display: none; flex-direction: column; height: 100vh; padding: 6px; gap: 6px;
}
#party-panel {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; height: 136px;
}
.player-card {
  border: 1px solid var(--border); background: var(--panel); padding: 6px 8px;
  display: flex; flex-direction: column; justify-content: space-between; font-size: 12px;
}
.player-card.active-turn { border: 2px solid var(--yellow); box-shadow: 0 0 10px rgba(230,184,0,0.25); }
.player-card.dead { border-color: var(--blood); opacity: 0.7; }
.bar-hp { color: var(--blood); font-weight: bold; }
.bar-mp { color: #4682b4; font-weight: bold; }
.bar-san { color: var(--sanity); font-weight: bold; }

#main-area { display: flex; flex: 1; gap: 6px; min-height: 0; }
#map-container {
  flex: 65; border: 1px solid var(--border); background: #030303;
  display: flex; flex-direction: column; position: relative; overflow: hidden;
}
#act-header {
  background: #12100c; color: var(--yellow); padding: 5px 10px;
  border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; font-weight: bold; font-size: 13px;
}
#ascii-map {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 17px; line-height: 1.1; letter-spacing: 3px; overflow: hidden; padding: 10px;
}
#side-panel {
  flex: 35; border: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column;
}
#event-log {
  flex: 1; padding: 8px; overflow-y: auto; font-size: 12px; border-bottom: 1px solid var(--border);
}
.log-entry { margin-bottom: 6px; }
.log-yellow { color: var(--yellow); }
.log-blood { color: #d93838; }
.log-sanity { color: #b366ff; font-style: italic; }
.log-lore { color: #e0c068; border-left: 2px solid #e6b800; padding-left: 6px; font-style: italic; }
.log-codex { color: #5cd6d6; border-left: 2px solid #5cd6d6; padding-left: 6px; }
.log-system { color: #7a7464; }
#chat-box { display: flex; }
#chat-input { border: none; border-top: 1px solid var(--border); flex: 1; }
#chat-send { width: 70px; margin: 0; border: none; border-left: 1px solid var(--border); }

#control-panel {
  height: 92px; border: 1px solid var(--border); background: var(--panel);
  padding: 6px 8px; display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.action-buttons { display: flex; gap: 4px; flex-wrap: wrap; }
.action-buttons button { width: auto; padding: 5px 9px; margin: 0; font-size: 12px; }
.legend { font-size: 11px; color: #8c8573; max-width: 360px; }

/* Modal del Manual */
.modal-overlay {
  display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.85); align-items: center; justify-content: center; z-index: 999;
}
.modal-box {
  background: #0a0908; border: 2px solid var(--yellow); padding: 18px;
  width: 90%; max-width: 760px; max-height: 85vh; display: flex; flex-direction: column;
}
.manual-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.manual-tabs button { margin: 0; font-size: 12px; padding: 6px; }
.manual-content {
  flex: 1; overflow-y: auto; text-align: left; font-size: 13px; white-space: pre-wrap;
  line-height: 1.45; padding: 10px; background: #050505; border: 1px solid var(--border);
}

