/* The mod console: phone first (a tab bar at the bottom, clear of the home indicator), the map beside a sidebar on
   wide screens. System fonts only: the CSP allows nothing from elsewhere. Dark unless the device is in light mode. */
:root {
  --bg: #0e1620; --panel: #16212d; --panel2: #1d2b3a; --line: #2a3b4e; --text: #e8eef4; --muted: #94a6b8;
  --accent: #ffd640; --accent-text: #1b1400; --bad: #ff6b6e; --bad-bg: rgba(229,56,59,0.18); --mute: #8fc1ff; --admin: #e8b923;
  --tab-h: 58px; --top-h: 44px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #eef2f6; --panel: #ffffff; --panel2: #f3f6f9; --line: #d5dde6; --text: #13202d; --muted: #5a6b7c;
    --accent: #ffcc1a; --bad: #c62828; --bad-bg: rgba(198,40,40,0.1); --mute: #1d63b8; --admin: #9a7300;
    color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
button, input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.boot, .noscript { margin: 40vh auto 0; text-align: center; color: var(--muted); }
code { font: 13px ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---- buttons, fields */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 8px 14px; border: 1px solid var(--line);
  border-radius: 10px; background: var(--panel2); cursor: pointer; text-decoration: none; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 650; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--mute); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--bad); }
.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; color: var(--muted); }
input[type=text], input[type=password], input[type=search], select, input.copy, input.token-copy {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 16px; }
select { width: auto; }
.stack { display: grid; gap: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 14px; color: var(--muted); }
.error { color: var(--bad); margin: 6px 0 0; min-height: 0; }
.error:empty { display: none; }

/* ---- signing in */
.card.login { max-width: 420px; margin: max(24px, env(safe-area-inset-top)) auto 24px; padding: 24px 20px; display: grid; gap: 14px; }
.login h1 { margin: 0 0 4px; font-size: 26px; }
.login h1 .sub { display: block; font-size: 15px; font-weight: 500; color: var(--muted); }
.login .note { padding: 10px 12px; border-radius: 10px; background: var(--panel2); margin: 0; }
.fallback summary { cursor: pointer; color: var(--muted); padding: 6px 0; }
.fallback form { margin-top: 10px; }
.key code { font-size: 17px; letter-spacing: 1px; word-break: break-all; user-select: all; }

/* ---- the shell: a top bar, the panes, the tabs */
.shell { position: fixed; inset: 0; display: grid; grid-template-rows: calc(var(--top-h) + env(safe-area-inset-top)) 1fr calc(var(--tab-h) + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; gap: 10px; padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
  background: var(--panel); border-bottom: 1px solid var(--line); white-space: nowrap; overflow: hidden; }
.top .who { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.live-state { margin-left: auto; font-size: 13px; color: var(--muted); }
.live-state[data-s=live] { color: #39d47a; }
.live-state[data-s=retrying], .live-state[data-s=paused] { color: var(--accent); }
.panes { position: relative; min-height: 0; }
.pane { position: absolute; inset: 0; display: none; flex-direction: column; min-height: 0; padding: 0 max(0px, env(safe-area-inset-right)) 0 max(0px, env(safe-area-inset-left)); }
.pane.on { display: flex; }
.pane-head { display: flex; align-items: baseline; gap: 10px; padding: 12px 14px 4px; }
.pane-head h2 { margin: 0; font-size: 20px; }
.summary, .chat-state { color: var(--muted); font-size: 14px; }
.warn { color: var(--bad); }
.pane-tools { display: flex; gap: 10px; align-items: center; padding: 6px 14px 10px; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--panel); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { border: 0; background: none; display: grid; justify-items: center; align-content: center; gap: 1px; font-size: 12px; color: var(--muted); cursor: pointer; min-height: var(--tab-h); }
.tab-icon { font-size: 20px; line-height: 1.1; }
.tab.on { color: var(--text); font-weight: 650; }
.tab.on .tab-icon { filter: drop-shadow(0 0 6px rgba(255,214,64,0.6)); }

/* ---- players */
.rows { list-style: none; margin: 0; padding: 0 8px 12px; }
.rows .empty, .chatlines .empty { color: var(--muted); padding: 24px 10px; text-align: center; }
.row { display: flex; gap: 10px; width: 100%; text-align: left; padding: 10px 8px; border: 0; border-bottom: 1px solid var(--line); background: none; cursor: pointer; align-items: flex-start; }
.row:active, .row:hover { background: var(--panel2); }
.row .icon { font-size: 22px; width: 30px; text-align: center; flex: none; line-height: 1.2; }
.row .main { min-width: 0; flex: 1; display: grid; gap: 2px; }
.line1 { display: flex; gap: 8px; align-items: baseline; min-width: 0; }
.line1 .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line1 .user { color: var(--mute); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line1 .id { color: var(--muted); font-size: 12px; margin-left: auto; flex: none; }
.line2 { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.chip { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.chip.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }
.chip.mute { color: var(--mute); }
.chip.admin { color: var(--admin); }
.chip.old { color: var(--muted); }

/* ---- the player sheet (a bottom sheet on phones, a drawer on wide screens) */
.sheet-back { position: fixed; inset: 0; background: rgba(0,0,0,0); transition: background 0.18s; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-back.on { background: rgba(0,0,0,0.45); }
.sheet { width: 100%; max-height: calc(100% - 40px - env(safe-area-inset-top)); overflow-y: auto; background: var(--panel); border-radius: 16px 16px 0 0;
  padding: 0 16px calc(16px + env(safe-area-inset-bottom)); transform: translateY(30px); opacity: 0; transition: transform 0.18s, opacity 0.18s; overscroll-behavior: contain; }
.sheet-back.on .sheet { transform: none; opacity: 1; }
.sheet-head { position: sticky; top: 0; display: flex; align-items: center; padding: 12px 0 8px; background: var(--panel); z-index: 1; }
.sheet-head h2 { margin: 0; font-size: 15px; color: var(--muted); font-weight: 600; }
.x { margin-left: auto; width: 40px; height: 40px; border-radius: 20px; border: 0; background: var(--panel2); cursor: pointer; font-size: 16px; }
.who .big { display: flex; gap: 10px; align-items: center; font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
.who .user { color: var(--mute); }
.who .pid { color: var(--muted); font-size: 13px; margin-top: 2px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.block { border-top: 1px solid var(--line); padding: 10px 0; }
.block h3 { margin: 0 0 6px; font-size: 15px; }
.block h4 { margin: 12px 0 4px; font-size: 14px; color: var(--muted); }
.more .block { padding: 12px 14px; }
.kv { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; overflow-wrap: anywhere; }
.kv.log { gap: 6px; font-size: 14px; }
.addr { color: var(--muted); font-size: 14px; margin-top: 2px; }
.reveal { border: 1px dashed var(--line); background: none; border-radius: 6px; padding: 1px 8px; color: var(--muted); cursor: pointer; font-size: 13px; }
.stats { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; }
.stats dt { color: var(--muted); }
.stats dd { margin: 0; }
.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.person { padding: 10px; background: var(--panel2); border-radius: 12px; display: grid; gap: 6px; }
.person .line1 { flex-wrap: wrap; }
.row-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.ua { color: var(--muted); }
input.copy, input.token-copy { margin: 6px 0; font: 13px ui-monospace, Menlo, monospace; }

/* ---- chat */
.pane-chat .pane-tools .search { flex: 1; }
.chat-wrap { position: relative; flex: 1; min-height: 0; display: flex; }
.chat-scroll { flex: 1; display: flex; flex-direction: column; }
.chat-scroll > .older { margin-top: auto; }   /* (a short log sits at the bottom, by the newest line, like any chat) */
.older { text-align: center; padding: 10px; }
.chatlines { list-style: none; margin: 0; padding: 0 12px 12px; }
.chatlines li { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; overflow-wrap: anywhere; }
.chatlines .time { color: var(--muted); font-size: 12px; flex: none; font-variant-numeric: tabular-nums; }
.chatlines .who { flex: none; font-weight: 650; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: none; padding: 0; cursor: pointer; color: var(--mute); }
span.who { cursor: default; }
.chatlines .text { min-width: 0; white-space: pre-wrap; }
.chatlines .system .text { color: var(--muted); font-style: italic; }
.chatlines .ann .text { color: var(--accent); font-style: normal; font-weight: 600; }
.newpill { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); border: 0; border-radius: 999px; padding: 8px 16px; background: var(--accent); color: var(--accent-text); font-weight: 650; cursor: pointer; box-shadow: 0 2px 10px rgba(0,0,0,0.3); }

/* ---- the map */
.pane-map { padding: 0; }
.map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: grab; display: block; }
.map-canvas:active { cursor: grabbing; }
.map-btns { position: absolute; right: max(10px, env(safe-area-inset-right)); top: 10px; display: grid; gap: 8px; }
.map-btn { width: 44px; height: 44px; border-radius: 12px; border: 1px solid rgba(255,255,255,0.15); background: rgba(14,22,32,0.82); color: #fff; font-size: 20px; cursor: pointer; }
.map-count { position: absolute; left: max(10px, env(safe-area-inset-left)); top: 10px; padding: 6px 12px; border-radius: 999px; background: rgba(14,22,32,0.82); color: #fff; font-size: 14px; pointer-events: none; }
.map-credit { position: absolute; right: 6px; bottom: 4px; font-size: 10px; color: rgba(255,255,255,0.8); text-shadow: 0 0 3px #000; pointer-events: none; }

/* ---- the heat map on the map (js/heat.js): a panel at the foot of the map, clear of the buttons (top right) and the tabs */
.heat-btn.on { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.heat-panel { position: absolute; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: 8px; max-height: 46%;
  overflow-y: auto; overscroll-behavior: contain; padding: 10px 12px; border-radius: 14px; background: rgba(14,22,32,0.9); color: #fff;
  display: grid; gap: 8px; box-shadow: 0 4px 18px rgba(0,0,0,0.35); }
.heat-panel.hidden { display: none; }
.hrow { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.hchip { min-height: 34px; padding: 4px 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,0.22); background: rgba(255,255,255,0.06); color: #fff; font-size: 14px; cursor: pointer; }
.hchip.on { background: var(--accent); color: var(--accent-text); border-color: transparent; font-weight: 650; }
.hchip:disabled { opacity: 0.4; cursor: default; }
.hchip.vs { margin-left: auto; }
.hslide { gap: 0; }
.hslider { width: 100%; min-height: 32px; accent-color: var(--accent); margin: 0; }
.htitle { font-weight: 650; font-size: 15px; }
.hnote { color: rgba(255,255,255,0.75); font-size: 13px; }
.hnote:empty { display: none; }
.htop { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; counter-reset: h; }
.htop li { counter-increment: h; }
.hplace { width: 100%; display: flex; gap: 8px; align-items: baseline; padding: 6px 4px; border: 0; border-radius: 8px; background: none; color: #fff; cursor: pointer; text-align: left; font-size: 14px; }
.hplace::before { content: counter(h); color: var(--accent); font-weight: 700; width: 1em; flex: none; }
.hplace:active, .hplace:hover { background: rgba(255,255,255,0.08); }
.hname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hval { flex: none; color: rgba(255,255,255,0.75); font-size: 13px; font-variant-numeric: tabular-nums; }
.pane-map.heat-on .map-credit { display: none; }
/* (a short landscape phone - the console's own breakpoint: on the left, as tall as the map less the "here" count's top strip) */
@media (max-height: 460px) and (orientation: landscape) {
  .heat-panel { right: auto; width: min(420px, 62%); max-height: calc(100% - 56px); }
}

/* ---- a toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; transition: 0.2s;
  background: #22303f; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30; pointer-events: none; max-width: calc(100% - 32px); box-shadow: 0 4px 16px rgba(0,0,0,0.35); }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: #7d1d20; }

/* ---- short landscape phones: a slimmer top bar and tabs */
@media (max-height: 460px) and (orientation: landscape) {
  :root { --tab-h: 46px; --top-h: 36px; }
  .tab { display: flex; justify-content: center; align-items: center; gap: 6px; font-size: 13px; }
  .pane-head { padding-top: 8px; }
  .pane-head h2 { font-size: 17px; }
}

/* ---- wide: the map on the left, the sidebar's tabs at its top */
@media (min-width: 900px) {
  .shell { grid-template-columns: 1fr 440px; grid-template-rows: var(--top-h) var(--tab-h) 1fr; }
  .top { grid-column: 1 / 3; }
  .panes { display: contents; }
  .pane-map { position: relative; grid-column: 1; grid-row: 2 / 4; display: block; }
  .pane:not(.pane-map) { position: relative; grid-column: 2; grid-row: 3; border-left: 1px solid var(--line); background: var(--panel); }
  .tabs { grid-column: 2; grid-row: 2; border-top: 0; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); padding: 0; }
  .tab[data-tab=map] { display: none; }
  .tabs { grid-template-columns: repeat(3, 1fr); }
  .tab { display: flex; justify-content: center; align-items: center; gap: 6px; font-size: 14px; }
  .sheet-back { justify-content: flex-end; align-items: stretch; }
  .sheet { width: 460px; max-height: none; height: 100%; border-radius: 0; transform: translateX(30px); }
  .toast { bottom: 24px; }
  .heat-panel { right: auto; width: min(520px, calc(100% - 90px)); }
  .card.login { margin-top: 10vh; background: var(--panel); border-radius: 16px; }
}
