/* --- CSS VARIABLES --- */
:root {
    --name-color: #9800eb; 
    --title-color: #ded4eb; 
    --background-main: #0d0022;
    --primary-text-color: #f0f0f0; 
    --secondary-text-color: #a09cb8; 
    --arrow-color: rgba(222, 212, 235, 0.4);
    
    --terminal-bg: #05000a; 
    --terminal-sidebar: #0a0014; 
    --terminal-text: #00ff9d; 
    --terminal-dim: #005f3d; 
    --terminal-alert: #ffcc00; 
    --terminal-error: #ff3333; 
    --terminal-gold: #ffd700; 
    --terminal-white: #ffffff; 
    --terminal-magenta: #ff00ff; 
    --terminal-cyan: #00ffff; 
    --terminal-border: #333; 
    --operator-color: #d4aaff;
  }
  
  /* --- RESET & ACCESSIBILITY --- */
  :focus-visible { outline: none !important; }
  
  * { 
    -webkit-tap-highlight-color: transparent; 
    -webkit-touch-callout: none; 
    user-select: none; 
    box-sizing: border-box; 
  }
  
  a, button, input, .playlist-item, .voice-btn, .ctrl-btn, .cycle-btn, #infinity-symbol, .nav-arrow {
    touch-action: manipulation;
  }
  
  /* --- BASE LAYOUT --- */
  html { 
    background-color: var(--background-main); 
    height: 100%; 
    overscroll-behavior-y: none; 
    -webkit-text-size-adjust: 100%; 
    text-size-adjust: 100%;
    overflow-x: hidden; 
  }
  
  body {
    font-family: "Zilla Slab", serif; margin: 0; padding: 20px; padding-bottom: 50px;
    min-height: 100dvh; 
    display: flex; flex-direction: column; 
    color: var(--primary-text-color); background-color: var(--background-main);
    background: linear-gradient(135deg, #080017, #100021, #0a001a, #140029, #080017);
    background-size: 600% 600%; 
    background-attachment: fixed; 
    animation: darkShift 30s ease infinite; 
  }
  
  body.no-scroll { overflow: hidden !important; width: 100%; position: fixed; }
  body.loading-lock { 
    overflow: hidden !important; 
    touch-action: none; 
    position: fixed; 
    top: 0; 
    left: 0;
    width: 100%; 
  }
  
  /* --- ANIMATIONS --- */
  @keyframes darkShift { 
    0% { background-position: 0% 50%; } 
    50% { background-position: 100% 50%; } 
    100% { background-position: 0% 50%; } 
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  @keyframes strobe { 
    0%, 100% { color: var(--name-color); text-decoration-color: var(--name-color); } 
    50% { color: #ffffff; text-decoration-color: #ffffff; } 
  }
  @keyframes faintFlash { 
    0%, 100% { opacity: 0.3; } 
    50% { opacity: 0.8; } 
  }
  @keyframes glitch-shake { 
    0% { transform: translate(0, 0); } 
    25% { transform: translate(1px, 0); } 
    50% { transform: translate(-1px, 0); } 
    75% { transform: translate(0, 1px); } 
    100% { transform: translate(0, -1px); } 
  }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
  
  /* --- EXPLORE CONTAINER --- */
  .explore-container { 
      width: 100%; max-width: 900px; margin: 0 auto; flex-grow: 1; 
      transition: opacity 1.2s ease; display: flex; flex-direction: column; overflow-x: hidden;
      animation: fadeIn 1s ease forwards;
  }
  
  .explore-header { text-align: center; margin-bottom: 30px; }
  .explore-header h1 { 
      color: var(--name-color); 
      font-size: clamp(1.2rem, 6vw, 3.5rem); 
      font-style: italic; font-weight: 700; margin-bottom: 10px; 
      letter-spacing: 1px; line-height: 1.2; padding: 0 15px;
      overflow-wrap: break-word; word-break: break-word;
  }
  
  /* --- PDF ENGINE --- */
  .pdf-container { 
      position: relative; 
      background-color: transparent !important; 
      display: flex; flex-direction: column; align-items: stretch; 
      min-height: 80vh; 
      padding: 10px; gap: 15px; border-radius: 4px; width: 100%;
      transition: background-color 0s; 
  }
  
  .pdf-container.ready {
      background-color: rgba(255, 255, 255, 0.03) !important; 
      transition: background-color 0.8s ease; 
  }
  
  #loading-overlay { 
    display: flex; align-items: center; justify-content: center; 
    position: fixed; 
    top: 0; left: 0; right: 0; bottom: 0; 
    z-index: 5000; background-color: transparent; 
    pointer-events: none;
  }
  .loading-spinner { 
      width: 50px; height: 50px; border: 4px solid rgba(255, 255, 255, 0.1); 
      border-top-color: var(--name-color); border-radius: 50%; 
      animation: spin 1s infinite linear; 
  }
  
  .pdf-page-wrapper { 
      width: 100%; max-width: 100%; height: auto; position: relative; margin: 0 auto; 
      border-radius: 4px; overflow: visible; 
      -webkit-mask-image: linear-gradient(to right, transparent 0%, black 2px, black calc(100% - 2px), transparent 100%);
      mask-image: linear-gradient(to right, transparent 0%, black 2px, black calc(100% - 2px), transparent 100%);
      margin-bottom: 0; 
      background: transparent; 
      line-height: 0; flex-shrink: 0; box-shadow: none;
      opacity: 0; 
      transform: translateY(10px);
      transition: opacity 0.8s ease, transform 0.8s ease; 
  }
  
  .pdf-page-wrapper.rendered {
      opacity: 1;
      transform: translateY(0);
  }
  
  .pdf-page-wrapper::before {
      content: ""; position: absolute; z-index: -1; bottom: 5px; left: 4px; right: 4px; height: 20px;
      box-shadow: 0 15px 35px rgba(0,0,0,0.7); border-radius: 50%;
  }
  
  .pdf-page-wrapper::after { 
      content: ""; position: absolute; top: 0; left: 0; right: 0; bottom: 0; 
      background: linear-gradient(120deg, rgba(255, 255, 255, 0) 30%, rgba(255, 255, 255, 0.15) 50%, rgba(255, 255, 255, 0) 70%); 
      background-size: 200% 200%; pointer-events: none; z-index: 10; mix-blend-mode: overlay; 
      opacity: 0; transition: opacity 0.4s ease; 
  }
  .pdf-page-wrapper.rendered::after { opacity: 1; }
  
  .pdf-page-canvas { 
      width: 100% !important; height: auto !important; display: block; 
      background-color: var(--background-main); clip-path: inset(0 3px 2px 0); object-fit: contain; 
      opacity: 0; transition: opacity 0.4s ease; 
  }
  .pdf-page-wrapper.rendered .pdf-page-canvas { opacity: 1; }
  
/* --- NAVIGATION HUD --- */
.nav-controls {
  position: fixed; z-index: 3000; pointer-events: none; 
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: center; 
  max-width: 1050px; margin: 0 auto; 
  padding: 0 5px; 
  opacity: 1;
  transition: opacity 0.3s ease; 
}
  
  body:not(.loaded) .nav-controls,
  body:not(.loaded) .nav-arrow {
      opacity: 0 !important;
      pointer-events: none !important;
      transition: none !important; 
  }
  
  .nav-arrow {
    pointer-events: auto; background: none; border: none; 
    color: var(--arrow-color); 
    font-size: clamp(4rem, 12vw, 7rem); 
    font-weight: 100; 
    width: auto; height: auto; 
    line-height: 0.6; 
    margin: 0 15px; 
    padding: 5px 5px; 
    cursor: pointer; 
    display: flex; justify-content: center; align-items: center;
    text-shadow: 0 0 30px rgba(0,0,0,0.8); 
    
    /* NEW FADE PROPERTIES */
    filter: opacity(1);
    visibility: visible;
    transition: filter 0.15s ease, visibility 0.15s ease, color 0.2s ease;
    will-change: filter, visibility;
  }
  .nav-arrow.disabled { opacity: 0 !important; pointer-events: none !important; visibility: hidden; }
  
  /* Animated visual child. Handles hover/active states without interrupting hit-box events. */
  .arrow-glyph {
    display: flex; justify-content: center; align-items: center;
    transition: transform 0.2s ease, opacity 0.2s ease, color 0.2s ease;
    pointer-events: none;
    position: relative;
    bottom: 0.05em; 
    animation: faintFlash 5s infinite ease-in-out;
    opacity: 0.6;
  }
  
  /* Optical centering for Zilla Slab's asymmetrical text boundaries. */
  #prev-doc .arrow-glyph { left: 0.04em; }
  #next-doc .arrow-glyph { right: 0.04em; }
  
  @media (hover: hover) {
    .nav-arrow:hover .arrow-glyph { 
        color: var(--name-color); 
        animation: none; 
        opacity: 1; 
        filter: drop-shadow(0 0 20px var(--name-color)); 
        transform: scale(1.2); 
    }
  }
  
  .nav-arrow:not(.disabled):active .arrow-glyph, 
  .nav-arrow:not(.disabled).active-state .arrow-glyph { 
      color: var(--name-color) !important; 
      opacity: 1 !important; 
      animation: none !important; 
      transform: scale(0.8) !important; 
  }
  
/* --- VOID MECHANIC (PDF Tools) --- */
.pdf-tools {
  position: fixed; right: 20px; bottom: 20px; z-index: 2500; height: 50px; 
  display: flex; align-items: center;
  background-color: transparent; border: 1px solid var(--arrow-color); border-radius: 0; color: var(--arrow-color);
  animation: faintFlash 5s infinite ease-in-out; 
  opacity: 0.8; 
  max-width: 50px; overflow: hidden; 
  
  visibility: visible;
  filter: opacity(1); /* INDEPENDENT FADE LAYER */
  transform: translateZ(0); /* Hardware acceleration */
  
  transition: max-width 0.4s cubic-bezier(0.25, 1, 0.5, 1), background-color 0.2s, border-color 0.2s, filter 0.15s ease, visibility 0.15s ease;
  backdrop-filter: blur(2px);
  -webkit-mask-image: linear-gradient(to right, black calc(100% - 20px), transparent 100%);
  mask-image: linear-gradient(to right, black calc(100% - 20px), transparent 100%);
  pointer-events: none;
}

.pdf-tools.active { 
  max-width: 200px; 
  opacity: 1 !important; 
  animation: none !important; 
  border-color: rgba(152, 0, 235, 0.3); 
  background-color: rgba(13, 0, 34, 0.9); 
}
  .tools-toggle {
      pointer-events: auto; width: 50px; min-width: 50px; height: 100%;
      display: flex; justify-content: center; align-items: center; cursor: pointer;
      background: rgba(13, 0, 34, 0.9); border-right: 1px solid transparent; 
      transition: background-color 0.2s, color 0.2s, border-right-color 0.2s;
  }
  .pdf-tools.active .tools-toggle { border-right-color: rgba(152, 0, 235, 0.3); }
  .tools-toggle svg { width: 20px; height: 20px; fill: currentColor; transform: rotate(180deg); transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1); }
  .pdf-tools.active .tools-toggle svg { transform: rotate(0deg); }
  .tool-content { min-width: 120px; height: 100%; display: flex; opacity: 0; transition: opacity 0.3s ease 0.1s; pointer-events: auto; }
  .pdf-tools.active .tool-content { opacity: 1; }
  .tool-btn {
      flex-grow: 1; height: 100%; display: flex; align-items: center; justify-content: center; 
      padding-right: 20px; text-decoration: none; color: inherit; 
      font-family: "Space Mono", monospace; font-weight: 600; 
      font-size: clamp(0.7em, 2vw, 0.85em); 
      letter-spacing: 1px;
      white-space: nowrap; background: rgba(13, 0, 34, 0.9); transition: background-color 0.2s, color 0.2s;
  }
  
  /* --- FOOTER & LINKS --- */
  .footer { text-align: center; padding: 20px 0 10px 0; font-size: 0.85em; color: var(--secondary-text-color); border-top: 1px solid rgba(255, 255, 255, 0.08); margin-top: 20px; }
  #infinity-symbol { display: inline-block; transition: text-shadow 0.3s, color 0.3s; padding: 0 5px; font-weight: bold; cursor: default; pointer-events: none; }
  #infinity-symbol.active { cursor: pointer; pointer-events: auto; }
  #infinity-symbol.active:hover { color: #fff; text-shadow: 0 0 15px var(--name-color); }
  
  #infinity-symbol.active:active, 
  #infinity-symbol.active.active-state { 
      color: #ffffff !important; 
      text-shadow: 0 0 15px #ffffff, 0 0 30px var(--name-color) !important;
      transition: none !important;
  }
  
  #infinity-symbol.active-state-red {
      color: #ff3333 !important;
      text-shadow: 0 0 15px #ff0000, 0 0 30px #ff0000 !important;
      transition: none !important;
  }
  
  #song-link-container { transition: opacity 0.8s ease, visibility 0.8s; display: inline-block; margin-top: 0px; }
  #song-link { color: var(--name-color); text-decoration: underline; text-decoration-color: var(--name-color); text-underline-offset: 2px; font-weight: 600; transition: color 0.1s; }
  
  body #song-link.active-state, body #song-link:active {
      background: transparent !important; border: none !important; box-shadow: none !important;
      color: #ffd700 !important; text-shadow: 0 0 8px #ffd700, 0 0 15px rgba(255, 215, 0, 0.7) !important;
      text-decoration: underline !important; text-decoration-color: var(--name-color) !important; 
      text-underline-offset: 4px; animation: none !important; transition: none !important; filter: brightness(1.2) !important;
  }
  
  @media (hover: hover) {
    .pdf-tools:hover { 
        opacity: 1 !important; 
        animation: none !important; 
        border-color: var(--name-color); 
    }
      .tools-toggle:hover { background-color: rgba(152, 0, 235, 0.15); color: #fff; }
      .tool-btn:hover { background-color: rgba(152, 0, 235, 0.15); color: #fff; text-shadow: 0 0 10px var(--name-color); }
      #song-link:hover { animation: strobe var(--bpm-duration, 1s) infinite; }
  }
  
  /* --- MOBILE RESPONSIVENESS --- */
  @media (max-width: 900px) {
      body {
          padding: 20px 8px; 
          padding-bottom: 50px;
      }

      .nav-controls {
        padding: 0 !important; /* Removes the 5px container bumper */
      }
  
      .nav-arrow {
        margin: 0 !important;
        font-weight: 600 !important; 
        padding: 30px 20px !important; 
      }
  
      .explore-container, .pdf-container {
          overflow: visible !important;
      }
  
      .pdf-container {
          padding: 0; 
          gap: 15px;
          background-color: transparent !important;
      }
  
      .pdf-tools { bottom: 20px; height: 56px; max-width: 56px; }
      .pdf-tools.active { max-width: 220px; }
      .tools-toggle { width: 56px; min-width: 56px; }
      .tools-toggle svg { width: 24px; height: 24px; }
      .tool-btn { font-size: 0.95em; }
  
      .progress-area { margin-bottom: 5px; }
      .time-marker { margin-top: 0px; margin-bottom: 5px; }
      .buttons { justify-content: flex-start !important; margin-top: 5px; margin-bottom: 20px; }
      .utility-btns { margin-left: auto !important; }
      .playlist-container { max-height: 220px; }
  }

/* --- BULLETPROOF SCROLL LOCK --- */
html.loading-lock, body.loading-lock {
  overflow: hidden !important;
  height: 100dvh !important;
  position: fixed !important;
  top: 0; left: 0; width: 100%;
  touch-action: none !important;
  overscroll-behavior: none !important;
}

/* Kills the weird Windows scrollbar thumb box on ALL elements */
html.loading-lock::-webkit-scrollbar, 
body.loading-lock::-webkit-scrollbar,
html.loading-lock *::-webkit-scrollbar, 
body.loading-lock *::-webkit-scrollbar {
  display: none !important;
  width: 0 !important;
  height: 0 !important;
  -webkit-appearance: none !important;
  background: transparent !important;
}

body.loading-lock .footer,
body.loading-lock .footer *,
body.loading-lock #music-section,
body.loading-lock #music-section *,
body.loading-lock #pdf-tools,
body.loading-lock #pdf-tools * {
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
    transition: none !important; 
    animation: none !important;
}

.nav-arrow.out-of-bounds,
.pdf-tools.out-of-bounds {
    filter: opacity(0) !important;
    visibility: hidden !important;
    pointer-events: none !important;
}