/*
 * 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).
 *
 * The fade ends at the image's own opacity (no `to` keyframe) and holds
 * nothing afterwards (fill `backwards`), so an inline opacity a page sets
 * still wins. With `to { opacity: 1 }` and fill `both`, every network-loaded
 * image was pinned at 1: /time's dimmed and filtered-out tiles drew at full
 * strength on a cold cache (moma 51bf4a9d), and Aperture's swipe-out fade
 * never faded.
 * -------------------------------------------------------------------------- */
@keyframes img-fade-in {
  from { opacity: 0; }
}

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 backwards;
}

/* --------------------------------------------------------------------------
 * 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;
  }
}

/* /time axis and region labels: a halo in the scene colour, as map labels
   have, so they read over dots. The default view shows works from before
   1875 in the left margin, under the region labels (3b35a1a5). A ring of
   hard 1px shadows, not one soft blur: a blur fades out before it covers
   a dot behind 9px text. */
.time-label-halo {
  text-shadow:
    1px 0 0 var(--scene-bg), -1px 0 0 var(--scene-bg),
    0 1px 0 var(--scene-bg), 0 -1px 0 var(--scene-bg),
    1px 1px 0 var(--scene-bg), -1px -1px 0 var(--scene-bg),
    1px -1px 0 var(--scene-bg), -1px 1px 0 var(--scene-bg),
    0 0 3px var(--scene-bg);
}

/* /time bottom fade: the scene colour, solid under the axis toggle and
   decade labels, easing out above "YEAR CREATED". Its top (150px) is
   where the default view's field begins: the title's top sits about 111px
   up, plus the 40px padding (dcf9bb2b), so the unzoomed field is
   untouched. Px stops, because the chrome it clears is placed in px. */
.time-bottom-fade {
  /* The solid band: no dot shows there, so the controller lets none be
     picked there either (33bd452b). It holds the control bar, the ticks and
     the title (5bc33ce0). */
  --fade-solid: 100px;
  height: 150px;
  background: linear-gradient(to top,
    var(--scene-bg) 0px,
    var(--scene-bg) var(--fade-solid),
    color-mix(in srgb, var(--scene-bg) 85%, transparent) calc(var(--fade-solid) + 16px),
    color-mix(in srgb, var(--scene-bg) 35%, transparent) calc(var(--fade-solid) + 34px),
    transparent calc(var(--fade-solid) + 50px));
}

/* Pale dots on the dark scene still show through a ramp that hides them
   on the light one, so dark mode stays solid a little higher. */
.dark .time-bottom-fade {
  --fade-solid: 110px;
  background: linear-gradient(to top,
    var(--scene-bg) 0px,
    var(--scene-bg) var(--fade-solid),
    color-mix(in srgb, var(--scene-bg) 90%, transparent) calc(var(--fade-solid) + 12px),
    color-mix(in srgb, var(--scene-bg) 45%, transparent) calc(var(--fade-solid) + 28px),
    transparent calc(var(--fade-solid) + 40px));
}

/* /time year axis (time/decades.js, b8661959). The strip itself ignores
   the pointer; its ticks take it, for the hover count and, on a decade,
   the click that zooms there. */
.time-tick {
  position: absolute;
  bottom: 2px;
  transform: translateX(-50%);
  padding: 2px 4px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.05em;
  line-height: 1;
  white-space: nowrap;
  color: var(--text-muted);
  pointer-events: auto;
  cursor: default;
  border-radius: 3px;
}
.time-tick-decade { cursor: pointer; }
.time-tick-decade:hover { color: var(--text); }
.time-tick:focus-visible { outline: 1px solid var(--session-color); outline-offset: 1px; color: var(--text); }
.time-tick[data-tip]:hover::after,
.time-tick[data-tip]:focus-visible::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 8px;
  border-radius: 6px;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  color: var(--text-secondary);
  font-weight: 500;
  letter-spacing: 0.02em;
  pointer-events: none;
}

/* /time bottom chrome, from the bottom up: the control bar (5bc33ce0) and
   its readout line, the year ticks, the x-axis title. In px, and moved up
   together on a phone, where the bar takes two rows. The controller
   measures the band from the title's top (dcf9bb2b), so the field follows
   whatever these say. */
/* Edge to edge, children centred: a box placed at left: 50% only gets half
   the width to shrink into, which wrapped the phone bar into three rows. The
   wrap lets the pointer through; only the bar takes it. */
.time-bar-wrap {
  left: 8px;
  right: 8px;
  bottom: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  pointer-events: none;
}
.time-bar {
  pointer-events: auto;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px;
  border-radius: 12px;
  background: var(--glass-bg);
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
.time-lens {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: var(--text-muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}
button.time-lens:hover { background: var(--hover-bg); color: var(--text-secondary); }
.time-lens:focus-visible { outline: 1px solid var(--session-color); outline-offset: 1px; }
.time-spread { padding-right: 6px; cursor: default; }
.time-bar-sep { width: 1px; align-self: stretch; margin: 6px 4px; background: var(--glass-border); }
.time-axis-toggle { display: flex; border-radius: 8px; overflow: hidden; }
.time-axis-toggle button {
  height: 32px;
  padding: 0 14px;
  font-size: 10px;
  letter-spacing: 0.15em;
  border-bottom: 2px solid transparent;
}
.time-readout {
  display: flex;
  gap: 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
  white-space: nowrap;
  pointer-events: none;
}
.time-readout-rings { font-weight: 500; color: var(--text-subtle); }
.time-ticks { bottom: 84px; }
.time-xtitle { bottom: 100px; }
.time-region-strip { bottom: 100px; }
.time-dept-legend { bottom: 132px; }

/* The bar's tiers follow the canvas's own width (a container query on
   canvasWrap, .time-field), not the window's: the inspector takes 320px of
   a desktop window without the viewport changing. With labels the bar is
   about 840px wide; icons only, about 540.
   - 880px and up: labels, one row (the rules above).
   - Under 880px: icons only, one row.
   - Under 560px (a phone): icons in two rows (lenses and spread, then the
     axis), no readout line, and everything above the bar moves up with it. */
.time-field { container: field / inline-size; }
@container field (max-width: 879px) {
  .time-lens { padding: 0 9px; }
  .time-lens-label { display: none; }
}
@container field (max-width: 559px) {
  .time-bar { flex-wrap: wrap; justify-content: center; row-gap: 4px; }
  .time-bar-sep-axis { display: none; }
  .time-axis-toggle { flex-basis: 100%; justify-content: center; }
  .time-readout { display: none; }
  .time-ticks { bottom: 96px; }
  .time-xtitle { bottom: 112px; }
  .time-region-strip { bottom: 112px; }
  .time-dept-legend { bottom: 144px; }
}

@container field (max-width: 559px) {
  .time-bottom-fade { --fade-solid: 112px; height: 166px; }
  .dark .time-bottom-fade { --fade-solid: 122px; }
}
