:root {
  --ink: #1c1915;
  --cream: #f4ecdf;
  --cream-deep: #e7dcc8;
  --card: #fffaf3;
  --stamp: #c83a2b;
  --stamp-dark: #8e2419;
  --indigo: #243056;
  --gold: #e4b24a;
  --line: rgba(28, 25, 21, 0.14);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --shadow: 0 18px 40px rgba(60, 36, 12, 0.12);
  --hit: 44px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(900px 420px at 0% -10%, #fff 0%, transparent 55%),
    linear-gradient(180deg, #f7f1e6 0%, #e9dcc6 100%);
  min-height: 100vh;
}
img, svg { max-width: 100%; }
a { color: var(--stamp-dark); }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--indigo); outline-offset: 2px; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  z-index: 20;
}
.skip:focus { top: 12px; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  padding: 10px 14px;
  background: var(--indigo);
  color: #f6efe2;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  font-family: var(--serif);
  font-size: 1.6rem;
  letter-spacing: -0.03em;
}
.brand svg { display: block; }
.nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.nav a {
  color: #f6efe2;
  text-decoration: none;
  min-height: var(--hit);
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
}
.nav a[aria-current="page"] { background: rgba(255, 255, 255, 0.12); }

.btn {
  min-height: var(--hit);
  min-width: var(--hit);
  border: 0;
  border-radius: 999px;
  padding: 0 16px;
  background: var(--card);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.btn.primary { background: var(--stamp); color: white; font-weight: 700; }
.btn.primary:hover { background: var(--stamp-dark); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.xl { min-height: 52px; padding: 0 28px; font-size: 1.15rem; letter-spacing: 0.01em; }
.site-header .btn.primary { background: var(--stamp); }

main { padding: 28px 20px 64px; max-width: 1120px; margin: 0 auto; }
.site-footer {
  padding: 28px 22px 40px;
  color: #4d463c;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  border-top: 1px solid var(--line);
}
.site-footer a {
  margin-right: 12px;
  display: inline-flex;
  align-items: center;
  min-height: 24px;
}

.hero { display: grid; gap: 28px; align-items: center; }
.hero h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.6rem, 6vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
  margin: 0 0 12px;
}
.lede { font-size: 1.15rem; max-width: 38rem; line-height: 1.45; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.hero-stage {
  background: var(--indigo);
  border-radius: 28px;
  min-height: 280px;
  padding: 18px;
  box-shadow: var(--shadow);
}
.stage-slot, .fold-host, .hero-stage .fold-host { width: min(100%, 460px); margin: 0 auto; }
.stage {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  perspective-origin: 50% 50%;
  touch-action: none;
  overflow: hidden;
}
.fold-host, .hero-stage, .author-stage { overflow: hidden; }
.player { overflow: visible; }
.rig, .flap {
  position: absolute;
  transform-style: preserve-3d;
  -webkit-transform-style: preserve-3d;
}
.rig { inset: 18%; }
.flap { inset: 0; pointer-events: none; }
.fold-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.section-title {
  font-family: var(--serif);
  font-size: 2rem;
  margin: 48px 0 14px;
}
.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
}
.model-card {
  background: linear-gradient(135deg, transparent 18px, var(--card) 18px);
  border-radius: 18px;
  padding: 16px 16px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
  min-height: 100%;
}
.model-card h2 { font-family: var(--serif); font-size: 1.45rem; margin: 0; }
.model-card h2 a { display: inline-flex; align-items: center; min-height: 44px; }
.shelf-grid { grid-template-columns: repeat(auto-fill, minmax(230px, 320px)); }
.model-card p { margin: 0; line-height: 1.4; }
.model-card .meta { color: #5c5348; font-size: 0.92rem; }
.credit { color: #5c5348; max-width: 62ch; }
.card-links { display: flex; gap: 8px; margin-top: auto; padding-top: 8px; }
.icon { width: 100%; height: 92px; }

.studio {
  max-width: 1200px;
}
.studio-app { display: flex; flex-direction: column; gap: 12px; }
.section-note { margin: 0 0 16px; max-width: 62ch; color: #5c5348; }
.model-picker { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; align-items: center; }
.picker-label { font-weight: 700; white-space: nowrap; padding: 0 4px; }
.model-choice {
  min-height: var(--hit);
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--card);
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
}
.model-choice[aria-pressed="true"] { background: var(--indigo); color: #f6efe2; border-color: var(--indigo); }
.model-title { font-family: var(--serif); font-size: 2rem; margin: 0; }
.note { margin: 0; color: #5c5348; }
.paper-wrap { display: grid; justify-items: center; }
.paper, .fold-host {
  position: relative;
  width: min(100%, 640px);
  aspect-ratio: 1;
  touch-action: none;
}
.paper {
  background: #fffdf8;
  box-shadow: var(--shadow), 0 1px 0 rgba(255,255,255,0.8) inset;
  border-radius: 4px;
}
.paper[data-side="back"] { background: #f6e2b0; }
.paper.is-net, .paper.is-net[data-side="back"] { background: transparent; box-shadow: none; }
.paper canvas, .creases {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.paper canvas { border-radius: 4px; }
.paper canvas:not(.is-active) { visibility: hidden; pointer-events: none; }
.paper canvas:focus-visible { outline: 3px solid var(--indigo); outline-offset: -3px; }
input[type="color"] {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.creases { pointer-events: none; }
.creases line { stroke-width: 0.6; fill: none; }
.creases .valley { stroke: rgba(159, 42, 28, 0.55); stroke-dasharray: 2.2 1.3; }
.creases .mountain { stroke: rgba(36, 48, 86, 0.55); stroke-dasharray: 0.4 1.3; }
.creases .guide { stroke: rgba(28, 25, 21, 0.35); stroke-dasharray: 0; stroke-width: 0.4; }
.creases .net-outline { stroke: rgba(28, 25, 21, 0.8); stroke-width: 0.9; fill: none; }
.creases.is-off { display: none; }

.toolbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: rgba(255, 250, 243, 0.96);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.tool-group { display: flex; gap: 6px; align-items: center; }
.tool-btn, .swatch {
  min-width: var(--hit);
  min-height: var(--hit);
  border-radius: 12px;
  border: 1px solid var(--line);
  background: white;
  cursor: pointer;
  padding: 0 8px;
}
.tool-btn[aria-pressed="true"], .swatch[aria-pressed="true"] {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 2px var(--ink);
}
.swatch { padding: 0; }
.tool-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#side-note { flex-basis: 100%; max-width: 11rem; }
.fold-bar { display: flex; justify-content: center; }
.transport { display: grid; gap: 8px; width: min(100%, 640px); margin: 0 auto; }
.transport input[type="range"] { width: 100%; min-height: var(--hit); }
.transport-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.step-label { margin: 0; font-family: var(--serif); font-size: 1.25rem; }
.banner {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  background: #fff4d6;
  border: 1px solid #e4b24a;
  border-radius: 14px;
  padding: 8px 12px;
}
.banner p { margin: 0; }

dialog {
  border: 0;
  border-radius: 20px;
  padding: 18px;
  width: min(520px, calc(100% - 24px));
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(28, 25, 21, 0.45); }
dialog h2 { font-family: var(--serif); margin: 0 0 8px; }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }
#share-url { width: 100%; min-height: var(--hit); border-radius: 10px; border: 1px solid var(--line); padding: 8px; }
.status { min-height: 1.4em; font-weight: 650; }

.model-page h1 { font-family: var(--serif); font-size: clamp(1.8rem, 4vw, 2.6rem); line-height: 1.15; letter-spacing: -0.03em; }
.facts { display: grid; gap: 6px; padding: 0; margin: 12px 0; }
.facts div { display: grid; grid-template-columns: 11rem 1fr; gap: 8px; }
.facts dt { font-weight: 700; }
.facts dd { margin: 0; }
.est { display: block; font-size: 0.78rem; letter-spacing: 0.04em; text-transform: uppercase; color: #6b6256; }
.player { background: var(--indigo); border-radius: 20px; padding: 12px; margin: 16px 0; color: #f6efe2; }
.player .btn { color: var(--ink); }
.player .btn.primary { color: #fff; }
.player .step-label, #mini-label { color: #f6efe2; }
.steps { list-style: none; padding: 0; display: grid; gap: 14px; }
.steps li {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  background: var(--card);
  border-radius: 16px;
  padding: 10px;
  box-shadow: 0 8px 20px rgba(60, 36, 12, 0.06);
}
.steps h3 { margin: 0 0 4px; font-size: 1rem; }
.tip { margin: 6px 0 0; color: #5c5348; }
.step-diagram { width: 120px; height: 120px; background: #f7f1e6; border-radius: 10px; }
.teacher {
  border-left: 6px solid var(--gold);
  background: #fffaf3;
  padding: 12px 14px;
  border-radius: 12px;
  margin: 18px 0;
}
.cta-row { margin: 18px 0; }
.print-only { display: none; }
.crease-wrap { max-width: 420px; }
.crease-wrap svg { width: 100%; height: auto; background: white; }
.legend { font-size: 0.9rem; }

.count-optout {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  margin: 0 0 12px;
  font-weight: 700;
  cursor: pointer;
}
.count-optout input {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  flex: 0 0 44px;
  accent-color: var(--indigo);
}
.count-optout.is-locked {
  margin-bottom: 4px;
  color: var(--ink);
  cursor: not-allowed;
}
.count-optout.is-locked input:disabled {
  appearance: none;
  -webkit-appearance: none;
  opacity: 1;
  cursor: not-allowed;
  border: 3px solid #243056;
  border-radius: 10px;
  background-color: #243056;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23fffaf3' stroke-width='3' stroke-linecap='round' stroke-linejoin='round' d='M5 12.5l4.5 4.5L19 7'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 26px 26px;
}
.count-optout-note {
  margin: 0 0 12px;
  color: #1c1915;
  font-size: 1rem;
  line-height: 1.45;
}
.about, .faq { max-width: 44rem; }
.about h1, .faq h1 { font-family: var(--serif); font-size: clamp(2rem, 5vw, 3.2rem); letter-spacing: -0.03em; }
.faq details { background: var(--card); border-radius: 12px; padding: 8px 14px; margin: 8px 0; }
.faq summary { min-height: var(--hit); display: flex; align-items: center; cursor: pointer; font-weight: 700; }

.author-layout { display: grid; gap: 16px; }
.sliders { display: grid; gap: 6px; max-height: 50vh; overflow: auto; }
.sliders label { display: grid; grid-template-columns: 8rem 1fr 3rem; gap: 8px; align-items: center; min-height: 44px; }
.sliders input[type="range"] { width: 100%; min-height: 44px; }
.author-layout select { min-height: 44px; min-width: 44px; }
.author-layout input[type="checkbox"] { width: 44px; height: 44px; min-width: 44px; min-height: 44px; }
.author-actions { display: flex; flex-wrap: wrap; gap: 8px; }
textarea.dump { width: 100%; min-height: 120px; font-family: ui-monospace, monospace; font-size: 12px; }
.author-stage { position: relative; width: min(100%, 480px); }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }

@media (max-width: 879px) {
  main { padding: 12px 12px 28px; }
  .player { padding-bottom: 18px; }
  .transport { padding-bottom: 8px; }
  body.studio main { padding-bottom: 12px; }
  body.studio .paper,
  body.studio .fold-host { width: min(100%, max(260px, calc(100dvh - 530px))); }
  /* Width, not a max-height: Safari's toolbar grows the viewport by about 80px and would turn a height query back on mid-scroll. */
  .toolbar,
  body.studio #fold-ui {
    position: static;
  }
  body.studio #fold-ui {
    z-index: 4;
    background: rgba(255, 250, 243, 0.96);
    padding-top: 6px;
  }
  .studio-app { display: flex; flex-direction: column; }
  .model-picker { order: 1; flex-wrap: wrap; overflow-x: visible; }
  .paper-wrap, .fold-column { order: 2; }
  .fold-bar { order: 3; }
  .toolbar { order: 4; }
  .model-title { font-size: 1.55rem; }
}

@media (min-width: 880px) {
  .hero { grid-template-columns: 1.1fr 0.9fr; }
  body.studio main { padding-top: 10px; padding-bottom: 12px; }
  body.studio .model-title { font-size: 1.55rem; line-height: 1.1; }
  body.studio .paper,
  body.studio .fold-host { width: min(100%, 640px, max(300px, calc(100dvh - 460px))); }
  body.studio .transport { gap: 4px; }
  body.studio .step-label { font-size: 1.1rem; }
  .studio-app {
    display: grid;
    grid-template-columns: 132px 1fr;
    grid-template-areas:
      "tools picker"
      "tools stage"
      "tools fold";
    align-items: start;
  }
  .toolbar {
    grid-area: tools;
    position: sticky;
    top: 12px;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    max-height: calc(100vh - 24px);
    bottom: auto;
  }
  .model-picker { grid-area: picker; }
  .paper-wrap, .fold-column { grid-area: stage; }
  .fold-bar { grid-area: fold; justify-content: flex-start; }
  .tool-group { flex-wrap: wrap; }
  .steps li { grid-template-columns: 160px 1fr; }
  .step-diagram { width: 160px; height: 160px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { animation: none !important; transition: none !important; }
}

@media print {
  .site-header, .site-footer, .no-print, .player, .cta-row { display: none !important; }
  body { background: white; font-size: 10.5pt; line-height: 1.3; overflow: visible; }
  main { max-width: none; padding: 0; }
  .print-only { display: block; }
  .model-page h1,
  .model-page h2,
  .model-page h3,
  .model-page p { margin: 0; }
  .model-page h1 { font-size: 16pt; line-height: 1.15; margin-bottom: 3pt; }
  .intro { font-size: 11pt; margin: 0 0 4pt; }
  .facts { font-size: 10.5pt; gap: 1pt; margin: 0 0 4pt; }
  .facts div { grid-template-columns: 42mm 1fr; gap: 2mm; }
  .est { font-size: 9pt; }
  .teacher { font-size: 10.5pt; border: 0; padding: 0; margin: 4pt 0 0; background: transparent; }
  .teacher h2 { font-size: 12pt; margin: 0 0 2pt; }
  .steps { columns: 2; column-gap: 6mm; display: block; margin: 0; }
  .steps li {
    break-inside: avoid;
    box-shadow: none;
    display: block;
    padding: 0 0 4pt;
    margin: 0;
    background: transparent;
  }
  .steps li::after { content: ""; display: block; clear: both; }
  .steps h3 { font-size: 10.5pt; line-height: 1.25; margin: 0; }
  .tip { font-size: 10pt; margin: 0; }
  .step-diagram { width: 22mm; height: 22mm; float: left; margin: 0 2mm 1mm 0; border-radius: 1mm; }
  .crease-wrap { width: 150mm; margin: 2pt auto 4pt; break-inside: avoid; }
  .crease-wrap.is-net { width: 100%; max-width: none; margin: 0 auto 2pt; }
  .crease-wrap h2 { font-size: 12pt; margin: 0 0 2pt; text-align: center; }
  .crease-wrap svg { border: 0.4mm solid black; }
  .crease-wrap.is-net svg { border: 0; }
  .legend { font-size: 10pt; margin: 2pt 0 0; text-align: center; }
  @page { size: A4; margin: 8mm; }
}
