/* ==========================================================================
   The Truck Collision Record — bespoke stylesheet
   Warm white, ink, rust-orange rules, condensed headings, asymmetric ledger.
   ========================================================================== */

:root {
  --paper: #faf7f2;
  --ink: #1f1f1f;
  --rust: #b7410e;
  --rust-dark: #8f2f0a;
  --line: #d9d2c8;
  --muted: #5a5348;
  --white: #ffffff;
  --focus: #1a5c8a;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --measure: 68ch;
  --font-body: Georgia, "Times New Roman", serif;
  --font-head: "Arial Narrow", "Helvetica Neue", Arial, sans-serif;
}

/* Reset and base */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 19px;
  line-height: 1.6;
  min-width: 320px;
  overflow-x: hidden;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--rust-dark);
  text-decoration: underline;
  text-underline-offset: 0.15em;
  overflow-wrap: break-word;
  word-break: break-word;
}

a:hover,
a:focus {
  color: var(--rust);
  text-decoration-thickness: 0.08em;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Shared shell */
.site-header {
  background: var(--paper);
  border-bottom: 3px solid var(--rust);
  padding: 1rem 0;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem 2rem;
}

.brand {
  font-family: var(--font-head);
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  line-height: 1.1;
  color: var(--ink);
  text-decoration: none;
}

.brand:hover,
.brand:focus {
  color: var(--rust);
  text-decoration: none;
}

.site-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1.5rem;
  padding: 0;
}

.site-nav a {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  padding: 0.25rem 0;
  border-bottom: 2px solid transparent;
}

.site-nav a:hover,
.site-nav a:focus {
  color: var(--rust);
  border-bottom-color: var(--rust);
}

.site-footer {
  background: var(--ink);
  color: var(--paper);
  padding: 2rem 0;
  margin-top: 4rem;
}

.footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem 2rem;
  font-size: 0.9rem;
}

.footer-nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding: 0;
}

.footer-nav a {
  color: var(--paper);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.footer-nav a:hover,
.footer-nav a:focus {
  color: var(--rust);
}

.footer-copy {
  color: #d9d2c8;
  font-size: 0.85rem;
  line-height: 1.5;
  max-width: 60ch;
}

/* Main layout */
.outermain {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.page {
  padding: 2rem 0 3rem;
}

/* Home page */
.page.home {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
}

.article-figure {
  margin: 0;
  border-top: 3px solid var(--rust);
  border-bottom: 1px solid var(--line);
}

.article-figure img {
  width: 100%;
  height: auto;
  object-fit: cover;
}

.media-caption {
  font-size: 0.85rem;
  color: var(--muted);
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  line-height: 1.4;
}

.ledger-intro {
  max-width: var(--measure);
  padding: 1rem 0;
}

.ledger-intro h1 {
  font-family: var(--font-head);
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.01em;
  text-transform: uppercase;
  color: var(--ink);
  border-bottom: 3px solid var(--rust);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.ledger-intro p {
  margin-bottom: 1rem;
}

.ledger-row {
  border-top: 1px solid var(--line);
  padding: 1.5rem 0;
  max-width: var(--measure);
}

.ledger-row h2 {
  font-family: var(--font-head);
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--rust-dark);
  margin-bottom: 0.75rem;
  line-height: 1.2;
}

.ledger-row p {
  margin-bottom: 0.75rem;
}

.ledger-row a {
  font-weight: 600;
}

/* Tool page */
.page.tool.tool-page {
  max-width: var(--measure);
  margin: 0 auto;
}

.tool-shell {
  background: var(--white);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 2rem;
}

.tool-shell h1 {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 3px solid var(--rust);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
}

.tool-intro {
  font-size: 1rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

form {
  margin: 0;
}

fieldset {
  border: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

legend {
  font-family: var(--font-head);
  font-size: 1.1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 1rem;
  color: var(--ink);
}

.field-group {
  margin-bottom: 1.25rem;
}

.field-group label {
  display: block;
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  margin-bottom: 0.35rem;
  color: var(--ink);
}

.field-group input,
.field-group select,
.field-group textarea {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 0;
  transition: border-color 0.15s ease;
}

.field-group input:focus,
.field-group select:focus,
.field-group textarea:focus {
  border-color: var(--rust);
  outline: none;
}

.field-group textarea {
  resize: vertical;
  min-height: 5rem;
}

.field-help {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
  line-height: 1.4;
}

.tool-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.tool-actions button {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.6rem 1.25rem;
  background: var(--rust);
  color: var(--white);
  border: 2px solid var(--rust);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.tool-actions button:hover,
.tool-actions button:focus {
  background: var(--rust-dark);
  border-color: var(--rust-dark);
}

.tool-actions button:disabled {
  background: var(--line);
  border-color: var(--line);
  color: var(--muted);
  cursor: not-allowed;
}

#status {
  margin-top: 1rem;
  font-size: 0.9rem;
  color: var(--muted);
}

#results {
  margin-top: 1.5rem;
  border-top: 1px solid var(--line);
  padding-top: 1rem;
}

#results table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  overflow-x: auto;
  display: block;
}

#results th,
#results td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

#results th {
  font-family: var(--font-head);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.8rem;
  color: var(--rust-dark);
}

noscript {
  display: block;
  margin-top: 1.5rem;
  padding: 1rem;
  background: var(--paper);
  border-left: 4px solid var(--rust);
  font-size: 0.9rem;
}

/* Article pages (guides) */
.article.page.article {
  max-width: var(--measure);
  margin: 0 auto;
}

.article-header {
  border-bottom: 3px solid var(--rust);
  padding-bottom: 1rem;
  margin-bottom: 2rem;
}

.article-header h1 {
  font-family: var(--font-head);
  font-size: clamp(1.8rem, 4vw, 2.8rem);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.article-body {
  font-size: 1rem;
  line-height: 1.7;
}

.article-body p {
  margin-bottom: 1rem;
}

.article-body h2,
.article-body h3 {
  font-family: var(--font-head);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
  color: var(--rust-dark);
}

.article-body ul,
.article-body ol {
  margin: 0 0 1rem 1.5rem;
}

.article-body li {
  margin-bottom: 0.5rem;
}

/* Professional review aside */
aside.professional-review {
  margin-top: 2rem;
  padding: 1.5rem;
  background: var(--white);
  border: 1px solid var(--line);
  border-left: 4px solid var(--rust);
  font-size: 0.9rem;
  line-height: 1.5;
}

aside.professional-review h2 {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.5rem;
  color: var(--rust-dark);
}

aside.professional-review p {
  margin-bottom: 0.5rem;
}

/* Directory / program list (if used) */
.program-list {
  list-style: none;
  padding: 0;
  margin: 1.5rem 0;
}

.program-row {
  border-top: 1px solid var(--line);
  padding: 1rem 0;
}

.program-title {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--rust-dark);
  margin-bottom: 0.25rem;
}

.program-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.program-summary {
  font-size: 0.95rem;
  line-height: 1.5;
}

/* Tables (general) */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
}

th,
td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  font-family: var(--font-head);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.8rem;
  color: var(--rust-dark);
}

/* Responsive: 390px */
@media (max-width: 480px) {
  body {
    font-size: 17px;
  }

  .header-inner {
    padding: 0 1rem;
    flex-direction: column;
    align-items: flex-start;
  }

  .site-nav ul {
    gap: 0.25rem 1rem;
  }

  .outermain {
    padding: 0 1rem;
  }

  .page {
    padding: 1.5rem 0 2rem;
  }

  .ledger-intro h1 {
    font-size: 2rem;
  }

  .ledger-row h2 {
    font-size: 1.2rem;
  }

  .tool-shell {
    padding: 1.25rem;
  }

  .tool-actions {
    flex-direction: column;
  }

  .tool-actions button {
    width: 100%;
  }

  .article-figure img {
    height: auto;
  }

  .footer-inner {
    flex-direction: column;
    gap: 1rem;
  }
}

/* Responsive: 1440px and up */
@media (min-width: 1440px) {
  .outermain {
    max-width: 1400px;
    padding: 0 2rem;
  }

  .page.home {
    grid-template-columns: 1fr 2fr;
    gap: 2rem 3rem;
  }

  .page.home .ledger-intro {
    grid-column: 1 / -1;
  }

  .page.home .article-figure:first-of-type {
    grid-column: 1 / -1;
  }

  .page.home .ledger-row {
    grid-column: 2;
  }

  .page.home .article-figure:nth-of-type(2) {
    grid-column: 1;
    grid-row: auto;
  }

  .page.home .ledger-row:nth-of-type(4) {
    grid-column: 2;
  }

  .page.home .article-figure:nth-of-type(3) {
    grid-column: 1;
  }

  .page.home .ledger-row:last-of-type {
    grid-column: 2;
  }

  /* Fixed left rail for navigation on article pages */
  .article.page.article {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 2rem;
    max-width: 1200px;
    margin: 0 auto;
  }

  .article-header {
    grid-column: 2;
  }

  .article-body {
    grid-column: 2;
  }

  .article-figure {
    grid-column: 2;
  }

  aside.professional-review {
    grid-column: 2;
  }

  /* Left rail could be a nav element; if not present, we can use a placeholder */
  .article.page.article::before {
    content: "";
    position: sticky;
    top: 2rem;
    height: 100%;
    border-right: 1px solid var(--line);
    margin-right: 2rem;
  }
}

/* Reduced 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;
  }
}

/* Utility: ensure links break anywhere */
a {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* Ensure images never hidden */
img {
  display: block;
  width: 100%;
  height: auto;
}

/* Focus visible for all interactive elements */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Ensure contrast for muted text on paper */
.muted,
.media-caption,
.field-help,
.footer-copy {
  color: var(--muted);
}

/* Ensure contrast for links on rust-dark */
a {
  color: var(--rust-dark);
}

/* Ensure contrast for buttons */
.tool-actions button {
  color: var(--white);
  background: var(--rust);
}

.tool-actions button:disabled {
  color: var(--muted);
  background: var(--line);
}

/* Ensure contrast for nav links on paper */
.site-nav a {
  color: var(--ink);
}

.site-nav a:hover,
.site-nav a:focus {
  color: var(--rust);
}

/* Ensure contrast for footer links on ink */
.footer-nav a {
  color: var(--paper);
}

.footer-nav a:hover,
.footer-nav a:focus {
  color: var(--rust);
}

/* Ensure contrast for headings */
h1, h2, h3, h4, h5, h6 {
  color: var(--ink);
}

/* Ensure contrast for table headers */
th {
  color: var(--rust-dark);
}

/* Ensure contrast for captions */
.media-caption {
  color: var(--muted);
}

/* Ensure contrast for help text */
.field-help {
  color: var(--muted);
}

/* Ensure contrast for status */
#status {
  color: var(--muted);
}

/* Ensure contrast for results */
#results {
  color: var(--ink);
}

/* Ensure contrast for noscript */
noscript {
  color: var(--ink);
}

/* Ensure contrast for professional review */
aside.professional-review {
  color: var(--ink);
}

/* Ensure contrast for program meta */
.program-meta {
  color: var(--muted);
}

/* Ensure contrast for program summary */
.program-summary {
  color: var(--ink);
}

/* Ensure contrast for tool intro */
.tool-intro {
  color: var(--muted);
}

/* Ensure contrast for legend */
legend {
  color: var(--ink);
}

/* Ensure contrast for labels */
label {
  color: var(--ink);
}

/* Ensure contrast for inputs */
input, select, textarea {
  color: var(--ink);
  background: var(--paper);
}

/* Ensure contrast for placeholders */
::placeholder {
  color: var(--muted);
  opacity: 1;
}

/* Ensure contrast for disabled fields */
fieldset:disabled {
  opacity: 0.7;
}

/* Ensure contrast for disabled buttons */
button:disabled {
  color: var(--muted);
  background: var(--line);
  border-color: var(--line);
}

/* Ensure contrast for links in article body */
.article-body a {
  color: var(--rust-dark);
}

.article-body a:hover,
.article-body a:focus {
  color: var(--rust);
}

/* Ensure contrast for links in ledger rows */
.ledger-row a {
  color: var(--rust-dark);
}

.ledger-row a:hover,
.ledger-row a:focus {
  color: var(--rust);
}

/* Ensure contrast for links in tool intro */
.tool-intro a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in footer copy */
.footer-copy a {
  color: var(--paper);
}

/* Ensure contrast for links in professional review */
aside.professional-review a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in program list */
.program-list a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in table */
table a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in noscript */
noscript a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in media caption */
.media-caption a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in field help */
.field-help a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in status */
#status a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in results */
#results a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in tool actions */
.tool-actions a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in footer nav */
.footer-nav a {
  color: var(--paper);
}

/* Ensure contrast for links in site nav */
.site-nav a {
  color: var(--ink);
}

/* Ensure contrast for links in brand */
.brand {
  color: var(--ink);
}

/* Ensure contrast for links in header */
.header-inner a {
  color: var(--ink);
}

/* Ensure contrast for links in footer */
.footer-inner a {
  color: var(--paper);
}

/* Ensure contrast for links in outermain */
.outermain a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in page */
.page a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in article */
.article a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in tool */
.tool a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in home */
.home a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in tool-page */
.tool-page a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in article-page */
.article-page a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in program-row */
.program-row a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in program-title */
.program-title a {
  color: var(--rust-dark);
}

/* Ensure contrast for links in program-meta */
.program-meta a {
  color: var(--rust-dark);
}
