/* ==========================================================================
   Lang Marketing Analytics Centre — Working Paper Series
   langmac.ca

   Design system carried over from the souravray.ca academic site:
   the same warm-paper surfaces, archival-crimson accent, Instrument Serif
   display face and Satoshi body face, so the two sites read as siblings.

   1. Design tokens
   2. Base / reset
   3. Header + theme toggle
   4. Intro
   5. Paper list
   6. Buttons + abstract disclosure
   7. Footer
   8. Responsive + motion + print
   ========================================================================== */

/* 1. DESIGN TOKENS ======================================================== */

:root,
[data-theme='light'] {
  /* Type scale (fluid) */
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.2vw, 0.9375rem);
  --text-base: clamp(1rem, 0.95rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.0625rem, 1rem + 0.4vw, 1.25rem);
  --text-xl: clamp(1.25rem, 1.1rem + 0.7vw, 1.625rem);
  --text-2xl: clamp(1.75rem, 1.3rem + 1.8vw, 2.75rem);

  /* Spacing (4px base) */
  --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;

  /* Surfaces — warm paper */
  --color-bg: #faf7f1;
  --color-surface: #fdfbf7;
  --color-surface-offset: #f3efe6;
  --color-surface-offset-2: #ece7db;
  --color-divider: #e2dbcd;
  --color-border: #d3cbba;

  /* Ink */
  --color-text: #1f1c18;
  --color-text-muted: #6a6358;
  --color-text-faint: #a3998a;
  --color-text-inverse: #faf7f1;

  /* Accent — archival crimson */
  --color-primary: #8c1c2f;
  --color-primary-hover: #6d1424;
  --color-primary-active: #500e1a;
  --color-primary-highlight: #efdcdc;

  /* Radius, shadow, motion */
  --radius-sm: 2px;
  --radius-md: 3px;
  --shadow-sm: 0 1px 2px rgba(40, 32, 20, 0.06);
  --shadow-md: 0 6px 22px rgba(40, 32, 20, 0.08);
  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  /* Content width — one narrow reading column */
  --content: 52rem;

  /* Fonts */
  --font-display: 'Instrument Serif', 'Iowan Old Style', Georgia, serif;
  --font-body: 'Satoshi', 'Inter', 'Helvetica Neue', Arial, sans-serif;
}

[data-theme='dark'] {
  --color-bg: #17150f;
  --color-surface: #1c1a14;
  --color-surface-offset: #1e1c15;
  --color-surface-offset-2: #26241c;
  --color-divider: #2c2921;
  --color-border: #3b372d;
  --color-text: #e4dfd4;
  --color-text-muted: #9a9284;
  --color-text-faint: #6d665a;
  --color-text-inverse: #17150f;
  --color-primary: #dd9298;
  --color-primary-hover: #ecacb1;
  --color-primary-active: #f3c1c5;
  --color-primary-highlight: #3a2a2b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 6px 22px rgba(0, 0, 0, 0.45);
}

/* Visitors who have never touched the toggle get their OS preference. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --color-bg: #17150f;
    --color-surface: #1c1a14;
    --color-surface-offset: #1e1c15;
    --color-surface-offset-2: #26241c;
    --color-divider: #2c2921;
    --color-border: #3b372d;
    --color-text: #e4dfd4;
    --color-text-muted: #9a9284;
    --color-text-faint: #6d665a;
    --color-text-inverse: #17150f;
    --color-primary: #dd9298;
    --color-primary-hover: #ecacb1;
    --color-primary-active: #f3c1c5;
    --color-primary-highlight: #3a2a2b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 6px 22px rgba(0, 0, 0, 0.45);
  }
}

/* 2. BASE / RESET ========================================================= */

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body.mac-site {
  margin: 0;
  background-color: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color 240ms ease, color 240ms ease;
}

/* Base element rules use :where() so they carry zero specificity — a
   component class further down the file always wins without needing !important
   or long selectors. */
.mac-site :where(h1, h2, h3) {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.12;
  letter-spacing: -0.01em;
  margin: 0;
  text-wrap: balance;
}

.mac-site :where(p) {
  margin: 0 0 var(--space-4);
  max-width: 68ch;
}

.mac-site :where(a) {
  color: var(--color-primary);
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  transition: color var(--transition-interactive);
}

.mac-site :where(a):hover {
  color: var(--color-primary-hover);
}

.mac-site :focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.mac-wrap {
  width: 100%;
  max-width: var(--content);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.mac-skip {
  position: absolute;
  left: -9999px;
}

.mac-skip:focus {
  left: var(--space-4);
  top: var(--space-4);
  z-index: 50;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  padding: var(--space-2) var(--space-4);
}

/* 3. HEADER + THEME TOGGLE ================================================ */

.mac-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background-color: color-mix(in srgb, var(--color-bg) 92%, transparent);
  backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--color-divider);
}

/* Fallback for browsers without color-mix(). */
@supports not (background-color: color-mix(in srgb, red 50%, transparent)) {
  .mac-header {
    background-color: var(--color-bg);
  }
}

.mac-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 4.25rem;
  padding-block: var(--space-3);
}

.mac-header__titles {
  min-width: 0;
}

.mac-header__title {
  font-size: var(--text-lg);
  font-family: var(--font-display);
  letter-spacing: -0.005em;
}

.mac-header__title a {
  color: inherit;
  text-decoration: none;
}

.mac-header__sub {
  display: block;
  margin-top: 0.1rem;
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* The single twist in the header: one square day/night button. */
.mac-toggle {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  cursor: pointer;
  transition: background-color var(--transition-interactive),
    border-color var(--transition-interactive), color var(--transition-interactive);
}

.mac-toggle:hover {
  background-color: var(--color-surface-offset);
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.mac-toggle svg {
  width: 18px;
  height: 18px;
  display: block;
}

/* 4. INTRO ================================================================ */

.mac-intro {
  padding-block: var(--space-16) var(--space-12);
  border-bottom: 1px solid var(--color-divider);
}

.mac-intro__eyebrow {
  margin: 0 0 var(--space-4);
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* Keep "University of Guelph" from splitting across two lines: each half of
   the line is a nowrap unit, so the break can only happen at the middot. */
@media (min-width: 560px) {
  .mac-intro__eyebrow .mac-eyebrow__part {
    white-space: nowrap;
  }
}

.mac-intro h1 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-6);
}

.mac-intro p {
  font-size: var(--text-base);
  color: var(--color-text);
}

.mac-intro p + p {
  color: var(--color-text-muted);
}

/* 5. PAPER LIST =========================================================== */

.mac-papers {
  padding-block: var(--space-12) var(--space-16);
}

.mac-section-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}

.mac-section-head h2 {
  font-size: var(--text-xl);
  white-space: nowrap;
}

.mac-section-head::after {
  content: '';
  flex: 1 1 auto;
  height: 1px;
  background-color: var(--color-border);
}

.mac-section-head__count {
  font-size: var(--text-xs);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.mac-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: paper;
}

.mac-paper {
  counter-increment: paper;
  display: grid;
  grid-template-columns: 2.5rem 1fr;
  gap: 0 var(--space-4);
  padding-block: var(--space-8);
  border-top: 1px solid var(--color-divider);
}

.mac-paper:first-child {
  border-top: 0;
  padding-top: 0;
}

.mac-paper::before {
  content: counter(paper) '.';
  font-family: var(--font-display);
  font-size: var(--text-lg);
  line-height: 1.5;
  color: var(--color-text-faint);
  text-align: right;
}

.mac-paper__body {
  min-width: 0;
}

.mac-paper__number {
  display: inline-block;
  margin-bottom: var(--space-2);
  padding: 0.15rem var(--space-2);
  background-color: var(--color-surface-offset);
  border: 1px solid var(--color-divider);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.mac-paper__title {
  font-size: var(--text-lg);
  font-family: var(--font-body);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: -0.005em;
  margin-bottom: var(--space-3);
}

.mac-paper__meta {
  margin: 0 0 var(--space-1);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: none;
}

.mac-paper__meta strong {
  font-weight: 500;
  color: var(--color-text);
}

.mac-paper__affil {
  margin: var(--space-2) 0 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-xs);
  line-height: 1.6;
  /* Muted rather than faint: the faint tone does not clear the 4.5:1
     contrast floor at this size, in either theme. */
  color: var(--color-text-muted);
}

.mac-paper__note {
  margin: var(--space-3) 0 0;
  padding-left: var(--space-3);
  border-left: 2px solid var(--color-primary-highlight);
  font-size: var(--text-xs);
  font-style: italic;
  color: var(--color-text-muted);
}

/* 6. BUTTONS + ABSTRACT DISCLOSURE ======================================== */

.mac-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-5);
}

.mac-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-sm);
  font-weight: 500;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--transition-interactive),
    border-color var(--transition-interactive), color var(--transition-interactive),
    box-shadow var(--transition-interactive);
}

.mac-btn:hover {
  background-color: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-sm);
}

[data-theme='dark'] .mac-btn:hover {
  color: var(--color-bg);
}

.mac-btn svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
}

/* A link still pointing at a placeholder is dimmed and inert, so it is
   obvious at a glance which PDFs have not been wired up yet.
   JS adds this class; see assets/js/main.js. */
.mac-btn.is-unset {
  border-style: dashed;
  color: var(--color-text-faint);
  background-color: transparent;
  cursor: not-allowed;
}

.mac-btn.is-unset:hover {
  background-color: transparent;
  border-color: var(--color-border);
  color: var(--color-text-faint);
  box-shadow: none;
}

/* The abstract toggle is a native <details>/<summary>: it needs no JS,
   is keyboard accessible, and survives a WordPress paste untouched.
   It sits third in the button row while closed; once opened it claims a
   full-width row of its own so the abstract gets the whole reading measure. */
.mac-abstract {
  flex: 0 0 auto;
  min-width: 0;
}

.mac-abstract[open] {
  flex: 1 1 100%;
}

.mac-abstract > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  width: fit-content;
}

.mac-abstract > summary::-webkit-details-marker {
  display: none;
}

.mac-abstract__chev {
  transition: transform var(--transition-interactive);
}

.mac-abstract[open] .mac-abstract__chev {
  transform: rotate(90deg);
}

.mac-abstract__label-open {
  display: none;
}

.mac-abstract[open] .mac-abstract__label-open {
  display: inline;
}

.mac-abstract[open] .mac-abstract__label-closed {
  display: none;
}

.mac-abstract__panel {
  margin-top: var(--space-4);
  padding: var(--space-5) var(--space-5) var(--space-3);
  background-color: var(--color-surface-offset);
  border: 1px solid var(--color-divider);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius-sm);
}

.mac-abstract__panel h3 {
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: var(--space-2);
}

.mac-abstract__panel p {
  font-size: var(--text-sm);
  max-width: 72ch;
}

.mac-abstract__keywords {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-divider);
}

.mac-abstract__keywords p {
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* 7. FOOTER =============================================================== */

.mac-footer {
  border-top: 1px solid var(--color-divider);
  background-color: var(--color-surface);
  padding-block: var(--space-10);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.mac-footer p {
  margin-bottom: var(--space-2);
  max-width: 68ch;
}

.mac-footer__legal {
  margin-top: var(--space-5);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* 8. RESPONSIVE + MOTION + PRINT ========================================== */

@media (max-width: 640px) {
  .mac-paper {
    grid-template-columns: 1.75rem 1fr;
    gap: 0 var(--space-3);
  }

  .mac-paper::before {
    font-size: var(--text-base);
    line-height: 1.7;
  }

  .mac-intro {
    padding-block: var(--space-10) var(--space-8);
  }

  .mac-actions > .mac-btn {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* On a phone each control gets its own full-width row. */
  .mac-actions > .mac-abstract {
    flex: 1 1 100%;
  }

  .mac-abstract > summary {
    width: 100%;
    justify-content: center;
  }
}

@media (max-width: 400px) {
  .mac-header__sub {
    display: none;
  }
}

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

@media print {
  .mac-header,
  .mac-actions,
  .mac-abstract__chev {
    display: none !important;
  }

  .mac-abstract__panel {
    border-left-width: 1px;
  }

  body.mac-site {
    background: #fff;
    color: #000;
  }
}
