/* Manuscript Surgery
   One stylesheet for the whole site. The colours and sizes you are most
   likely to change are the variables at the top. */

/* ---------------------------------------------------------------- fonts */
/* Instrument Sans for text and Atkinson Hyperlegible Mono for code.
   Both are served from the fonts folder, so the page makes no outside requests. */
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/instrument-sans-latin-wght-normal.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("fonts/instrument-sans-latin-wght-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}
@font-face {
  font-family: "Atkinson Hyperlegible Mono";
  src: url("fonts/atkinson-hyperlegible-mono-latin-wght-normal.woff2") format("woff2");
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

/* ------------------------------------------------------------ variables */
:root {
  --paper: #ffffff;
  --wash: #f2f5f4;        /* pale background for alternate sections */
  --ink: #17211f;         /* main text */
  --ink-soft: #55615e;    /* secondary text */
  --rule: #d5dcd9;        /* thin lines */
  --accent: #0a6b55;      /* the one accent colour */
  --accent-dark: #07503f;
  --todo: #ffe27a;        /* highlights things still to confirm */

  --sans: "Instrument Sans", "Helvetica Neue", Arial, sans-serif;
  --mono: "Atkinson Hyperlegible Mono", ui-monospace, Menlo, Consolas, monospace;

  --width: 1120px;        /* widest the content gets */
  --measure: 62ch;        /* widest a paragraph gets */
  --gap: clamp(1.25rem, 3vw, 2.5rem);
  --section: clamp(4rem, 9vw, 7.5rem);
}

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

html { scroll-behavior: smooth; scroll-padding-top: 1.5rem; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3, h4 { margin: 0; line-height: 1.15; font-weight: 700; text-wrap: balance; }
h1 { font-size: clamp(2.3rem, 4.7vw, 3.7rem); line-height: 1.04; letter-spacing: -0.02em; }
h2 { font-size: clamp(1.75rem, 2.8vw, 2.3rem); letter-spacing: -0.012em; }
h3 { font-size: 1.25rem; }
h4 { font-size: 0.95rem; color: var(--accent); }

p { margin: 0 0 1rem; max-width: var(--measure); }
ul, ol { margin: 0; padding: 0; }

a { color: var(--accent); text-underline-offset: 0.18em; }
a:hover { color: var(--accent-dark); }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; border-radius: 2px; }

.wrap { max-width: var(--width); margin: 0 auto; padding: 0 var(--gap); }

.section { padding: var(--section) 0; }
.section--wash { background: var(--wash); }
.intro { font-size: 1.2rem; color: var(--ink-soft); margin: 1rem 0 0; }
.aside { margin: 2rem 0 0; color: var(--ink-soft); }

/* Highlighted notes for things David still needs to confirm.
   Search index.html for "todo" to find them all. */
mark.todo { background: var(--todo); color: var(--ink); padding: 0.1em 0.3em; border-radius: 3px; }

/* -------------------------------------------------------------- buttons */
.button {
  display: inline-block;
  padding: 0.85rem 1.4rem;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.button:hover { background: var(--accent-dark); color: #fff; }
.button--small { padding: 0.55rem 1rem; font-size: 0.95rem; white-space: nowrap; }
.text-link { font-weight: 600; }

/* --------------------------------------------------------------- header */
.site-header { border-bottom: 1px solid var(--rule); }
.header-row { display: flex; align-items: center; gap: 1.5rem; padding-top: 1rem; padding-bottom: 1rem; }
.wordmark {
  margin: 0 auto 0 0;
  color: var(--ink);
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  text-decoration: none;
  white-space: nowrap;
}
.wordmark span { color: var(--accent); }
.site-header nav { display: flex; gap: 1.5rem; }
.site-header nav a { color: var(--ink); font-size: 0.95rem; text-decoration: none; }
.site-header nav a:hover { color: var(--accent); text-decoration: underline; }

/* ----------------------------------------------------------------- hero */
.hero { padding: clamp(3rem, 7vw, 6rem) 0 0; }
.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: clamp(2rem, 5vw, 4.5rem);
  align-items: center;
}
.byline { margin: 1.1rem 0 1.6rem; font-size: 1.45rem; font-weight: 600; color: var(--accent); }
.lead { font-size: 1.25rem; line-height: 1.5; }
.for { color: var(--ink-soft); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 1.5rem; margin: 2rem 0 0; }

/* three plain facts under the hero */
.facts {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  margin-top: clamp(3rem, 7vw, 5.5rem);
  padding: 1.5rem 0;
  border-top: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  list-style: none;
  color: var(--ink-soft);
  font-size: 0.98rem;
}

/* --------------------------------------------- drag-to-compare figure */
.compare-figure { margin: 0; }
.compare-figure figcaption { margin-top: 0.8rem; font-size: 0.875rem; color: var(--ink-soft); }
.compare {
  position: relative;
  border: 1px solid var(--rule);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.compare img { width: 100%; }
.compare-before {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--pos)) 0 0);
}
.compare-label {
  position: absolute;
  top: 0.6rem;
  padding: 0.1rem 0.55rem;
  border-radius: 3px;
  background: var(--ink);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  pointer-events: none;
}
.compare-label--before { left: 0.6rem; }
.compare-label--after { right: 0.6rem; background: var(--accent); }
.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--pos);
  width: 2px;
  margin-left: -1px;
  background: var(--accent);
  pointer-events: none;
}
.compare-handle::after {           /* the round grip on the line */
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2.4rem;
  height: 2.4rem;
  margin: -1.2rem 0 0 -1.2rem;
  border: 2px solid #fff;
  border-radius: 50%;
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M9 7l-5 5 5 5M15 7l5 5-5 5'/%3E%3C/svg%3E") center / 1.3rem no-repeat;
  box-shadow: 0 1px 6px rgba(23, 33, 31, 0.25);
}
.compare input {                   /* invisible slider laid over the figure */
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: ew-resize;
}
.compare:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }

/* ---------------------------------------------------------------- cases */
.case { margin-top: clamp(3rem, 6vw, 5rem); padding-top: 2rem; border-top: 1px solid var(--rule); }
.case h3 { font-size: 1.45rem; }
.case-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: var(--gap);
  margin-top: 1.75rem;
}
.plate--before { grid-column: 1 / 6; }
.plate--after { grid-column: 6 / 11; }
.notes { grid-column: 1 / 5; }
.code { grid-column: 5 / 11; }

/* wide layout: notes sit beside the original, the rebuild spans the page */
.case--wide .plate--before { grid-column: 1 / 6; grid-row: 1; }
.case--wide .notes { grid-column: 6 / 11; grid-row: 1; align-self: center; }
.case--wide .plate--after { grid-column: 1 / 11; grid-row: 2; }
.case--wide .code { grid-column: 1 / 11; grid-row: 3; }

.plate { margin: 0; padding: 1rem; border-radius: 6px; background: var(--wash); }
.plate img { width: 100%; border-radius: 3px; background: #fff; }
.plate figcaption { margin-bottom: 0.7rem; font-size: 0.875rem; font-weight: 600; color: var(--ink-soft); }
.plate--after { box-shadow: inset 0 3px 0 var(--accent); }
.plate--after figcaption { color: var(--accent); }

.notes h4, .code h4 { margin-bottom: 0.4rem; }
.notes p + h4 { margin-top: 1.4rem; }
.notes p { margin-bottom: 0; }

pre {
  margin: 0;
  padding: 1rem 1.1rem;
  border-radius: 6px;
  background: var(--wash);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  line-height: 1.6;
  tab-size: 4;
}
code { font-family: var(--mono); }
pre .c { color: var(--ink-soft); }   /* code comments */

/* ---------------------------------------------------------------- parts */
.parts { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); margin-top: 3rem; }
.part { padding-top: 1.25rem; border-top: 3px solid var(--ink); }
.part h3 { margin-bottom: 0.9rem; font-size: 1.45rem; }
.part h4 { margin: 1.5rem 0 0.5rem; }
.part ul { padding-left: 1.1rem; }
.part li { margin-bottom: 0.35rem; }
.part li::marker { color: var(--accent); }

/* ---------------------------------------------------------------- steps */
.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
  margin-top: 3rem;
  list-style: none;
  counter-reset: step;
}
.steps li { counter-increment: step; padding-top: 1rem; border-top: 1px solid var(--rule); }
.steps li::before {
  content: counter(step);
  display: block;
  margin-bottom: 0.6rem;
  color: var(--accent);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}
.steps h3 { margin-bottom: 0.5rem; font-size: 1.1rem; line-height: 1.25; }
.steps p { margin: 0; color: var(--ink-soft); font-size: 0.98rem; }

/* --------------------------------------------------------------- prices */
.prices { width: 100%; margin-top: 2.5rem; border-collapse: collapse; text-align: left; }
.prices th, .prices td { padding: 1.1rem 1.5rem 1.1rem 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
.prices thead th { padding-bottom: 0.6rem; border-bottom: 2px solid var(--ink); color: var(--ink-soft); font-size: 0.9rem; font-weight: 600; }
.prices tbody th { width: 26%; font-size: 1.1rem; }
.prices td { color: var(--ink-soft); }
.prices .price { width: 27%; padding-right: 0; color: var(--ink); font-size: 1.1rem; font-weight: 700; white-space: nowrap; }
.prices .price small { display: block; color: var(--ink-soft); font-size: 0.9rem; font-weight: 400; }

/* ---------------------------------------------------------------- about */
.about-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: clamp(2rem, 6vw, 5rem); }
.about-grid h2 { margin-bottom: 1.5rem; }
.about-grid h3 { margin: 0.6rem 0 1rem; }
.portrait { width: 160px; height: 160px; margin-bottom: 1.5rem; border-radius: 6px; object-fit: cover; }
.papers { list-style: none; font-size: 0.95rem; color: var(--ink-soft); }
.papers li { padding: 0.9rem 0; border-top: 1px solid var(--rule); }
.papers b { color: var(--ink); }
.papers-note { margin: 0; padding: 0.7rem 0; border-top: 1px solid var(--rule); color: var(--ink-soft); font-size: 0.875rem; }

/* ------------------------------------------------------------------ faq */
.faq-wrap details { max-width: 780px; }
.faq-wrap h2 { margin-bottom: 1.5rem; }
details { border-top: 1px solid var(--rule); }
details:last-of-type { border-bottom: 1px solid var(--rule); }
summary {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 0;
  font-size: 1.15rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--accent); font-size: 1.4rem; font-weight: 400; line-height: 1; }
details[open] summary::after { content: "\2212"; }   /* minus sign */
details p { margin: 0 0 1.3rem; }
details ul { margin: 0 0 1.3rem; padding-left: 1.2rem; }
details li { margin-bottom: 0.3rem; }
details li::marker { color: var(--accent); }

/* the folded-away part of the papers list in the About section */
details.more-papers { border-bottom: 0; }
.more-papers summary { justify-content: flex-start; gap: 0.5rem; padding: 0.9rem 0; color: var(--accent); font-size: 0.95rem; }
.more-papers summary::after { font-size: 1.1rem; }
.more-papers ul { margin: 0; padding: 0; }
.more-papers li { margin: 0; }

/* -------------------------------------------------------------- contact */
.contact-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: clamp(2rem, 6vw, 5rem); align-items: start; }
.contact-grid h2 { margin-bottom: 1.25rem; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem 1.25rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: 0.95rem; font-weight: 600; }
.optional { color: var(--ink-soft); font-weight: 400; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid #9aa5a1;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
.field input, .field select { height: 3rem; }
.field textarea { resize: vertical; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
.form .button { justify-self: start; align-self: flex-start; }

/* --------------------------------------------------------------- footer */
.site-footer { padding: 3rem 0; border-top: 1px solid var(--rule); color: var(--ink-soft); font-size: 0.92rem; }
.footer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(2rem, 6vw, 5rem); }
.site-footer .wordmark { margin-bottom: 0.75rem; font-size: 1.05rem; }
.site-footer h2 { margin-bottom: 0.6rem; color: var(--ink); font-size: 1rem; letter-spacing: 0; }

/* thank-you page */
.thanks { padding: var(--section) 0; }
.thanks h1 { margin-bottom: 1.25rem; font-size: clamp(2rem, 4vw, 3rem); }

/* --------------------------------------------------- tablets and phones */
@media (max-width: 900px) {
  .site-header nav { display: none; }
  .hero-grid, .about-grid, .contact-grid, .footer-grid { grid-template-columns: 1fr; }
  .parts { grid-template-columns: 1fr; }
  .steps { grid-template-columns: 1fr 1fr; }
  .case-grid { grid-template-columns: minmax(0, 1fr); }
  .case-grid > *, .case--wide .case-grid > * { grid-column: 1; grid-row: auto; }
  /* the wide three-panel figure scrolls sideways so its text stays readable */
  .scroll { overflow-x: auto; }
  .scroll img { min-width: 640px; }
}

@media (max-width: 600px) {
  body { font-size: 1rem; }
  .facts { grid-template-columns: 1fr; gap: 0.6rem; }
  .steps { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }

  /* the price table becomes a stack of blocks */
  .prices thead { display: none; }
  .prices, .prices tbody, .prices tr, .prices th, .prices td { display: block; width: auto; }
  .prices tr { padding: 1.1rem 0; border-bottom: 1px solid var(--rule); }
  .prices th, .prices td { padding: 0 0 0.3rem; border: 0; }
  .prices tbody th, .prices .price { width: auto; white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
