:root {
  --bg: #f5f1ea;
  --card: #ffffff;
  --ink: #1e1b17;
  --muted: #5d574e;
  --line: #d9d1c3;
  --accent: #8c4a2b;
  --accent-ink: #ffffff;
  --chip: #ebe5da;
  --red: #b3261e;
  --red-bg: #fdecea;
  --stage: #e9e4da;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161412;
    --card: #211e1a;
    --ink: #f1ece4;
    --muted: #b3ab9d;
    --line: #3b352e;
    --accent: #e0946a;
    --accent-ink: #1b130d;
    --chip: #2c2823;
    --red: #ff8a80;
    --red-bg: #3a1613;
    --stage: #24211d;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.wrap {
  max-width: 46rem;
  margin: 0 auto;
  padding: 0 16px;
}

a {
  color: var(--accent);
  text-underline-offset: 0.15em;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0;
}

/* Masthead */
.masthead {
  padding: 28px 0 18px;
}
.kicker {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
h1 {
  font-size: 2.1rem;
  letter-spacing: -0.02em;
}
.lede {
  margin: 8px 0 0;
  color: var(--muted);
}

/* Jump bar */
.jump {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.jump__row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-top: 8px;
  padding-bottom: 8px;
  scrollbar-width: none;
}
.jump__row::-webkit-scrollbar {
  display: none;
}
.jump a {
  flex: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  text-decoration: none;
}

/* Sections */
main > section {
  padding: 28px 0 8px;
  scroll-margin-top: 56px;
}
h2 {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  margin-bottom: 12px;
}
h3 {
  font-size: 1.15rem;
  margin: 28px 0 10px;
  scroll-margin-top: 64px;
}
p {
  margin: 0 0 12px;
}
.note {
  color: var(--muted);
  font-size: 0.92rem;
}
ol,
ul {
  margin: 0 0 12px;
  padding-left: 1.4em;
}
li {
  margin-bottom: 10px;
}
li::marker {
  color: var(--accent);
  font-weight: 700;
}

/* Non-negotiables */
main > .redbox {
  margin-top: 20px;
  padding: 16px 16px 8px;
  border: 2px solid var(--red);
  border-radius: 12px;
  background: var(--red-bg);
}
.redbox h2 {
  color: var(--red);
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.redbox__sub {
  font-weight: 700;
  margin-bottom: 8px;
}
.redbox li {
  font-weight: 600;
}
.redbox li::marker {
  color: var(--red);
}

/* 3D viewer */
.viewer {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: hidden;
  margin-bottom: 10px;
}
.viewer__stage {
  position: relative;
  height: min(52vh, 420px);
  min-height: 280px;
  background: radial-gradient(circle at 50% 40%, #ffffff 0%, #e7e2d8 100%);
}
@media (prefers-color-scheme: dark) {
  .viewer__stage {
    background: radial-gradient(circle at 50% 40%, #3a362f 0%, #1f1c18 100%);
  }
}
.viewer canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
.viewer canvas:active {
  cursor: grabbing;
}
.viewer__status {
  position: absolute;
  inset: auto 0 12px 0;
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  pointer-events: none;
}
.viewer__fallback {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}
.viewer--failed canvas,
.viewer--failed .viewer__controls {
  display: none;
}
.viewer--failed .viewer__fallback {
  display: block;
}
.viewer__controls {
  display: grid;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--line);
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chips button {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.chips--toggle button[aria-pressed="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.chips--toggle button[aria-pressed="false"] {
  background: transparent;
  color: var(--muted);
  text-decoration: line-through;
}
.extlink {
  font-weight: 600;
}
.extlink::after {
  content: " \2197";
}

/* Figures */
figure {
  margin: 16px 0;
}
.zoom {
  display: block;
  width: 100%;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  cursor: zoom-in;
}
.zoom img {
  display: block;
  width: 100%;
  height: auto;
}
figcaption {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}
.gallery {
  display: grid;
  gap: 4px 12px;
}
@media (min-width: 640px) {
  .gallery {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  font-size: 0.94rem;
  margin-bottom: 12px;
}
th,
td {
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
tbody tr:last-child > * {
  border-bottom: 0;
}
thead th {
  background: var(--chip);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
tbody th {
  font-weight: 600;
}
.kv td {
  font-variant-numeric: tabular-nums;
}
.schedule td:last-child,
.schedule th:last-child {
  text-align: right;
  white-space: nowrap;
}

/* Build stages */
.stage {
  margin: 18px -16px 0;
  padding: 18px 16px 6px;
  background: var(--stage);
  scroll-margin-top: 56px;
}
@media (min-width: 46rem) {
  .stage {
    margin-inline: 0;
    border-radius: 12px;
  }
}
.stage h3 {
  margin-top: 0;
  font-size: 1.25rem;
}
.stage__n {
  display: block;
  margin-bottom: 2px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* Sign-off checklist */
.checks {
  list-style: none;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.checks li {
  margin: 0;
  border-bottom: 1px solid var(--line);
}
.checks li:last-child {
  border-bottom: 0;
}
.checks label {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px;
  cursor: pointer;
}
.checks input {
  flex: none;
  width: 22px;
  height: 22px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}
.checks input:checked + span {
  color: var(--muted);
  text-decoration: line-through;
}

.foot {
  margin-top: 32px;
  padding: 20px 0 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

/* Lightbox */
.lightbox {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #111;
  color: #fff;
}
.lightbox[open] {
  display: flex;
  flex-direction: column;
}
.lightbox__bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 600;
}
.lightbox__bar span {
  flex: 1;
  min-width: 0;
}
.lightbox__bar button {
  min-height: 40px;
  padding: 6px 14px;
  border: 1px solid #555;
  border-radius: 999px;
  background: #222;
  color: #fff;
  font: inherit;
  cursor: pointer;
}
.lightbox__scroll {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  background: #fff;
  -webkit-overflow-scrolling: touch;
}
.lightbox__scroll img {
  display: block;
  width: 100%;
  height: auto;
  margin: auto;
  cursor: zoom-in;
}
.lightbox--zoomed .lightbox__scroll img {
  width: 260%;
  max-width: none;
  cursor: zoom-out;
}

@media print {
  .jump,
  .viewer__controls,
  .lightbox {
    display: none;
  }
}
