@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/ibmplex-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/ibmplex-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("../fonts/ibmplex-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

html[data-theme="green"] {
  --bg: #000000;
  --fg: #33ff33;
  --dim: #1f8a3a;
  --accent: #33ff33;
  --c-border: #0c3d1c;
  --c-border-active: #37f55c;
  --c-user: #33ff33;
  --c-sys: #ff4b3e;
  --c-irq: #ffcc33;
  --c-nice: #33cccc;
  --c-mem-used: #3b6eff;
  --c-mem-buf: #33ff33;
  --c-mem-cache: #ffcc33;
  --c-swap: #ff4b3e;
  --c-meter-empty: #0d2b14;
  --log-info: #33ff33;
  --log-warn: #ffcc33;
  --log-err: #ff5544;
  --log-alert-bg: #ff3333;
  --log-alert-fg: #1a0000;
  --log-debug: #33cccc;
  --log-access: #1e8a3a;
  --log-method: #8aff8a;
  --status-bg: #15993b;
  --status-fg: #001a06;
  --status-dim: #0a5c20;
  --c-spark: #33ff33;
  --c-net-rx: #33ff33;
  --c-net-tx: #ffcc33;
  --sel-bg: #33ff33;
  --sel-fg: #001a00;
  --match-bg: rgba(51, 255, 51, 0.22);
  --crt-opacity: 1;
  --help-bg: rgba(0, 6, 1, 0.92);
}

html[data-theme="amber"] {
  --bg: #0a0600;
  --fg: #ffb454;
  --dim: #8f6a2e;
  --accent: #ffb454;
  --c-border: #4a3310;
  --c-border-active: #ffc14d;
  --c-user: #ffb454;
  --c-sys: #ff4b3e;
  --c-irq: #ffd766;
  --c-nice: #ff8f3c;
  --c-mem-used: #5c9cff;
  --c-mem-buf: #ffb454;
  --c-mem-cache: #ffd766;
  --c-swap: #ff4b3e;
  --c-meter-empty: #2a1d08;
  --log-info: #ffb454;
  --log-warn: #ffd766;
  --log-err: #ff6a55;
  --log-alert-bg: #ff4b3e;
  --log-alert-fg: #1a0500;
  --log-debug: #ff8f3c;
  --log-access: #8f6a2e;
  --log-method: #ffd9a0;
  --status-bg: #b06100;
  --status-fg: #1c0e00;
  --status-dim: #6b3a00;
  --c-spark: #ffb454;
  --c-net-rx: #ffb454;
  --c-net-tx: #ffd766;
  --sel-bg: #ffb454;
  --sel-fg: #1c0e00;
  --match-bg: rgba(255, 180, 84, 0.22);
  --crt-opacity: 1;
  --help-bg: rgba(12, 7, 0, 0.92);
}

html[data-theme="dark"] {
  --bg: #0f1420;
  --fg: #c0caf5;
  --dim: #565f89;
  --accent: #7aa2f7;
  --c-border: #262d44;
  --c-border-active: #7aa2f7;
  --c-user: #7aa2f7;
  --c-sys: #f7768e;
  --c-irq: #e0af68;
  --c-nice: #7dcfff;
  --c-mem-used: #7aa2f7;
  --c-mem-buf: #9ece6a;
  --c-mem-cache: #e0af68;
  --c-swap: #f7768e;
  --c-meter-empty: #1a2133;
  --log-info: #c0caf5;
  --log-warn: #e0af68;
  --log-err: #f7768e;
  --log-alert-bg: #f7768e;
  --log-alert-fg: #1a050d;
  --log-debug: #7dcfff;
  --log-access: #565f89;
  --log-method: #9ece6a;
  --status-bg: #1a1f2e;
  --status-fg: #c0caf5;
  --status-dim: #3b4261;
  --c-spark: #7dcfff;
  --c-net-rx: #7aa2f7;
  --c-net-tx: #e0af68;
  --sel-bg: #7aa2f7;
  --sel-fg: #0f1420;
  --match-bg: rgba(122, 162, 247, 0.22);
  --crt-opacity: 0.55;
  --help-bg: rgba(15, 20, 32, 0.94);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  color: var(--fg);
  font-family: "IBM Plex Mono", "SF Mono", Menlo, Consolas, "DejaVu Sans Mono", monospace;
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

#screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 6px 6px 0;
}

#grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--gc1) var(--gc2) var(--gc3);
  grid-template-rows: var(--gr1) var(--gr2) var(--gr3);
  gap: 2px;
}

#grid.zoomed .pane.hidden {
  display: none;
}

#grid.zoomed .pane.active {
  border-color: var(--c-border-active);
}

.pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
  border: 1px solid var(--c-border);
  transition: border-color 0.18s ease;
}

.pane.active {
  border-color: var(--c-border-active);
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.04);
}

.pane-label {
  position: absolute;
  top: -1px;
  left: 6px;
  z-index: 3;
  padding: 0 6px;
  font-size: 0.74em;
  line-height: 1.5;
  background: var(--c-border);
  color: var(--bg);
  letter-spacing: 0.04em;
}

.pane.active .pane-label {
  background: var(--c-border-active);
  color: var(--bg);
  font-weight: 600;
}

.pane-body {
  position: absolute;
  inset: 0;
  padding: 8px 8px 6px;
  overflow: hidden;
  font-size: var(--fs, clamp(11px, 1.18vmin, 30px));
  line-height: 1.22;
  white-space: nowrap;
}

#statusbar {
  flex: none;
  display: flex;
  align-items: stretch;
  height: 27px;
  margin-top: 4px;
  background: var(--status-bg);
  color: var(--status-fg);
  font-size: calc(var(--fs, 13px) * 0.9);
  line-height: 27px;
  letter-spacing: 0.03em;
}

.status-left {
  padding: 0 12px;
  background: var(--status-bg);
  font-weight: 700;
}

.status-left.prefix {
  background: var(--status-fg);
  color: var(--status-bg);
  animation: blink 0.9s steps(1) infinite;
}

.status-center {
  padding: 0 12px;
  font-weight: 600;
}

.status-center.msg {
  background: var(--accent);
  color: var(--bg);
  font-weight: 700;
}

.status-right {
  margin-left: auto;
  padding: 0 12px;
  font-weight: 600;
}

/* ---------- htop ---------- */

#pane-body-htop {
  display: flex;
  flex-direction: column;
}

.htop-head {
  display: flex;
  justify-content: space-between;
  gap: 2ch;
  white-space: nowrap;
  overflow: hidden;
  font-weight: 600;
  flex: none;
}

.htop-meters {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  padding-top: 5px;
  flex: none;
}

.meter-row {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 84px;
  flex: 1 1 auto;
}

.meter-tag {
  flex: none;
  min-width: 7ch;
  font-weight: 600;
}

.meter-val {
  flex: none;
  font-size: 0.9em;
}

.meter-pct {
  flex: none;
  font-size: 0.9em;
  min-width: 6ch;
  text-align: right;
}

.meter {
  flex: 1;
  height: 1.05em;
  display: flex;
  min-width: 40px;
  background: var(--c-meter-empty);
}

.meter-seg {
  height: 100%;
}

.pane-sep {
  flex: none;
  height: 1px;
  margin: 5px 0 3px;
  background: var(--c-border);
}

.htop-cols,
.htop-row {
  display: flex;
  white-space: nowrap;
  flex: none;
}

.htop-cols {
  font-weight: 700;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 1px;
  margin-bottom: 1px;
}

.htop-cols span,
.htop-row span {
  flex: none;
  overflow: hidden;
}

.c-pid { width: 6ch; }
.c-user { width: 8ch; }
.c-pri { width: 3ch; }
.c-ni { width: 4ch; }
.c-virt { width: 8ch; }
.c-res { width: 8ch; }
.c-shr { width: 7ch; }
.c-s { width: 2ch; }
.c-cpu { width: 6ch; }
.c-mem { width: 6ch; }
.c-time { width: 10ch; }
.c-cmd { flex: 1; overflow: hidden; }

.htop-rows {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.htop-row.sel {
  background: var(--sel-bg);
  color: var(--sel-fg);
  font-weight: 600;
}

.htop-row.match {
  background: var(--match-bg);
}

.defunct {
  opacity: 0.55;
}

.cursor-cell {
  background: var(--sel-fg);
  color: var(--sel-bg);
  animation: blink 1.06s steps(1) infinite;
}

.htop-searchline,
.htop-filterline {
  flex: none;
  font-weight: 600;
  color: var(--log-warn);
}

.htop-keys {
  flex: none;
  display: flex;
  gap: 2.2ch;
  white-space: nowrap;
  overflow: hidden;
  padding-top: 4px;
  font-size: 0.92em;
}

.htop-keys .dim {
  opacity: 0.5;
}

.htop-copy {
  margin-left: auto;
  opacity: 0.55;
  font-size: 0.88em;
  align-self: center;
}

/* ---------- services ---------- */

#pane-body-svc {
  display: flex;
  flex-direction: column;
}

.svc-head,
.svc-row {
  display: flex;
  white-space: nowrap;
  flex: none;
}

.svc-head {
  font-weight: 700;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 1px;
}

.svc-mark { width: 2ch; }
.svc-unit { width: 26ch; overflow: hidden; }
.svc-load { width: 8ch; }
.svc-active { width: 9ch; }
.svc-sub { width: 14ch; }
.svc-desc { flex: 1; overflow: hidden; opacity: 0.8; }

.svc-row.sel {
  background: var(--sel-bg);
  color: var(--sel-fg);
  font-weight: 600;
}

.svc-row.sel .svc-desc { opacity: 1; }

.st-active-running { color: var(--accent); }
.st-active-waiting { color: var(--dim); }
.st-active-reloading { color: var(--log-warn); }
.st-deactivating-stop { color: var(--log-warn); }
.st-activating-start, .st-activating-auto-restart { color: var(--log-warn); }
.st-failed { color: var(--log-err); font-weight: 700; }
.st-inactive-dead { color: var(--dim); }

.svc-foot {
  flex: none;
  display: flex;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 4px;
  font-size: 0.9em;
  opacity: 0.85;
}

.svc-hint {
  opacity: 0.6;
}

/* ---------- network ---------- */

#pane-body-net {
  display: flex;
  flex-direction: column;
}

.net-graph {
  flex: 1;
  min-height: 54px;
  position: relative;
}

.net-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.net-max {
  position: absolute;
  top: 2px;
  right: 4px;
  font-size: 0.8em;
  opacity: 0.55;
}

.net-rate {
  flex: none;
  display: flex;
  gap: 3ch;
  padding: 3px 0;
  font-weight: 700;
}

.net-rx { color: var(--c-net-rx); }
.net-tx { color: var(--c-net-tx); }

.net-table {
  flex: none;
}

.net-row {
  display: flex;
  white-space: nowrap;
}

.net-if { width: 9ch; font-weight: 600; }
.net-desc { width: 10ch; opacity: 0.6; }
.net-rx { width: 12ch; }
.net-tx { width: 12ch; }
.net-tot { opacity: 0.75; overflow: hidden; }

.net-tcp {
  flex: none;
  margin-top: auto;
  padding-top: 3px;
  display: flex;
  gap: 3ch;
  font-size: 0.88em;
  opacity: 0.7;
}

/* ---------- disk ---------- */

#pane-body-disk {
  display: flex;
  flex-direction: column;
}

.disk-head,
.disk-row {
  display: flex;
  white-space: nowrap;
  flex: none;
}

.disk-head {
  font-weight: 700;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 1px;
}

.d-fs { width: 14ch; overflow: hidden; }
.d-size { width: 7ch; }
.d-used { width: 7ch; }
.d-avail { width: 7ch; }
.d-pct { width: 5ch; }
.d-bar {
  flex: 1;
  min-width: 30px;
  height: 0.9em;
  background: var(--c-meter-empty);
  margin: 0 8px 0 4px;
  align-self: center;
}

.d-bar-fill {
  height: 100%;
  background: var(--accent);
}

.d-bar.bar-warn .d-bar-fill { background: var(--log-warn); }
.d-bar.bar-err .d-bar-fill { background: var(--log-err); }
.d-pct.bar-warn { color: var(--log-warn); }
.d-pct.bar-err { color: var(--log-err); }

.d-mount { overflow: hidden; }

.disk-spark {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 6px;
  margin-top: auto;
}

.disk-spark svg {
  width: 120px;
  height: 30px;
  flex: none;
  background: var(--c-meter-empty);
}

.disk-io {
  flex: none;
  display: flex;
  gap: 3ch;
  padding-top: 3px;
  font-size: 0.88em;
}

.dim { opacity: 0.6; }

/* ---------- logs ---------- */

#pane-body-logs {
  display: flex;
  flex-direction: column;
}

.logs-head {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 2ch;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 2px;
  margin-bottom: 2px;
  font-weight: 600;
  overflow: hidden;
}

.logs-host { opacity: 0.55; }

.logs-body {
  flex: 1;
  min-height: 0;
  overflow-y: scroll;
  scrollbar-width: none;
}

.logs-body::-webkit-scrollbar {
  display: none;
}

.log-line {
  white-space: nowrap;
  overflow: hidden;
}

.log-time { opacity: 0.6; }
.log-host { opacity: 0.75; }
.log-prog { font-weight: 600; }
.log-msg { opacity: 0.9; }

.log-info .log-prog { color: var(--log-info); }
.log-info .log-msg { color: var(--log-info); opacity: 0.85; }

.log-debug { opacity: 0.8; }
.log-debug .log-prog { color: var(--log-debug); }
.log-debug .log-msg { color: var(--log-debug); }

.log-warn .log-prog { color: var(--log-warn); }
.log-warn .log-msg { color: var(--log-warn); }

.log-error .log-prog { color: var(--log-err); }
.log-error .log-msg { color: var(--log-err); }

.log-alert {
  background: var(--log-alert-bg);
  color: var(--log-alert-fg);
  font-weight: 700;
}

.log-alert .log-time { opacity: 0.75; }
.log-alert .log-prog { color: var(--log-alert-fg); }
.log-alert .log-msg { color: var(--log-alert-fg); }

.log-access .log-prog { color: var(--log-access); }
.log-access .log-msg { color: var(--log-access); }
.log-method { color: var(--log-method); font-weight: 600; }

.logs-marker {
  position: absolute;
  top: 22px;
  right: 8px;
  background: var(--status-fg);
  color: var(--status-bg);
  font-size: 0.8em;
  padding: 1px 6px;
  z-index: 5;
  display: none;
}

/* ---------- summary ---------- */

#pane-body-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sum-clock-head {
  flex: none;
  opacity: 0.5;
  font-size: 0.85em;
}

.sum-clock {
  flex: none;
  font-size: clamp(1.9em, 4.2vmin, 3.2em);
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 0 0;
}

.sum-colon {
  animation: blink 1s steps(1) infinite;
}

.sum-date {
  flex: none;
  opacity: 0.75;
  font-size: 0.9em;
}

.sum-sep {
  flex: none;
  width: 80%;
  height: 1px;
  margin: 7px 0;
  background: var(--c-border);
}

.sum-info {
  flex: none;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sum-row {
  display: flex;
  white-space: nowrap;
}

.sum-k { width: 7ch; opacity: 0.55; }
.sum-v { font-weight: 600; }

.sum-alerts {
  margin-top: auto;
  align-self: stretch;
  padding-top: 6px;
  font-size: 0.88em;
}

.sum-ok { color: var(--accent); font-weight: 600; }
.sum-warn { color: var(--log-warn); font-weight: 700; }
.sum-alert { overflow: hidden; text-overflow: ellipsis; }
.al-err { color: var(--log-err); }
.al-warn { color: var(--log-warn); }

/* ---------- prompts & cursors ---------- */

.term-prompt {
  position: absolute;
  bottom: 30px;
  left: 8px;
  right: 8px;
  z-index: 6;
  background: var(--bg);
  border: 1px solid var(--c-border-active);
  display: flex;
  align-items: center;
  padding: 2px 6px;
}

.term-prompt-label {
  flex: none;
  font-weight: 700;
  color: var(--log-warn);
}

.term-prompt input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--fg);
  font-family: inherit;
  font-size: 1em;
  caret-color: var(--accent);
}

.cursor-block {
  animation: blink 1.06s steps(1) infinite;
}

.ps1 {
  opacity: 0.8;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: var(--help-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}

.attach-box {
  color: var(--fg);
  font-size: calc(var(--fs, 13px) * 1.15);
}

.attach-line {
  display: flex;
  gap: 1ch;
}

.attach-sub {
  margin-top: 8px;
  opacity: 0.65;
  font-size: 0.9em;
}

.attach-box.fade {
  opacity: 0;
  transition: opacity 0.25s ease;
}

.help-box {
  width: min(880px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  scrollbar-width: none;
  border: 1px solid var(--c-border-active);
  background: var(--bg);
  padding: 16px 20px 12px;
  box-shadow: 0 0 40px rgba(0, 0, 0, 0.6);
}

.help-box::-webkit-scrollbar { display: none; }

.help-title {
  font-weight: 700;
  font-size: 1.1em;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
  margin-bottom: 10px;
}

.help-grid {
  display: flex;
  gap: 28px;
}

.help-col { flex: 1; min-width: 0; }

.help-col-title {
  font-weight: 700;
  color: var(--accent);
  padding-bottom: 4px;
}

.help-row {
  display: flex;
  white-space: nowrap;
  overflow: hidden;
  padding: 1px 0;
}

.help-key {
  width: 34ch;
  flex: none;
  font-weight: 600;
}

.help-desc { opacity: 0.8; overflow: hidden; text-overflow: ellipsis; }

.help-foot {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--c-border);
  font-size: 0.85em;
  opacity: 0.6;
}

.quit-box {
  text-align: center;
  font-size: calc(var(--fs, 13px) * 1.2);
}

.quit-exited {
  font-weight: 700;
  color: var(--fg);
  font-size: 1.3em;
  margin-bottom: 18px;
}

.quit-line {
  display: flex;
  gap: 1ch;
  justify-content: center;
}

.quit-hint {
  margin-top: 18px;
  opacity: 0.6;
  font-size: 0.85em;
}

/* ---------- CRT texture ---------- */

#crt {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  opacity: var(--crt-opacity);
  background:
    repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.13) 0px, rgba(0, 0, 0, 0.13) 1px, transparent 1px, transparent 3px),
    radial-gradient(ellipse at center, transparent 52%, rgba(0, 0, 0, 0.34) 100%);
  animation: crt-flicker 9s infinite;
}

@keyframes crt-flicker {
  0%, 100% { opacity: var(--crt-opacity); }
  92% { opacity: calc(var(--crt-opacity) * 0.985); }
  94% { opacity: calc(var(--crt-opacity) * 1); }
  96% { opacity: calc(var(--crt-opacity) * 0.99); }
}

@keyframes blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  html, body { overflow: auto; height: auto; }
  #screen { height: auto; padding: 4px; }
  #grid { display: block; }
  .pane { height: 62vh; margin-bottom: 6px; }
  #pane-htop { height: 80vh; }
  #statusbar { position: sticky; bottom: 0; }
}
