/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* --------------------------------------------------------------------------
 * Global image fade-in
 *
 * Every <img> starts invisible and fades in when loaded. A MutationObserver
 * in application.js marks images with [data-loaded] as they complete.
 * Cached images are marked synchronously so there's no visible flash.
 *
 * Uses a CSS animation instead of a transition so it composes cleanly with
 * Tailwind's transition-transform utilities (hover scale effects on cards).
 * -------------------------------------------------------------------------- */
@keyframes img-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

img:not([data-loaded]):not(.pswp__img) {
  opacity: 0;
}

/* Cached images: appear instantly, no animation */
img[data-loaded=""]:not(.pswp__img) {
  opacity: 1;
}

/* Network-loaded images: fade in over 200ms */
img[data-loaded="fade"]:not(.pswp__img) {
  animation: img-fade-in 200ms ease both;
}

/* --------------------------------------------------------------------------
 * Gift box: lightbox deep links hide the page until artwork is shown
 *
 * The inline <script> in <head> adds .ab-gift-box to <html> before paint.
 * Everything is hidden; PhotoSwipe (z-index ~1.5M) renders on top of the
 * black void. On close, aperture_controller removes the class and the
 * page content fades in.
 * -------------------------------------------------------------------------- */
html.ab-gift-box { background: #000 !important; }
html.ab-gift-box body { background: #000 !important; }
html.ab-gift-box body > *:not(.pswp) { opacity: 0 !important; }

/* --------------------------------------------------------------------------
 * Shared UI patterns
 * -------------------------------------------------------------------------- */

/* Back navigation hover: all detail pages use this */
.back-nav-link:hover,
.term-back-link:hover { color: #000; }

/* Pagination link hover */
.pagination-link:hover,
.collection-page-link:hover { border-color: #000 !important; color: #000 !important; }

/* --------------------------------------------------------------------------
 * Words: viewport-filling layout (same pattern as aperture .ab-workspace)
 * -------------------------------------------------------------------------- */
body:has(.words-workspace) {
  overflow: hidden;
  height: 100vh;
}

body:has(.words-workspace) main {
  overflow: hidden;
}

.words-workspace {
  display: flex;
  overflow: hidden;
  position: relative;
  font-family: Georgia, 'Times New Roman', serif;
}

/* Thinking dots: three dots that pulse while waiting for tokens */
.words-dots span {
  font-size: 2em;
  line-height: 0.5;
  opacity: 0.2;
  animation: words-dot-pulse 1.4s ease-in-out infinite;
}
.words-dots span:nth-child(2) { animation-delay: 0.2s; }
.words-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes words-dot-pulse {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 0.8; }
}

/* Chapter groups: active chapter at full opacity, others dimmed */
.words-chapter-group {
  opacity: 0.1;
  transition: opacity 0.2s ease;
}
.words-chapter-group.active {
  opacity: 1;
}

/* Cross-dissolve layers control their own image opacity */
.words-workspace img {
  opacity: revert;
  animation: none;
}

/* --------------------------------------------------------------------------
 * About page: two-column layout with sidebar TOC
 * -------------------------------------------------------------------------- */

/* Mobile: single column, TOC inline */
.about-layout {
  position: relative;
}

.about-toc {
  margin-bottom: 32px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.about-toc-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 6px;
}

/* Inline code within about content */
.about-content code {
  font-size: 0.88em;
  padding: 2px 6px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* Desktop (xl+): sidebar + content grid */
@media (min-width: 1200px) {
  .about-layout {
    display: grid;
    grid-template-columns: 176px 1fr;
    gap: 48px;
    align-items: start;
  }

  .about-toc {
    position: sticky;
    top: 72px; /* navbar height + session bar + breathing room */
    margin-bottom: 0;
    padding: 16px 0 16px 0;
    border: none;
    border-right: 1px solid var(--border);
    border-radius: 0;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
  }

  .about-toc-links {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
}

/* --------------------------------------------------------------------------
 * Scrollspy: sticky TOC with active-section highlighting
 * -------------------------------------------------------------------------- */

/* Links: shared base style */
.scrollspy-link {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  border-radius: 4px;
  padding: 3px 8px;
}

.scrollspy-link:hover {
  color: var(--text-secondary);
}

/* Active state: mobile (pill highlight) */
.scrollspy-link.scrollspy-active {
  background: color-mix(in srgb, var(--session-color) 18%, transparent);
  color: var(--text) !important;
  font-weight: 600;
}

/* Active state: desktop sidebar (left border accent) */
@media (min-width: 1200px) {
  .scrollspy-link {
    padding: 5px 12px;
    border-radius: 0;
    border-left: 2px solid transparent;
  }

  .scrollspy-link.scrollspy-active {
    background: color-mix(in srgb, var(--session-color) 10%, transparent);
    border-left-color: var(--session-color);
    color: var(--text) !important;
    font-weight: 600;
  }
}

/* When TOC is stuck below the navbar (mobile only) */
.scrollspy-stuck {
  padding-top: 10px !important;
  padding-bottom: 10px !important;
  border-radius: 0 !important;
  border-left: none !important;
  border-right: none !important;
  border-top-color: transparent !important;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

:root[data-theme="dark"] .scrollspy-stuck {
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

@media (min-width: 1200px) {
  .scrollspy-stuck {
    /* Disable stuck styles on desktop - the sidebar handles its own sticky */
    padding-top: 0 !important;
    padding-bottom: 0 !important;
    border: none !important;
    box-shadow: none !important;
  }
}
