:root {
  /* CryptoPanic palette — synced with chat.css */
  --bg:        #0d0d0d;
  --bg2:       #141414;
  --bg3:       #1a1a1a;
  --bg-hover:  #1e1e1e;
  --bg-sel:    #0f1a28;

  --line:      #1e1e1e;
  --line2:     #2a2a2a;

  --ink:       #c8ccd4;
  --ink-dim:   #767980;
  --ink-dim2:  #444850;

  --accent:    #5bc8e8;
  --accent-soft: #5bc8e818;

  --bull:  #4caf7d;
  --bear:  #e05c5c;
  --warn:  #f0a04b;
  --info:  #5bc8e8;

  --radius:    2px;
  --radius-sm: 2px;

  --font: "Courier New", Courier, "Lucida Console", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: var(--font);
  font-size: 14px; line-height: 1.55;
  overflow: hidden;
  overscroll-behavior: none;
}

#bar {
  position: fixed; top: 0; left: 0; right: 0;
  height: calc(44px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
  padding-left: max(14px, env(safe-area-inset-left));
  padding-right: max(14px, env(safe-area-inset-right));
  display: flex; align-items: center; gap: 12px;
  background: #161922e6; backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); z-index: 10; font-size: 13px;
}
.logo { font-weight: 700; letter-spacing: .3px; color: var(--ink);
  font-size: 15px; }
.logo::first-letter { color: var(--accent); }

/* status pill */
.status { padding: 4px 10px 4px 22px; border-radius: 999px; font-size: 11px;
  font-weight: 600; line-height: 1; display: inline-flex; align-items: center;
  letter-spacing: .3px; text-transform: lowercase; position: relative;
  border: 1px solid transparent; }
.status::before { content: ""; position: absolute; left: 9px; top: 50%;
  transform: translateY(-50%); width: 7px; height: 7px; border-radius: 50%; }
.status.on  { background: #16c78418; color: var(--bull);
  border-color: #16c78444; }
.status.on::before  { background: var(--bull); box-shadow: 0 0 6px var(--bull); }
.status.off { background: #ea394318; color: var(--bear);
  border-color: #ea394344; }
.status.off::before { background: var(--bear); }

.count { margin-left: auto; color: var(--ink-dim2); font-size: 12px;
  font-family: var(--font-mono); }

#office { display: block; image-rendering: pixelated; }

#legend {
  position: fixed; bottom: calc(10px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  display: flex; gap: 18px; font-size: 11px; color: var(--ink-dim);
  background: #161922e6; padding: 8px 14px; border-radius: 999px;
  z-index: 10; border: 1px solid var(--line);
  backdrop-filter: blur(8px); font-weight: 500;
}
#legend i.sw { display: inline-block; width: 9px; height: 9px; margin-right: 6px;
  vertical-align: -1px; border-radius: 50%; }
.sw.term { background: var(--info); }
.sw.board { background: var(--warn); }
.sw.lib  { background: #a855f7; }
.sw.coffee { background: #fb923c; }
#legend .credit { color: var(--ink-dim2); }
#legend .credit a { color: var(--ink-dim); }

/* ---- buttons ---- */
.barbtn, .primarybtn, .dangerbtn {
  font-family: inherit; font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid var(--line2); background: var(--bg3); color: var(--ink-dim);
  padding: 6px 12px; border-radius: var(--radius-sm); line-height: 1;
  transition: background .12s, border-color .12s, color .12s;
}
.barbtn:hover { background: var(--bg-hover); color: var(--ink); }
.primarybtn { background: var(--accent-strong); border-color: var(--accent-strong);
  color: #fff; font-weight: 600; }
.primarybtn:hover { background: var(--accent); border-color: var(--accent); }
.dangerbtn { background: transparent; border-color: #ea394355;
  color: var(--bear); }
.dangerbtn:hover { background: #ea394318; border-color: var(--bear); }
.hidden { display: none !important; }

/* ---- chat drawer ---- */
#panel {
  position: fixed; top: calc(44px + env(safe-area-inset-top));
  right: 0; bottom: 0; width: 360px; max-width: 86vw;
  display: flex; flex-direction: column; z-index: 20;
  background: var(--bg2); border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px #0008;
}
#panelHead {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}
#panelTitle { font-weight: 600; color: var(--ink); font-size: 14px; }
#panelMeta { font-size: 11px; color: var(--ink-dim2); flex: 1;
  font-family: var(--font-mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat { flex: 1; overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
#chat::-webkit-scrollbar { width: 8px; }
#chat::-webkit-scrollbar-track { background: transparent; }
#chat::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 4px; }

.msg { max-width: 88%; padding: 8px 12px; border-radius: var(--radius);
  font-size: 13px; line-height: 1.5; white-space: pre-wrap;
  word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-strong);
  color: #fff; border-bottom-right-radius: 2px; }
.msg.assistant { align-self: flex-start; background: var(--bg3);
  color: var(--ink); border: 1px solid var(--line);
  border-bottom-left-radius: 2px; }
.msg.sys { align-self: center; font-size: 11px; color: var(--ink-dim2);
  background: var(--bg3); padding: 3px 10px; border-radius: 999px; }

#chatForm { display: flex; gap: 8px; padding: 10px;
  border-top: 1px solid var(--line); background: var(--bg2); }
/* font-size must be ≥16px or iOS Safari auto-zooms on focus */
#chatText { flex: 1; font-family: inherit; font-size: 16px; padding: 9px 12px;
  border-radius: var(--radius); border: 1px solid var(--line2);
  background: var(--bg3); color: var(--ink);
  transition: border-color .12s, box-shadow .12s; }
#chatText::placeholder { color: var(--ink-dim2); }
#chatText:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
#chatText:disabled { opacity: .4; }
#sendBtn { font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 0 16px; cursor: pointer; border: 1px solid var(--accent-strong);
  background: var(--accent-strong); color: #fff; border-radius: var(--radius); }
#sendBtn:hover { background: var(--accent); border-color: var(--accent); }
#panelFoot { padding: 10px; border-top: 1px solid var(--line);
  background: var(--bg2); }
#killBtn { width: 100%; }

/* ---- spawn modal ---- */
#spawnModal { position: fixed; inset: 0; z-index: 30;
  background: #0008; backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 16px; }
#spawnForm { width: 380px; max-width: 100%; background: var(--bg2);
  border: 1px solid var(--line2); border-radius: 10px; padding: 22px;
  display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 16px 40px #000a; }
#spawnForm h3 { margin: 0 0 2px; color: var(--ink);
  font-size: 16px; font-weight: 600; }
#spawnForm label { display: flex; flex-direction: column; gap: 5px;
  font-size: 11px; color: var(--ink-dim); font-weight: 500;
  letter-spacing: .3px; text-transform: uppercase; }
#spawnForm input, #spawnForm select { font-family: inherit; font-size: 16px;
  padding: 9px 12px; border-radius: var(--radius); border: 1px solid var(--line2);
  background: var(--bg3); color: var(--ink); text-transform: none;
  transition: border-color .12s, box-shadow .12s; }
#spawnForm input:focus, #spawnForm select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft); }
.modalbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.err { color: var(--bear); font-size: 12px; min-height: 14px; margin: 0; }

/* status dot per session in chat header */
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 6px; vertical-align: 0; flex-shrink: 0; }
.dot.ready { background: var(--bull); box-shadow: 0 0 5px var(--bull); }
.dot.thinking { background: var(--warn); }
.dot.starting { background: var(--info); }
.dot.exited, .dot.error { background: var(--bear); }
