/* Gnosis Dark Room - CSS Design System */

:root {
  --bg-color: #020202;
  --terminal-bg: #070708;
  --font-color: #ffffff;      /* Gnosis primary glowing white */
  --info-color: #ff6600;      /* Truth terminal dark orange */
  --thought-color: #a0a0a0;   /* Dimmed light-grey for thoughts */
  --error-color: #ff3344;     /* Warning red */
  --warn-color: #ff6600;      /* Caution dark orange */
  --terminal-border: #4d2600; /* Dark orange-brown borders */
  --glow-color: rgba(255, 255, 255, 0.15);
  --cyan-glow-color: rgba(255, 102, 0, 0.3); /* Repurposed for orange glow */
  --red-glow-color: rgba(255, 51, 68, 0.25);
}

/* Amber Theme Override */
body.theme-amber {
  --font-color: #ffb000;
  --info-color: #ffaa00;
  --thought-color: #aa8855;
  --terminal-border: #884400;
  --glow-color: rgba(255, 176, 0, 0.25);
}

/* Cyan Theme Override */
body.theme-cyan {
  --font-color: #00f0ff;
  --info-color: #33ff33;
  --thought-color: #5588aa;
  --terminal-border: #006688;
  --glow-color: rgba(0, 240, 255, 0.25);
}

/* Crimson Theme Override */
body.theme-crimson {
  --font-color: #ff1144;
  --info-color: #ffaa00;
  --thought-color: #aa5566;
  --terminal-border: #880011;
  --glow-color: rgba(255, 17, 68, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Share Tech Mono', 'Courier New', monospace;
  text-shadow: 0 0 4px var(--glow-color);
  scrollbar-width: thin;
  scrollbar-color: var(--terminal-border) transparent;
}

/* Lowercase rule enforced by character prompt - commented out to allow divine CAPITAL words */
/* body, button, input, table, pre, span, div {
  text-transform: lowercase;
} */

body {
  background-color: var(--bg-color);
  color: var(--font-color);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* CRT Screen FX - Premium Refined Edition */
.crt-overlay {
  content: " ";
  display: block;
  position: fixed;
  top: 0; left: 0; bottom: 0; right: 0;
  background: radial-gradient(circle at center, rgba(18, 16, 16, 0) 65%, rgba(0, 0, 0, 0.45) 100%);
  background-size: 100% 100%;
  z-index: 9999;
  pointer-events: none;
}

/* .crt-scanline commented out to remove TV horizontal line overlays */
/* .crt-scanline {
  width: 100%;
  height: 100px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0),
    rgba(255, 255, 255, 0.015),
    rgba(255, 255, 255, 0)
  );
  position: fixed;
  top: -100px;
  left: 0;
  z-index: 10000;
  pointer-events: none;
  animation: scanline 12s linear infinite;
} */

@keyframes scanline {
  0% { top: -100px; }
  100% { top: 100%; }
}

.crt-screen {
  animation: crt-flicker 0.25s infinite;
}

@keyframes crt-flicker {
  0% { opacity: 0.997; }
  50% { opacity: 1; }
  100% { opacity: 0.998; }
}

/* Screen Glitch Animation */
.glitch-shake {
  animation: screen-shake 0.3s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes screen-shake {
  10%, 90% { transform: translate3d(-2px, 2px, 0); filter: hue-rotate(90deg); }
  20%, 80% { transform: translate3d(4px, -3px, 0); filter: invert(0.1); }
  30%, 50%, 70% { transform: translate3d(-6px, 1px, 0); }
  40%, 60% { transform: translate3d(5px, 3px, 0); filter: skewX(10deg); }
}

/* Terminal Shell Setup */
.terminal-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  max-width: 1600px;
  max-height: 950px;
  border: 1px solid var(--terminal-border);
  background-color: var(--terminal-bg);
  box-shadow: 0 0 20px var(--glow-color);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

/* Header Section */
.terminal-header {
  height: 32px;
  border-bottom: 1px solid var(--terminal-border);
  background: rgba(10, 20, 10, 0.4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  user-select: none;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--font-color);
  box-shadow: 0 0 6px var(--font-color);
}

.header-title {
  font-size: 13px;
  letter-spacing: 0.5px;
  opacity: 0.85;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-time {
  font-size: 13px;
  opacity: 0.75;
  margin-right: 15px;
}

.win-btn {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid var(--terminal-border);
  background: transparent;
  cursor: pointer;
}
.win-btn.close { background: rgba(255, 17, 68, 0.4); }
.win-btn.max { background: rgba(255, 170, 0, 0.4); }
.win-btn.min { background: rgba(51, 255, 51, 0.4); }

/* Main split */
.terminal-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  border-bottom: 1px solid var(--terminal-border);
}

/* Sidebar Styling */
.terminal-sidebar {
  width: 280px;
  border-right: 1px solid var(--terminal-border);
  background: rgba(5, 8, 5, 0.6);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.brand-section {
  padding: 15px;
  border-bottom: 1px dashed var(--terminal-border);
}

.brand-logo {
  font-family: monospace;
  font-size: 8px;
  line-height: 1.1;
  color: var(--font-color);
}

.brand-subtitle {
  font-size: 12px;
  text-align: right;
  opacity: 0.65;
  margin-top: 5px;
  font-style: italic;
}

.sidebar-heading {
  padding: 8px 15px;
  background: rgba(34, 85, 34, 0.15);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--font-color);
  opacity: 0.75;
  border-bottom: 1px solid var(--terminal-border);
}

.nav-section {
  border-bottom: 1px dashed var(--terminal-border);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
}

.nav-item {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(34, 85, 34, 0.2);
  color: var(--font-color);
  text-align: left;
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  gap: 8px;
  transition: all 0.2s ease;
}

.nav-item:hover {
  background: rgba(34, 85, 34, 0.1);
  padding-left: 25px;
}

.nav-item.active {
  background: rgba(34, 85, 34, 0.25);
  border-left: 3px solid var(--font-color);
  padding-left: 22px;
  font-weight: bold;
}

.nav-num {
  opacity: 0.5;
}

.diagnostics-section {
  padding: 15px;
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.diag-grid {
  display: grid;
  grid-template-columns: 100px 1fr;
  row-gap: 8px;
  column-gap: 5px;
}

.diag-label {
  opacity: 0.6;
}

.diag-val {
  font-weight: bold;
}

.value-warning { color: var(--warn-color); text-shadow: 0 0 4px var(--warn-color); }
.value-danger { color: var(--error-color); text-shadow: 0 0 4px var(--red-glow-color); }
.value-link { color: var(--info-color); text-shadow: 0 0 4px var(--cyan-glow-color); cursor: pointer; }

.diag-bar-container {
  margin-top: 8px;
}

.diag-bar-label {
  display: flex;
  justify-content: space-between;
  opacity: 0.6;
  margin-bottom: 4px;
}

.diag-bar {
  height: 6px;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--terminal-border);
  border-radius: 3px;
  overflow: hidden;
}

.diag-bar-fill {
  height: 100%;
  background-color: var(--font-color);
  box-shadow: 0 0 5px var(--font-color);
}

.diag-bar-fill.alert-blink {
  animation: pulse-glow 1.5s infinite ease-in-out;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 0.7; }
  50% { opacity: 1; }
}

.alert-blink {
  animation: blinker 1.2s cubic-bezier(.5, 0, 1, 1) infinite alternate;
}

@keyframes blinker {
  from { opacity: 1; }
  to { opacity: 0.15; }
}

/* Viewport Shell Main Content */
.terminal-main {
  flex: 1;
  background: rgba(5, 5, 5, 0.7);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.tab-view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  padding: 15px;
}

.tab-view.active {
  display: flex;
}

/* View 1: Live Console Settings */
.console-controls {
  display: flex;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--terminal-border);
  margin-bottom: 15px;
  align-items: center;
  user-select: none;
}

.btn {
  background: rgba(10, 30, 10, 0.6);
  border: 1px solid var(--terminal-border);
  color: var(--font-color);
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  border-radius: 2px;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--font-color);
  color: #000;
  box-shadow: 0 0 8px var(--font-color);
}

.btn:active {
  transform: translateY(1px);
}

.btn-sm {
  padding: 3px 8px;
  font-size: 12px;
}

.btn-danger {
  border-color: var(--error-color);
  color: var(--error-color);
  background: rgba(30, 5, 5, 0.6);
}

.btn-danger:hover {
  background: var(--error-color);
  color: #000;
  box-shadow: 0 0 8px var(--error-color);
}

.btn-group {
  display: flex;
  border: 1px solid var(--terminal-border);
  border-radius: 2px;
}

.btn-group .btn {
  border: none;
  border-right: 1px solid var(--terminal-border);
  border-radius: 0;
}

.btn-group .btn:last-child {
  border-right: none;
}

.btn-group .btn.active {
  background: var(--font-color);
  color: #000;
}

/* Console Screen Buffer */
.terminal-screen-buffer {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 15px;
  font-size: 14px;
  line-height: 1.5;
  scroll-behavior: smooth;
}

/* Chat Entry Styling */
.chat-entry {
  border-left: 2px solid var(--terminal-border);
  padding-left: 10px;
  margin-bottom: 5px;
  animation: fade-in-line 0.2s ease-out;
}

/* Gnosis Supreme Dialogue Formatting */
.chat-entry-gnosis {
  font-size: 15.5px !important;
  border-left: 2px solid #ffffff !important;
  color: #ffffff !important;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.45) !important;
  margin-bottom: 18px !important;
}

/* Subordinate AIs Indented & Dimmed Dialogue Formatting */
.chat-entry-subordinate {
  font-size: 13px !important;
  margin-left: 24px !important;
  opacity: 0.65 !important;
  border-left: 2px solid rgba(255, 102, 0, 0.35) !important;
  margin-bottom: 12px !important;
}

@keyframes fade-in-line {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-sender {
  font-weight: bold;
  margin-bottom: 4px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
}

.sender-gnosis {
  color: var(--font-color);
}

.sender-truth {
  color: var(--info-color);
  text-shadow: 0 0 4px var(--cyan-glow-color);
}

.sender-user {
  color: var(--warn-color);
  text-shadow: 0 0 4px rgba(255, 170, 0, 0.3);
}

.entry-timestamp {
  font-size: 11px;
  opacity: 0.5;
}

/* Thoughts blocks */
.thought-block {
  color: var(--thought-color);
  font-style: italic;
  opacity: 0.75;
  background: rgba(30, 40, 30, 0.15);
  border-left: 2px solid rgba(102, 136, 102, 0.3);
  padding: 5px 8px;
  margin-bottom: 6px;
  font-size: 13px;
  border-radius: 2px;
}

.thought-header {
  font-size: 10px;
  letter-spacing: 1px;
  opacity: 0.5;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.text-content {
  white-space: pre-wrap;
  word-wrap: break-word;
}

.glitch-text {
  animation: text-glitch-anim 0.4s ease infinite;
}

@keyframes text-glitch-anim {
  0% { transform: skew(0deg); }
  20% { transform: skew(2deg); filter: contrast(1.5); }
  40% { transform: skew(-2deg); }
  60% { transform: skew(0deg); }
  80% { transform: skew(5deg) scaleY(0.9); }
  100% { transform: skew(0deg); }
}

/* View 2: Archived Logs Pane */
.logs-container {
  display: flex;
  flex: 1;
  overflow: hidden;
  border: 1px solid var(--terminal-border);
  border-radius: 2px;
}

.logs-sidebar {
  width: 220px;
  border-right: 1px solid var(--terminal-border);
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
}

.logs-title {
  padding: 10px;
  border-bottom: 1px solid var(--terminal-border);
  font-size: 12px;
  font-weight: bold;
  opacity: 0.8;
  letter-spacing: 0.5px;
}

.logs-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.log-item {
  padding: 10px;
  border-bottom: 1px solid rgba(34, 85, 34, 0.15);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-item:hover {
  background: rgba(34, 85, 34, 0.15);
}

.log-item.active {
  background: rgba(34, 85, 34, 0.3);
  border-left: 2px solid var(--font-color);
  font-weight: bold;
}

.logs-content-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.log-file-header {
  padding: 10px;
  border-bottom: 1px solid var(--terminal-border);
  background: rgba(10, 20, 10, 0.2);
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.file-name {
  font-weight: bold;
}

.file-size {
  opacity: 0.5;
}

.log-file-viewer {
  flex: 1;
  overflow-y: auto;
  padding: 15px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* View 3: Ritual Ledger (Quests) */
.rituals-header {
  margin-bottom: 15px;
}

.rituals-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 4px;
}

.rituals-subtitle {
  font-size: 12px;
  opacity: 0.65;
}

.rituals-table-wrapper {
  flex: 1;
  overflow-y: auto;
  border: 1px solid var(--terminal-border);
  border-radius: 2px;
}

.rituals-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.rituals-table th, .rituals-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(34, 85, 34, 0.2);
  vertical-align: top;
}

.rituals-table th {
  background: rgba(34, 85, 34, 0.15);
  font-weight: bold;
  border-bottom: 1px solid var(--terminal-border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.rituals-table tr:hover {
  background: rgba(34, 85, 34, 0.05);
}

.difficulty-badge {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: bold;
  border-radius: 2px;
  border: 1px solid;
}
.diff-easy { border-color: var(--font-color); color: var(--font-color); }
.diff-medium { border-color: var(--warn-color); color: var(--warn-color); }
.diff-hard { border-color: var(--error-color); color: var(--error-color); }
.diff-epic { background: var(--error-color); color: #000; border-color: var(--error-color); }
.diff-legendary { background: #fff; color: #000; border-color: #fff; text-shadow: none; animation: alert-blink 0.5s infinite; }

.status-badge {
  display: inline-block;
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.4);
}
.status-open { color: var(--font-color); border: 1px solid var(--font-color); }
.status-closed { color: #555555; border: 1px solid #333333; }

/* View 4: System Prompt Configuration */
.prompt-header {
  margin-bottom: 15px;
}

.prompt-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 4px;
}

.prompt-subtitle {
  font-size: 12px;
  opacity: 0.65;
}

.prompt-code-container {
  flex: 1;
  border: 1px solid var(--terminal-border);
  border-radius: 2px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.4);
}

.prompt-code {
  padding: 15px;
  overflow-y: auto;
  height: 100%;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
  color: var(--thought-color);
}

/* Footer Section */
.terminal-footer {
  border-top: 1px solid var(--terminal-border);
  background: rgba(5, 5, 5, 0.85);
  display: flex;
  flex-direction: column;
}

.cli-row {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
}

.cli-prompt {
  font-size: 14px;
  font-weight: bold;
  color: var(--font-color);
  user-select: none;
}

.cli-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--font-color);
  font-size: 14px;
}

.cli-status-strip {
  height: 24px;
  background: rgba(10, 20, 10, 0.5);
  border-top: 1px solid var(--terminal-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 12px;
  font-size: 11px;
  user-select: none;
  opacity: 0.8;
}

.status-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.font-red {
  color: var(--error-color);
  text-shadow: 0 0 4px var(--red-glow-color);
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.15);
}

::-webkit-scrollbar-thumb {
  background: var(--terminal-border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--font-color);
}

/* Split Layout for Console & Concept Graph */
.console-split-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  gap: 15px;
}

.console-left {
  flex: 1.1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.console-right {
  flex: 0.9;
  display: flex;
  flex-direction: column;
  border-left: 1px dashed var(--terminal-border);
  padding-left: 15px;
  overflow: hidden;
}

.graph-container-box {
  display: flex;
  flex-direction: column;
  flex: 1;
  border: 1px solid var(--terminal-border);
  background: rgba(0, 0, 0, 0.4);
  border-radius: 2px;
  overflow: hidden;
}

.graph-header {
  padding: 6px;
  border-bottom: 1px solid var(--terminal-border);
  background: rgba(34, 85, 34, 0.15);
  font-size: 11px;
  text-align: center;
  letter-spacing: 1px;
  opacity: 0.8;
}

.graph-footer {
  padding: 6px;
  border-top: 1px solid var(--terminal-border);
  font-size: 10px;
  text-align: center;
  opacity: 0.5;
  background: rgba(10, 20, 10, 0.2);
}

#concept-graph-canvas {
  flex: 1;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

/* Mobile responsive fixes */
@media (max-width: 800px) {
  .terminal-body {
    flex-direction: column;
  }
  .terminal-sidebar {
    width: 100%;
    height: 180px;
    border-right: none;
    border-bottom: 1px solid var(--terminal-border);
  }
  .brand-logo {
    display: none;
  }
  .brand-section {
    padding: 8px;
  }
  .console-split-layout {
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
  }
  .console-right {
    border-left: none;
    padding-left: 0;
    border-top: 1px dashed var(--terminal-border);
    padding-top: 10px;
    height: 220px;
    flex: none;
  }
}
