:root {
  --bg: #fbfbfa;
  --fg: #1b1c1e;
  --muted: #74767c;
  --faint: #a5a7ad;
  --rule: #e4e4e2;
  --rule-strong: #c9c9c6;
  --accent: #2050c8;
  --hover: rgba(27, 28, 30, 0.04);
  --open-bg: rgba(27, 28, 30, 0.025);
  --overlay: rgba(251, 251, 250, 0.95);
  --screen: #f4f5f4;
  --screen-glow: rgba(32, 80, 200, 0.015);
  --scanline: rgba(0, 0, 0, 0.02);
  --glare-edge: rgba(32, 80, 200, 0.01);
  --glare-core: rgba(32, 80, 200, 0.04);
  --glare-mid: rgba(255, 255, 255, 0.015);
  --glare-glow: rgba(0, 255, 65, 0.015);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0f11;
    --fg: #cfd0d2;
    --muted: #7e8188;
    --faint: #55585f;
    --rule: #232427;
    --rule-strong: #3a3b3f;
    --accent: #82a7f0;
    --hover: rgba(207, 208, 210, 0.05);
    --open-bg: rgba(207, 208, 210, 0.03);
    --overlay: rgba(14, 15, 17, 0.95);
    --screen: #0d1012;
    --screen-glow: rgba(0, 255, 65, 0.04);
    --screen-shadow: rgba(0, 0, 0, 0.45);
    --scanline: rgba(0, 0, 0, 0.25);
    --glare-edge: rgba(255, 255, 255, 0.01);
    --glare-core: rgba(0, 255, 65, 0.03);
    --glare-mid: rgba(0, 255, 65, 0.015);
    --glare-glow: rgba(0, 255, 65, 0.015);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--screen);
  color: var(--fg);
  font-family: "SF Mono", SFMono-Regular, ui-monospace, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  position: relative;
  isolation: isolate;
  box-shadow: inset 0 0 48px var(--screen-glow);
}

/* horizontal glare sweep (VHS / CRT) + distortion behind band */
.glare-sweep {
  position: fixed;
  left: 0;
  right: 0;
  height: 15px;
  top: -15px;
  pointer-events: none;
  z-index: 5;
  background: linear-gradient(
    180deg,
    transparent 0%,
    var(--glare-edge) 20%,
    var(--glare-core) 45%,
    var(--glare-mid) 50%,
    var(--glare-core) 55%,
    var(--glare-edge) 80%,
    transparent 100%
  );
  backdrop-filter: blur(0.5px) brightness(1.2) saturate(1.1);
  box-shadow: 0 0 18px var(--glare-glow);
  will-change: top;
  animation: glare-sweep 30s linear infinite;
  opacity: 0.5;
  @media (prefers-color-scheme: light) {
    opacity: 0.3;
  }
}

@keyframes glare-sweep {
  0% { top: -24px; }
  100% { top: 100vh; }
}

/* CRT scanlines */
body.pipboy-screen::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 3;
  background: repeating-linear-gradient(
    0deg,
    transparent 0px,
    transparent 1px,
    var(--scanline) 1px,
    var(--scanline) 2px
  );
}

body.pipboy-screen > *:not(.glare-sweep) {
  position: relative;
  z-index: 1;
}

main {
  max-width: 76ch;
  margin: 0 auto;
  padding: 2.25rem 1.25rem 3rem;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---- header ---- */

h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.01em;
}

.cursor {
  display: inline-block;
  width: 0.55em;
  height: 1.05em;
  vertical-align: text-bottom;
  background: var(--fg);
  margin-left: 0.12em;
  animation: blink 1.2s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.meta {
  margin: 0.2rem 0 1.1rem;
  color: var(--muted);
}
.meta .sep { color: var(--faint); margin: 0 0.4ch; }

/* ---- listing ---- */

.listing {
  border-top: 1px solid var(--rule-strong);
  border-bottom: 1px solid var(--rule-strong);
}

.cols,
.row {
  display: grid;
  grid-template-columns: minmax(16ch, 1fr) 5ch 9ch 11ch;
  gap: 2ch;
  align-items: baseline;
  padding: 0.32rem 0.5ch;
}

.cols {
  color: var(--muted);
  border-bottom: 1px solid var(--rule);
  user-select: none;
}
.cols span[data-sort] { cursor: pointer; }
.cols span[data-sort]:hover { color: var(--fg); }
.cols .dir-ind { color: var(--faint); }

.entry { border-bottom: 1px solid var(--rule); }
.entry:last-child { border-bottom: none; }

.entry summary {
  list-style: none;
  cursor: pointer;
}
.entry summary::-webkit-details-marker { display: none; }

.row {
  transition: background-color 0.12s ease;
  position: relative;
}
.row:hover, .row:focus-visible { background: var(--hover); outline: none; }

.row:hover .name a,
.row:focus-visible .name a { color: var(--accent); }

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.name a:hover { text-decoration: underline; text-underline-offset: 2px; }

.type, .stat, .date { color: var(--muted); white-space: nowrap; }
.stat.paused::before {
  content: "";
  display: inline-block;
  width: 0.5ch;
  height: 0.5ch;
  border-radius: 50%;
  background: var(--faint);
  margin-right: 0.7ch;
  vertical-align: 0.15em;
}
.stat.active::before {
  content: "";
  display: inline-block;
  width: 0.5ch;
  height: 0.5ch;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 0.7ch;
  vertical-align: 0.15em;
}

/* expand indicator, only visible on hover / open */
.entry summary .date::after {
  content: "+";
  color: var(--faint);
  margin-left: 1ch;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.entry summary:hover .date::after { opacity: 1; }
.entry[open] summary .date::after { content: "−"; opacity: 1; }

.entry[open] { background: var(--open-bg); }

.desc {
  padding: 0.1rem 0.5ch 0.55rem 2.5ch;
  color: var(--muted);
  max-width: 62ch;
  white-space: pre-wrap;
}
.desc::before { content: "└ "; color: var(--faint); }
.desc a { color: var(--accent); }
.desc a:hover { text-decoration: underline; text-underline-offset: 2px; }

/* plain (non-expandable) rows, e.g. ../ */
a.row { display: grid; }

/* ---- footer ---- */

footer {
  margin-top: 1rem;
  color: var(--faint);
  display: flex;
  justify-content: space-between;
  gap: 1ch;
  flex-wrap: wrap;
}
footer a { color: var(--muted); }
footer a:hover { color: var(--accent); }
footer kbd { font-family: inherit; }

/* ---- help overlay ---- */

#help {
  position: fixed;
  inset: 0;
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding-top: 18vh;
  background: var(--overlay);
  z-index: 10;
}
#help.open { display: flex; }

#help .box {
  width: min(44ch, calc(100vw - 2rem));
  border: 1px solid var(--rule-strong);
  background: var(--bg);
  padding: 0.8rem 1.1rem 1rem;
}
#help h2 {
  font-size: inherit;
  font-weight: 600;
  margin: 0 0 0.5rem;
  color: var(--muted);
}
#help dl {
  margin: 0;
  display: grid;
  grid-template-columns: 8ch 1fr;
  gap: 0.15rem 1.5ch;
}
#help dt { color: var(--fg); }
#help dd { margin: 0; color: var(--muted); }

@media (max-width: 560px) {
  .cols, .row { grid-template-columns: minmax(12ch, 1fr) 5ch 9ch; gap: 1.5ch; }
  .col-date, .date { display: none; }
  .entry summary .stat::after {
    content: "+";
    color: var(--faint);
    margin-left: 1ch;
  }
  .entry[open] summary .stat::after { content: "−"; }
}
