:root {
  --bg: #121212;
  --panel-bg: #121212;
  --fg: #d0d0d0;
  --dim: #808080;
  --border: #444444;
  --green: #5faf5f;
  --red: #d75f5f;
  --yellow: #d7af00;
  --cyan: #5fafd7;
  --accent: #ff8700;
  --mono: ui-monospace, "Cascadia Mono", "Fira Code", "DejaVu Sans Mono", "Liberation Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.25;
  overflow-x: hidden;
}

/* thin dark scrollbars everywhere a box scrolls internally — the native light/wide
   default reads as a bright foreign strip against this palette */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: var(--bg); }
*::-webkit-scrollbar-thumb { background: var(--border); border: 1px solid var(--bg); }
*::-webkit-scrollbar-thumb:hover { background: var(--dim); }

body { min-height: 100vh; }

button, input {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 16px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 0 6px;
  height: 20px;
  outline: none;
}

button { cursor: pointer; white-space: nowrap; }
button:hover, button:active, button.selected { background: #ffffff; color: #000000; border-color: #ffffff; }
button:disabled { color: var(--dim); cursor: default; }
button:disabled:hover { background: var(--bg); color: var(--dim); border-color: var(--border); }
button.danger { color: var(--red); }
button.danger:hover, button.danger:active { color: #000000; }

input:focus { border-color: var(--accent); }

a { color: var(--cyan); text-decoration: none; }
a:hover { background: #ffffff; color: #000000; }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dim);
  margin-right: 4px;
  flex-shrink: 0;
}
.dot.live { background: var(--green); }
.dot.warn { background: var(--yellow); }
.dot.danger { background: var(--red); }

#app { display: flex; flex-direction: column; min-height: 100vh; }

.screen { display: flex; flex: 1; min-height: 0; }
/* author display rules must never beat the hidden attribute */
[hidden] { display: none !important; }

/* ---- login ---- */

#login-screen { align-items: center; justify-content: center; }
.login-box {
  border: 1px solid var(--border);
  padding: 24px 32px;
  text-align: center;
}
.login-title { font-size: 18px; color: var(--accent); margin-bottom: 4px; }
.login-sub { color: var(--dim); margin-bottom: 16px; }
.login-link { display: inline-block; }

/* ---- main layout ---- */

#main-screen { flex-direction: column; width: 100%; height: 100vh; padding: 4px; gap: 4px; min-height: 0; }

.header, .status-line, .cmdbar, .admin-strip, .say-row {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  padding: 2px 8px;
  flex: 0 0 auto;
  min-height: 22px;
}

.header {
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.header-group { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.brand { color: var(--accent); font-weight: bold; }

.channel-tabs { display: flex; flex-wrap: wrap; gap: 2px; min-width: 0; }
.channel-tab {
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  padding: 0 6px;
  height: 18px;
  cursor: pointer;
  color: var(--dim);
}
.channel-tab .num { color: var(--dim); margin-right: 3px; }
.channel-tab .dot { margin-right: 4px; }
/* flex drops a leading space inside the viewer span, so the gap is a margin */
.channel-tab .dim { margin-left: 4px; }
.channel-tab:hover { background: #ffffff; color: #000000; }
.channel-tab:hover .num, .channel-tab:hover .dot { color: #000000; }
.channel-tab.active { color: var(--fg); border-color: var(--accent); }

.whoami { color: var(--dim); }

.cmdbar { gap: 6px; }
.cmdbar-prefix { color: var(--accent); }
.cmd-input { flex: 0 0 320px; border: none; padding: 0; height: auto; }
.cmd-input:focus { border: none; }
.cmdbar:has(.cmd-input:focus) { border-color: var(--accent); }
.cmd-preview { color: var(--cyan); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmd-preview.err { color: var(--red); }

/* ---- box grid: shared 1px borders, zero gap, no page scroll at >=1280x720 ---- */

.grid {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas: none;
  gap: 0;
  padding-top: 8px; /* clears the ┤ title ├ that floats above each box's top edge */
  overflow-y: auto;
  overflow-x: hidden;
}

@media (min-width: 700px) {
  .grid { grid-template-columns: 1fr 1fr; grid-template-areas: none; }
}

@media (min-width: 1280px) {
  html, body { height: 100%; overflow: hidden; }
  .grid {
    grid-template-columns: 1fr 1fr 2fr 1.2fr;
    grid-template-rows: 1fr 1fr 1fr;
    grid-template-areas:
      "switches questions questions activity"
      "switches questions questions people"
      "trivia   chatrules raidgeon  log";
    overflow-y: hidden;
  }
  .pane { min-height: 0; }
  /* named areas only where a template defines them: outside it every named pane lands in
     the same implicit cell and the boxes pile on top of each other */
  #pane-switches { grid-area: switches; }
  #pane-chatrules { grid-area: chatrules; }
  #pane-trivia { grid-area: trivia; }
  #pane-questions { grid-area: questions; }
  #pane-activity { grid-area: activity; }
  #pane-people { grid-area: people; }
  #pane-raidgeon { grid-area: raidgeon; }
  #pane-log { grid-area: log; }
}

.pane {
  position: relative;
  border: 1px solid var(--border);
  padding: 12px 6px 4px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 130px;
  overflow: visible; /* the border title sits above the box; .pane-body owns scrolling */
}
/* every box keeps its own full border (not just right+bottom) — the ┤ title ├ straddles
   THIS box's own top border, and at gap:0 that only works if every row has one; two
   adjoining boxes' borders touch, reading as one clean line rather than a visible gap */
.pane.focused { border-color: var(--accent); }
.pane.focused > .pane-title { color: var(--accent); }
.pane.focused > .pane-title::before, .pane.focused > .pane-title::after { color: var(--accent); }

.pane-title {
  position: absolute;
  top: -7px;
  left: 10px;
  height: 14px;
  line-height: 14px;
  margin: 0;
  padding: 0 2px;
  background: var(--panel-bg);
  color: var(--dim);
  font-size: 13px;
  font-weight: normal;
  white-space: nowrap;
}
.pane-title::before { content: '┤ '; color: var(--border); }
.pane-title::after { content: ' ├'; color: var(--border); }

.pane-body {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 2px;
  min-width: 0;
}
.row.selected { background: #ffffff; color: #000000; }
.row.selected .dim, .row.selected * { color: inherit; }
/* buttons on a selected (white) row invert back so they stay readable */
.row.selected button, .vibe-row.selected button { background: #000000; color: #ffffff; border-color: #000000; }

.dim { color: var(--dim); }
.ok { color: var(--green); }
.ok-dim { color: #4f8f4f; }
.warn { color: var(--yellow); }
.danger { color: var(--red); }
.info { color: var(--cyan); }

.row-label { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row button { flex-shrink: 0; }

.mono-btns { display: flex; gap: 3px; margin-left: auto; flex-shrink: 0; }

.pane-empty { color: var(--dim); padding: 1px 2px; }

.pane-controls {
  display: flex;
  gap: 4px;
  padding-top: 3px;
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  margin-top: 3px;
  flex-wrap: wrap;
}
.pane-controls input { flex: 1; min-width: 60px; }

.list-scroll { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; gap: 1px; }

.vibe-row { display: flex; flex-direction: column; padding: 1px 2px; min-width: 0; gap: 0; }
.vibe-row.selected { background: #ffffff; color: #000000; }
.vibe-row.selected * { color: inherit; }
.vibe-row .row { padding: 0; }
.vibe-instruction {
  padding-left: 14px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.audit-row { gap: 6px; }
.audit-line { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-source { color: var(--dim); flex-shrink: 0; }

/* ---- switches box: one line per switch ----
   grid, not flex: the label and state columns size to their own content and never
   shrink; only the buttons column is elastic, wrapping onto a 2nd line under pressure
   rather than ever truncating the label. */

.switch-row { display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 6px; }
.switch-label { white-space: nowrap; }
.switch-state { white-space: nowrap; }
.switch-btns { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }

/* ---- status line (segmented, plain-word health readout) ---- */

.status-line {
  gap: 10px;
  flex-wrap: wrap;
  color: var(--dim);
}
.status-seg { display: flex; align-items: center; gap: 3px; white-space: nowrap; }
.status-sep { color: var(--border); }

/* ---- activity box: sparkline + meters ---- */

.spark { font-variant-numeric: tabular-nums; letter-spacing: 0; white-space: pre; overflow: hidden; }
.meter-row { display: flex; flex-direction: column; gap: 0; padding: 1px 2px; }
.meter-label { display: flex; justify-content: space-between; gap: 8px; }
.meter-bar { font-variant-numeric: tabular-nums; white-space: pre; }
.meter-bar.warn { color: var(--yellow); }
.meter-bar.danger { color: var(--red); }

/* ---- questions box: one line per question ---- */

.q-row { gap: 6px; }
.q-age { color: var(--dim); flex-shrink: 0; width: 2.4em; }
.q-user { color: var(--cyan); flex-shrink: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 9em; }
.q-line { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.q-ms { color: var(--dim); flex-shrink: 0; }
.q-miss-reason { color: var(--red); flex-shrink: 0; }
.q-hint {
  color: var(--dim);
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  margin-top: 3px;
  padding-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- people box: top askers ---- */

.top-user-row { gap: 6px; }
.top-user-cap { color: var(--dim); flex-shrink: 0; }

.admin-strip {
  gap: 6px;
  border-color: var(--yellow);
}
.admin-label { color: var(--yellow); }
.admin-input { flex: 0 0 200px; }

.say-row { gap: 6px; }
.say-prefix { color: var(--dim); }
.say-input { flex: 1; }

.status-line.ok { color: var(--green); }
.status-line.fail { color: var(--red); }

.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.help-box {
  border: 1px solid var(--accent);
  background: var(--bg);
  padding: 16px 24px;
  max-width: 480px;
}
.help-box h3 { margin: 0 0 8px; color: var(--accent); font-size: 13px; }
.help-box .row { justify-content: space-between; gap: 16px; }
.help-key { color: var(--cyan); }

/* ---- phone width (base styles above are mobile-first; this narrows further; page
   scroll is allowed below the 1280 breakpoint, so nothing here locks height/overflow) ---- */

@media (max-width: 699px) {
  #main-screen { height: auto; min-height: 100vh; padding: 8px; gap: 8px; }
  .grid { overflow-y: visible; }
  .header { flex-direction: column; align-items: flex-start; gap: 6px; }
  .cmd-input { flex: 1 1 auto; }
  .admin-input { flex: 1 1 auto; }
}
