/* ============================================================
   ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM
   Fallout terminal — phosphor green CRT aesthetic
   ============================================================ */

@font-face {
  font-family: "VT323";
  src: url("/fonts/VT323-Regular.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "ArkPixel";
  src: url("/fonts/ark-pixel-12px-monospaced-zh_cn.ttf.woff2") format("woff2");
  font-display: swap;
}

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

:root {
  --fg: #39ff14;
  --fg-dim: #00d400;
  --fg-faint: #007a00;
  --bg: #0a0a00;
  --font: "VT323", "ArkPixel", "Courier New", monospace;
}

/* ── Amber theme override ──────────────────────────────────── */
:root {
  --theme-hue: 60deg; /* green phosphor */
}

[data-theme="amber"] {
  --fg: #ffb000;
  --fg-dim: #c28000;
  --fg-faint: #6b4400;
  --bg: #0d0a00;
  --theme-hue: 20deg; /* amber */
}

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

/* ── CRT vignette ─────────────────────────────────────────── */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at center, transparent 60%, rgba(0, 0, 0, 0.35) 100%);
  pointer-events: none;
  z-index: 100;
}

/* ── Scanlines ────────────────────────────────────────────── */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    to bottom,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.18) 2px,
    rgba(0, 0, 0, 0.18) 4px
  );
  pointer-events: none;
  z-index: 99;
}

/* ── Login overlay ────────────────────────────────────────── */
#login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  background: var(--bg);
}

#login-screen.hidden {
  display: none;
}

.login-box {
  border: 1px solid var(--fg-dim);
  padding: 2rem 3rem;
  width: min(480px, 90vw);
  text-align: center;
}

.login-box h1 {
  font-size: 2rem;
  color: var(--fg);
  text-shadow: 0 0 12px var(--fg);
  margin-bottom: 0.25rem;
  letter-spacing: 0.1em;
}

.login-box .subtitle {
  color: var(--fg-dim);
  margin-bottom: 2rem;
  font-size: 0.9rem;
}

.login-box label {
  display: block;
  text-align: left;
  color: var(--fg-dim);
  margin-bottom: 0.25rem;
  font-size: 0.9rem;
}

.login-box input {
  width: 100%;
  background: transparent;
  border: 1px solid var(--fg-dim);
  color: var(--fg);
  font-family: var(--font);
  font-size: 1rem;
  padding: 0.4rem 0.6rem;
  margin-bottom: 1rem;
  outline: none;
}

.login-box input:focus {
  border-color: var(--fg);
  box-shadow: 0 0 6px var(--fg-faint);
}

.login-box button {
  width: 100%;
  background: transparent;
  border: 1px solid var(--fg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 1.1rem;
  padding: 0.5rem;
  cursor: pointer;
  letter-spacing: 0.15em;
  text-shadow: 0 0 8px var(--fg);
  transition: background 0.15s;
}

.login-box button:hover {
  background: rgba(57, 255, 20, 0.1);
}

.login-error {
  color: var(--fg);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  min-height: 1.2em;
}

/* ── Terminal wrapper ─────────────────────────────────────── */
#terminal-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 1.5rem 2rem 1rem;
}

#terminal-screen.hidden {
  display: none;
}

.term-header {
  color: var(--fg-dim);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
}

.term-header .logo {
  color: var(--fg);
  font-size: 1rem;
  text-shadow: 0 0 8px var(--fg);
  letter-spacing: 0.2em;
}

.term-header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

#logout-btn {
  background: transparent;
  border: 1px solid var(--fg-faint);
  color: var(--fg-dim);
  font-family: var(--font);
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  transition:
    border-color 0.1s,
    color 0.1s;
}

#logout-btn:hover {
  border-color: var(--fg);
  color: var(--fg);
}

#theme-toggle {
  background: transparent;
  border: 1px solid var(--fg-faint);
  padding: 0.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition:
    border-color 0.1s,
    filter 0.1s;
  filter: brightness(0.6) sepia(1) saturate(3) hue-rotate(var(--theme-hue, 60deg));
}

#theme-toggle img {
  display: block;
  width: 24px;
  height: 24px;
  object-fit: contain;
}

#theme-toggle #icon-amber {
  display: none;
}

[data-theme="amber"] #theme-toggle #icon-green {
  display: none;
}
[data-theme="amber"] #theme-toggle #icon-amber {
  display: block;
}

#theme-toggle:hover {
  border-color: var(--fg);
  filter: brightness(1) sepia(1) saturate(3) hue-rotate(var(--theme-hue, 60deg));
}

/* ── Admin nav strip (visible to admins only) ─────────────── */
.admin-nav {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.2rem 0;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--fg-faint);
  font-size: 0.8rem;
}

.admin-nav.hidden {
  display: none;
}

.admin-nav-label {
  color: var(--fg-faint);
  user-select: none;
}

.admin-nav a {
  color: var(--fg-dim);
  text-decoration: none;
  letter-spacing: 0.05em;
  transition: color 0.1s;
}

.admin-nav a:hover {
  color: var(--fg);
  text-shadow: 0 0 6px var(--fg);
}

/* ── Tab panels ───────────────────────────────────────────── */
.tab-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.tab-panel.hidden {
  display: none;
}

/* ── Radio bar ────────────────────────────────────────────── */
.radio-bar.hidden {
  display: none;
}

.radio-bar {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.3rem;
  padding: 0.45rem 0;
  margin-bottom: 0.5rem;
  border-bottom: 1px solid var(--fg-faint);
  flex-shrink: 0;
  min-width: 0;
}

.radio-track-name {
  width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--fg);
  text-shadow: 0 0 8px var(--fg);
  font-size: 0.85rem;
  letter-spacing: 0.1em;
}

.radio-controls-row {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.radio-btn {
  background: transparent;
  border: 1px solid var(--fg-faint);
  color: var(--fg-dim);
  font-family: var(--font);
  font-size: 0.72rem;
  padding: 0.1rem 0.6rem;
  cursor: pointer;
  letter-spacing: 0.08em;
  flex-shrink: 0;
  transition:
    border-color 0.1s,
    color 0.1s;
}

.radio-btn:hover {
  border-color: var(--fg);
  color: var(--fg);
}

.radio-volume-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.radio-vol-label {
  color: var(--fg-faint);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  user-select: none;
}

/* Custom bar-grid volume slider */
.radio-vol-slider {
  position: relative;
  width: 120px;
  height: 14px;
  border: 1px solid var(--fg-dim);
  box-sizing: border-box;
  cursor: pointer;
  outline: none;
  user-select: none;
  overflow: hidden;
  /* unfilled bar grid — bright bars replaced by fill div over the left portion */
  background: repeating-linear-gradient(
    to right,
    var(--fg-faint) 0px,
    var(--fg-faint) 4px,
    var(--bg) 4px,
    var(--bg) 6px
  );
}

.radio-vol-slider:focus {
  border-color: var(--fg);
}

/* Filled portion — same bar grid, brighter colour, width set by JS */
.radio-vol-fill {
  position: absolute;
  inset: 0;
  width: 50%;
  background: repeating-linear-gradient(
    to right,
    var(--fg-dim) 0px,
    var(--fg-dim) 4px,
    var(--bg) 4px,
    var(--bg) 6px
  );
}

/* Thumb — a bright vertical bar at the fill boundary */
.radio-vol-thumb {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 3px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  box-shadow:
    0 0 6px var(--fg),
    0 0 12px var(--fg);
}

/* ── Split view layout ────────────────────────────────────── */
.split-view {
  flex: 1;
  display: flex;
  flex-direction: row;
  min-height: 0;
  overflow: hidden;
}

.note-panel {
  flex: 3;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  padding-right: 1rem;
}

.panel-separator {
  width: 1px;
  background: var(--fg-faint);
  flex-shrink: 0;
  align-self: stretch;
  margin: 0 1rem;
}

.chat-panel {
  flex: 2;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.panel-header {
  color: var(--fg-faint);
  font-size: 0.72rem;
  letter-spacing: 0.2em;
  padding-bottom: 0.3rem;
  margin-bottom: 0.4rem;
  border-bottom: 1px solid var(--fg-faint);
  flex-shrink: 0;
}

/* ── Note panel content area ──────────────────────────────── */
.note-content {
  flex: 1;
  overflow-y: auto;
  min-height: 60px;
  scrollbar-width: thin;
  scrollbar-color: var(--fg-faint) transparent;
  /* Scope layout and style recalculations to this element. */
  contain: layout style;
}

.note-content::-webkit-scrollbar {
  width: 4px;
}
.note-content::-webkit-scrollbar-button {
  display: none;
}
.note-content::-webkit-scrollbar-thumb {
  background: var(--fg-faint);
  min-height: 24px;
}

.note-placeholder {
  color: var(--fg-faint);
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-align: center;
  margin-top: 5rem;
}

.note-menu-title {
  color: var(--fg);
  text-shadow: 0 0 8px var(--fg);
  letter-spacing: 0.1em;
  margin-bottom: 0.4rem;
}

.note-storage-usage {
  color: var(--fg-faint);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
}

.note-menu-item {
  display: flex;
  align-items: baseline;
  padding: 0.15rem 0;
  color: var(--fg-dim);
  letter-spacing: 0.04em;
}

.note-menu-item.selected {
  color: var(--fg);
  text-shadow: 0 0 6px var(--fg);
}

.note-menu-item.back-item {
  color: var(--fg-faint);
  margin-top: 0.6rem;
}

.note-menu-item.back-item.selected {
  color: var(--fg-dim);
  text-shadow: none;
}

.note-cursor-indicator {
  width: 3ch;
  flex-shrink: 0;
  font-size: 0.85em;
  margin-right: 0.5ch;
  white-space: pre;
}

.note-back-hint {
  color: var(--fg-faint);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  margin-top: 1.5rem;
}

/* Nav hint strip at bottom of note panel */
.note-nav-hint {
  flex-shrink: 0;
  color: var(--fg-faint);
  font-size: 0.68rem;
  letter-spacing: 0.05em;
  text-align: center;
  padding-top: 0.3rem;
  margin-top: 0.4rem;
  border-top: 1px solid var(--fg-faint);
}

.note-nav-hint.hidden {
  display: none;
}

/* ── Scrollback output (chat panel) ──────────────────────── */
#output {
  flex: 1;
  overflow-y: auto;
  min-height: 60px;
  padding-right: 0.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--fg-faint) transparent;
  /* Scope layout and style recalculations — appending lines won't cascade outward. */
  contain: layout style;
}

#output::-webkit-scrollbar {
  width: 4px;
}
#output::-webkit-scrollbar-button {
  display: none;
}
#output::-webkit-scrollbar-thumb {
  background: var(--fg-faint);
  min-height: 24px;
}

.line {
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.line.user-input {
  color: var(--fg);
}
.line.system {
  color: var(--fg-dim);
}
.line.content {
  color: var(--fg);
  text-shadow: 0 0 6px var(--fg);
}
.line.error {
  color: #ff4444;
}
.line.meta {
  color: var(--fg-faint);
  font-size: 0.85em;
}

/* ANSI-like colour spans rendered by the frontend parser */
.ansi-bold {
  font-weight: bold;
}
.ansi-green {
  color: var(--fg);
}
.ansi-dim {
  color: var(--fg-dim);
}
.ansi-red {
  color: #ff4444;
}
.ansi-yellow {
  color: #ffff00;
}
.ansi-cyan {
  color: #00ffff;
}
.md-bold {
  font-weight: bold;
}
.md-italic {
  font-style: italic;
}

/* ── Input line ───────────────────────────────────────────── */
.input-row {
  display: flex;
  align-items: center;
  margin-top: 0.75rem;
  border-top: 1px solid var(--fg-faint);
  padding-top: 0.5rem;
}

.prompt {
  color: var(--fg);
  text-shadow: 0 0 8px var(--fg);
  margin-right: 0.4rem;
  user-select: none;
  flex-shrink: 0;
}

/* Wrapper holds both the visible mirror layer and the hidden input */
.input-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  cursor: text;
  min-width: 0;
}

/* Mirrors what the user has typed — purely visual */
.input-mirror {
  color: var(--fg);
  text-shadow: 0 0 8px var(--fg);
  white-space: pre; /* preserve spaces exactly */
  pointer-events: none;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1;
}

/* Blinking block cursor — sits immediately after the mirrored text */
.cursor {
  color: var(--fg);
  text-shadow: 0 0 8px var(--fg);
  animation: blink 1s step-end infinite;
  pointer-events: none;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1;
  user-select: none;
  white-space: pre; /* prevent space characters from collapsing when mid-text */
}

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

/* Mid-text cursor: alternate block/character colors so the character stays
   readable in fg color when the block blinks off. */
@keyframes blink-mid {
  0%,
  100% {
    background-color: var(--fg);
    color: var(--bg);
    text-shadow: none;
  }
  50% {
    background-color: transparent;
    color: var(--fg);
    text-shadow: 0 0 8px var(--fg);
  }
}

.cursor.mid-text {
  animation: blink-mid 1s step-end infinite;
}

/* The real input sits over the wrapper and captures keystrokes,
   but is invisible — all visual rendering is done by the mirror+cursor spans. */
#input {
  position: absolute;
  inset: 0;
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: transparent;
  caret-color: transparent;
  font-family: var(--font);
  font-size: 1rem;
}

/* ── Flicker animation for the whole terminal ─────────────── */
@keyframes flicker {
  0% {
    opacity: 1;
  }
  92% {
    opacity: 1;
  }
  93% {
    opacity: 0.85;
  }
  94% {
    opacity: 1;
  }
  96% {
    opacity: 0.9;
  }
  100% {
    opacity: 1;
  }
}

#terminal-screen {
  animation: flicker 8s infinite;
  /* Promote to compositor layer so opacity changes don't repaint page content. */
  will-change: opacity;
}

/* ── Status bar ───────────────────────────────────────────── */
.status-bar {
  color: var(--fg-faint);
  font-size: 0.75rem;
  margin-top: 0.25rem;
  display: flex;
  gap: 1.5rem;
}

.status-bar .connected {
  color: var(--fg-dim);
}
.status-bar .disconnected {
  color: #ff4444;
}
