/* === RESET & BASE === */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --primary: #c8c0b0;
  --primary-dim: #6b6560;
  --primary-dark: #2a2725;
  --accent: #d4a857;
  --accent-dim: #8a7340;
  --red-glitch: #8b2030;
  --bg: #0d0c0b;
  --text: #c8c0b0;
  --text-secondary: #7a7368;
  --scanline: rgba(0, 0, 0, 0.15);
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Courier New', Consolas, monospace;
  font-size: 15px;
  line-height: 1.7;
  min-height: 100vh;
  overflow-x: hidden;
}

/* === BACKGROUND === */
.bg-layer {
  position: fixed;
  top: -10%;
  left: -10%;
  width: 120%;
  height: 120%;
  background: url('bg.jpg') center/cover no-repeat;
  filter: brightness(0.35) saturate(0.6);
  z-index: -3;
  will-change: transform;
}

/* === CRT SCANLINES === */
.scanlines {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    var(--scanline) 3px,
    var(--scanline) 4px
  );
  pointer-events: none;
  z-index: 9998;
}

/* === CRT FLICKER (controlled by JS) === */
.crt-flicker {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 9997;
  opacity: 0;
  background: white;
  transition: none;
}

/* === VIGNETTE === */
.bg-layer::after {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: radial-gradient(ellipse at center, transparent 40%, rgba(0,0,0,0.7) 100%);
}

/* === MAIN CONTAINER === */
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 40px 20px;
  position: relative;
  z-index: 1;
}

/* === HEADER === */
.header {
  margin-bottom: 40px;
  border-bottom: 1px solid var(--primary-dark);
  padding-bottom: 20px;
}

.header-path {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 8px;
}

.header-title {
  font-size: 22px;
  font-weight: normal;
  color: var(--accent);
  position: relative;
  display: inline-block;
}

.header-title .cursor {
  display: inline-block;
  width: 10px;
  height: 1.1em;
  background: var(--accent);
  margin-left: 4px;
  animation: blink 1s step-end infinite;
  vertical-align: text-bottom;
}

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

/* === GLITCH EFFECT === */
.glitch {
  position: relative;
}

.glitch::before,
.glitch::after {
  content: attr(data-text);
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
}

.glitch.active::before {
  animation: glitch-1 0.3s linear;
  color: var(--red-glitch);
  z-index: -1;
}

.glitch.active::after {
  animation: glitch-2 0.3s linear;
  color: rgba(100, 140, 160, 0.6);
  z-index: -2;
}

@keyframes glitch-1 {
  0% { opacity: 0; transform: translate(0); }
  20% { opacity: 0.6; transform: translate(-3px, 2px); clip-path: inset(20% 0 60% 0); }
  40% { opacity: 0.6; transform: translate(3px, -1px); clip-path: inset(50% 0 20% 0); }
  60% { opacity: 0.6; transform: translate(-2px, 1px); clip-path: inset(10% 0 70% 0); }
  80% { opacity: 0.6; transform: translate(2px, -2px); clip-path: inset(70% 0 5% 0); }
  100% { opacity: 0; transform: translate(0); }
}

@keyframes glitch-2 {
  0% { opacity: 0; transform: translate(0); }
  20% { opacity: 0.4; transform: translate(3px, -2px); clip-path: inset(60% 0 10% 0); }
  40% { opacity: 0.4; transform: translate(-3px, 1px); clip-path: inset(30% 0 40% 0); }
  60% { opacity: 0.4; transform: translate(2px, -1px); clip-path: inset(80% 0 5% 0); }
  80% { opacity: 0.4; transform: translate(-2px, 2px); clip-path: inset(5% 0 80% 0); }
  100% { opacity: 0; transform: translate(0); }
}

/* === FILE LISTING (INDEX) === */
.file-listing {
  width: 100%;
}

.file-listing-header {
  color: var(--text-secondary);
  font-size: 13px;
  padding: 8px 0;
  border-bottom: 1px solid var(--primary-dark);
  display: grid;
  grid-template-columns: 120px 100px 60px 1fr;
  gap: 12px;
}

.file-row {
  display: grid;
  grid-template-columns: 120px 100px 60px 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(200, 192, 176, 0.06);
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s;
  cursor: pointer;
  position: relative;
}

.file-row:hover {
  background: rgba(200, 192, 176, 0.06);
}

.file-row .perms { color: var(--text-secondary); font-size: 13px; }
.file-row .date { color: var(--text-secondary); }
.file-row .size { color: var(--text-secondary); text-align: right; }
.file-row .name { color: var(--text); }
.file-row .name .doc-num { color: var(--accent-dim); }

/* Row glitch on hover */
.file-row.row-glitch {
  animation: row-glitch 0.15s linear;
}

@keyframes row-glitch {
  0% { transform: translate(0); }
  25% { transform: translate(-2px, 0); filter: hue-rotate(40deg); }
  50% { transform: translate(1px, 0); }
  75% { transform: translate(-1px, 0); filter: hue-rotate(-40deg); }
  100% { transform: translate(0); filter: none; }
}

/* === AUDIO CONTROLS === */
.audio-control {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  background: rgba(200, 192, 176, 0.06);
  border: 1px solid var(--primary-dark);
  color: var(--text-secondary);
  padding: 10px 16px;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.audio-control:hover {
  background: rgba(200, 192, 176, 0.1);
  border-color: var(--primary-dim);
  color: var(--text);
}

.audio-control.playing {
  animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { border-color: var(--primary-dark); box-shadow: none; }
  50% { border-color: var(--accent-dim); box-shadow: 0 0 15px rgba(212, 168, 87, 0.1); }
}

/* === NOTE PAGE === */
.note-header {
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid var(--primary-dark);
}

.note-meta {
  color: var(--text-secondary);
  font-size: 13px;
  margin-bottom: 4px;
}

.note-title {
  font-size: 18px;
  font-weight: normal;
  color: var(--accent);
}

.note-body {
  line-height: 1.9;
  max-width: 700px;
}

.note-body .separator {
  color: var(--primary-dark);
  text-align: center;
  margin: 20px 0;
  letter-spacing: 8px;
}

.note-body .testimony {
  color: var(--text);
  padding-left: 20px;
  border-left: 2px solid var(--accent-dim);
  margin: 16px 0;
}

.note-body .footnote {
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
  margin-top: 20px;
}

/* Photographic attachment inside a note */
.note-photo {
  margin: 28px 0 10px;
  border: 1px solid var(--primary-dark);
  padding: 10px;
  background: rgba(0, 0, 0, 0.25);
}

.note-photo img {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  filter: brightness(0.78) saturate(0.55) contrast(1.05);
  transition: filter 0.4s;
}

.note-photo:hover img {
  filter: brightness(0.95) saturate(0.8) contrast(1.02);
}

.note-photo figcaption {
  color: var(--text-secondary);
  font-size: 12px;
  letter-spacing: 1px;
  margin-top: 10px;
}

/* Typewriter cursor for note content */
.typewriter-cursor {
  display: inline-block;
  width: 8px;
  height: 1em;
  background: var(--accent);
  animation: blink 0.7s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

/* === NAVIGATION === */
.note-nav {
  margin-top: 50px;
  padding-top: 20px;
  padding-bottom: 60px;
  border-top: 1px solid var(--primary-dark);
  display: flex;
  justify-content: space-between;
  font-size: 14px;
}

.note-nav a {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.note-nav a:hover {
  color: var(--accent);
}

/* === RANDOM GLITCH OVERLAY === */
.glitch-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 9999;
  opacity: 0;
}

.glitch-overlay.active {
  animation: screen-glitch 0.4s linear;
}

@keyframes screen-glitch {
  0% { opacity: 0; }
  10% { opacity: 1; background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    rgba(200, 192, 176, 0.02) 2px,
    transparent 4px
  ); transform: translate(5px, 0) skewX(2deg); }
  20% { transform: translate(-3px, 0) skewX(-1deg); }
  30% { opacity: 1; transform: translate(0, 2px); background: rgba(139, 32, 48, 0.04); }
  40% { transform: translate(2px, -1px) skewX(1deg); }
  60% { opacity: 0.5; transform: translate(-1px, 0); }
  100% { opacity: 0; transform: translate(0); }
}

/* === RESPONSIVE === */
@media (max-width: 600px) {
  .container { padding: 20px 12px; }
  .file-listing-header,
  .file-row {
    grid-template-columns: 1fr;
    gap: 2px;
  }
  .file-row .perms,
  .file-listing-header span:first-child { display: none; }
  .file-row .size { text-align: left; }
  body { font-size: 13px; }
}
