/* ============================================================
   BY THE TIME YOU GOT HERE — style.css
   Aesthetic: Minimal Forensic / Terminal Elegy
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400;1,700&display=swap');

/* ── CSS Variables ─────────────────────────────────────── */
:root {
  --bg:            #000000;
  --fg:            #c4c4b8;          /* slightly decayed off-white */
  --fg-dim:        #5a5a52;          /* ghost text */
  --fg-ghost:      #2e2e28;          /* near-invisible */
  --accent:        #e8e0cc;          /* warm parchment — one accent only */
  --drawer-bg:     rgba(0, 0, 0, 0.72);
  --drawer-border: rgba(255, 255, 255, 0.06);
  --status-ok:     #4a7c59;
  --status-dim:    #3a3a32;
  --mono:          'Courier Prime', 'Courier New', Courier, monospace;
  --drawer-width:  420px;
  --transition:    0.48s cubic-bezier(0.16, 1, 0.3, 1);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;          /* lock the viewport — drawer never shifts layout */
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.02em;
  -webkit-font-smoothing: antialiased;
}

/* ── Layer 0 — Full-Screen Background ───────────────────── */
#background-stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

/* Placeholder gradient — simulates "AWAITING INPUT" state */
#bg-gradient {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 30% 40%, rgba(28, 28, 22, 0.9) 0%, transparent 70%),
    radial-gradient(ellipse 60% 80% at 70% 60%, rgba(18, 18, 14, 0.95) 0%, transparent 70%),
    linear-gradient(160deg, #0a0a08 0%, #111110 40%, #0d0d0b 100%);
  animation: breathe 12s ease-in-out infinite alternate;
}

@keyframes breathe {
  0%   { opacity: 0.85; }
  100% { opacity: 1; }
}

/* Noise / grain overlay for texture */
#bg-gradient::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  background-size: 256px 256px;
  opacity: 0.35;
  pointer-events: none;
}

/* WebRTC video — hidden until stream is live */
#live-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transition: opacity 1.2s ease;
}

#live-video.active {
  opacity: 1;
}

/* Subtle scan-line overlay */
#scanlines {
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.03) 2px,
    rgba(0, 0, 0, 0.03) 4px
  );
  pointer-events: none;
  z-index: 1;
}

/* ── Layer 1 — Interface ────────────────────────────────── */
#interface {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;  /* pass clicks through by default */
}

/* ── Trigger — Drawer Opener ────────────────────────────── */
#drawer-trigger {
  position: fixed;
  top: 50%;
  left: 0;
  transform: translateY(-50%);
  z-index: 20;
  pointer-events: all;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 16px 16px;
  background: transparent;
  border: none;
  outline: none;
  transition: opacity var(--transition);
  opacity: 0.4;
}

#drawer-trigger:hover {
  opacity: 1;
}

/* The thin vertical line */
#trigger-line {
  width: 1px;
  height: 64px;
  background: linear-gradient(to bottom, transparent, var(--fg-dim) 30%, var(--fg-dim) 70%, transparent);
  transition: background var(--transition), height var(--transition);
}

#drawer-trigger:hover #trigger-line,
#drawer-trigger[aria-expanded="true"] #trigger-line {
  height: 80px;
  background: linear-gradient(to bottom, transparent, var(--accent) 30%, var(--accent) 70%, transparent);
}

#trigger-label {
  writing-mode: vertical-lr;
  text-orientation: mixed;
  font-size: 9px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--fg-dim);
  transition: color var(--transition);
  user-select: none;
}

#drawer-trigger:hover #trigger-label,
#drawer-trigger[aria-expanded="true"] #trigger-label {
  color: var(--accent);
}

/* ── Memory Drawer ──────────────────────────────────────── */
#memory-drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--drawer-width);
  height: 100%;
  z-index: 15;
  pointer-events: none;

  /* Glassmorphism */
  background: var(--drawer-bg);
  backdrop-filter: blur(14px) saturate(0.7);
  -webkit-backdrop-filter: blur(14px) saturate(0.7);
  border-right: 1px solid var(--drawer-border);

  display: flex;
  flex-direction: column;

  /* Hidden state — translate left off screen */
  transform: translateX(-100%);
  transition: transform var(--transition);

  overflow: hidden;
}

#memory-drawer.open {
  transform: translateX(0);
  pointer-events: all;
}

/* Drawer header */
#drawer-header {
  padding: 32px 28px 20px;
  border-bottom: 1px solid var(--drawer-border);
  flex-shrink: 0;
}

#drawer-title {
  font-size: 9px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 6px;
}

#drawer-subtitle {
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--fg);
  line-height: 1.4;
}

#drawer-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: var(--fg-dim);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  cursor: pointer;
  padding: 6px 8px;
  transition: color var(--transition);
}

#drawer-close:hover {
  color: var(--accent);
}

/* Phase marker */
#phase-marker {
  padding: 12px 28px;
  border-bottom: 1px solid var(--drawer-border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#phase-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--status-ok);
  box-shadow: 0 0 6px var(--status-ok);
  animation: pulse-dot 3s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.3; }
}

#phase-label {
  font-size: 9px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

/* Memory log scroll area */
#memory-log {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
  scroll-behavior: smooth;
}

/* Custom scrollbar */
#memory-log::-webkit-scrollbar {
  width: 2px;
}
#memory-log::-webkit-scrollbar-track {
  background: transparent;
}
#memory-log::-webkit-scrollbar-thumb {
  background: var(--fg-ghost);
}

/* Individual memory entry */
.memory-entry {
  padding: 18px 28px;
  border-bottom: 1px solid var(--drawer-border);
  cursor: default;
  transition: background 0.2s ease;
  opacity: 0;
  transform: translateY(6px);
  animation: entry-in 0.4s ease forwards;
}

.memory-entry:hover {
  background: rgba(255, 255, 255, 0.02);
}

@keyframes entry-in {
  to { opacity: 1; transform: translateY(0); }
}

.memory-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.memory-id {
  font-size: 8px;
  letter-spacing: 0.2em;
  color: var(--fg-ghost);
}

.memory-date {
  font-size: 8px;
  letter-spacing: 0.12em;
  color: var(--fg-dim);
}

.memory-status {
  margin-left: auto;
  font-size: 7px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--status-dim);
  border: 1px solid var(--fg-ghost);
  padding: 2px 6px;
}

.memory-text {
  font-size: 13.5px;
  line-height: 1.78;
  color: var(--fg);
  font-weight: 400;   /* Courier Prime has no 300 weight — 400 italic is the refined read */
  font-style: italic;
  letter-spacing: 0.01em;
}

/* Empty state */
#memory-empty {
  padding: 40px 28px;
  font-size: 10px;
  color: var(--fg-ghost);
  line-height: 2;
  letter-spacing: 0.06em;
  display: none;
}

/* Drawer footer — loading state */
#drawer-footer {
  padding: 16px 28px;
  border-top: 1px solid var(--drawer-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

#entry-count {
  font-size: 8px;
  letter-spacing: 0.14em;
  color: var(--fg-dim);
}

#load-more {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--fg-dim);
  background: none;
  border: 1px solid var(--fg-ghost);
  padding: 5px 10px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s;
}

#load-more:hover {
  color: var(--accent);
  border-color: var(--fg-dim);
}

/* ── Status Bar — Bottom Right ──────────────────────────── */
#status-bar {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  pointer-events: none;
}

#utc-clock {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
}

#system-status {
  font-size: 8px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--fg-ghost);
}

/* ── Project Title — Top Left ───────────────────────────── */
#project-id {
  position: fixed;
  top: 28px;
  left: 28px;
  z-index: 20;
  pointer-events: none;
}

#project-name {
  font-size: 9px;
  letter-spacing: 0.26em;
  text-transform: uppercase;
  color: var(--fg-dim);
  margin-bottom: 2px;
}

#project-artist {
  font-size: 8px;
  letter-spacing: 0.16em;
  color: var(--fg-ghost);
}

/* ── Awaiting Input Overlay ─────────────────────────────── */
#await-overlay {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  pointer-events: none;
  transition: opacity 1.5s ease;
}

#await-text {
  font-size: 10px;
  letter-spacing: 0.36em;
  text-transform: uppercase;
  color: var(--fg-ghost);
  animation: blink-slow 4s ease-in-out infinite;
}

@keyframes blink-slow {
  0%, 100% { opacity: 0.4; }
  50%       { opacity: 0.9; }
}

#await-sub {
  font-size: 8px;
  letter-spacing: 0.2em;
  color: var(--fg-ghost);
  opacity: 0.5;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 540px) {
  :root {
    --drawer-width: 100vw;
  }

  #memory-drawer {
    border-right: none;
    border-top: 1px solid var(--drawer-border);
    width: 100vw;
    height: 80vh;
    top: auto;
    bottom: 0;
    left: 0;
    transform: translateY(100%);
    border-radius: 0;
  }

  #memory-drawer.open {
    transform: translateY(0);
  }

  #drawer-trigger {
    top: auto;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    flex-direction: column;
    padding: 12px 20px 16px;
    gap: 8px;
  }

  #trigger-line {
    width: 40px;
    height: 1px;
    background: linear-gradient(to right, transparent, var(--fg-dim) 30%, var(--fg-dim) 70%, transparent);
  }

  #drawer-trigger:hover #trigger-line,
  #drawer-trigger[aria-expanded="true"] #trigger-line {
    width: 60px;
    height: 1px;
  }

  #trigger-label {
    writing-mode: horizontal-tb;
  }

  #project-id {
    top: 20px;
    left: 20px;
  }

  #status-bar {
    bottom: 20px;
    right: 20px;
  }
}

/* ── Reduced Motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #bg-gradient { animation: none; }
  #phase-dot   { animation: none; }
  #await-text  { animation: none; opacity: 0.6; }
  .memory-entry { animation: none; opacity: 1; transform: none; }
}
