/* ===================================================================
   Shared styles — atmospheric horror scrollytelling
   =================================================================== */
@use 'vars';
@use 'mixins' as m; 

// ===== Reset =====
* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: clip;
}

body {
  min-height: 100vh;
  position: relative;
}

// ===== Atmospheric overlays =====
.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9000;
  opacity: var(--grain-opacity, 0.18);
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
}

.vignette {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8500;
  background: radial-gradient(ellipse at center, transparent 40%, var(--vignette) 100%);
  animation: vignette-pulse 9s ease-in-out infinite;
}

@keyframes vignette-pulse {
  0%, 100% { opacity: 0.85; }
  50% { opacity: 1; }
}

.flicker {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 8000;
  background: rgba(255, 240, 230, 0.02);
  animation: flicker 7s steps(2, end) infinite;
}

@keyframes flicker {
  0%, 92%, 100% { opacity: 0; }
  93% { opacity: 1; }
  94% { opacity: 0.2; }
  95% { opacity: 0.9; }
  96% { opacity: 0; }
}

[data-effects="off"] {
  .grain, .vignette, .flicker { display: none; }
  .reveal { opacity: 1; transform: none; }
  .glitch {
    &::before, &::after { display: none; }
  }
}

// ===== Top bar =====
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 40px;
  pointer-events: none;

  > * { pointer-events: auto; }
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 17px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 12px;

  &::before {
    content: "";
    width: 8px;
    height: 8px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 12px var(--accent);
  }
}

// ===== Menu button =====
.menu-btn {
  background: transparent;
  border: none;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 10px;
  @include m.mono-label(11px, 0.2em);
  align-items: flex-end;

  &:hover { color: var(--accent-bright); }

  &-lines {
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: flex-end;

    span {
      display: block;
      height: 1px;
      background: currentColor;

      &:nth-child(1) { width: 28px; }
      &:nth-child(2) { width: 20px; }
      &:nth-child(3) { width: 28px; }
    }
  }
}

// ===== Menu overlay =====
.menu-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 1500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease;

  &.open { opacity: 1; pointer-events: auto; }

  &::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.6 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
    opacity: 0.15;
    mix-blend-mode: overlay;
    pointer-events: none;
  }
}

.menu-close {
  position: absolute;
  top: 28px;
  right: 40px;
  background: transparent;
  border: none;
  color: var(--ink);
  @include m.mono-label(11px, 0.2em);
  cursor: pointer;
  padding: 10px;
  z-index: 10;

  &:hover { color: var(--accent-bright); }
}

.menu-inner {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
  grid-template-rows: auto 1fr;
  grid-template-areas: "head head" "list side";
  padding: 90px 64px 48px;
  gap: 0 64px;
  max-height: 100vh;
}

.menu-head {
  grid-area: head;
  display: flex;
  align-items: center;
  gap: 32px;
  padding-bottom: 24px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}

.menu-filter {
  flex: 1;
  min-width: 220px;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink);
  padding: 12px 16px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  outline: none;
  transition: border-color 0.2s;

  &:focus { border-color: var(--accent); }

  &::placeholder {
    color: var(--ink-faint);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    font-size: 11px;
  }
}

.menu-section-label {
  @include m.mono-label(11px, 0.25em);
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;

  &::after {
    content: "";
    width: 80px;
    height: 1px;
    background: var(--accent-deep);
  }
}

.menu-list {
  grid-area: list;
  overflow-y: auto;
  padding-right: 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-deep) transparent;

  &::-webkit-scrollbar { width: 6px; }
  &::-webkit-scrollbar-thumb { background: var(--accent-deep); }
  &::-webkit-scrollbar-track { background: transparent; }

  &.is-empty {
    .menu-empty { display: block; }
    .menu-part { display: none; }
  }
}

.menu-part {
  margin-bottom: 40px;

  &-head {
    position: sticky;
    top: 0;
    background: linear-gradient(to bottom, var(--bg) 70%, transparent);
    padding: 8px 0 14px;
    display: flex;
    align-items: baseline;
    gap: 16px;
    border-bottom: 1px solid var(--rule);
    margin-bottom: 8px;
    z-index: 2;
  }

  &-label {
    @include m.mono-label(10px, 0.3em);
    color: var(--accent);
  }

  &-sub {
    @include m.display-italic(18px);
    color: var(--ink-dim);
    letter-spacing: 0;
  }
}

.menu-chapters {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 32px;

  li {
    border-bottom: 1px solid var(--rule);
    transition: opacity 0.2s;

    &.hidden { display: none; }

    &.current {
      position: relative;

      a { color: var(--accent-bright); }
      .num { color: var(--accent-bright); }
      a::before {
        width: 2px;
        background: var(--accent-bright);
      }

      &::after {
        content: "READING";
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        @include m.mono-label(9px, 0.25em);
        color: var(--accent);
        padding: 4px 8px;
        border: 1px solid var(--accent-deep);
      }
    }
  }

  a {
    display: grid;
    grid-template-columns: 36px 1fr;
    gap: 20px;
    align-items: baseline;
    padding: 14px 0 14px 14px;
    text-decoration: none;
    color: var(--ink);
    @include m.display-italic(22px);
    font-weight: 400;
    transition: color 0.25s, padding 0.25s, background 0.25s;
    position: relative;
    text-wrap: balance;

    &:hover {
      color: var(--accent-bright);
      padding-left: 22px;
      background: rgba(185, 28, 28, 0.04);

      &::before { width: 2px; }
    }

    &::before {
      content: "";
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      width: 0;
      background: var(--accent);
      transition: width 0.25s;
    }
  }

  .num {
    font-family: var(--font-mono);
    font-style: normal;
    font-size: 11px;
    letter-spacing: 0.2em;
    color: var(--ink-faint);
    align-self: center;
  }

  .title { line-height: 1.2; }
}

.menu-side {
  grid-area: side;
  align-self: stretch;
  border-left: 1px solid var(--rule);
  padding-left: 40px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.menu-about {
  @include m.display-italic(19px);
  color: var(--ink-dim);
  line-height: 1.5;
}

.menu-progress {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--rule);

  &-bar {
    height: 2px;
    background: var(--rule);
    margin-bottom: 12px;
    position: relative;

    span {
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      background: var(--accent);
      box-shadow: 0 0 8px var(--accent);
    }
  }

  &-meta {
    display: flex;
    justify-content: space-between;
    @include m.mono-label(10px, 0.25em);
    color: var(--ink-dim);

    .accent { color: var(--accent-bright); }
  }
}

.menu-empty {
  padding: 24px;
  @include m.mono-label(11px, 0.2em);
  color: var(--ink-faint);
  text-align: center;
  display: none;
}

// ===== Chapter footer =====
.chapter-footer {
  position: relative;
  padding: 120px 40px 80px;
  border-top: 1px solid var(--rule);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  background: var(--bg);

  &::before {
    content: "";
    position: absolute;
    top: -1px;
    left: 50%;
    transform: translateX(-50%);
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 0 4px var(--bg), 0 0 20px var(--accent);
  }
}

.nav-card {
  text-decoration: none;
  color: var(--ink);
  display: block;
  padding: 28px;
  border: 1px solid var(--rule);
  transition: border-color 0.3s, background 0.3s, transform 0.4s;
  position: relative;
  overflow: hidden;
  min-height: 180px;

  &:hover {
    border-color: var(--accent);
    background: rgba(185, 28, 28, 0.05);

    .arrow { color: var(--accent-bright); }
  }

  &.disabled {
    opacity: 0.3;
    pointer-events: none;
  }

  &.prev {
    .arrow { left: 28px; }
    &:hover .arrow { transform: translateX(-6px); }
  }

  &.next {
    text-align: right;
    .arrow { right: 28px; }
    &:hover .arrow { transform: translateX(6px); }
  }

  .label, .num-big, .title { display: block; }

  .label {
    @include m.mono-label(11px, 0.25em);
    color: var(--ink-faint);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
  }

  .num-big {
    font-family: var(--font-display);
    font-size: 14px;
    letter-spacing: 0.2em;
    color: var(--accent);
    margin-bottom: 8px;
  }

  .title {
    @include m.display-italic(28px);
    line-height: 1.2;
  }

  .arrow {
    position: absolute;
    bottom: 24px;
    @include m.mono-label(11px, 0.2em);
    color: var(--ink-faint);
    transition: color 0.3s, transform 0.3s;
  }
}

// ===== Brush dividers =====
.brush-divider {
  width: 100%;
  height: 24px;
  margin: 80px 0;
  opacity: 0.7;
}

// ===== Reveal on scroll =====
.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 1.2s ease, transform 1.2s ease;

  &.in {
    opacity: 1;
    transform: translateY(0);
  }
}

// ===== Glitch / chromatic aberration =====
.glitch {
  position: relative;
  display: inline-block;
  color: var(--ink);

  &::before,
  &::after {
    content: attr(data-text);
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
    opacity: 0.7;
  }

  &::before {
    color: var(--accent-bright);
    transform: translate(-1.5px, 0);
    mix-blend-mode: screen;
    animation: glitch-shift 4s infinite steps(2, end);
  }

  &::after {
    color: #1ea7c4;
    transform: translate(1.5px, 0);
    mix-blend-mode: screen;
    animation: glitch-shift 4.3s infinite steps(2, end) reverse;
  }
}

@keyframes glitch-shift {
  0%, 88%, 100% { transform: translate(0, 0); opacity: 0; }
  90% { transform: translate(-2px, 0.5px); opacity: 0.8; }
  92% { transform: translate(2px, -0.5px); opacity: 0.6; }
  94% { transform: translate(-1px, 0); opacity: 0.4; }
}

// ===== Scroll progress bar =====
.progress {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  background: var(--accent);
  z-index: 200;
  width: 0%;
  transition: width 0.1s linear;
  box-shadow: 0 0 8px var(--accent);
}

// ===== Utility =====
.mono { @include m.mono-label(11px, 0.15em); }
.dim { color: var(--ink-dim); }
.faint { color: var(--ink-faint); }

::selection {
  background: var(--accent);
  color: var(--paper);
}

// ===== Responsive =====
@include m.bp(m.$bp-laptop) {
  .menu-inner {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: "head" "list" "side";
    padding: 80px 32px 24px;
    gap: 16px;
  }

  .menu-list { min-height: 50vh; padding-right: 8px; }

  .menu-side {
    border-left: none;
    border-top: 1px solid var(--rule);
    padding-left: 0;
    padding-top: 16px;
    gap: 12px;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;

    .menu-section-label { display: none; }
  }

  .menu-about { display: none; }

  .menu-progress {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    flex: 1;
    min-width: 200px;
  }

  .menu-chapters { grid-template-columns: 1fr; }
}

@include m.bp(m.$bp-mobile) {
  .menu-close { top: 18px; right: 20px; }
  .menu-inner { padding: 70px 20px 24px; }
  .menu-list { min-height: 55vh; }

  .menu-chapters {
    a { font-size: 19px; padding: 12px 0 12px 10px; }
    .current::after { display: none; }
  }

  .menu-head { gap: 16px; }
}
