/* =====================================================================
   retro.css -- black screen, white phosphor text, old-computer vibe
   ===================================================================== */

@font-face {
  font-family: "Monaco Web";
  src: url("../assets/fonts/monaco.woff2") format("woff2"),
       url("../assets/fonts/monaco.woff") format("woff");
  font-weight: normal;
  font-style: normal;
  font-display: swap;
  /* Bundled file is a tiny subset with broken space metrics — not used for body text. */
}

:root {
  --mono: "SF Mono", "Menlo", "Consolas", "Liberation Mono", ui-monospace, monospace;
  --mono-display: "Monaco Web", var(--mono);
  --bg: #000000;
  --fg: #e6e6e6;        /* phosphor white */
  --dim: #7a7a7a;       /* muted */
  --faint: #4a4a4a;     /* rules, borders */
  --sel-bg: #e6e6e6;    /* inverted selection */
  --sel-fg: #000000;
  --link: #ffffff;
}

html, body {
  height: 100%;
  background: var(--bg);
  overflow: hidden;
}

body {
  font-family: var(--mono);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--sel-bg); color: var(--sel-fg); }

/* ---- CRT shell ---------------------------------------------------- */
.crt {
  position: fixed;
  inset: 0;
  background: var(--bg);
  overflow: hidden;
}

.screen {
  position: relative;
  z-index: 1;
  height: 100%;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 34px 40px 40px;
  display: flex;
  flex-direction: column;
  animation: powerOn 0.6s ease-out;
}
@keyframes powerOn {
  from { opacity: 0; transform: scale(0.998); filter: brightness(2.2); }
  to   { opacity: 1; transform: scale(1);     filter: brightness(1); }
}

/* very subtle flicker on the whole screen */
.screen { animation: powerOn 0.6s ease-out, flicker 5s infinite steps(60); }
@keyframes flicker {
  0%, 96%, 100% { opacity: 1; }
  97% { opacity: 0.96; }
  98% { opacity: 1; }
  99% { opacity: 0.97; }
}

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

/* ---- Layout: menu + reader --------------------------------------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 34px;
  min-height: 0;
}

/* ---- Menu (section chooser) -------------------------------------- */
.menu {
  overflow-y: auto;
  padding-right: 8px;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.menu-group {
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.14em;
  margin: 18px 0 6px;
  text-transform: uppercase;
}
.menu-group:first-child { margin-top: 0; }

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--fg);
  padding: 3px 8px 3px 18px;
  position: relative;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.04s linear;
}
.menu-item::before {
  content: ">";
  position: absolute;
  left: 4px;
  color: var(--fg);
  opacity: 0;
}
.menu-item:hover { color: #fff; }
.menu-item:hover::before { opacity: 0.5; }
.menu-item.active {
  background: var(--sel-bg);
  color: var(--sel-fg);
}
.menu-item.active::before { opacity: 1; color: var(--sel-fg); }
.menu-item:focus { outline: none; }
.menu-item:focus-visible { outline: 1px dashed var(--dim); outline-offset: -1px; }

/* ---- Reader ------------------------------------------------------- */
.reader {
  overflow-y: auto;
  padding: 0 6px 60px 4px;
  max-width: 70ch;
  outline: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.doc { animation: docIn 0.18s ease-out; }
@keyframes docIn { from { opacity: 0; } to { opacity: 1; } }

.doc-title {
  font-size: 16px;
  color: var(--fg);
  text-shadow: 0 0 6px rgba(230, 230, 230, 0.25);
  margin-bottom: 2px;
}
.doc-rule {
  color: var(--faint);
  white-space: pre;
  overflow: hidden;
  margin-bottom: 16px;
  user-select: none;
}

.doc-body {
  font: 15px/1.6 var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
  letter-spacing: normal;
  word-spacing: normal;
  font-feature-settings: normal;
  font-variant-ligatures: none;
  text-transform: none;
  text-rendering: auto;
  color: var(--fg);
}

.doc-meta { color: var(--dim); margin-bottom: 14px; }

.doc-section {
  color: var(--dim);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 22px 0 6px;
}

.doc a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.doc a:hover { background: var(--sel-bg); color: var(--sel-fg); text-decoration: none; }

.doc-row {
  white-space: pre-wrap;
  font: 15px/1.6 var(--mono);
  letter-spacing: normal;
  word-spacing: normal;
}

/* ---- Books + star rating ----------------------------------------- */
.book {
  margin: 18px 0;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--faint);
}
.book:last-of-type { border-bottom: none; }
.book-title { color: var(--fg); letter-spacing: normal; word-spacing: normal; }
.book-author { color: var(--dim); }
.book-note { color: var(--dim); margin-top: 4px; letter-spacing: normal; word-spacing: normal; }

.rating {
  display: inline-flex;
  align-items: center;
  margin: 6px 0 2px;
  font-family: var(--mono);
  user-select: none;
}
.rating-bracket { color: var(--faint); }
.rating-num { color: var(--dim); }
.star {
  font-family: var(--mono);
  font-size: 15px;
  color: var(--dim);
  padding: 0 1px;
  line-height: 1;
  transition: color 0.08s linear, text-shadow 0.08s linear;
}
.star.on { color: var(--fg); text-shadow: 0 0 6px rgba(230, 230, 230, 0.4); }
.rating-readonly .star { cursor: default; }

.doc-empty { color: var(--faint); margin-top: 4px; }

.doc-end {
  display: inline-block;
  margin-top: 22px;
  color: var(--fg);
  animation: blink 1.05s steps(1) infinite;
}

/* ---- Scrollbars (thin, retro) ------------------------------------- */
.menu::-webkit-scrollbar,
.reader::-webkit-scrollbar { width: 8px; }
.menu::-webkit-scrollbar-thumb,
.reader::-webkit-scrollbar-thumb { background: var(--faint); }
.menu::-webkit-scrollbar-track,
.reader::-webkit-scrollbar-track { background: transparent; }

/* ---- CRT overlays ------------------------------------------------- */
.scanlines {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0, 0, 0, 0) 0px,
    rgba(0, 0, 0, 0) 2px,
    rgba(0, 0, 0, 0.16) 3px,
    rgba(0, 0, 0, 0.16) 3px
  );
  background-size: 100% 3px;
  opacity: 0.55;
}
.vignette {
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    rgba(0, 0, 0, 0) 55%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

/* ---- Responsive --------------------------------------------------- */
@media (max-width: 720px) {
  .screen { padding: 20px 18px 24px; }
  .layout {
    grid-template-columns: 1fr;
    gap: 18px;
    overflow-y: auto;
  }
  .menu {
    overflow: visible;
    border-bottom: 1px solid var(--faint);
    padding-bottom: 14px;
  }
  .reader { overflow: visible; max-width: none; padding-bottom: 30px; }
  .logo { font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  .screen, .cursor, .doc, .doc-end { animation: none !important; }
}
