:root {
  --bg: #15181c; --panel: #1c2026; --line: #2a3038; --text: #d7dce2; --muted: #8a94a0; --accent: #4ea1ff;
  --ok: #3fbf6f; --warn: #e3a92b; --bad: #e05252; --chat: #9ad0ff;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); font: 13px/1.4 system-ui, sans-serif; }
body { display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 16px; padding: 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); display: inline-block; }
.dot.on { background: var(--ok); }
.status { display: flex; gap: 14px; color: var(--muted); flex-wrap: wrap; }
.status b { color: var(--text); font-weight: 600; }
.spacer { flex: 1; }
.admin { color: var(--muted); }
input, button { background: #10131a; color: var(--text); border: 1px solid var(--line); border-radius: 4px; padding: 3px 6px; font: inherit; }
button { cursor: pointer; background: #262c35; }
button:hover { background: #313844; }
button.danger { background: #6a2424; }
button.danger:hover { background: #8a2c2c; }
button.small, label.small { font-size: 11px; padding: 1px 5px; color: var(--muted); }

main { flex: 1; display: grid; grid-template-columns: 300px 1fr 520px; min-height: 0; }
#left, #right { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
#center { position: relative; min-height: 0; }
.panel-head { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid var(--line); font-weight: 600; }
.panel-head input { margin-left: auto; }
.list { overflow: auto; flex: 1; }
.player { padding: 6px 10px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; }
.player:hover { background: #242a33; }
.player.active { background: #273344; }
.player .name { font-weight: 600; }
.player .meta { color: var(--muted); font-size: 11px; grid-column: 1 / span 2; display: flex; gap: 10px; flex-wrap: wrap; }
.player .hp { font-variant-numeric: tabular-nums; }
.hpbar { height: 3px; background: #2a3038; grid-column: 1 / span 2; }
.hpbar i { display: block; height: 100%; background: var(--ok); }
.team { color: var(--accent); }

#map { position: absolute; inset: 0; background: #0b1f2e; }
.layers { position: absolute; top: 8px; left: 50px; z-index: 500; background: rgba(20,24,30,.85); padding: 4px 8px; border-radius: 4px; display: flex; gap: 10px; align-items: center; }
.layers label { color: var(--muted); display: flex; gap: 3px; align-items: center; }
.mapinfo { color: var(--muted); font-size: 11px; margin-left: 8px; }
.leaflet-container { font: inherit; }
.leaflet-tooltip { background: rgba(20,24,30,.9); color: var(--text); border: 1px solid var(--line); }
.plabel { background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 3px; padding: 1px 4px; font-size: 11px; font-weight: 600; white-space: nowrap; pointer-events: none; }
.plabel:before { display: none; }
.gridlabel { color: rgba(255,255,255,.55); font-size: 10px; white-space: nowrap; }
.evlabel { color: #fff; font-size: 10px; text-shadow: 0 0 3px #000, 0 0 3px #000; white-space: nowrap; }

.shopicon { background: rgba(20,24,30,.85); border: 1px solid #ffd166; border-radius: 5px; padding: 1px; }
.shopicon img { width: 22px; height: 22px; display: block; }
.shopicon.closed { border-color: #555; filter: grayscale(1); opacity: .75; }
.leaflet-popup-content-wrapper { background: #1c2026; color: var(--text); border: 1px solid var(--line); border-radius: 6px; }
.leaflet-popup-tip { background: #1c2026; }
.leaflet-popup-content { margin: 10px 12px; font: 12px/1.4 system-ui, sans-serif; }
.shop h4 { margin: 0 0 2px; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.shop h4 img { width: 22px; height: 22px; }
.shop .owner { color: var(--muted); margin-bottom: 8px; }
.shop .order { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.shop .order.out { opacity: .45; }
.shop .slot { position: relative; width: 44px; height: 44px; background: #2b313a; border-radius: 4px; flex: none; display: block; }
.shop .slot img { width: 40px; height: 40px; margin: 2px; display: block; }
.shop .slot b { position: absolute; right: 3px; bottom: 1px; font-size: 12px; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000; }
.shop .slot.bp { background: #1f3a5a; box-shadow: inset 0 0 0 2px #3b7ddd; }
.shop .for { color: var(--muted); font-size: 11px; }
.shop .names { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.25; }
.shop .names .muted { color: var(--muted); font-size: 11px; }
.shop .stock { white-space: nowrap; color: var(--muted); font-size: 11px; }
.shop .out { color: var(--bad); }
.detail { position: absolute; top: 8px; right: 8px; bottom: 8px; width: 360px; z-index: 600; background: rgba(28,32,38,.97); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow: auto; }
.detail h2 { margin: 0 0 2px; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.detail .sid { color: var(--muted); font-size: 11px; user-select: all; }
.detail .close { margin-left: auto; font-size: 16px; line-height: 1; padding: 2px 8px; }
.detail .closebar { display: none; }
.detail dl { display: grid; grid-template-columns: 90px 1fr; gap: 3px 8px; margin: 8px 0; }
.detail dt { color: var(--muted); }
.detail h3 { font-size: 12px; color: var(--muted); text-transform: uppercase; margin: 10px 0 4px; letter-spacing: .04em; }
.detail h3.collapsible { cursor: pointer; user-select: none; display: flex; align-items: center; gap: 5px; }
.detail h3.collapsible::before { content: "▾"; font-size: 9px; transition: transform .12s; }
.detail h3.collapsible.collapsed::before { transform: rotate(-90deg); }
.detail h3.collapsible:hover { color: var(--text); }
.detail h3.collapsible.collapsed + * { display: none; }
.detail .lines { font: 11px/1.4 ui-monospace, monospace; white-space: pre-wrap; word-break: break-word; background: #10131a; padding: 6px; border-radius: 4px; max-height: 160px; overflow: auto; }
.detail .actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.detail .homes a { cursor: pointer; color: var(--accent); margin-right: 8px; }
.invblock { margin: 4px 0 8px; }
.invlabel { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.invrow { display: grid; gap: 3px; }
.islot { position: relative; aspect-ratio: 1; background: #2b313a; border-radius: 4px; overflow: hidden; }
.islot img { width: 100%; height: 100%; object-fit: contain; display: block; }
.islot b { position: absolute; right: 2px; bottom: 1px; font-size: 11px; color: #fff; text-shadow: 0 0 3px #000, 0 0 3px #000; }
.islot .cond { position: absolute; left: 0; bottom: 0; height: 2px; }
.islot u { position: absolute; left: 2px; top: 2px; width: 5px; height: 5px; border-radius: 50%; background: #4ea1ff; }
.hidden { display: none !important; }
.tag { background: #2a3443; border-radius: 3px; padding: 0 5px; font-size: 11px; margin-right: 4px; display: inline-block; }

.console { flex: 1; overflow: auto; font: 12px/1.35 ui-monospace, monospace; padding: 6px 8px; white-space: pre-wrap; word-break: break-word; }
.console .line { padding: 1px 0; border-bottom: 1px solid #1f242b; }
.console .ts { color: var(--muted); margin-right: 6px; }
.console .Command { color: var(--accent); font-weight: 600; }
.console .Chat, .console .chat { color: var(--chat); }
.console .Error { color: var(--bad); }
.console .Warning { color: var(--warn); }
.console .Event { color: var(--ok); }
.console .reply { color: #c9d4a3; }
.tabs { display: flex; gap: 2px; }
.tab { background: transparent; border: 0; color: var(--muted); padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.tab.active { background: #2a3443; color: var(--text); }
.chat { flex: 1; overflow: auto; padding: 6px 10px; }
.chat .line { padding: 4px 0; border-bottom: 1px solid #1f242b; display: flex; gap: 8px; align-items: flex-start; }
.chat .avatar { width: 32px; height: 32px; border-radius: 3px; background: #2a3038; flex: none; margin-top: 2px; }
.chat .body { flex: 1; min-width: 0; line-height: 1.35; }
.chat .ts { color: var(--muted); font-size: 11px; margin-right: 6px; font-family: ui-monospace, monospace; }
.chat .title { margin-right: 4px; font-weight: 700; }
.chat .name { font-weight: 700; cursor: pointer; }
.chat .team { color: var(--muted); font-size: 11px; margin-left: 4px; }
.chat .event { color: var(--muted); font-style: italic; }
.chat .msg { white-space: pre-wrap; word-break: break-word; }
.chatas { color: var(--muted); align-self: center; white-space: nowrap; }
.badge { background: var(--accent); color: #fff; border-radius: 8px; padding: 0 5px; font-size: 10px; margin-left: 3px; }
#eventsPane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.evfilters { display: flex; flex-wrap: wrap; gap: 6px 10px; padding: 4px 10px; border-bottom: 1px solid var(--line); font-size: 11px; color: var(--muted); }
.evfilters label { display: flex; align-items: center; gap: 3px; }
.evfilters i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.events { flex: 1; overflow: auto; padding: 4px 10px; font-size: 12px; }
.events .ev { display: flex; gap: 8px; align-items: baseline; padding: 3px 0; border-bottom: 1px solid #1f242b; }
.events .ev i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; position: relative; top: -1px; }
.events .ts { color: var(--muted); font-family: ui-monospace, monospace; font-size: 11px; flex: none; }
.events .txt { flex: 1; }
.events .grid { color: var(--accent); cursor: pointer; flex: none; font-variant-numeric: tabular-nums; }
.quick { display: flex; gap: 4px; flex-wrap: wrap; padding: 4px 8px; border-top: 1px solid var(--line); }
.quick button { font-size: 11px; padding: 2px 6px; }
.cmdform { display: flex; gap: 6px; padding: 6px 8px; border-top: 1px solid var(--line); }
.cmdform input { flex: 1; font-family: ui-monospace, monospace; }

.ltab { background: transparent; border: 0; color: var(--muted); padding: 2px 8px; border-radius: 4px; font-weight: 600; }
.ltab.active { background: #2a3443; color: var(--text); }
.flag { margin-right: 4px; font-size: 14px; }
.sessions { padding: 6px 10px; font-size: 12px; }
.sessions .axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; margin: 0 0 4px 96px; }
.sessions .row { display: grid; grid-template-columns: 90px 1fr; gap: 6px; align-items: center; padding: 3px 0; border-bottom: 1px solid var(--line); }
.sessions .row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.sessions .row.online .n { color: var(--ok); }
.sessions .track { position: relative; height: 12px; background: #10131a; border-radius: 2px; }
.sessions .bar { position: absolute; top: 0; height: 100%; background: #4ea1ff; border-radius: 2px; min-width: 2px; }
.sessions .bar.open { background: var(--ok); }
.sessions .bar.unknown { background: #4ea1ff80; }
.sleepicon { background: rgba(60,66,76,.9); color: #cfd6de; border: 1px solid #000; border-radius: 50%; width: 12px !important; height: 12px !important; line-height: 11px; text-align: center; font-size: 9px; font-weight: 700; }
.tcpop h4, .whois h4 { margin: 0 0 4px; font-size: 13px; }
.tcpop .muted, .whois .muted, .muted { color: var(--muted); }
.tcpop .auth a { cursor: pointer; color: var(--accent); margin-right: 6px; }
.tcpop .upkeep { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tcpop .upkeep span { display: inline-flex; align-items: center; gap: 2px; background: #2b313a; border-radius: 3px; padding: 1px 4px; }
.tcpop .upkeep img { width: 16px; height: 16px; }
.whois .own { padding: 3px 0; border-top: 1px solid var(--line); }
.whois .own b { cursor: pointer; }
.whois ul { margin: 4px 0 0 14px; padding: 0; }
.modal .box.wide { width: 640px; }
.modal .muted { font-weight: 400; }
#quickTable { width: 100%; border-collapse: collapse; }
#quickTable td { padding: 2px; }
#quickTable input[type=text] { width: 100%; }
.me { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.me img { width: 24px; height: 24px; border-radius: 50%; }
.me b { color: var(--text); }
.me a { color: var(--muted); }
.readonly-note { display: none; font-size: 11px; }
body.noconsole .needs-console { display: none !important; }
body.noconsole .readonly-note { display: block; }
body.noconsole .detail .actions { display: none; }
.console .by { color: var(--muted); font-weight: 400; margin-right: 4px; }
#mnav { display: none; }

/* phone: one column, bottom bar switches the view */
@media (max-width: 900px) {
  html, body { height: 100%; }
  body { padding-bottom: 52px; }
  header { gap: 8px 12px; padding: 6px 10px; flex-wrap: wrap; }
  .status { gap: 8px 12px; font-size: 12px; }
  main { grid-template-columns: 1fr; }
  #left, #center, #right { display: none; border: 0; }
  body[data-mview="map"] #center, body[data-mview="players"] #left,
  body[data-mview="console"] #right, body[data-mview="chat"] #right, body[data-mview="events"] #right { display: flex; }
  #center { display: none; }
  body[data-mview="map"] #center { display: block; }
  #mnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; height: 52px; background: var(--panel); border-top: 1px solid var(--line); z-index: 1500; padding-bottom: env(safe-area-inset-bottom); }
  #mnav button { flex: 1; background: transparent; border: 0; border-radius: 0; color: var(--muted); font-size: 13px; font-weight: 600; }
  #mnav button.active { color: var(--text); background: #2a3443; }
  .layers { left: 8px; right: 8px; top: auto; bottom: 8px; flex-wrap: wrap; gap: 6px 10px; font-size: 12px; }   /* below the map, clear of the zoom buttons */
  .mapinfo { display: none; }
  .detail { left: 8px; right: 8px; top: 8px; bottom: 8px; width: auto; padding-bottom: 56px; }
  .detail .close { font-size: 22px; padding: 6px 14px; }
  .detail .closebar { display: block; position: sticky; bottom: -10px; width: 100%; margin-top: 12px; padding: 12px; font-size: 15px; font-weight: 600; background: #2a3443; }
  .leaflet-popup-content { max-width: 80vw; }
  .modal .box, .modal .box.wide { width: 94vw; }
  .player { padding: 10px; }
  .tab, .ltab { padding: 6px 10px; }
  input, button { padding: 6px 8px; }
  .quick button { padding: 4px 8px; }
  .cmdform input { font-size: 16px; }   /* no zoom-on-focus on iOS */
  #chatText { font-size: 16px; }
  .sessions .row { grid-template-columns: 80px 1fr; }
}
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 2000; display: flex; align-items: center; justify-content: center; }
.modal .box { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 16px; width: 420px; display: flex; flex-direction: column; gap: 10px; }
.modal code { background: #10131a; padding: 2px 4px; border-radius: 3px; }
.modal .buttons { display: flex; gap: 8px; justify-content: flex-end; }
