/* ============================================================
   RAVENSWORTH EXPEDITION ARCHIVE — Digital Companion
   Design tokens: clean museum-microsite chrome (teal/off-white)
   + period parchment accents inside document viewers.
   ============================================================ */

:root,
[data-theme='light'] {
  /* ---- Surfaces (museum off-white) ---- */
  --color-bg: #faf9f6;
  --color-surface: #ffffff;
  --color-surface-2: #f4f2ec;
  --color-surface-offset: #eeece3;
  --color-surface-offset-2: #e6e3d8;
  --color-surface-dynamic: #dcd8ca;
  --color-divider: #e2dfd4;
  --color-border: #d3cfc0;

  /* ---- Text ---- */
  --color-text: #1c211f;
  --color-text-muted: #5c6360;
  --color-text-faint: #9aa19c;
  --color-text-inverse: #f8f7f2;

  /* ---- Primary accent: Verrick teal ---- */
  --color-primary: #0f6f62;
  --color-primary-hover: #0b5449;
  --color-primary-active: #083d35;
  --color-primary-highlight: #d3e6e1;

  /* ---- Warning / ochre (kraft dossier accent) ---- */
  --color-warning: #96631f;
  --color-warning-hover: #714b17;
  --color-warning-active: #4b3210;
  --color-warning-highlight: #e6d7bb;

  /* ---- Error / signal red (used sparingly: reveal marks) ---- */
  --color-error: #9c2b2b;
  --color-error-hover: #7a2020;
  --color-error-active: #571616;
  --color-error-highlight: #e8cfcb;

  --color-success: #43683a;
  --color-success-hover: #2f4c28;

  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.85rem;
  --radius-xl: 1.25rem;
  --radius-full: 9999px;

  --transition-ui: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --shadow-sm: 0 1px 2px oklch(0.2 0.02 170 / 0.08);
  --shadow-md: 0 4px 16px oklch(0.2 0.02 170 / 0.10);
  --shadow-lg: 0 16px 40px oklch(0.2 0.02 170 / 0.16);

  --content-narrow: 640px;
  --content-default: 960px;
  --content-wide: 1200px;
  --content-full: 100%;

  --font-display: 'Fraunces', 'Libre Caslon Display', Georgia, serif;
  --font-body: 'General Sans', 'Inter', sans-serif;
  --font-period: 'EB Garamond', Georgia, serif;
  --font-mono: 'Courier Prime', 'Courier New', monospace;

  /* per-document paper tones (canon) */
  --paper-report: #f6f0e1;
  --paper-plates: #dad3c3;
  --paper-dossier: #c7a76c;
  --paper-findingaid: #f1f1ee;
  --paper-packaging: #fafaf9;
  --paper-committee: #e3e9eb;
  --paper-committee-buff: #ede7d8;
  --paper-notebook: #ead9a8;
  --paper-interval: #ccd6c6;
}

[data-theme='dark'] {
  --color-bg: #14171a;
  --color-surface: #1a1e1c;
  --color-surface-2: #1f2320;
  --color-surface-offset: #232723;
  --color-surface-offset-2: #2a2e29;
  --color-surface-dynamic: #33372f;
  --color-divider: #2a2e29;
  --color-border: #3b3f37;

  --color-text: #e7e6de;
  --color-text-muted: #a3a89f;
  --color-text-faint: #6c716a;
  --color-text-inverse: #1c211f;

  --color-primary: #4fa696;
  --color-primary-hover: #6fc0b0;
  --color-primary-active: #8bd4c4;
  --color-primary-highlight: #223835;

  --color-warning: #c99a4f;
  --color-warning-hover: #dcb26a;
  --color-warning-active: #eac789;
  --color-warning-highlight: #3a301e;

  --color-error: #c56060;
  --color-error-hover: #d47f7f;
  --color-error-active: #571616;
  --color-error-highlight: #3a2323;

  --color-success: #7ea973;

  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.3);
  --shadow-md: 0 4px 16px oklch(0 0 0 / 0.35);
  --shadow-lg: 0 16px 40px oklch(0 0 0 / 0.5);

  --paper-report: #d8cfb4;
  --paper-plates: #b9b09a;
  --paper-dossier: #9c7c47;
  --paper-findingaid: #cfcfc7;
  --paper-packaging: #d4d4d1;
  --paper-committee: #b9c3c6;
  --paper-committee-buff: #c7bfa2;
  --paper-notebook: #c2ab74;
  --paper-interval: #a3b39c;
}

/* ---- Type scale ---- */
:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.5rem);
  --text-3xl: clamp(2.5rem, 1rem + 4vw, 5rem);
  --text-hero: clamp(2.75rem, 0.5rem + 6vw, 6.5rem);
}

/* ---- Spacing ---- */
:root {
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
  --space-32: 8rem;
}

/* ============================================================
   LAYOUT PRIMITIVES
   ============================================================ */

.wrap {
  width: 100%;
  max-width: var(--content-wide);
  margin-inline: auto;
  padding-inline: var(--space-6);
}
.wrap--narrow {
  max-width: var(--content-default);
}
.wrap--prose {
  max-width: 68ch;
}

section {
  padding-block: clamp(var(--space-12), 8vw, var(--space-24));
}

/* ============================================================
   HEADER / NAV
   ============================================================ */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--color-divider);
  transition: box-shadow var(--transition-ui), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.site-header.is-scrolled {
  box-shadow: var(--shadow-sm);
}
.site-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding-block: var(--space-4);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--text-base);
  color: var(--color-text);
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.brand svg { flex-shrink: 0; }
.brand__sub {
  display: block;
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.nav {
  display: flex;
  align-items: center;
  gap: var(--space-6);
}
.nav__list {
  display: flex;
  gap: var(--space-5);
  align-items: center;
}
.nav__link {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
  position: relative;
  padding-block: var(--space-1);
}
.nav__link:hover,
.nav__link:focus-visible,
.nav__link.is-active {
  color: var(--color-primary);
}
.nav__link.is-active::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -6px;
  height: 2px;
  background: var(--color-primary);
  border-radius: var(--radius-full);
}

.nav-toggle {
  display: none;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
}

.theme-toggle {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--color-text-muted);
}
.theme-toggle:hover { color: var(--color-primary); background: var(--color-surface-offset); }

@media (max-width: 860px) {
  .nav__list { display: none; }
  .nav-toggle { display: flex; }
  .nav.is-open .nav__list {
    display: flex;
    position: fixed;
    top: 64px;
    left: 0;
    right: 0;
    bottom: 0;
    height: calc(100vh - 64px);
    height: calc(100dvh - 64px);
    margin: 0;
    flex-direction: column;
    background: var(--color-bg);
    padding: var(--space-8) var(--space-6);
    gap: var(--space-6);
    align-items: flex-start;
    align-self: auto;
    overflow-y: auto;
    z-index: 150;
  }
  .nav.is-open .nav__link { font-size: var(--text-lg); }
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  font-size: var(--text-sm);
  font-weight: 600;
  text-decoration: none;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.btn--primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.btn--primary:hover { background: var(--color-primary-hover); }
.btn--ghost {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text);
}
.btn--ghost:hover { border-color: var(--color-primary); color: var(--color-primary); }
.btn--sm { padding: var(--space-2) var(--space-4); font-size: var(--text-xs); }

/* ---- Catalogue / working reference desk ---- */
.reference-desk {
  max-width: 680px;
  margin-top: var(--space-8);
  padding: var(--space-5);
  border: 1px solid var(--color-border);
  background: color-mix(in oklab, var(--color-surface) 86%, var(--color-surface-offset));
}
.reference-desk > label {
  display: block;
  color: var(--color-text);
  font: 600 var(--text-sm) var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.reference-desk > p:not(.reference-desk__status):not(.reference-desk__noscript) {
  margin: var(--space-2) 0 var(--space-4);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}
.reference-desk__row { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.reference-desk input {
  min-width: min(100%, 20rem);
  flex: 1 1 18rem;
  min-height: 44px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  background: var(--color-bg);
  font: 0.9rem var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.reference-desk input:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.reference-desk__status { min-height: 1.5em; margin-top: var(--space-4); color: var(--color-text-muted); font-size: var(--text-sm); }
.reference-desk__status.is-error { color: var(--color-error); }
.reference-desk__status.is-recognised { color: var(--color-success); }
.reference-desk__reconcile { margin-top: var(--space-2); min-height: 44px; }
.reference-desk__noscript { margin-top: var(--space-4); color: var(--color-text-muted); font-size: var(--text-xs); }

/* ============================================================
   COMPASS / BEARING MOTIF (recurring chrome element)
   ============================================================ */

.bearing-mark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--color-text-faint);
  text-transform: uppercase;
}
.bearing-mark svg { width: 14px; height: 14px; }

.date-stamp {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
  transform: rotate(-1.5deg);
}

/* ============================================================
   FOOTER
   ============================================================ */

.site-footer {
  border-top: 1px solid var(--color-divider);
  padding-block: var(--space-16) var(--space-10);
  background: var(--color-surface-2);
}
.footer-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr 1fr;
  gap: var(--space-10);
}
.footer-col h4 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-faint);
  margin-bottom: var(--space-4);
}
.footer-col a,
.footer-col p {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  margin-bottom: var(--space-2);
}
.footer-col a:hover { color: var(--color-primary); }
.footer-bottom {
  margin-top: var(--space-12);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-divider);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-4);
  font-size: var(--text-xs);
  color: var(--color-text-faint);
}

@media (max-width: 780px) {
  .footer-grid { grid-template-columns: 1fr 1fr; }
}

/* ============================================================
   WORKING RECORD / OPEN QUESTIONS (persistent modules)
   ============================================================ */

.working-record {
  position: fixed;
  left: 0;
  bottom: var(--space-10);
  z-index: 90;
}
.working-record__tab {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  background: var(--color-surface);
  color: var(--color-primary);
  padding: var(--space-4) var(--space-2);
  border: 1px solid var(--color-border);
  border-left: none;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  font: 600 var(--text-xs) var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  box-shadow: var(--shadow-md);
}
.working-record__tab:hover { background: var(--color-primary-highlight); }
.working-record__panel {
  position: fixed;
  left: 0;
  /* The parent shell deliberately sits beneath the persistent header. Start
     the parchment below the measured header rather than allowing the title
     and close control to disappear beneath the archive chrome. */
  top: var(--site-header-height, 64px);
  bottom: 0;
  width: min(400px, 92vw);
  overflow-y: auto;
  z-index: 201;
  padding: var(--space-10) var(--space-6) var(--space-8);
  color: #201f1a;
  background:
    linear-gradient(90deg, transparent 0 2.2rem, rgba(150, 99, 31, 0.15) 2.2rem 2.28rem, transparent 2.28rem),
    repeating-linear-gradient(0deg, #f7f1e4 0 1.84rem, #e6dece 1.85rem 1.9rem);
  border-right: 1px solid #cbbda4;
  box-shadow: var(--shadow-lg);
  transform: translateX(calc(-100% - 2px));
  visibility: hidden;
  pointer-events: none;
  transition:
    transform 360ms cubic-bezier(0.16, 1, 0.3, 1),
    visibility 0s linear 360ms;
  will-change: transform;
}
.working-record__panel.is-open {
  transform: translateX(0);
  visibility: visible;
  pointer-events: auto;
  transition-delay: 0s;
}
[data-theme='dark'] .working-record__panel { color: #201f1a; }
.working-record__close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: #5f594c;
}
.working-record__eyebrow {
  margin-right: var(--space-8);
  color: #756b57;
  font: 600 0.72rem var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.working-record__panel h3 {
  margin: var(--space-3) 0 var(--space-4);
  color: #24231e;
  font: 500 var(--text-xl) var(--font-display);
}
.working-record__intro,
.working-record__note {
  color: #5f594c;
  font: var(--text-sm) var(--font-period);
  line-height: 1.55;
}
.working-record__list {
  display: grid;
  gap: var(--space-4);
  margin: var(--space-8) 0;
  padding: 0;
  list-style: none;
}
.working-record__list li {
  display: grid;
  gap: var(--space-1);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid rgba(115, 95, 61, 0.28);
  color: #3b372e;
  font: 0.96rem/1.45 var(--font-period);
}
.working-record__list strong {
  color: #665020;
  font: 600 0.68rem var(--font-mono);
  letter-spacing: 0.07em;
  text-transform: uppercase;
}
.working-record__reference {
  margin: var(--space-6) 0 var(--space-4);
  padding-block: var(--space-4);
  border-block: 1px solid rgba(115, 95, 61, 0.35);
  color: #483e2a;
  font: 600 0.74rem/1.45 var(--font-mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.working-record__note { font-size: 0.86rem; }
.working-record__tab-short { display: none; }

.questions-drawer {
  position: fixed;
  right: 0;
  bottom: var(--space-10);
  z-index: 90;
  display: flex;
  align-items: stretch;
}
.questions-drawer__tab {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  background: var(--color-primary);
  color: var(--color-text-inverse);
  padding: var(--space-4) var(--space-2);
  border-radius: var(--radius-md) 0 0 var(--radius-md);
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}
.questions-drawer__tab:hover { background: var(--color-primary-hover); }
.questions-drawer__panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(420px, 92vw);
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform 320ms cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  z-index: 200;
  padding: var(--space-8) var(--space-6);
}
.questions-drawer__panel.is-open { transform: translateX(0); }
.questions-drawer__scrim {
  position: fixed;
  inset: 0;
  background: oklch(0.15 0.02 170 / 0.35);
  z-index: 190;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-ui);
}
.questions-drawer__scrim.is-open { opacity: 1; pointer-events: auto; }
.questions-drawer__close {
  position: absolute;
  top: var(--space-5);
  right: var(--space-5);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
}

.questions-drawer__tab-short { display: none; }
@media (max-width: 640px) {
  .site-header__inner { gap: var(--space-2); padding-inline: var(--space-4); }
  .brand { gap: var(--space-2); font-size: 0.875rem; }
  .brand__sub { display: none; }
  .nav { gap: var(--space-1); }
  .theme-toggle { width: 32px; height: 32px; }
  .nav-toggle { width: 36px; height: 36px; }
  .questions-drawer {
    position: static;
    justify-content: center;
    margin: var(--space-8) auto;
  }
  .questions-drawer__tab {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    transform: none;
    border-radius: var(--radius-full);
    padding: var(--space-3) var(--space-5);
    font-size: 0.7rem;
    box-shadow: var(--shadow-md);
  }
  .questions-drawer__tab-full { display: none; }
  .questions-drawer__tab-short { display: inline; }
  .working-record { position: static; margin: var(--space-8) auto; text-align: center; }
  .working-record__tab {
    writing-mode: horizontal-tb;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-full);
    padding: var(--space-3) var(--space-5);
    font-size: 0.7rem;
  }
  .working-record__tab-full { display: none; }
  .working-record__tab-short { display: inline; }
  .working-record__panel { width: 100vw; padding-top: var(--space-12); }
}

/* ============================================================
   SKIP LINK
   ============================================================ */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--color-primary);
  color: var(--color-text-inverse);
  padding: var(--space-3) var(--space-5);
  z-index: 999;
  border-radius: var(--radius-sm);
}
.skip-link:focus { left: var(--space-4); top: var(--space-4); }

/* ============================================================
   MOTION — reveal on scroll (minimal, purposeful)
   ============================================================ */
.js [data-reveal] {
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 700ms cubic-bezier(0.16, 1, 0.3, 1), transform 700ms cubic-bezier(0.16, 1, 0.3, 1);
}
.js [data-reveal].is-visible {
  opacity: 1;
  transform: translateY(0);
}
@media (prefers-reduced-motion: reduce) {
  .js [data-reveal] { opacity: 1; transform: none; transition: none; }
  .working-record__panel { transition: none; }
}


/* Production utilities */
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body.is-nav-open,
body.is-overlay-open { overflow: hidden; }
body.is-nav-open .questions-drawer { visibility: hidden; }
.noscript-banner {
  padding: var(--space-3) var(--space-6);
  background: var(--color-warning-highlight);
  color: var(--color-text);
  border-bottom: 1px solid var(--color-warning);
  text-align: center;
  font-size: var(--text-sm);
}
.noscript-banner a { color: var(--color-primary); font-weight: 600; }

/* First-session visual cue. It is deliberately non-modal and aria-hidden. */
.access-slip {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: grid;
  place-items: center;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
  background: color-mix(in oklab, var(--color-bg) 88%, transparent);
  cursor: pointer;
  opacity: 0;
  transition: opacity 180ms ease;
}
.access-slip.is-visible { opacity: 1; }
.access-slip.is-leaving { opacity: 0; pointer-events: none; }
.access-slip__sheet {
  display: grid;
  gap: var(--space-3);
  width: min(31rem, 100%);
  padding: clamp(1.5rem, 7vw, 3rem);
  border: 1px solid color-mix(in oklab, var(--color-primary) 64%, var(--color-border));
  background: color-mix(in oklab, var(--color-surface) 94%, transparent);
  box-shadow: var(--shadow-lg);
  color: var(--color-text);
  text-align: center;
}
.access-slip__mark,
.access-slip__sheet > span:last-child {
  color: var(--color-text-muted);
  font: .68rem var(--font-mono);
  letter-spacing: .13em;
  text-transform: uppercase;
}
.access-slip__sheet strong {
  color: var(--color-primary);
  font: 500 clamp(1.5rem, 5vw, 2.4rem) var(--font-display);
}
@media (prefers-reduced-motion: reduce) {
  .access-slip { display: none !important; }
}

@media (max-width: 860px) {
  .nav.is-open .nav__list {
    top: var(--site-header-height, 64px);
    height: calc(100dvh - var(--site-header-height, 64px));
  }
}
