:root {
  --bg:     #000000;
  --text:   #f0ede8;
  --accent: #8b0000;
  --dim:    rgba(240, 237, 232, 0.30);
  --sidebar-w: 260px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  overflow: hidden;
}

/* Noise grain */
.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 1000;
  opacity: 0.045;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 180px 180px;
}

/* Layout */
.terminal {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  border-right: 1px solid rgba(240,237,232,0.08);
  display: flex;
  flex-direction: column;
  padding-top: 52px;
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 26px 22px;
  border-bottom: 1px solid rgba(240,237,232,0.07);
  margin-bottom: 10px;
}

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(240,237,232,0.35);
  flex-shrink: 0;
}

.partition-label {
  font-size: 10px;
  letter-spacing: 0.13em;
  color: rgba(240,237,232,0.35);
  text-transform: lowercase;
}

.file-list {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px 9px 24px;
  cursor: pointer;
  transition: background 0.1s;
}

.file-item:hover { background: rgba(240,237,232,0.05); }

.file-item.active {
  background: rgba(240,237,232,0.88);
}

/* Folder icon */
.ico {
  display: inline-block;
  flex-shrink: 0;
  position: relative;
}

.ico-folder {
  width: 15px;
  height: 11px;
  background: rgba(240,237,232,0.28);
  border-radius: 0 2px 2px 2px;
}

.ico-folder::before {
  content: '';
  position: absolute;
  top: -3px;
  left: 0;
  width: 6px;
  height: 4px;
  background: rgba(240,237,232,0.28);
  border-radius: 1px 2px 0 0;
}

/* Document icon */
.ico-doc {
  width: 12px;
  height: 14px;
  background: rgba(240,237,232,0.28);
  border-radius: 1px 1px 1px 1px;
}

.ico-doc::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 4px 4px 0;
  border-color: transparent var(--bg) var(--bg) transparent;
}

/* Active item: icon becomes dark */
.file-item.active .ico-folder,
.file-item.active .ico-folder::before,
.file-item.active .ico-doc {
  background: rgba(0,0,0,0.35);
}

.file-item.active .ico-doc::before {
  border-color: transparent rgba(240,237,232,0.88) rgba(240,237,232,0.88) transparent;
}

.file-name {
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--dim);
  transition: color 0.1s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item:hover .file-name { color: var(--text); }
.file-item.active .file-name { color: #111; }

.tag-deleted {
  font-size: 9px;
  color: rgba(139,0,0,0.5);
  letter-spacing: 0.08em;
}

.file-item.active .tag-deleted { color: rgba(139,0,0,0.6); }

/* Content panel */
.panel {
  flex: 1;
  overflow-y: auto;
  display: flex;
  padding: 60px 64px;
}

.panel-inner {
  width: 100%;
  max-width: 660px;
}

/* Content types */
.prompt-text {
  font-size: 12px;
  color: var(--dim);
  letter-spacing: 0.15em;
}

.deleted-text {
  font-size: 12px;
  color: rgba(240,237,232,0.45);
  letter-spacing: 0.13em;
}
.deleted-text::before { content: '> '; }

.file-img {
  display: block;
  width: 100%;
  height: auto;
}

/* Carousel (folder 01) */
.carousel { width: 100%; }
.car-viewport {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.car-viewport::-webkit-scrollbar { display: none; }
.car-track {
  display: flex;
  -webkit-touch-callout: none;
}
.car-slide {
  flex: 0 0 100%;
  min-width: 0;
  display: flex;
  justify-content: center;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
.car-img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 200px);
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.car-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.6rem;
  margin-top: 1.2rem;
}
.car-btn {
  background: none;
  border: 1px solid rgba(240,237,232,0.2);
  color: var(--text);
  font-family: 'Space Mono', monospace;
  font-size: 18px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, opacity 0.2s;
}
.car-btn:hover { border-color: var(--accent); color: var(--accent); }
.car-btn:disabled { opacity: 0.15; cursor: default; border-color: rgba(240,237,232,0.2); color: var(--text); }
.car-count {
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--dim);
  min-width: 6em;
  text-align: center;
}
.car-count.glitching { color: #00ff41; animation: c-tick 0.12s steps(2) infinite; }
@keyframes c-tick { 50% { transform: translateX(2px); opacity: 0.6; } }

/* Corrupted note 02 */
.corrupt-page {
  position: relative;
  overflow: hidden;
  background: #000;
}
.corrupt-page .car-img { filter: blur(3px) grayscale(0.6) contrast(1.6) brightness(0.6); }
.corrupt-page .c-red,
.corrupt-page .c-cyan {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  mix-blend-mode: screen;
}
.corrupt-page .c-red  { filter: blur(2px) sepia(1) saturate(9) hue-rotate(75deg) brightness(0.75); animation: c-slice-a 0.5s steps(1) infinite; }
.corrupt-page .c-cyan { filter: blur(2px) sepia(1) saturate(7) hue-rotate(85deg) brightness(0.4); animation: c-slice-b 0.42s steps(1) infinite; }
.corrupt-page .c-base { animation: c-jitter 0.18s steps(2) infinite; }
.c-bars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    repeating-linear-gradient(to bottom, rgba(0,0,0,0.55) 0 2px, transparent 2px 4px),
    linear-gradient(to bottom, transparent 22%, rgba(0,255,65,0.18) 22% 24%, transparent 24% 61%, rgba(0,255,65,0.35) 61% 64%, transparent 64%);
  animation: c-bars 0.3s steps(1) infinite;
}
.c-label {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: #00ff41;
  text-shadow: 0 0 6px rgba(0,255,65,0.7);
  background: #000;
  padding: 8px 12px;
  border: 1px solid #00ff41;
  animation: c-jitter 0.25s steps(2) infinite;
}
@keyframes c-jitter {
  0%   { transform: translate(-50%, -50%) translateX(0); }
  50%  { transform: translate(-50%, -50%) translateX(3px); }
}
.corrupt-page .c-base { animation-name: c-shake; }
@keyframes c-shake {
  0%  { transform: translateX(0); }
  50% { transform: translateX(-4px) skewX(-2deg); }
}
@keyframes c-slice-a {
  0%  { clip-path: inset(10% 0 70% 0); transform: translateX(-12px); }
  25% { clip-path: inset(45% 0 35% 0); transform: translateX(10px); }
  50% { clip-path: inset(70% 0 12% 0); transform: translateX(-6px); }
  75% { clip-path: inset(28% 0 58% 0); transform: translateX(14px); }
}
@keyframes c-slice-b {
  0%  { clip-path: inset(60% 0 25% 0); transform: translateX(10px); }
  33% { clip-path: inset(5% 0 82% 0);  transform: translateX(-14px); }
  66% { clip-path: inset(38% 0 44% 0); transform: translateX(6px); }
}
@keyframes c-bars {
  0%  { background-position: 0 0, 0 0; }
  50% { background-position: 0 1px, 0 -90px; }
}

.readme {
  font-size: 11px;
  line-height: 2.3;
  letter-spacing: 0.05em;
  color: rgba(240,237,232,0.48);
  white-space: pre-wrap;
  word-break: break-word;
}

/* Code gate (file 04) */
.gate-access {
  font-size: 0.85rem;
  letter-spacing: 0.3em;
  color: var(--accent);
  margin-bottom: 0.5rem;
  animation: blink-gate 1.1s step-end infinite;
}
@keyframes blink-gate {
  0%, 49%  { opacity: 1; }
  50%, 100% { opacity: 0; }
}
.gate-access.gate-unlocked {
  animation: none;
  opacity: 1;
  color: #2d6a2d;
}
.gate-title {
  font-size: 0.6rem;
  letter-spacing: 0.45em;
  color: var(--dim);
  margin-bottom: 2rem;
}
.gate-slots {
  display: flex;
  gap: 0.9rem;
  margin-bottom: 1.4rem;
}
.gslot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 1px solid rgba(240,237,232,0.22);
  background: transparent;
  transition: background 0.1s, border-color 0.1s;
}
.gslot.filled { background: var(--text); border-color: var(--text); }
#gate-input {
  font-family: 'Space Mono', monospace;
  color: transparent;
  background: transparent;
  border: none;
  border-bottom: 1px solid rgba(240,237,232,0.12);
  outline: none;
  text-align: center;
  width: 7rem;
  font-size: 16px;
  padding: 0.3rem 0;
  cursor: crosshair;
  caret-color: var(--accent);
}
.gate-error {
  font-size: 0.65rem;
  letter-spacing: 0.25em;
  color: var(--dim);
  opacity: 0;
  margin-top: 1.6rem;
  transition: opacity 0.5s;
  min-height: 1rem;
}
.gate-error.visible { opacity: 0.5; }

/* Exit button */
.exit-btn {
  position: fixed;
  bottom: calc(28px + env(safe-area-inset-bottom));
  left: calc(28px + env(safe-area-inset-left));
  background: var(--bg);
  border: 1px solid rgba(240,237,232,0.15);
  color: rgba(240,237,232,0.3);
  font-family: 'Space Mono', monospace;
  font-size: 10px;
  letter-spacing: 0.14em;
  padding: 9px 16px;
  cursor: pointer;
  text-transform: uppercase;
  transition: color 0.2s, border-color 0.2s;
  z-index: 10;
}
.exit-btn:hover {
  color: var(--text);
  border-color: rgba(240,237,232,0.4);
}

/* Mobile */
@media (max-width: 620px) {
  html, body { overflow: auto; }

  .terminal {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid rgba(240,237,232,0.08);
    padding-top: 36px;
  }

  .file-list {
    display: flex;
    flex-wrap: wrap;
    padding: 6px 0 10px;
  }

  .file-item { padding: 8px 14px; }

  .panel {
    padding: 32px 24px 100px;
    overflow-y: visible;
  }
}
