/* ============================================
   ENARGEIA — memoir.css
   "retroethereal" — WoH bones, Y2K chrome, Amano mood
   ============================================ */

/* ---------- LOCAL TOKENS ---------- */
/* Pulling from your global palette but defining a few memoir-specific ones */
.memoir-page {
  --m-bg:        #1a0f2e;   /* bruise base */
  --m-bg-deep:   #0a0612;   /* even deeper for vignette edges */
  --m-panel:     #050208;   /* near-1-bit panel interior */
  --m-panel-2:   #0d0814;   /* alt panel tone for striped lists */
  --m-ink:       #e8def5;   /* off-white silver text */
  --m-ink-dim:   #8a7fa8;   /* muted label text */
  --m-ink-faint: #4a4060;   /* placeholder/empty state */
  --m-rule:      #2a1f44;   /* hairline rule color */
  --m-accent:    #ff7eb3;   /* opal pink — selection/hover */
  --m-accent-2:  #5eead4;   /* opal teal — "now"/active pip */
  --m-warn:      #fde68a;   /* gold — warnings/idle pings */

  /* iridescent chrome gradient — used on borders */
  --m-chrome: linear-gradient(
    135deg,
    #c4b5fd 0%,
    #ff7eb3 22%,
    #fde68a 44%,
    #5eead4 66%,
    #c084fc 88%,
    #c4b5fd 100%
  );
}

/* ---------- PAGE SHELL ---------- */
html, body { height: 100%; }
html:has(.memoir-page) { overflow: hidden; }   /* no page scroll, like the gate */

.memoir-page {
  min-height: 100vh;
  background: var(--m-bg);
  color: var(--m-ink);
  font-family: "Little-Monster", Georgia, serif;
  display: grid;
  grid-template-rows: auto 1fr auto;   /* statusbar / main / log */
  position: relative;
  overflow: hidden;
}

/* ---------- AMBIENT BACKGROUND LAYERS ---------- */
/* Layer 1: ghost cursive script texture, drifting slowly */
.memoir-bg-script {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.06;
  background-image:
    /* fake handwritten script via repeating wavy gradients — replace with a real script PNG later */
    repeating-linear-gradient(
      92deg,
      transparent 0 22px,
      rgba(232, 222, 245, 0.4) 22px 23px,
      transparent 23px 48px
    ),
    repeating-linear-gradient(
      88deg,
      transparent 0 60px,
      rgba(232, 222, 245, 0.25) 60px 61px,
      transparent 61px 130px
    );
  background-size: 600px 600px, 800px 800px;
  animation: scriptDrift 240s linear infinite;
}
@keyframes scriptDrift {
  from { background-position: 0 0, 0 0; }
  to   { background-position: 600px 600px, -800px 800px; }
}
/* NOTE: when you have a real handwritten-script PNG, replace .memoir-bg-script
   background-image with: url('/assets/images/script-texture.png'); and bump opacity */

/* Layer 2: film grain dither — animated noise */
.memoir-bg-grain {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 1;
  opacity: 0.18;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
  animation: grainShift 0.7s steps(4) infinite;
}
@keyframes grainShift {
  0%   { transform: translate(0, 0); }
  25%  { transform: translate(-3px, 2px); }
  50%  { transform: translate(2px, -2px); }
  75%  { transform: translate(-1px, 3px); }
  100% { transform: translate(0, 0); }
}

/* Layer 3: edge vignette */
.memoir-bg-vignette {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 2;
  background: radial-gradient(
    ellipse at center,
    transparent 40%,
    rgba(5, 2, 8, 0.55) 90%,
    var(--m-bg-deep) 100%
  );
}

/* All real content sits above the bg layers */
.memoir-statusbar,
.memoir-main,
.memoir-log,
.memoir-lightbox { position: relative; z-index: 10; }

/* ============================================
   STATUS BAR (top)
   ============================================ */
.memoir-statusbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--m-panel);
  border-bottom: 1px solid transparent;
  border-image: var(--m-chrome) 1;
  font-family: "Pixel-LCD-7", "Courier New", monospace;
  font-size: 0.95rem;
  letter-spacing: 0.08em;
  color: var(--m-ink);
  text-transform: uppercase;
}
.status-cell { display: flex; align-items: center; gap: 0.6rem; }
.status-date  { justify-content: flex-start; }
.status-title { justify-content: center;   color: var(--m-accent-2); }
.status-time  { justify-content: flex-end; }

.status-icon { color: var(--m-accent); font-size: 0.9em; }
.status-glyph { color: var(--m-accent); }
.status-blink { animation: blink 1s steps(2) infinite; color: var(--m-accent-2); }
@keyframes blink { 50% { opacity: 0.15; } }

/* ============================================
   MAIN GRID — 3 PANELS
   ============================================ */
.memoir-main {
  display: grid;
  grid-template-columns: 22% 52% 26%;
  gap: 0.6rem;
  padding: 0.6rem;
  overflow: hidden;
  min-height: 0;   /* critical: lets children scroll within their box */
}

/* ---------- SHARED PANEL CHROME ---------- */
/* This is the iridescent Y2K bezel. Every panel gets this. */
.panel {
  position: relative;
  background: var(--m-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  /* iridescent border via border-image */
  border: 1.5px solid transparent;
  border-image: var(--m-chrome) 1;
  /* outer glow + inner highlight bevel */
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 0 18px rgba(192, 132, 252, 0.18),
    inset 0 0 0 1px rgba(232, 222, 245, 0.06),
    inset 0 1px 0 rgba(232, 222, 245, 0.12);
}
/* slow shimmer on the border — re-paints the chrome gradient subtly */
.panel::before {
  content: "";
  position: absolute; inset: -2px;
  pointer-events: none;
  background: var(--m-chrome);
  background-size: 300% 300%;
  z-index: -1;
  filter: blur(6px);
  opacity: 0.18;
  animation: chromeShimmer 14s linear infinite;
}
@keyframes chromeShimmer {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* ---------- PANEL TITLE BARS ---------- */
.panel-title-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.7rem;
  background: linear-gradient(
    to bottom,
    rgba(192, 132, 252, 0.12) 0%,
    rgba(192, 132, 252, 0.04) 50%,
    rgba(0, 0, 0, 0.4) 100%
  );
  border-bottom: 1px solid var(--m-rule);
  font-family: "Pixel-LCD-7", "Courier New", monospace;
  font-size: 0.85rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--m-ink);
  flex-shrink: 0;
}
.panel-count, .panel-glyph { color: var(--m-accent); font-size: 0.85em; }

/* ============================================
   LEFT PANEL — ENTRY LIST
   ============================================ */
.panel-list { /* inherits .panel */ }

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  font-family: "Pixel-LCD-7", "Courier New", monospace;
}
.entry-list-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem;
  padding: 0.55rem 0.7rem;
  border-bottom: 1px dashed var(--m-rule);
  cursor: pointer;
  color: var(--m-ink);
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
}
.entry-list-item:nth-child(even) { background: var(--m-panel-2); }
.entry-list-item:hover {
  background: rgba(255, 126, 179, 0.08);
  color: var(--m-accent);
}
.entry-list-item.is-active {
  background: rgba(94, 234, 212, 0.10);
  color: var(--m-accent-2);
}
.entry-list-item.is-active::before {
  content: "▸";
  position: absolute;
  left: 0.15rem; top: 50%;
  transform: translateY(-50%);
  color: var(--m-accent-2);
  animation: blink 1.4s steps(2) infinite;
}
.entry-list-num {
  color: var(--m-ink-dim);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}
.entry-list-title {
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-list-date {
  font-size: 0.7rem;
  color: var(--m-ink-dim);
  grid-column: 2;
  margin-top: 2px;
}

.panel-pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.7rem;
  border-top: 1px solid var(--m-rule);
  font-family: "Pixel-LCD-7", monospace;
  font-size: 0.8rem;
  color: var(--m-ink-dim);
  flex-shrink: 0;
}
.pager-btn {
  background: transparent;
  border: 1px solid var(--m-rule);
  color: var(--m-ink);
  padding: 0.15rem 0.6rem;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
}
.pager-btn:hover {
  border-color: var(--m-accent);
  color: var(--m-accent);
  box-shadow: 0 0 8px rgba(255, 126, 179, 0.4);
}
.pager-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ============================================
   CENTER PANEL — ENTRY VIEWER
   ============================================ */
.entry-view {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 2.4rem 3rem;
  scroll-behavior: smooth;
}
.entry-view::-webkit-scrollbar { width: 8px; }
.entry-view::-webkit-scrollbar-track { background: var(--m-panel); }
.entry-view::-webkit-scrollbar-thumb {
  background: var(--m-rule);
  border-radius: 0;
}
.entry-view::-webkit-scrollbar-thumb:hover { background: var(--m-accent); }

/* empty state */
.entry-empty {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%;
  color: var(--m-ink-faint);
  font-family: "Pixel-LCD-7", monospace;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.85rem;
  text-align: center;
}
.entry-empty-glyph {
  font-size: 3rem;
  color: var(--m-rule);
  margin-bottom: 1rem;
  animation: blink 3s steps(2) infinite;
}

/* actual entry content */
.entry-title {
  font-family: "IBM-Logo";
  font-size: clamp(1.8rem, 3.2vw, 2.8rem);
  color: var(--m-ink);
  letter-spacing: 0.02em;
  line-height: 1.1;
  margin-bottom: 0.4rem;
  text-shadow:
    0 0 18px rgba(192, 132, 252, 0.35),
    0 0 2px rgba(232, 222, 245, 0.4);
}
.entry-datestamp {
  font-family: "Pixel-LCD-7", monospace;
  font-size: 0.8rem;
  color: var(--m-accent-2);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 1.6rem;
  padding-bottom: 1rem;
  border-bottom: 1px dashed var(--m-rule);
}
.entry-datestamp::before { content: "✦  "; color: var(--m-accent); }

.entry-body {
  font-family: "Little-Monster", Georgia, serif;
  font-size: 1.5rem;
  line-height: 1.75;
  color: var(--m-ink);
}
.entry-body p { margin-bottom: 1.1em; }
.entry-body p:first-of-type::first-letter {
  font-family: "Pixel-LCD-7", serif;
  font-size: 3em;
  float: left;
  line-height: 0.85;
  padding: 0.1em 0.1em 0 0;
  color: var(--m-accent);
  text-shadow: 0 0 12px rgba(255, 126, 179, 0.4);
}
.entry-body a { color: var(--m-accent); text-decoration: underline dotted; }
.entry-body a:hover { color: var(--m-accent-2); }
.entry-body em { color: var(--m-accent); font-style: italic; }
.entry-body blockquote {
  border-left: 2px solid var(--m-accent);
  padding-left: 1rem;
  margin: 1.4em 0;
  color: var(--m-ink-dim);
  font-style: italic;
}
.entry-body hr {
  border: none;
  text-align: center;
  margin: 2em 0;
  color: var(--m-ink-dim);
}
.entry-body hr::before {
  content: "✦  ✦  ✦";
  letter-spacing: 1em;
}

/* ---------- POLAROID PHOTOS ---------- */
.entry-photos {
  display: flex;
  flex-wrap: wrap;
  gap: 1.6rem;
  justify-content: center;
  margin: 2rem 0;
}
.polaroid {
  background: #f0e6ff;
  padding: 12px 12px 36px;
  box-shadow:
    0 8px 24px rgba(0, 0, 0, 0.6),
    0 0 0 1px rgba(192, 132, 252, 0.3);
  transform: rotate(var(--rot, -3deg));
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: zoom-in;
  max-width: 220px;
  position: relative;
}
.polaroid:nth-child(2n)   { --rot:  4deg; }
.polaroid:nth-child(3n)   { --rot: -2deg; }
.polaroid:nth-child(4n+1) { --rot:  2deg; }
.polaroid:hover {
  transform: rotate(0deg) scale(1.05);
  box-shadow:
    0 14px 36px rgba(0, 0, 0, 0.7),
    0 0 24px rgba(255, 126, 179, 0.4);
  z-index: 5;
}
.polaroid img {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: auto;
}
.polaroid figcaption {
  position: absolute;
  bottom: 8px; left: 0; right: 0;
  text-align: center;
  font-family: "kuchibue", cursive;
  font-size: 0.78rem;
  color: #2a1f44;
  letter-spacing: 0.04em;
}

/* ============================================
   RIGHT PANEL — MARGINALIA (WoH style: meta on top, portrait at bottom)
   ============================================ */
.panel-margin {
  display: flex;
  flex-direction: column;
}

.margin-meta {
  margin: 0;
  padding: 0.9rem 0.9rem 0.6rem;
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 0.7rem;
  row-gap: 0.55rem;
  font-family: "Pixel-LCD-7", "Courier New", monospace;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  flex: 0 0 auto;
  align-content: start;
  overflow-y: auto;
  border-bottom: 1px solid var(--m-rule);
}

.portrait-frame {
  margin-top: auto;
  margin-left: auto;
  margin-right: 0.9rem;
  margin-bottom: 0;
  padding: 6px;
  background: var(--m-panel-2);
  border: 1px solid var(--m-rule);
  position: relative;
  box-shadow:
    inset 0 0 0 1px rgba(232, 222, 245, 0.08),
    0 0 12px rgba(192, 132, 252, 0.15);
}

#portraitCanvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  width: 120px;
  height: 140px;
  background: #0a0612;
}
.portrait-label {
  position: absolute;
  top: -10px; left: 6px;
  background: var(--m-panel);
  padding: 0 6px;
  font-family: "Pixel-LCD-7", monospace;
  font-size: 0.65rem;
  letter-spacing: 0.15em;
  color: var(--m-accent);
  border: 1px solid var(--m-rule);
}

.margin-footer {
  padding: 0.5rem 0.9rem 0.7rem;
  border-top: 1px solid var(--m-rule);
  font-family: "Pixel-LCD-7", monospace;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}
.margin-back {
  color: var(--m-ink-dim);
  text-decoration: none;
  text-transform: uppercase;
}
.margin-back:hover { color: var(--m-accent); }

/* ============================================
   BOTTOM LOG FEED
   ============================================ */
.memoir-log {
  background: var(--m-panel);
  border-top: 1px solid transparent;
  border-image: var(--m-chrome) 1;
  padding: 0.5rem 1rem 0.6rem;
  font-family: "Pixel-LCD-7", "Courier New", monospace;
  font-size: 0.78rem;
  color: var(--m-ink);
  height: 110px;             /* fixed height instead of max-height */
  overflow: hidden;
  position: relative;
}
.memoir-log::after {
  /* fade the OLDER (lower) log lines into shadow at the bottom */
  content: "";
  position: absolute;
  bottom: 0; left: 0; right: 0; height: 40px;
  background: linear-gradient(to top, var(--m-panel), transparent);
  pointer-events: none;
  z-index: 2;
}
.log-feed {
  list-style: none;
  margin: 0; padding: 0;
  display: flex;
  flex-direction: column;
}
.log-feed li {
  padding: 1px 0;
  letter-spacing: 0.04em;
  animation: logIn 0.35s ease-out;
}
.log-feed li.is-newest {
  color: var(--m-ink);
  font-weight: bold;
}
.log-feed li:not(.is-newest) { color: var(--m-ink-dim); }
.log-feed li.log-eerie { color: var(--m-warn); font-style: italic; }
.log-time { color: var(--m-accent-2); margin-right: 0.6rem; }

@keyframes logIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================
   IMAGE LIGHTBOX
   ============================================ */
.memoir-lightbox {
  position: fixed; inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.memoir-lightbox[hidden] { display: none; }
.lightbox-backdrop {
  position: absolute; inset: 0;
  background: rgba(5, 2, 8, 0.92);
  backdrop-filter: blur(4px);
  cursor: zoom-out;
}
.lightbox-figure {
  position: relative;
  max-width: 80vw;
  max-height: 80vh;
  background: #f0e6ff;
  padding: 18px 18px 50px;
  box-shadow:
    0 30px 80px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(192, 132, 252, 0.4),
    0 0 40px rgba(255, 126, 179, 0.3);
  transform: rotate(-1deg);
}
.lightbox-figure img {
  display: block;
  max-width: 100%;
  max-height: 65vh;
  width: auto; height: auto;
}
.lightbox-figure figcaption {
  position: absolute;
  bottom: 14px; left: 0; right: 0;
  text-align: center;
  font-family: "kuchibue", cursive;
  font-size: 0.95rem;
  color: #2a1f44;
}
.lightbox-close {
  position: absolute;
  top: -14px; right: -14px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--m-panel);
  border: 1.5px solid transparent;
  border-image: var(--m-chrome) 1;
  color: var(--m-ink);
  cursor: pointer;
  font-family: "Pixel-LCD-7", monospace;
  font-size: 0.9rem;
}
.lightbox-close:hover { color: var(--m-accent); }

/* ============================================
   RESPONSIVE — collapse to stacked on narrow screens
   ============================================ */
@media (max-width: 900px) {
  html:has(.memoir-page) { overflow: auto; }
  .memoir-page { height: auto; min-height: 100vh; }
  .memoir-main {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .panel-list   { max-height: 220px; }
  .panel-margin { max-height: 280px; }
  .portrait-frame { align-self: flex-start; margin: 0.8rem 0.9rem; }
}