:root {
  --bg: #0d0b09;
  --panel: #19140f;
  --border: #786032;
  --accent: #e6c88c;
  --text: #d6d0c4;
  --dim: #8a8478;
  --mono: "DejaVu Sans Mono", "Menlo", "Consolas", "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

#app {
  display: grid;
  grid-template: "top top" auto "left side" 1fr / 1fr 380px;
  height: 100vh;
  height: 100dvh;
}
#top { grid-area: top; }
#left {
  grid-area: left;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  min-width: 0;
}
#side {
  grid-area: side;
  min-height: 0;
  overflow-y: auto;
  background: #0a0806;
  border-left: 1px solid var(--border);
}

#top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 4px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#top .title { color: var(--accent); font-weight: 700; letter-spacing: 0.05em; }
.conn { font-size: 0.8rem; color: var(--dim); }
.conn.on { color: #7fc77f; }
.conn.off { color: #e07a5f; }

.toggles { display: none; gap: 6px; }
.toggle { padding: 1px 10px; font-size: 0.85rem; }
.toggle.active { background: #4a3a22; }

/* ---- chat ---- */
#chat {
  display: flex;
  flex-direction: column;
  height: 170px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
#chat-tabs { display: flex; gap: 2px; padding: 4px 8px 0; }
#chat-tabs button {
  border-radius: 4px 4px 0 0;
  border-bottom: none;
  padding: 2px 12px;
  font-size: 0.85rem;
  background: #231b12;
}
#chat-tabs button.active { background: #46341e; font-weight: 700; }
#chat-tabs button.unread { font-weight: 700; color: #ffe08a; }
#chat-logs { flex: 1; min-height: 0; position: relative; }
.chat-log {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  padding: 4px 10px;
  background: #000;
  font: 13px/1.35 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.chat-log[hidden] { display: none; }
.chat-log .time { color: var(--dim); }

/* ---- map ---- */
#side h2 { display: flex; justify-content: space-between; align-items: center; z-index: 1; }
.zoom { display: inline-flex; gap: 4px; }
.zoom button { padding: 0 9px; line-height: 1.3; }
#map-box { position: relative; border-bottom: 1px solid var(--border); }
#map { display: block; width: 100%; height: 300px; background: #000; cursor: crosshair; }
#map-info {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 2px 8px;
  font-size: 0.8rem;
  color: #f0e6d0;
  background: #000a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#map-info:empty { display: none; }

/* ---- objects ---- */
#side h2 {
  margin: 0;
  padding: 4px 10px;
  font-size: 0.9rem;
  color: var(--accent);
  background: #281e14;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
}
.items { padding: 4px 6px 10px; font: 13px/1.45 var(--mono); }
.item { display: flex; gap: 6px; padding: 1px 4px; border-radius: 3px; }
.item.click { cursor: pointer; }
.item.click:hover { background: #2a2117; }
.item .slot { color: #3aa6b9; flex: 0 0 9.5em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .name { color: #eee; min-width: 0; }
.item .count { color: var(--dim); }
.item .tags { color: var(--dim); }
.item .worn { color: #e0b030; }
.item .worn.bad { color: #e05a4a; }
.item .open { color: var(--dim); }
.item .unseen { color: var(--dim); }
.contents { margin-left: 2.2em; border-left: 1px solid #3a2e1e; padding-left: 4px; }
.contents .note { color: var(--dim); padding: 1px 4px; }
.items .empty { color: var(--dim); padding: 2px 4px; }

#menu {
  position: fixed;
  z-index: 10;
  min-width: 150px;
  background: #1f1810;
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 16px #000a;
  padding: 3px 0;
}
#menu .head { padding: 3px 12px 4px; color: var(--dim); font-size: 0.8rem; border-bottom: 1px solid #3a2e1e; }
#menu button {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-radius: 0;
  background: none;
  color: var(--text);
  padding: 4px 12px;
}
#menu button:hover, #menu button:focus { background: #3a2c1a; color: #fff; outline: none; }

#main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#output {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  font: 14px/1.35 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#output .line { min-height: 1.35em; }
#output .cmd { color: var(--dim); }

#closed {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 12px;
  background: #3a1d17;
  color: #f0c0b0;
}
#closed[hidden] { display: none; }

button {
  font: inherit;
  color: var(--accent);
  background: #2a2117;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 12px;
  cursor: pointer;
}

#input-form { padding: 6px 12px 8px; border-top: 1px solid #2a2218; }
#input {
  width: 100%;
  font: 15px var(--mono);
  color: var(--text);
  background: #120f0b;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  outline: none;
}
#input:focus { border-color: var(--accent); }

#bars {
  padding: 6px 12px 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}
#bars .row { display: flex; gap: 8px; }
#bars .row + .row { margin-top: 5px; }

.gauge {
  position: relative;
  flex: 1;
  height: 22px;
  min-width: 0;
  background: #262626;
  border: 1px solid #111;
  border-radius: 3px;
  overflow: hidden;
}
.gauge .fill { position: absolute; inset: 0 auto 0 0; width: 0; transition: width 0.2s; }
.gauge .label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 12px var(--mono);
  color: #fff;
  text-shadow: 0 1px 2px #000;
  white-space: nowrap;
  overflow: hidden;
}
.gauge.hp .fill { background: linear-gradient(#f05050, #b01010); }
.gauge.mana .fill { background: linear-gradient(#5080f0, #1030b0); }
.gauge.mv .fill { background: linear-gradient(#50d050, #108010); }
.gauge.enemy .fill { background: linear-gradient(#f0a040, #b06010); }
.gauge.tank .fill { background: linear-gradient(#c070e0, #702090); }
.gauge.empty .label { color: var(--dim); font-weight: 400; }

.statusline {
  flex: 1.2;
  min-width: 0;
  display: flex;
  align-items: center;
  font-size: 0.85rem;
  color: #d8c090;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ANSI colours (the game's &-codes end up as these) */
.fg-0 { color: #4a4a4a; } .fg-1 { color: #c0392b; } .fg-2 { color: #3fa34d; } .fg-3 { color: #c9a227; }
.fg-4 { color: #4b6fd6; } .fg-5 { color: #b44fb4; } .fg-6 { color: #3aa6b9; } .fg-7 { color: #c8c8c8; }
.fg-8 { color: #7a7a7a; } .fg-9 { color: #ff5c4d; } .fg-10 { color: #6ee36e; } .fg-11 { color: #ffe066; }
.fg-12 { color: #7a9cff; } .fg-13 { color: #ff7aff; } .fg-14 { color: #66e6f5; } .fg-15 { color: #ffffff; }
.bg-0 { background: #000; } .bg-1 { background: #7a1d14; } .bg-2 { background: #1e6b28; } .bg-3 { background: #7a6214; }
.bg-4 { background: #1d3a8a; } .bg-5 { background: #6b256b; } .bg-6 { background: #1a6672; } .bg-7 { background: #8a8a8a; }
.ul { text-decoration: underline; }

@media (max-width: 900px) {
  #app { grid-template: "top" auto "left" 1fr / 1fr; }
  .toggles { display: inline-flex; }
  #chat { display: none; }
  #chat.open { display: flex; height: 38vh; }
  #side {
    display: none;
    position: fixed;
    z-index: 5;
    top: 33px;
    right: 0;
    bottom: 0;
    width: min(380px, 92vw);
    box-shadow: -4px 0 16px #000a;
  }
  #side.open { display: block; }
}

@media (max-width: 700px) {
  #output { font-size: 12.5px; padding: 6px 8px; }
  #bars .row { flex-wrap: wrap; }
  .statusline { flex-basis: 100%; }
}
