/* =========================================================
   pipe-works-base.css
   Pipe-Works — Unified Foundation

   MERGED FROM:
   - shared-base.css (The Daily Undertaking foundation)
   - pipe-works-base.css (Pipe-Works theming)

   PURPOSE
   - Global tokens (fonts, colors, spacing)
   - Minimal reset + accessibility
   - Pipe-works palette and theming
   - Common components (sheet, sticker, ascii, imprint)

   RULE OF THUMB
   This file defines the pamphleteer voice and vocabulary.
   Page CSS (index.css, crooked-pipe.css, etc.) writes sentences.

   TODO: Consolidate color palettes (newsprint vs pipe-works)
   ========================================================= */

/* =========================================================
   1) TOKENS — COLOR PALETTES
   ========================================================= */

:root {
  /* ---------------------------------------------------------
     1.1 NEWSPRINT PALETTE (from Daily Undertaking)
     Keeping for potential future use / reference
     --------------------------------------------------------- */
  --ink-absolute: #000;
  --ink-none: transparent;
  --ink-newsprint-black: var(--ink-absolute);
  --ink-newsprint-gray: #2b2b2b;
  --ink-newsprint-faded: #4a4a4a;
  --ink-red: #c41e3a;
  --ink-accent: #1a1a1a;
  --ink-warning: #1a1a1a;
  --ink-error: #1a1a1a;
  --ink-success: #1a1a1a;
  --paper-newsprint: #f2efe9;
  --paper-muted: #ebe5d6;
  --surface-backdrop: #2a2a2a;
  --rule: #2c2c2c;
  --rule-muted: #3a3a3a;
  --rule-faint: #5a5a5a;
  --shadow-soft: rgb(0 0 0 / 10%);
  --shadow-medium: rgb(43 43 43 / 15%);
  --overlay-paper: rgb(214 209 199 / 20%);

  /* ---------------------------------------------------------
     1.2 PIPE-WORKS PALETTE (current theme)
     Aged paper, ink, blood accents
     --------------------------------------------------------- */
  --paper: #f3ecd8;
  --ink: #2a1f14;
  --ink-faded: #453728;
  --blood: #7a1f1f;
  --pin: #8b5e3c;
  --cooling-brown: #4a3a2a;
  --bg: #2b241c;
}

/* =========================================================
   2) TOKENS — TYPOGRAPHY
   ========================================================= */

:root {
  /* Font families */
  --font-masthead: 'IM Fell English SC', serif;
  --font-headline: 'Libre Baskerville', serif;
  --font-body: 'Crimson Text', serif;
  --font-record:
    'Courier Prime', ui-monospace, sfmono-regular, menlo, monaco, consolas, 'Liberation Mono',
    monospace;
  --font-data:
    'Courier Prime', ui-monospace, sfmono-regular, menlo, monaco, consolas, 'Liberation Mono',
    monospace;
  --font-console:
    'Courier Prime', ui-monospace, sfmono-regular, menlo, monaco, consolas, 'Liberation Mono',
    monospace;
  --font-symbols: 'IM Fell English', serif;
  --font-accent:
    'Special Elite', ui-monospace, sfmono-regular, menlo, monaco, consolas, 'Liberation Mono',
    monospace;

  /* Font sizes & rhythm */
  --text-size: 16px;
  --text-line: 1.35;
}

/* =========================================================
   3) TOKENS — SPACING & RADII
   ========================================================= */

:root {
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-1: 2px;
  --radius-2: 4px;

  /* ---------------------------------------------------------
     QUIRK SYSTEM — Intentional Misalignment

     Separates structural layout from aesthetic offsets.
     Quirks use transforms (don't affect document flow).
     Adjust --quirk-intensity at breakpoints as needed.
     --------------------------------------------------------- */
  --quirk-intensity: 1;
}

/* =========================================================
   4) RESET — MINIMAL + PREDICTABLE
   ========================================================= */

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

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

body {
  margin: 0;
}

img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
}

input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  background: none;
  border: 0;
  padding: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  margin: 0;
  padding: 0;
}

p,
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
}

::selection {
  background: var(--overlay-paper);
}

/* =========================================================
   5) ACCESSIBILITY & MOTION
   ========================================================= */

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

/* =========================================================
   6) UTILITIES
   ========================================================= */

.u-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.u-nowrap {
  white-space: nowrap;
}

.u-muted {
  color: var(--ink-faded);
}

.u-faint {
  color: var(--ink-faded);
  opacity: 0.85;
}

.u-rule-top {
  border-top: 1px solid var(--rule);
}

.u-rule-bottom {
  border-bottom: 1px solid var(--rule);
}

/* Quirk utility — apply transform-based offsets
   Elements define their own --quirk-x, --quirk-y, --quirk-rotate
   These are multiplied by --quirk-intensity for responsive scaling */
.u-quirk {
  --quirk-x: 0rem;
  --quirk-y: 0rem;
  --quirk-rotate: 0deg;
  transform: translate(
      calc(var(--quirk-x) * var(--quirk-intensity)),
      calc(var(--quirk-y) * var(--quirk-intensity))
    )
    rotate(calc(var(--quirk-rotate) * var(--quirk-intensity)));
}

/* =========================================================
   7) SCROLLBAR STYLING
   ========================================================= */

/* WebKit browsers (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: var(--paper);
}

::-webkit-scrollbar-thumb {
  background: var(--ink-faded);
  border-radius: var(--radius-1);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--ink);
}

/* Firefox */
* {
  scrollbar-color: var(--ink-faded) var(--paper);
  scrollbar-width: thin;
}

/* =========================================================
   8) BODY & SHEET — PIPE-WORKS LAYOUT
   ========================================================= */

body {
  padding: 2rem 1rem;
  background: var(--bg);
  font-family: var(--font-body);
  color: var(--ink);
  line-height: 1.55;
}

.sheet {
  max-width: 42rem;
  margin: 0 auto;
  padding: 3rem 2.5rem 2.5rem;
  background: var(--paper);
  box-shadow:
    0 0 0 2px rgba(0, 0, 0, 0.05),
    0 12px 30px rgba(0, 0, 0, 0.35);
  position: relative;

  /* Subtle damage / noise */
  background-image: radial-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 3px 3px;
}

/* Fake pin */
.sheet::before {
  content: '';
  position: absolute;
  top: 0.75rem;
  left: 50%;
  width: 0.75rem;
  height: 0.75rem;
  background: var(--cooling-brown);
  border-radius: 50%;
  transform: translateX(-50%);
  box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.4);
}

/* =========================================================
   9) TYPOGRAPHY — PIPE-WORKS VOICE
   ========================================================= */

h1 {
  text-align: center;
  font-family: var(--font-masthead);
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.strapline {
  text-align: center;
  font-style: italic;
  color: var(--ink-faded);
  margin-bottom: 1.5rem;
}

h2,
h3 {
  margin-top: 2rem;
  font-family: var(--font-headline);
  font-weight: 700;
  letter-spacing: 0.02em;
  border-bottom: 1px solid rgba(0, 0, 0, 0.25);
  padding-bottom: 0.25rem;
}

p {
  line-height: 1.5;
  margin: 0.75rem 0;
}

.emphasis {
  font-weight: bold;
  font-size: 1.2rem;
}

.small {
  font-size: 0.8rem;
  font-style: italic;
}

/* =========================================================
   10) SECTIONS — NOTICE, LEDGER, RULE
   ========================================================= */

.notice,
.ledger,
.rule,
.margin-note {
  font-family: var(--font-record);
}

.notice {
  font-size: 1.05rem;
}

.rule {
  margin-top: 2.5rem;
  padding-left: 1rem;
  border-left: 4px solid var(--blood);
}

.ledger ul {
  list-style: square;
  padding-left: 1.25rem;
}

/* =========================================================
   11) MARGIN NOTES
   ========================================================= */

.margin-note {
  font-size: 0.75rem;
  font-style: italic;
  color: var(--ink-faded);
  max-width: 18rem;
}

/* =========================================================
   12) ASCII ART
   ========================================================= */

.ascii {
  margin-block-start: -2em;
  margin-block-end: -8em;
}

.ascii--stamp pre {
  display: inline-block;
  transform: rotate(-3.8deg);
  opacity: 0.82;
}

.ascii pre {
  margin: 0;
  padding: 1rem 1.25rem;
  overflow-x: auto;
  white-space: pre;
  tab-size: 2;
}

.ascii code {
  display: block;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New',
    monospace;
  font-size: 0.95rem;
  line-height: 1.15;
  color: var(--ink-faded);
}

.ascii--mark {
  margin-left: -0.5rem;
  margin-inline-start: 48px;
  margin-inline-end: 40px;
}

/* =========================================================
   13) STICKER (index, goblin-laws)
   ========================================================= */

.sticker {
  position: absolute;
  top: 1rem;
  right: -1.5rem;
  background: #f6e27a;
  color: #2a1f14;
  padding: 0.75rem 1rem 0.65rem;
  font-family: 'Arial Black', Impact, sans-serif;
  font-size: 0.75rem;
  text-align: center;
  transform: rotate(6deg);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(0, 0, 0, 0.3);
}

.sticker::after {
  content: '';
  position: absolute;
  bottom: 0.2rem;
  right: 0.2rem;
  width: 0.6rem;
  height: 0.6rem;
  background: rgba(255, 255, 255, 0.35);
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}

.sticker strong {
  letter-spacing: 0.05em;
}

.sticker span {
  font-weight: normal;
  font-size: 0.65rem;
}

.sticker em {
  font-style: italic;
  font-size: 0.6rem;
}

/* =========================================================
   14) FOOTER / IMPRINT
   ========================================================= */

.imprint {
  margin-top: 3rem;
  font-size: 0.9rem;
  color: var(--ink-faded);
}

.back-to-top {
  margin-top: 3rem;
  margin-left: 1.5rem;
  font-family: var(--font-record);
  font-size: 0.85rem;
  opacity: 0.7;
}

.back-to-top a {
  text-decoration: none;
  border-bottom: 1px dotted currentcolor;
}

.back-to-top a:hover {
  opacity: 1;
}

/* =========================================================
   15) EDITORIAL MARKS
   ========================================================= */

.marker,
.ReferenceMark {
  font-family: var(--font-symbols);
  font-weight: 400;
  color: var(--ink);
  flex-shrink: 0;
  line-height: 1;
}

/* =========================================================
   16) RESPONSIVE — MOBILE ADJUSTMENTS
   ========================================================= */

@media (width <= 600px) {
  :root {
    /* Reduce quirk intensity on mobile — still quirky, just less so */
    --quirk-intensity: 0.3;
  }

  .sheet {
    padding: 2rem 1.5rem;
  }

  .sticker {
    position: relative;
    right: auto;
    top: auto;
    margin-bottom: 1rem;
    transform: rotate(2deg);
  }

  .margin-note {
    position: relative;
    margin: 1rem 0;
    max-width: 100%;
  }

  .ascii--mark {
    display: none; /* or reposition */
  }
}

/* Kill quirks entirely if user prefers reduced motion */
@media (prefers-reduced-motion: reduce) {
  :root {
    --quirk-intensity: 0;
  }
}
