@import url('https://fonts.googleapis.com/css2?family=Share+Tech+Mono&display=swap');

:root {
  --phosphor: #00FF41;
  --phosphor-dim: #008f24;
  --phosphor-dark: #004d13;
  --substrate: #0a0e0a;
  --substrate-light: #1a241a;
  --border-hard: #00FF41;
  --rust: #8f4400;
  --rust-bright: #c4652a;
  --breach: #ff2020;
  --snare: #ffaa00;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-font-smoothing: none;
  -moz-osx-font-smoothing: none;
  text-rendering: geometricPrecision;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--substrate);
  color: var(--phosphor);
  font-family: 'Share Tech Mono', 'Lucida Console', 'Courier New', monospace;
  font-size: 14px;
  letter-spacing: 12px;
}

/* Scanline overlay */
body::after {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.08) 0px,
    rgba(0, 0, 0, 0.08) 1px,
    transparent 1px,
    transparent 3px
  );
}

#terminal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--substrate);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.overlay-ascii {
  color: var(--phosphor);
  font-size: 13px;
  line-height: 1.3;
  text-shadow: 0 0 8px var(--phosphor-dim);
}

#terminal {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  padding: 8px;
  gap: 4px;
}

#header-bar {
  display: flex;
  justify-content: space-between;
  padding: 6px 12px;
  border: 1px solid var(--border-hard);
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 2px;
  text-shadow: 0 0 6px var(--phosphor-dim);
  background: var(--substrate-light);
}

#main-display {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 4px;
  flex: 1;
  min-height: 0;
}

.panel {
  border: 1px solid var(--border-hard);
  background: var(--substrate);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-hard);
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 2px;
  text-transform: uppercase;
  background: var(--substrate-light);
  color: var(--phosphor);
}

canvas {
  width: 100%;
  height: 100%;
  flex: 1;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#readout-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 4px;
  flex: 1;
  overflow: hidden;
}

.readout-cell {
  border: 1px solid var(--phosphor-dark);
  padding: 3px 5px;
  font-size: 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.readout-cell .node-label {
  color: var(--phosphor-dim);
  font-size: 9px;
}

.readout-cell .node-weight {
  color: var(--phosphor);
  font-size: 12px;
  font-weight: bold;
}

.readout-cell.rust-decay .node-weight {
  color: var(--rust-bright);
}

.readout-cell.breach .node-weight {
  color: var(--breach);
}

#integrity-panel {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: 4px 8px;
  gap: 12px;
}

#integrity-panel .panel-header {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

#integrity-bar-container {
  flex: 1;
  height: 16px;
  border: 1px solid var(--border-hard);
  background: var(--substrate);
  overflow: hidden;
}

#integrity-bar {
  width: 100%;
  height: 100%;
  background: var(--phosphor);
  transition: none;
}

#integrity-bar.cascade {
  background: var(--breach);
}

#cascade-readout {
  font-size: 11px;
  letter-spacing: 1px;
  white-space: nowrap;
  min-width: 220px;
}

#command-bar {
  padding: 6px 12px;
  border: 1px solid var(--border-hard);
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--phosphor-dim);
  background: var(--substrate-light);
}

#command-bar kbd {
  display: inline-block;
  padding: 1px 5px;
  border: 1px solid var(--phosphor-dim);
  color: var(--phosphor);
  font-family: inherit;
  font-size: 10px;
  background: var(--substrate);
}

#log-panel {
  height: 120px;
  border: 1px solid var(--border-hard);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#log-output {
  flex: 1;
  overflow-y: hidden;
  padding: 4px 8px;
  font-size: 10px;
  line-height: 1.4;
  color: var(--phosphor-dim);
}

.log-line {
  margin-bottom: 1px;
}

.log-line.breach {
  color: var(--breach);
}

.log-line.snare {
  color: var(--snare);
}

.log-line.blackout {
  color: #666;
  text-decoration: line-through;
}

/* Blackout state */
#terminal.blackout {
  opacity: 0.3;
}

#terminal.blackout #main-display {
  opacity: 0;
}

#terminal.blackout #header-bar {
  color: #333;
  border-color: #333;
}

/* Stencil bleed - geometric erosion effect */
@keyframes stencil-bleed {
  0% { clip-path: inset(0 0 0 0); }
  25% { clip-path: inset(2px 0 0 3px); }
  50% { clip-path: inset(0 2px 1px 0); }
  75% { clip-path: inset(1px 0 2px 0); }
  100% { clip-path: inset(0 0 0 0); }
}

#terminal.stencil-active .readout-cell {
  animation: stencil-bleed 0.4s steps(4) infinite;
}

/* Cascade mode - frantic */
@keyframes cascade-pulse {
  0%, 100% { border-color: var(--breach); }
  50% { border-color: var(--phosphor); }
}

#terminal.cascade-active canvas,
#terminal.cascade-active .panel {
  animation: cascade-pulse 0.11s steps(2) infinite;
}

/* Breach state */
@keyframes breach-flash {
  0% { color: var(--phosphor); }
  50% { color: var(--breach); text-shadow: 0 0 12px var(--breach); }
  100% { color: var(--phosphor); }
}

#terminal.breach-active #status {
  animation: breach-flash 0.22s steps(2) infinite;
}

/* Responsive: compress kerning if rasterization fails */
@media (max-width: 900px) {
  body { letter-spacing: 4px; }
  #main-display {
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }
  #integrity-panel { grid-column: 1; }
}
