:root {
  --bg: #020604;
  --bg-panel: #04120a;
  --fg: #33ff66;
  --fg-dim: #1a8f3f;
  --fg-faint: #0e4d24;
  --amber: #ffb000;
  --red: #ff3355;
  --cyan: #22e0e0;
  --glow: 0 0 6px rgba(51, 255, 102, 0.55);
  --mono: "Cascadia Mono", "Fira Code", "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  overflow: hidden;
}

.crt {
  display: flex;
  flex-direction: column;
  /* --app-height tracks visualViewport so the on-screen keyboard never hides
     the input row or the latest output (iOS keyboard overlays 100dvh) */
  height: var(--app-height, 100dvh);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: boot-flicker 1.1s ease-out 1;
}

@keyframes boot-flicker {
  0% { opacity: 0; }
  8% { opacity: 0.9; }
  12% { opacity: 0.2; }
  20% { opacity: 1; }
  26% { opacity: 0.55; }
  35% { opacity: 1; }
  100% { opacity: 1; }
}

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--fg-faint);
  background: var(--bg-panel);
  text-shadow: var(--glow);
  flex-wrap: wrap;
}

.brand { letter-spacing: 0.12em; font-weight: 700; white-space: nowrap; }
.brand-glyph { color: var(--cyan); text-shadow: 0 0 6px rgba(34, 224, 224, 0.6); }
.dim { color: var(--fg-dim); }

.controls { display: flex; align-items: center; gap: 0.5rem; }
.baud-label { font-size: 0.75rem; letter-spacing: 0.08em; }

#baud {
  width: 6.5rem;
  background: var(--bg);
  border: 1px solid var(--fg-dim);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 16px;
  padding: 0.25rem 0.4rem;
  text-shadow: var(--glow);
  outline: none;
}
#baud:focus { border-color: var(--fg); box-shadow: var(--glow); }

.link-state { font-size: 0.7rem; letter-spacing: 0.1em; }
.link-state.online { color: var(--fg); }
.link-state.offline { color: var(--red); text-shadow: 0 0 6px rgba(255, 51, 85, 0.6); animation: blink 1s step-end infinite; }

/* ---- status bar ---- */
.statusbar {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.3rem 0.85rem;
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  border-bottom: 1px dashed var(--fg-faint);
  background: rgba(4, 18, 10, 0.6);
}

.status { font-weight: 700; text-shadow: var(--glow); }
.status.idle { color: var(--fg-dim); }
.status.sent { color: var(--cyan); text-shadow: 0 0 6px rgba(34, 224, 224, 0.6); }
.status.executing { color: var(--amber); text-shadow: 0 0 6px rgba(255, 176, 0, 0.6); animation: blink 0.8s step-end infinite; }
.status.executed { color: var(--fg); }
.status.printing { color: var(--fg); animation: blink 0.5s step-end infinite; }
.status.error { color: var(--red); text-shadow: 0 0 6px rgba(255, 51, 85, 0.6); }

.status-meta { font-size: 0.7rem; }

@keyframes blink { 50% { opacity: 0.25; } }

/* ---- screen ---- */
.screen {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.85rem 1.25rem;
  cursor: text;
  overscroll-behavior: contain;
}

.scrollback {
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-word;
  text-shadow: var(--glow);
}

.scrollback .echo { color: var(--cyan); text-shadow: 0 0 5px rgba(34, 224, 224, 0.5); }
.scrollback .meta { color: var(--fg-dim); }
.scrollback .err { color: var(--red); text-shadow: 0 0 5px rgba(255, 51, 85, 0.5); }
.scrollback .banner { color: var(--fg-dim); }

.cursor {
  display: inline-block;
  animation: blink 1s step-end infinite;
  text-shadow: var(--glow);
}

/* ---- inline prompt row (flows after the scrollback, like a real shell) ---- */
.cmdform {
  display: flex;
  align-items: center;
  gap: 0.5ch;
}
.cmdform.hidden { display: none; }

.prompt {
  white-space: nowrap;
  text-shadow: var(--glow);
  font-size: 16px;
  line-height: 1.35;
}

#cmd {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  padding: 0;
  color: var(--fg);
  font-family: var(--mono);
  font-size: 16px;
  line-height: 1.35;
  caret-color: var(--fg);
  text-shadow: var(--glow);
}
#cmd:disabled { opacity: 0.4; }

.exec-btn {
  background: transparent;
  border: 1px solid var(--fg-faint);
  color: var(--fg-dim);
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  touch-action: manipulation;
}
.exec-btn:active { background: var(--fg-faint); color: var(--fg); }
.exec-btn:disabled { opacity: 0.35; cursor: default; }

/* ---- CRT overlays ---- */
.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.22) 3px
  );
  mix-blend-mode: multiply;
  z-index: 10;
}

.vignette {
  pointer-events: none;
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(0, 0, 0, 0.55) 100%);
  z-index: 11;
}

/* ---- login gate ---- */
.gate { align-items: center; justify-content: center; }
.gate-box {
  border: 1px solid var(--fg-dim);
  background: var(--bg-panel);
  padding: 1.5rem 1.75rem;
  max-width: 26rem;
  width: calc(100% - 2rem);
  box-shadow: 0 0 24px rgba(51, 255, 102, 0.12);
}
.gate-banner { color: var(--fg); text-shadow: var(--glow); font-size: 0.8rem; line-height: 1.2; }
.gate-title { margin: 0.9rem 0 1.1rem; font-size: 0.75rem; letter-spacing: 0.12em; color: var(--amber); text-shadow: 0 0 6px rgba(255, 176, 0, 0.5); }
.gate-form { display: flex; flex-direction: column; gap: 0.6rem; }
.gate-label { font-size: 0.75rem; letter-spacing: 0.1em; color: var(--fg-dim); }
#password {
  background: var(--bg);
  border: 1px solid var(--fg-dim);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 16px;
  padding: 0.45rem 0.5rem;
  outline: none;
  letter-spacing: 0.3em;
}
#password:focus { border-color: var(--fg); box-shadow: var(--glow); }
.gate-form .exec-btn { padding: 0.35rem 0.7rem; color: var(--fg); border-color: var(--fg-dim); font-size: 0.8rem; letter-spacing: 0.08em; text-shadow: var(--glow); }
.gate-msg { min-height: 1.2em; margin-top: 0.8rem; font-size: 0.75rem; letter-spacing: 0.1em; }
.gate-msg.err { color: var(--red); text-shadow: 0 0 6px rgba(255, 51, 85, 0.5); }
.gate-msg.ok { color: var(--fg); text-shadow: var(--glow); }

/* ---- admin dashboard ---- */
.admin { overflow-y: auto; }
.admin-body { flex: 1; overflow-y: auto; padding: 0.85rem; display: flex; flex-direction: column; gap: 1.1rem; }
.admin-title { color: var(--cyan); text-shadow: 0 0 6px rgba(34, 224, 224, 0.5); }
.admin-link { text-decoration: none; font-size: 0.75rem; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: 0.6rem; }
.tile { border: 1px solid var(--fg-faint); background: var(--bg-panel); padding: 0.55rem 0.7rem; }
.tile-label { font-size: 0.65rem; letter-spacing: 0.12em; color: var(--fg-dim); }
.tile-value { font-size: 1.15rem; margin-top: 0.2rem; text-shadow: var(--glow); }
.tile.warn .tile-value { color: var(--amber); text-shadow: 0 0 6px rgba(255, 176, 0, 0.55); }

.admin-h { font-size: 0.75rem; letter-spacing: 0.12em; color: var(--fg-dim); margin-bottom: 0.5rem; font-weight: 700; }
.table-wrap { overflow-x: auto; border: 1px solid var(--fg-faint); }
.admin-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.admin-table th, .admin-table td { text-align: left; padding: 0.35rem 0.6rem; border-bottom: 1px solid var(--fg-faint); white-space: nowrap; }
.admin-table th { color: var(--fg-dim); letter-spacing: 0.08em; background: var(--bg-panel); }
.admin-table td.ok { color: var(--fg); text-shadow: var(--glow); }
.admin-table td.warn { color: var(--amber); }

.admin-logs { display: grid; grid-template-columns: minmax(16rem, 1fr) 2fr; gap: 1rem; min-height: 0; }
.logs-list ul { list-style: none; max-height: 22rem; overflow-y: auto; border: 1px solid var(--fg-faint); padding: 0.4rem 0.6rem; }
.logs-list li { padding: 0.2rem 0; font-size: 0.75rem; }
.logs-list a { color: var(--cyan); text-decoration: none; }
.logs-list a:hover { text-shadow: 0 0 6px rgba(34, 224, 224, 0.6); }
.logs-list li .dim { display: block; font-size: 0.65rem; }
.log-content {
  border: 1px solid var(--fg-faint);
  background: var(--bg-panel);
  padding: 0.6rem;
  max-height: 22rem;
  overflow: auto;
  font-size: 0.72rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-break: break-word;
}

@media (max-width: 700px) {
  .admin-logs { grid-template-columns: 1fr; }
}

/* ---- mobile ---- */
@media (max-width: 560px) {
  .topbar { padding: 0.45rem 0.6rem; }
  .brand { font-size: 0.85rem; }
  .scrollback { font-size: 0.8rem; }
  .statusbar { padding: 0.25rem 0.6rem; }
}
