/* ─────────────────────────────────────────────────────────────
   BACK IN BEAT — Service Manual / Technical Plate
   Aesthetic: 1920s pocket-watch service manual, 1940s machinist's
   handbook. Workshop, not luxury. Print-feel even on screen.
   ───────────────────────────────────────────────────────────── */

/* Fonts — Fraunces (display, old-style serif), Spectral (body
   long-form serif), JetBrains Mono (industrial mono for data &
   labels). All via Google Fonts; font-display: swap so paint
   isn't blocked. */
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,500;9..144,700&family=Spectral:wght@400;600&family=JetBrains+Mono:wght@400;500;700&display=swap');

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

:root {
  /* Surfaces */
  --bg: #fafaf9;
  --paper: #f5f1e8;
  --parchment: #ede4cf;
  --card-bg: #ffffff;

  /* Ink */
  --text: #1c1917;
  --text-soft: #3a342f;
  --muted: #78716c;
  --border: #d6cfc4;
  --rule: #1c1917;

  /* Accents */
  --accent: #b45309;        /* amber, primary action / data */
  --accent-deep: #7a3530;   /* oxblood, danger / negative diff */
  --accent-cool: #3b556f;   /* blueprint slate, technical lines */
  --accent-light: #fef3c7;

  /* Texture URLs (relative to css/main.css) */
  --tex-hero: url('../img/hero-bg.webp');
  --tex-paper: url('../img/paper.webp');
  --tex-parchment: url('../img/parchment.webp');
  --tex-divider: url('../img/divider.webp');
  --tex-gears: url('../img/section-gears.webp');

  /* Type system */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-body: 'Spectral', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', ui-monospace, monospace;

  /* Geometry */
  --radius: 2px;            /* sharper corners — print feel */
  --shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
  --rule-thin: 1px;
  --rule-bold: 2px;

  /* Motion */
  --ease: cubic-bezier(0.2, 0.6, 0.2, 1);

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #14110d;
  --paper: #1c1814;
  --parchment: #221d16;
  --card-bg: #1c1814;

  --text: #e8e2d4;
  --text-soft: #c9c2b3;
  --muted: #908778;
  --border: #3a342b;
  --rule: #e8e2d4;

  --accent: #d97706;
  --accent-deep: #b45a52;
  --accent-cool: #6b8aa8;
  --accent-light: #2a1f10;

  --tex-hero: url('../img/hero-bg-dark.webp');

  --shadow: 0 1px 0 rgba(0, 0, 0, 0.4);

  color-scheme: dark;
}

/* ─────────────────────────────────────────────────────────────
   Base
   ───────────────────────────────────────────────────────────── */

html {
  font-size: 16px;
  /* Subtle blueprint texture across the entire page, sits behind
     content. Low-opacity layer composited via background-blend. */
  background-color: var(--bg);
  background-image: var(--tex-hero);
  background-repeat: repeat;
  background-size: 480px 480px;
  background-attachment: fixed;
}

[data-theme="dark"] html { background-color: var(--bg); }

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.65;
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  /* Keeps readable text against the tiled background by floating
     a translucent paper layer above the html-level texture. */
  background: linear-gradient(
    to bottom,
    rgba(250, 250, 249, 0.82),
    rgba(250, 250, 249, 0.92)
  );
  transition: color 0.2s var(--ease);
  font-feature-settings: "kern", "liga", "calt";
}

[data-theme="dark"] body {
  background: linear-gradient(
    to bottom,
    rgba(20, 17, 13, 0.84),
    rgba(20, 17, 13, 0.94)
  );
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.container-wide {
  max-width: 960px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

/* ─────────────────────────────────────────────────────────────
   Typography
   ───────────────────────────────────────────────────────────── */

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 500;
  line-height: 1.2;
  letter-spacing: -0.015em;
  margin: 0 0 0.6rem;
  color: var(--text);
  font-variation-settings: "opsz" 96;
}

h1 {
  font-size: clamp(2rem, 4.5vw, 2.75rem);
  font-weight: 500;
  letter-spacing: -0.025em;
  font-variation-settings: "opsz" 144;
  margin-bottom: 1rem;
}

h2 {
  font-size: 1.5rem;
  margin-top: 2.5rem;
  position: relative;
  padding-top: 1.25rem;
}

/* Hairline rule above every h2 — service-manual vibe.
   Skip when h2 follows certain wrappers via .no-rule. */
h2:not(.no-rule)::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 3rem;
  height: var(--rule-bold);
  background: var(--rule);
}

h3 {
  font-size: 1.125rem;
  margin-top: 1.75rem;
  font-variation-settings: "opsz" 36;
}

p {
  margin: 0 0 1.1rem;
  /* Prose readability — slightly wider tracking + good rhythm */
  hanging-punctuation: first allow-end;
}

p + p { margin-top: 0; }

a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s var(--ease);
}
a:hover {
  text-decoration: none;
  border-bottom-color: var(--accent);
}

strong { font-weight: 600; color: var(--text); }
em { font-style: italic; color: var(--text-soft); }

code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--accent-light);
  padding: 0.05em 0.35em;
  border-radius: var(--radius);
  color: var(--text);
}

/* Numerals: tabular figures everywhere by default — measurements
   line up across rows. */
:root { font-variant-numeric: tabular-nums; }

/* Drop cap — opt-in via .lead-in on the first paragraph of
   long-form reference content. */
.lead-in::first-letter {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 3.6rem;
  line-height: 0.9;
  float: left;
  padding: 0.4rem 0.6rem 0 0;
  margin-top: 0.15rem;
  color: var(--accent);
  font-variation-settings: "opsz" 144;
}

/* ─────────────────────────────────────────────────────────────
   Plate / fig labels — small mono UPPERCASE markers used
   throughout to evoke service-manual indexing.
   ───────────────────────────────────────────────────────────── */

.plate-label,
.section-mark {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

.plate-label {
  display: inline-block;
  padding: 0.15rem 0;
  border-top: var(--rule-thin) solid var(--rule);
  border-bottom: var(--rule-thin) solid var(--rule);
  color: var(--text);
}

.section-mark {
  display: block;
  margin-bottom: 0.5rem;
}

/* Decorative section divider — uses the engraved gear divider
   image at low opacity. Replaces plain <hr>. */
.divider-rule,
hr.divider-rule {
  border: none;
  height: 32px;
  background-image: var(--tex-divider);
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  opacity: 0.55;
  margin: 3rem auto;
  max-width: 480px;
}

[data-theme="dark"] .divider-rule { opacity: 0.45; filter: invert(0.92); }

/* Slim default hr falls back to a thin rule, but real dividers
   should use .divider-rule. */
hr {
  border: none;
  border-top: var(--rule-thin) solid var(--border);
  margin: 2.5rem 0;
}

/* ─────────────────────────────────────────────────────────────
   Navigation
   ───────────────────────────────────────────────────────────── */

.site-nav {
  position: relative;
  border-bottom: var(--rule-bold) solid var(--rule);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  background: var(--bg);
}

/* Nav fine-rule echo — second pinstripe just below the bold rule */
.site-nav::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: var(--rule-thin);
  background: var(--rule);
}

/* Brand: the ruled "Back in Beat" wordmark (inline SVG from website/templates/wordmark.svg,
   synced into every page by website/tools/sync-chrome.pl). Ink follows --text, ticks use --accent. */
.site-nav .brand {
  display: inline-flex;
  align-items: center;
  color: var(--text);
  text-decoration: none;
  margin-right: auto;
  border-bottom: none;
  padding: 0;
}
.site-nav .brand:hover { border-bottom: none; }
.site-nav .brand-wordmark {
  display: block;
  height: 2.6rem;
  width: auto;
  overflow: visible;
}
.site-nav .brand:hover .brand-wordmark { opacity: 0.8; }
.site-nav .brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }
@media (max-width: 480px) { .site-nav .brand-wordmark { height: 2.2rem; } }

/* Copyright line at the bottom of every page (website/templates/site-footer.html) */
.site-copyright {
  max-width: 960px;
  margin: 3rem auto 0;
  padding: 1.25rem 1.5rem 2rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  color: var(--muted);
  text-align: center;
}

/* Stacked logo (mark over ruled wordmark), used in the homepage hero */
.logo-stacked { display: block; width: 100%; height: auto; color: var(--text); overflow: visible; }

.site-nav a {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-decoration: none;
  border-bottom: none;
  padding: 0.25rem 0;
  position: relative;
}

.site-nav a:not(.brand)::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -2px;
  height: var(--rule-thin);
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s var(--ease);
}
.site-nav a:not(.brand):hover { color: var(--text); }
.site-nav a:not(.brand):hover::after { transform: scaleX(1); }

/* Theme toggle — square icon button, no text. Sun/moon SVG inside. */
.theme-toggle {
  background: none;
  border: var(--rule-thin) solid var(--rule);
  border-radius: var(--radius);
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--text);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.theme-toggle:hover {
  background: var(--text);
  color: var(--bg);
}
.theme-toggle svg {
  width: 16px;
  height: 16px;
  display: block;
  transition: transform 0.4s var(--ease);
}
.theme-toggle .icon-moon { display: block; }
.theme-toggle .icon-sun  { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun  { display: block; }
.theme-toggle:hover svg { transform: rotate(40deg); }

/* ─────────────────────────────────────────────────────────────
   Cards
   ───────────────────────────────────────────────────────────── */

.card {
  background: var(--card-bg);
  background-image: var(--tex-paper);
  background-blend-mode: multiply;
  background-size: 320px 320px;
  border: var(--rule-thin) solid var(--rule);
  border-radius: var(--radius);
  padding: 1.75rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  position: relative;
}

[data-theme="dark"] .card {
  background-blend-mode: overlay;
  opacity: 0.99;
}

/* Card with a corner plate label ("§ A — Inputs", etc.) */
.card-plate {
  position: absolute;
  top: -0.6rem;
  left: 1.25rem;
  background: var(--bg);
  padding: 0 0.5rem;
}

/* ─────────────────────────────────────────────────────────────
   Forms & Inputs
   ───────────────────────────────────────────────────────────── */

label {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

input[type="number"],
input[type="text"],
input[type="email"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: var(--rule-thin) solid var(--rule);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--font-mono);
  background: var(--card-bg);
  color: var(--text);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow:
    inset 0 0 0 1px var(--accent),
    0 0 0 4px rgba(180, 83, 9, 0.08);
}

input[readonly] {
  background: var(--accent-light);
  cursor: default;
  border-style: dashed;
}

.input-group { margin-bottom: 1rem; }

.input-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 480px) {
  .input-row { grid-template-columns: 1fr; }
}

button, .btn {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  background: var(--text);
  color: var(--bg);
  border: var(--rule-thin) solid var(--rule);
  border-radius: var(--radius);
  padding: 0.6rem 1.1rem;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
button:hover, .btn:hover {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}

/* ─────────────────────────────────────────────────────────────
   Results / data display
   ───────────────────────────────────────────────────────────── */

.result {
  font-family: var(--font-mono);
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.result-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 0.2rem;
}

/* ─────────────────────────────────────────────────────────────
   Page header — title block with optional decorative watermark
   ───────────────────────────────────────────────────────────── */

.page-header {
  position: relative;
  margin-bottom: 2.5rem;
  padding-top: 0.5rem;
}

.page-header h1 { margin-bottom: 0.5rem; }
.page-header > .section-mark { margin-bottom: 0.5rem; }

/* Spiral watermark — Archimedean coil sits behind the title at low
   opacity. Only the mainspring page (and any other decision-tree
   page that wants to evoke a coiled spring) opts in. */
.page-header--spiral {
  isolation: isolate;
}
.page-header--spiral::before {
  content: "";
  position: absolute;
  top: -1.5rem;
  right: -0.5rem;
  width: 220px;
  height: 220px;
  z-index: -1;
  background: url('../img/spiral.svg') no-repeat center / contain;
  opacity: 0.07;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,0.05));
  pointer-events: none;
}

[data-theme="dark"] .page-header--spiral::before {
  opacity: 0.14;
  filter: invert(1);
}

@media (max-width: 600px) {
  .page-header--spiral::before {
    width: 140px;
    height: 140px;
    top: -0.5rem;
    right: -1rem;
  }
}

/* ─────────────────────────────────────────────────────────────
   Page banner — full-bleed-feel B-roll above page intro
   ───────────────────────────────────────────────────────────── */

.page-banner,
.section-banner {
  margin: 0 auto;
  padding: 0 1.5rem;
  max-width: 1080px;
}

.page-banner { margin-top: 0.5rem; margin-bottom: 1rem; }
.section-banner { margin-top: 1.5rem; margin-bottom: 0.5rem; max-width: 800px; }

.page-banner-frame,
.section-banner-frame {
  position: relative;
  border: 1px solid var(--rule);
  background: var(--card-bg);
  overflow: hidden;
  box-shadow:
    0 0 0 6px var(--bg),
    0 0 0 7px var(--rule);
}

.page-banner-frame img,
.section-banner-frame img {
  display: block;
  width: 100%;
  height: auto;
  filter: saturate(0.92) contrast(1.04);
}

/* Banner photos carry their own weight — no caption strip needed.
   Captions stay on .inline-figure where they're earned. */
.page-banner-frame figcaption,
.section-banner-frame figcaption {
  display: none;
}

/* Inline figure — sits inside container width, aspect-ratio-honest,
   service-manual fig caption. Used inside long-form reference. */
.inline-figure {
  margin: 2rem 0 2.5rem;
  padding: 0;
}
.inline-figure-frame {
  position: relative;
  border: 1px solid var(--rule);
  background: var(--card-bg);
  overflow: hidden;
}
.inline-figure-frame img {
  display: block;
  width: 100%;
  height: auto;
  filter: saturate(0.92) contrast(1.04);
}
.inline-figure-frame figcaption {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding: 0.6rem 0.85rem;
  background: var(--text);
  color: var(--bg);
  font-family: var(--font-mono);
}
.inline-figure-frame figcaption .fig {
  font-size: 0.66rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}
.inline-figure-frame figcaption .cap {
  font-size: 0.78rem;
  font-style: italic;
  font-family: var(--font-body);
  opacity: 0.85;
}

/* ─────────────────────────────────────────────────────────────
   B-roll / photographic banners
   ───────────────────────────────────────────────────────────── */

.broll {
  position: relative;
  width: 100%;
  margin: 0 auto 2rem;
  overflow: hidden;
  border: var(--rule-thin) solid var(--rule);
  background: var(--card-bg);
}

.broll img {
  display: block;
  width: 100%;
  height: auto;
  filter: saturate(0.92) contrast(1.02);
}

/* Caption strip — runs along the bottom of a banner with a
   service-manual fig number on the left. */
.broll-cap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    rgba(28, 25, 23, 0.78),
    rgba(28, 25, 23, 0)
  );
  color: rgba(255, 250, 240, 0.92);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  padding: 1.5rem 1rem 0.75rem;
  display: flex;
  justify-content: space-between;
  gap: 1rem;
}
.broll-cap .fig {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  opacity: 0.85;
}

/* Section gears motif — used as an ornamental rule between blocks
   (think: a chapter break in a printed manual). Centered, with thin
   horizontal lines extending from each side to fill the width. */
.section-mark-graphic {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1.25rem;
  width: 100%;
  max-width: 540px;
  margin: 2.5rem auto 2rem;
  border: 0;
}
.section-mark-graphic::before,
.section-mark-graphic::after {
  content: "";
  height: 1px;
  background: var(--rule);
  opacity: 0.45;
}
.section-mark-graphic > img {
  display: block;
  height: 28px;
  width: auto;
  opacity: 0.7;
}
[data-theme="dark"] .section-mark-graphic > img {
  filter: invert(1) brightness(0.95);
  opacity: 0.85;
}
[data-theme="dark"] .section-mark-graphic::before,
[data-theme="dark"] .section-mark-graphic::after {
  background: var(--text-soft);
  opacity: 0.35;
}

/* Reference page parchment treatment — opt-in via .reference-body
   on the container of long-form text. */
.reference-body {
  background-image: var(--tex-parchment);
  background-blend-mode: multiply;
  background-size: 480px 480px;
  background-color: var(--parchment);
  padding: 2.5rem 2rem;
  border: var(--rule-thin) solid var(--rule);
  border-radius: var(--radius);
}

[data-theme="dark"] .reference-body { background-blend-mode: overlay; }

/* ─────────────────────────────────────────────────────────────
   Utility
   ───────────────────────────────────────────────────────────── */

.text-muted { color: var(--muted); }
.text-soft  { color: var(--text-soft); }
.text-sm    { font-size: 0.875rem; }
.text-xs    { font-size: 0.75rem; }
.mono       { font-family: var(--font-mono); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.center { text-align: center; }

.disclaimer {
  font-size: 0.85rem;
  font-family: var(--font-body);
  color: var(--muted);
  border-top: var(--rule-thin) solid var(--border);
  padding-top: 1rem;
  margin-top: 2.5rem;
  font-style: italic;
}

/* ─────────────────────────────────────────────────────────────
   Hero — landing-page band that frames a B-roll photo
   ───────────────────────────────────────────────────────────── */

.hero-band {
  position: relative;
  margin: 0 auto;
  max-width: 960px;
  padding: 0 1.5rem;
}

.hero-band .broll {
  margin-top: 1.5rem;
  margin-bottom: 0;
}

/* ─────────────────────────────────────────────────────────────
   Page-load entrance (subtle — print should never feel animated)
   ───────────────────────────────────────────────────────────── */

@keyframes rise-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.rise > * {
  animation: rise-in 0.5s var(--ease) both;
}
.rise > *:nth-child(1) { animation-delay: 0.05s; }
.rise > *:nth-child(2) { animation-delay: 0.15s; }
.rise > *:nth-child(3) { animation-delay: 0.25s; }
.rise > *:nth-child(4) { animation-delay: 0.35s; }
.rise > *:nth-child(5) { animation-delay: 0.45s; }
.rise > *:nth-child(6) { animation-delay: 0.55s; }

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

/* ─────────────────────────────────────────────────────────────
   Print — disables every texture, every background, every
   decorative flourish. Forms and reference content must look
   like pages from a workbook, not screen UI.
   ───────────────────────────────────────────────────────────── */

@media print {
  html, body {
    background: #fff !important;
    color: #000 !important;
  }
  body { font: 10pt/1.4 'Spectral', Georgia, serif; }
  .no-print { display: none !important; }
  .card, .reference-body, .broll {
    background: #fff !important;
    border: 1px solid #999 !important;
    box-shadow: none !important;
  }
  .broll img { filter: grayscale(1) contrast(1.05); }
  a { color: #000; border-bottom: none; }
  h1, h2, h3 { color: #000; font-family: 'Fraunces', Georgia, serif; }
  h2::before { background: #000 !important; }
  .divider-rule { opacity: 0.4; filter: grayscale(1); }
  .section-mark-graphic { filter: grayscale(1); opacity: 0.6; }
}
