/*
 * Vestes Archive — the atelier layer.
 * A pattern-sheet vocabulary shared by every page: measuring tape, stitches,
 * registration marks, figure captions and the stages that hold the 3D figures.
 * Colours come from the page (--ink / --paper / --accent), so it works on
 * parchment and on the Smart Wardrobe forest theme alike.
 */
:root {
  --thread: #C8643F;
  --thread-deep: #99462a;
  --at-ink: var(--ink, #191919);
  --at-line: color-mix(in srgb, var(--at-ink) 22%, transparent);
  --at-muted: color-mix(in srgb, var(--at-ink) 62%, transparent);
  --at-mono: 'Source Code Pro', ui-monospace, Menlo, monospace;
  --at-serif: 'Spectral', Georgia, serif;
  --at-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15'%3E%3Cpath d='M7.5 0v15M0 7.5h15' stroke='%23191919' stroke-opacity='.5'/%3E%3Ccircle cx='7.5' cy='7.5' r='3' fill='none' stroke='%23191919' stroke-opacity='.5'/%3E%3C/svg%3E");
}
.theme-sage {
  --thread: #A3B899;
  --thread-deep: #D4AF37;
  --at-ink: #F2F5F0;
  --at-line: rgba(242, 245, 240, .2);
  --at-muted: rgba(242, 245, 240, .64);
  --paper: #08120E;
  --at-mark: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='15' height='15'%3E%3Cpath d='M7.5 0v15M0 7.5h15' stroke='%23F2F5F0' stroke-opacity='.4'/%3E%3Ccircle cx='7.5' cy='7.5' r='3' fill='none' stroke='%23F2F5F0' stroke-opacity='.4'/%3E%3C/svg%3E");
}

/* ── Measuring tape along the left edge: it measures the scroll ── */
.tape, .tape-read { display: none; }
@media (min-width: 768px) {
  .tape {
    display: block; position: fixed; left: 0; top: 0; bottom: 0; width: var(--frame, 18px);
    z-index: 101; pointer-events: none; overflow: hidden; color: var(--at-ink);
  }
  .tape__ticks {
    position: absolute; inset: 0; opacity: .55;
    background:
      repeating-linear-gradient(to bottom, currentColor 0 1px, transparent 1px 80px) right 0 top var(--off, 0px) / 11px 100% no-repeat,
      repeating-linear-gradient(to bottom, currentColor 0 1px, transparent 1px 40px) right 0 top var(--off, 0px) / 7px 100% no-repeat,
      repeating-linear-gradient(to bottom, currentColor 0 1px, transparent 1px 8px) right 0 top var(--off, 0px) / 4px 100% no-repeat;
  }
  .tape__nums span {
    position: absolute; left: 1px; top: 3px; writing-mode: vertical-rl;
    font: 500 7px/1 var(--at-mono); letter-spacing: .06em; opacity: .7; will-change: transform;
  }
}
@media (min-width: 1024px) {
  .tape-read {
    display: flex; align-items: center; gap: 7px; position: fixed; left: var(--frame, 18px); top: 50%;
    transform: translateY(-50%); z-index: 101; pointer-events: none;
    font: 500 10px/1 var(--at-mono); letter-spacing: .08em; color: var(--thread-deep); font-variant-numeric: tabular-nums;
  }
  .tape-read::before { content: ''; border: 4px solid transparent; border-left: 6px solid currentColor; border-right: 0; }
}

/* ── Pattern-piece heading: number, running stitch, name ── */
.piece-head {
  display: flex; align-items: center; gap: 14px; margin: 0 0 clamp(22px, 3vw, 40px);
  font: 500 11px/1.4 var(--at-mono); letter-spacing: .14em; text-transform: uppercase; color: var(--at-muted);
}
.piece-head b { font-weight: 500; color: var(--thread-deep); white-space: nowrap; }
.piece-head span { white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.piece-head::after, .stitch {
  content: ''; flex: 1; height: 1px; min-width: 24px;
  background: repeating-linear-gradient(90deg, var(--thread) 0 9px, transparent 9px 15px);
}
.stitch { display: block; }
.piece-head i { font-style: normal; order: 3; white-space: nowrap; }
/* The stitch is sewn when it scrolls into view. */
@media (prefers-reduced-motion: no-preference) {
  [data-sew] .piece-head::after, [data-sew].piece-head::after, [data-sew] .stitch, .stitch[data-sew] {
    clip-path: inset(0 100% 0 0); transition: clip-path 1.4s cubic-bezier(.22, 1, .36, 1) .15s;
  }
  [data-sew].sewn .piece-head::after, [data-sew].sewn.piece-head::after, [data-sew].sewn .stitch, .stitch[data-sew].sewn { clip-path: inset(0); }
}

/* ── Stage: the box a 3D figure lives in ── */
.stage3d { position: relative; isolation: isolate; min-height: 220px; }
.stage3d > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; z-index: 1; outline: 0; }
.stage3d > .stage-fallback {
  position: absolute; inset: 0; margin: auto; max-width: 56%; max-height: 70%; width: auto; height: auto;
  object-fit: contain; transition: opacity .7s ease, visibility .7s; pointer-events: none;
}
.stage3d.is-live > .stage-fallback { opacity: 0; visibility: hidden; }
/* No WebGL and nothing to fall back on: give the space back. */
.stage3d.no-webgl:not(:has(.stage-fallback)) { display: none; }
/* Contact shadow on the paper. */
.stage3d--shadow::before {
  content: ''; position: absolute; left: 50%; bottom: var(--shadow-y, 7%); width: var(--shadow-w, 46%); height: 26px;
  transform: translateX(-50%); border-radius: 50%; z-index: 0; pointer-events: none;
  background: radial-gradient(closest-side, color-mix(in srgb, var(--at-ink) 26%, transparent), transparent);
  filter: blur(5px); opacity: 0; transition: opacity 1.2s ease .4s;
}
.stage3d--shadow.is-live::before { opacity: 1; }
/* Registration marks in the corners, as on a printed pattern. */
.marks {
  background-image: var(--at-mark), var(--at-mark), var(--at-mark), var(--at-mark);
  background-repeat: no-repeat; background-size: 15px 15px;
  background-position: 14px 14px, calc(100% - 14px) 14px, 14px calc(100% - 14px), calc(100% - 14px) calc(100% - 14px);
}

/* ── Figure caption ── */
.fig {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; margin: 0; max-width: none;
  font: 400 11px/1.5 var(--at-mono); letter-spacing: .06em; color: var(--at-muted);
}
.fig b { font-weight: 500; letter-spacing: .14em; color: var(--thread-deep); }
.fig .fig-hint { margin-left: auto; opacity: .8; }
.fig .fig-hint::before { content: '⟲ '; }
@media (hover: none) { .fig .fig-hint { display: none; } }

/* ── Measurement call-outs around a figure ── */
.callouts { list-style: none; margin: 0; padding: 0; position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.callouts li {
  position: absolute; left: var(--x); top: var(--y); display: flex; align-items: center; gap: 9px;
  font: 400 11px/1.25 var(--at-mono); letter-spacing: .06em; color: var(--at-muted); white-space: nowrap;
}
.callouts li b { font: 400 clamp(22px, 2.1vw, 32px)/1 var(--at-serif); letter-spacing: -.02em; color: var(--at-ink); }
.callouts li::after { content: ''; width: var(--len, 54px); height: 1px; background: currentColor; opacity: .55; }
.callouts li::before { content: ''; order: 9; width: 5px; height: 5px; margin-left: -9px; border-radius: 50%; background: var(--thread); }
.callouts li.flip { flex-direction: row-reverse; transform: translateX(-100%); }
.callouts li.flip::before { margin-left: 0; margin-right: -9px; }
@media (prefers-reduced-motion: no-preference) {
  .callouts li { opacity: 0; animation: callout-in .9s cubic-bezier(.22, 1, .36, 1) forwards; animation-delay: calc(1.5s + var(--i, 0) * .16s); }
  @keyframes callout-in { from { opacity: 0; clip-path: inset(0 0 0 100%); } to { opacity: 1; clip-path: inset(0 -10px); } }
  .callouts li.flip { animation-name: callout-in-flip; }
  @keyframes callout-in-flip { from { opacity: 0; clip-path: inset(0 100% 0 0); } to { opacity: 1; clip-path: inset(0 -10px); } }
}

/* ── Stitched button ── */
.btn-stitch {
  position: relative; display: inline-flex; align-items: center; justify-content: space-between; gap: 28px;
  padding: 15px 24px; border: 1px solid var(--at-ink); border-radius: 3px; background: transparent; color: var(--at-ink);
  font: 400 15px/1.2 'Hanken Grotesk', system-ui, sans-serif; text-decoration: none; transition: background .25s, color .25s;
}
.btn-stitch::before {
  content: ''; position: absolute; inset: 4px; border-radius: 1px; pointer-events: none; opacity: .5;
  background:
    repeating-linear-gradient(90deg, currentColor 0 6px, transparent 6px 11px) 0 0 / 100% 1px no-repeat,
    repeating-linear-gradient(90deg, currentColor 0 6px, transparent 6px 11px) 0 100% / 100% 1px no-repeat,
    repeating-linear-gradient(0deg, currentColor 0 6px, transparent 6px 11px) 0 0 / 1px 100% no-repeat,
    repeating-linear-gradient(0deg, currentColor 0 6px, transparent 6px 11px) 100% 0 / 1px 100% no-repeat;
}
.btn-stitch:hover { background: var(--at-ink); color: var(--paper, #F0EEE6); }
.btn-stitch--solid { background: var(--thread-deep); border-color: var(--thread-deep); color: #fbf9f1; }
.btn-stitch--solid:hover { background: #762c12; border-color: #762c12; color: #fbf9f1; }
@media (prefers-reduced-motion: no-preference) {
  .btn-stitch:hover::before { animation: stitch-run .7s linear infinite; }
  @keyframes stitch-run { to { background-position: 11px 0, -11px 100%, 0 -11px, 100% 11px; } }
}

/* ── Legal / plain document pages ── */
.doc-hero {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, .8fr); gap: 5vw; align-items: center;
  padding: clamp(36px, 6vw, 80px) 0 clamp(30px, 4vw, 56px);
}
.doc-hero h1 { font-size: clamp(36px, 5.2vw, 78px); margin-bottom: 22px; }
.doc-hero .lede { font-size: clamp(18px, 1.5vw, 21px); line-height: 1.55; max-width: 46ch; color: var(--at-muted); margin: 0; }
.doc-hero .stage3d { height: clamp(260px, 34vw, 420px); }
.doc-meta { display: flex; flex-wrap: wrap; gap: 8px 26px; margin: 26px 0 0; font: 12px/1.6 var(--at-mono); letter-spacing: .05em; color: var(--at-muted); }
.doc-meta a { color: inherit; }
.doc-lang { display: flex; gap: 6px; margin-top: 26px; }
.doc-lang a, .doc-lang button {
  border: 1px solid var(--at-line); background: transparent; padding: 9px 14px; border-radius: 3px; cursor: pointer;
  font: 13px/1 'Hanken Grotesk', sans-serif; color: var(--at-ink); text-decoration: none;
}
.doc-lang a:hover, .doc-lang button:hover { border-color: var(--at-ink); color: var(--at-ink); }
.doc-lang .active { background: var(--at-ink); color: var(--paper, #F0EEE6); border-color: var(--at-ink); }
.doc-body { max-width: 78ch; padding: 10px 0 90px; counter-reset: clause; }
.doc-body section + section, .doc-body hr + section { margin-top: 70px; }
.doc-body hr { border: 0; height: 1px; margin: 70px 0 0; background: repeating-linear-gradient(90deg, var(--thread) 0 9px, transparent 9px 15px); }
.doc-body h1 { font-size: clamp(30px, 3.2vw, 46px); margin: 0 0 10px; }
.doc-body h2 {
  font-size: clamp(22px, 2vw, 28px); margin: 48px 0 16px; padding-top: 22px; border-top: 1px solid var(--at-line);
  display: flex; gap: 16px; align-items: baseline; letter-spacing: -.015em;
}
.doc-body h3 { font: 600 17px/1.4 'Hanken Grotesk', sans-serif; letter-spacing: 0; margin: 26px 0 10px; }
.doc-body p, .doc-body li { font-size: 17px; line-height: 1.7; max-width: none; }
.doc-body p { margin: 0 0 16px; }
.doc-body ul, .doc-body ol { padding-left: 22px; margin: 0 0 18px; }
.doc-body li { margin-bottom: 8px; }
.doc-body li::marker { color: var(--thread-deep); }
.doc-body a { color: var(--thread-deep); }
.doc-body a:hover { color: var(--at-ink); }
.doc-body .last-updated { font: 12px/1.6 var(--at-mono); letter-spacing: .05em; color: var(--at-muted); margin-bottom: 26px; }
.doc-body .note, .doc-body .highlight {
  margin: 22px 0; padding: 18px 22px; background: #e6e1d3; border-left: 2px solid var(--thread); border-radius: 0 3px 3px 0; font-size: 16px; line-height: 1.65; color: var(--at-ink);
}
.doc-body table { font-size: 15px; }
.doc-body th, .doc-body td { white-space: normal; padding: 14px 12px; vertical-align: top; }
@media (max-width: 760px) {
  .doc-hero { grid-template-columns: 1fr; gap: 10px; }
  .doc-hero .stage3d { height: 240px; order: -1; }
  .doc-body p, .doc-body li { font-size: 16px; }
  .doc-body h2 { margin-top: 36px; }
}
