/* ==========================================================================
   Future Archive Instruments — shared foundation
   ==========================================================================
   Styling contract:
   * Every selector is namespaced beneath .archive-instrument (or an
     instrument block that itself lives inside it). No resets, no body/html
     rules, no bare element selectors, no unqualified links.
   * Host-site tokens are consumed through var() with robust fallbacks.
     The host may theme every instrument by defining --surface-1 etc.
   * Visual language: technical occult instrument. Black instrument glass,
     fine graphite rules, amber documentary emphasis, green strictly for
     active signals and successful traversal. Sparse, user-initiated motion.
   ========================================================================== */

.archive-instrument {
  /* Token bridge (host value, then archive fallback) */
  --instrument-bg: var(--surface-1, #0c0d0f);
  --instrument-panel: var(--surface-2, #141619);
  --instrument-ink: var(--ink-1, #e8e3d8);
  --instrument-muted: var(--ink-3, #aaa59b);
  --instrument-amber: var(--accent, #c58a2a);
  --instrument-signal: var(--signal, #9aac42);
  --instrument-rule: var(--rule, #34373b);

  /* Derived tokens shared by all instruments */
  --instrument-font-serif: var(--font-serif, "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif);
  --instrument-font-mono: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
  --instrument-amber-bright: #e3aa4b;
  --instrument-ink-faint: rgba(232, 227, 216, 0.6); /* ≥4.5:1 composited on the glass ground */
  --instrument-glass: #08090b;
  --instrument-focus: var(--instrument-amber-bright);
  --instrument-danger: #c96a4e; /* ≥4.5:1 on the instrument ground */

  color: var(--instrument-ink);
  font-family: var(--instrument-font-serif);
  font-size: 16px;
  line-height: 1.55;
  container-type: inline-size;
}

.archive-instrument *,
.archive-instrument *::before,
.archive-instrument *::after {
  box-sizing: border-box;
}

/* --- Header block ------------------------------------------------------- */

.archive-instrument .ai-kicker {
  font-family: var(--instrument-font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--instrument-amber);
  margin: 0 0 10px;
}

.archive-instrument .ai-title {
  font-family: var(--instrument-font-serif);
  font-weight: 400;
  font-size: clamp(30px, 4.5cqw, 52px);
  line-height: 1.06;
  margin: 0 0 14px;
  color: var(--instrument-ink);
}

.archive-instrument .ai-lede {
  font-size: clamp(16px, 1.6cqw, 19px);
  max-width: 62ch;
  color: var(--instrument-ink);
  margin: 0 0 8px;
}

.archive-instrument .ai-standfirst {
  font-family: var(--instrument-font-mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: var(--instrument-muted);
  margin: 0 0 6px;
}

/* Reserve the first viewport while fixture data hydrates. This keeps the
   footer and fallback disclosure from shifting after first paint. */
.archive-instrument [data-cc-app],
.archive-instrument [data-lte-app],
.archive-instrument [data-pc-app],
.archive-instrument [data-frt-app] {
  min-height: clamp(560px, 70vh, 760px);
}

.archive-instrument .instrument-loading {
  grid-column: 1 / -1;
  align-self: start;
  display: grid;
  gap: 8px;
  max-width: 62ch;
  padding: 18px 20px;
  border: 1px solid var(--instrument-rule);
  background: var(--instrument-panel);
  color: var(--instrument-muted);
}

.archive-instrument .instrument-loading__kicker {
  font-family: var(--instrument-font-mono);
  color: var(--instrument-amber);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.archive-instrument .instrument-loading strong {
  color: var(--instrument-ink);
  font-family: var(--instrument-font-serif);
  font-size: 20px;
  font-weight: 400;
}

.archive-instrument .instrument-loading p { margin: 0; }

/* --- Panels and rules ---------------------------------------------------- */

.archive-instrument .ai-panel {
  background: var(--instrument-panel);
  border: 1px solid var(--instrument-rule);
}

.archive-instrument .ai-rule {
  border: 0;
  border-top: 1px solid var(--instrument-rule);
  margin: 20px 0;
}

/* --- Controls ------------------------------------------------------------ */

.archive-instrument .ai-btn {
  appearance: none;
  font-family: var(--instrument-font-mono);
  font-size: 12px;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--instrument-ink);
  background: transparent;
  border: 1px solid var(--instrument-rule);
  padding: 9px 14px;
  min-height: 36px;
  cursor: pointer;
  transition: border-color 120ms linear, color 120ms linear;
}

.archive-instrument .ai-btn:hover {
  border-color: var(--instrument-amber);
  color: var(--instrument-amber-bright);
}

.archive-instrument .ai-btn[aria-pressed="true"],
.archive-instrument .ai-btn.ai-btn--active {
  border-color: var(--instrument-amber);
  color: var(--instrument-amber-bright);
  background: rgba(197, 138, 42, 0.08);
}

.archive-instrument .ai-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.archive-instrument .ai-btn--signal[aria-pressed="true"] {
  border-color: var(--instrument-signal);
  color: var(--instrument-signal);
  background: rgba(154, 172, 66, 0.08);
}

.archive-instrument .ai-link {
  color: var(--instrument-amber-bright);
  text-decoration: underline;
  text-decoration-color: rgba(197, 138, 42, 0.5);
  text-underline-offset: 3px;
}

.archive-instrument .ai-link:hover {
  text-decoration-color: var(--instrument-amber-bright);
}

/* --- Focus: never invisible ---------------------------------------------- */

.archive-instrument :focus {
  outline: none;
}

.archive-instrument :focus-visible {
  outline: 2px solid var(--instrument-focus);
  outline-offset: 2px;
}

/* --- Utility -------------------------------------------------------------- */

.archive-instrument .ai-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.archive-instrument .ai-mono {
  font-family: var(--instrument-font-mono);
  letter-spacing: 0.04em;
}

/* --- Status + circulation chips ------------------------------------------ */
/* One chip system for the exact attestation vocabulary. Colour is never the
   only signal: the chip always carries the status string as text. */

.archive-instrument .ai-chip {
  display: inline-block;
  font-family: var(--instrument-font-mono);
  font-size: 12px;
  letter-spacing: 0.07em;
  padding: 2px 8px;
  border: 1px solid var(--instrument-rule);
  color: var(--instrument-muted);
  white-space: nowrap;
}

.archive-instrument .ai-chip--primary-local,
.archive-instrument .ai-chip--primary-external {
  color: var(--instrument-ink);
  border-color: rgba(232, 227, 216, 0.45);
}

.archive-instrument .ai-chip--derived,
.archive-instrument .ai-chip--interpretive {
  color: var(--instrument-muted);
}

.archive-instrument .ai-chip--unverified {
  color: var(--instrument-muted);
  border-style: dashed;
}

.archive-instrument .ai-chip--contested {
  color: var(--instrument-amber-bright);
  border-color: var(--instrument-amber);
  border-style: dashed;
}

.archive-instrument .ai-chip--refuted {
  color: var(--instrument-danger);
  border-color: var(--instrument-danger);
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.archive-instrument .ai-chip--exhibit-fiction {
  color: var(--instrument-ink);
  border-color: var(--instrument-amber);
  background: rgba(197, 138, 42, 0.12);
}

.archive-instrument .ai-chip--circulation {
  border-style: dotted;
  color: var(--instrument-muted);
}

/* --- Error surface --------------------------------------------------------
   Data failures produce a compact explanation, never an empty black panel. */

.archive-instrument .ai-error {
  border: 1px solid var(--instrument-danger);
  background: var(--instrument-panel);
  padding: 14px 16px;
  max-width: 68ch;
}

.archive-instrument .ai-error .ai-error-title {
  font-family: var(--instrument-font-mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--instrument-danger);
  margin: 0 0 6px;
}

.archive-instrument .ai-error .ai-error-body {
  margin: 0;
  font-size: 15px;
  color: var(--instrument-ink);
}

/* --- Machine-ink register (spec 02 §5.2 — owned there, consumed site-wide) --
   Wraps ANY machine-authored text. Keyed to origin.kind == "machine", never to
   attestation: a human-authored exhibit-fiction keeps editorial ink; only
   machine text goes cold. The register carries redundant non-colour signals:
   the leading "⟡ machine" marker (canonical, lowercase, mono — the uppercase
   "⟡ MACHINE" string is reserved for the export banner), a hair-line left
   rule, and mono type. Phosphor #8FB4BA measures 8.92:1 on the glass ground,
   8.71:1 on --instrument-bg, 8.12:1 on the panel — AAA body text everywhere,
   dimmer than editorial ink by design, hue-distinct from amber and signal. */

.archive-instrument {
  --instrument-machine-ink: #8FB4BA;
  --instrument-machine-ink-bright: #A9CBD0;
  --instrument-machine-ink-rule: rgba(143, 180, 186, 0.45);
}

.archive-instrument .ai-machine {
  display: block;
  color: var(--instrument-machine-ink);
  font-family: var(--instrument-font-mono);
  font-size: 13px;
  line-height: 1.55;
  border-left: 1px solid var(--instrument-machine-ink-rule);
  padding-left: 12px;
}

.archive-instrument .ai-machine--inline {
  display: inline;
  border-left: 0;
  padding-left: 0;
}

.archive-instrument .ai-machine .ai-machine-marker {
  color: var(--instrument-machine-ink-bright);
  letter-spacing: 0.08em;
}

.archive-instrument .ai-machine--withdrawn {
  text-decoration: line-through;
  text-decoration-thickness: 1px;
}

.archive-instrument .ai-machine a,
.archive-instrument .ai-machine .ai-link {
  color: var(--instrument-machine-ink-bright);
  text-decoration-color: var(--instrument-machine-ink-rule);
}

/* --- Live region (SR announcements) --------------------------------------- */

.archive-instrument .ai-live {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

/* --- Calibration corners --------------------------------------------------
   Fine plate brackets used by instrument frames. Decorative: aria-hidden. */

.archive-instrument .ai-corner {
  position: absolute;
  width: 18px;
  height: 18px;
  border-color: var(--instrument-amber);
  border-style: solid;
  border-width: 0;
  opacity: 0.7;
  pointer-events: none;
}

.archive-instrument .ai-corner--tl { top: 0; left: 0; border-top-width: 1px; border-left-width: 1px; }
.archive-instrument .ai-corner--tr { top: 0; right: 0; border-top-width: 1px; border-right-width: 1px; }
.archive-instrument .ai-corner--bl { bottom: 0; left: 0; border-bottom-width: 1px; border-left-width: 1px; }
.archive-instrument .ai-corner--br { bottom: 0; right: 0; border-bottom-width: 1px; border-right-width: 1px; }

/* --- Fullscreen fallback mode ---------------------------------------------
   Used when the Fullscreen API is unavailable; element pins to viewport. */

.archive-instrument.ai-fullscreen-fallback {
  position: fixed;
  inset: 0;
  z-index: 9999;
  overflow: auto;
  background: var(--instrument-bg);
  padding: 16px;
}

/* --- Mobile ergonomics ------------------------------------------------------
   Essential controls get 44px targets below tablet width. */

@media (max-width: 768px) {
  .archive-instrument .ai-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 14px;
  }
}

/* --- Reduced motion ---------------------------------------------------------
   Removes rotations, animated paths, pulses, and parallax across every
   instrument. Instrument scripts must also consult
   ArchiveInstruments.prefersReducedMotion() before starting any animation. */

@media (prefers-reduced-motion: reduce) {
  .archive-instrument *,
  .archive-instrument *::before,
  .archive-instrument *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
