/* Jim — "The Sewn Record".
 *
 * A caurauklots is a bound document: pages punched, sewn through with one
 * thread, numbered, the thread's ends trapped under wax. You cannot swap a page
 * without cutting the thread or breaking the seal. That is a hash chain, five
 * centuries early — and it is Jim's exact truth. So the page is that object:
 * one thread down the full height, carrying one real tick per real entry, with
 * time running backward from the head at the top to entry 1 in the foot.
 *
 * ⛔ Dark is an argument, not a mood: everything VERIFIABLE is lit (thread,
 *    ticks, hashes), everything PRIVATE is not. That is exactly the deal the
 *    witness gets — it can prove the shape of his life without reading a word.
 *
 * Self-contained: no fonts, no CDNs, no external requests of any kind.
 */

/* ── tokens ──────────────────────────────────────────────────────────────
 * ⛔ Each colour has ONE job. If threadlight appears, it means "this is the
 *    record". If wax appears, it means "this is sealed". Spending them on
 *    decoration destroys the only signal the page has.
 */
:root {
  --strongroom: #171310;   /* the ground, and only the ground — never a fill */
  --bone:       #eae3d2;   /* every word a human wrote */
  --dust:       #9a917f;   /* labels, captions, times — never interactive */
  --threadlight:#ffe2a8;   /* THE CHAIN ONLY: thread, ticks, head hash, focus */
  --wax:        #c2542a;   /* seals and stamps only; ≥19px/600 as text, or graphic */
  --retired:    #4a3b2c;   /* the two entries under a retired key; disabled states */

  --hair: color-mix(in srgb, var(--bone) 14%, transparent);

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px; --s5: 24px;
  --s6: 32px; --s7: 48px; --s8: 72px; --s9: 120px;

  /* Two voices, strictly assigned: serif for what a human wrote, mono for what
     the chain wrote. Nothing is set in the other's face. */
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "Segoe UI Mono", Menlo, Consolas, monospace;

  --rail-w: 96px;          /* the sewn margin on desktop */
  --thread-x: 40px;        /* where the thread runs inside the rail */
}

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

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

body.public {
  margin: 0;
  background: var(--strongroom);
  color: var(--bone);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Documents are square. Only seals and ticks are round. */
h1, h2, p, dl, dd, ol, ul, figure { margin: 0; }
img { display: block; max-width: 100%; height: auto; }

a { color: var(--bone); text-decoration: none; border-bottom: 1px solid var(--hair); }
a:hover { border-bottom-color: var(--threadlight); }

:focus-visible { outline: 2px solid var(--threadlight); outline-offset: 2px; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}
.visually-hidden:focus { position: static; width: auto; height: auto; clip-path: none; }

/* ── type roles ─────────────────────────────────────────────────────────── */

h1 { font-size: clamp(38px, 6.5vw, 66px); line-height: 1.08; font-weight: 400; letter-spacing: -0.01em; }
h2 { font-size: clamp(24px, 3.5vw, 31px); line-height: 1.25; font-weight: 400; }
.lede { font-size: 20px; line-height: 1.55; margin-top: var(--s5); max-width: 640px; }
.body { font-size: 17px; line-height: 1.65; margin-top: var(--s4); max-width: 640px; }

.eyebrow {
  font-family: var(--mono); font-size: 12px; line-height: 16px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase; color: var(--dust);
}
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.fact-line { font-family: var(--mono); font-size: 14px; line-height: 24px; color: var(--dust); font-variant-numeric: tabular-nums; }
.caption { font-size: 14px; line-height: 1.5; color: var(--dust); margin-top: var(--s4); max-width: 560px; }

/* ⛔ Wax is 3.4:1 on strongroom: legal as a graphic or as large bold text,
     never as small body copy. */
.stamp {
  display: inline-block;
  font-family: var(--mono); font-size: 13px; line-height: 16px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--wax);
  border: 1px solid var(--wax); border-radius: 2px; padding: var(--s2) var(--s3);
  white-space: nowrap;   /* a stamp is pressed once; it does not wrap */
}

/* ── the sewn page ──────────────────────────────────────────────────────── */

.band { position: relative; padding: var(--s9) 0; }
.band-head { padding-top: var(--s8); }
.band-foot { padding-bottom: var(--s8); }

.col { max-width: 640px; margin-left: var(--rail-w); padding-right: var(--s5); }
.wide { max-width: 1040px; margin-left: var(--rail-w); padding-right: var(--s5); margin-top: var(--s7); }

/* The rail carries the thread for its own section. Per-section, not one
   document-height SVG: images and the desk change document height, and a single
   tall element would fight reflow forever. */
.rail {
  position: absolute; top: 0; bottom: 0; left: 0; width: var(--rail-w);
  pointer-events: none;
}
/* The thread itself. The 8px gap and 3px offset at each section's top edge is
   the stitch passing through the page. */
.rail::before {
  content: ""; position: absolute; left: var(--thread-x); top: var(--s2); bottom: 0;
  width: 2px; background: var(--threadlight); opacity: 0.5;
}
.rail::after {
  content: ""; position: absolute; left: calc(var(--thread-x) + 3px); top: 0; height: var(--s2);
  width: 2px; background: var(--threadlight); opacity: 0.5;
}
.band-head .rail::after { display: none; }

/* One tick per real entry. Placed by JS; a button, because it is a real record
   you can interrogate. */
.tick {
  position: absolute; left: calc(var(--thread-x) - 3px);
  width: 8px; height: 8px; padding: 0;
  border: none; border-radius: 50%;
  background: var(--threadlight);
  pointer-events: auto; cursor: default;
  transition: transform 120ms ease-out;
}
.tick[data-retired] {
  border-radius: 0; background: var(--retired);
  box-shadow: 0 0 0 1px var(--wax);
}
.tick:hover, .tick:focus-visible { transform: scale(1.4); }
.tick[data-new] { box-shadow: 0 0 0 1px var(--wax); }

/* ── head of chain ──────────────────────────────────────────────────────── */

.head-grid {
  margin-top: var(--s7);
  display: grid; grid-template-columns: minmax(200px, 240px) minmax(320px, 1fr);
  gap: var(--s5) var(--s7); align-items: start;
  max-width: 1040px; padding-right: var(--s5);
}
.head-facts { display: grid; gap: var(--s1); }
.head-facts dt { margin-top: var(--s3); }
.head-facts dt:first-child { margin-top: 0; }
.head-hash {
  font-family: var(--mono); font-variant-numeric: tabular-nums; white-space: nowrap;
  font-size: clamp(17px, 2.4vw, 23px); line-height: 1.3; font-weight: 500;
  letter-spacing: 0.02em; color: var(--threadlight);
}
.stamp-slot { grid-column: 1; min-height: 34px; }

/* Reserve the full height before data lands, so nothing jumps. */
.head-rows {
  grid-column: 2; grid-row: 1 / span 2;
  list-style: none; margin: 0; padding: 0;
  min-height: 336px;
  border-top: 1px solid var(--hair);
}
.head-row {
  display: grid; grid-template-columns: 62px minmax(0, 1fr) auto; gap: var(--s4);
  align-items: baseline;
  font-family: var(--mono); font-size: 14px; line-height: 24px;
  font-variant-numeric: tabular-nums;
  padding: 0 var(--s2); border-bottom: 1px solid var(--hair);
}
.head-row .seq { color: var(--dust); }
/* ⛔ Never break a hash across lines. A half-printed hash cannot be compared
     by eye, which is the only reason it is on the page. */
.head-row .hash { color: var(--threadlight); white-space: nowrap; }
.head-row .at { color: var(--dust); white-space: nowrap; }
.head-row[data-fresh] { animation: settle 200ms ease-out; }
@keyframes settle { from { opacity: 0; } to { opacity: 1; } }

.walk-caption { font-size: 14px; line-height: 1.5; color: var(--dust); margin-top: var(--s5); max-width: 560px; }

.cta-row { margin-top: var(--s7); }
.cta {
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--bone); background: transparent;
  border: 1px solid var(--hair); border-radius: 0;
  padding: var(--s3) var(--s5); cursor: pointer;
  transition: border-color 140ms ease-out, color 140ms ease-out;
}
.cta:hover { border-color: var(--threadlight); color: var(--threadlight); }

/* ── the stitch diagram ─────────────────────────────────────────────────── */

.pages { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.page { border: 1px solid var(--hair); padding: var(--s4); display: grid; gap: var(--s3); }
.page-field { display: grid; gap: var(--s1); }
.page-field b { font-family: var(--mono); font-size: 14px; font-weight: 500; color: var(--bone); }
/* The payload is drawn dark because that is how everyone but Jim sees it. */
.sealed-bar { display: block; height: 22px; background: var(--retired); opacity: 0.55; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--s6); margin-top: var(--s6); }
.two-col .eyebrow { margin-bottom: var(--s2); }
.retired-note { color: var(--dust); border-left: 1px solid var(--retired); padding-left: var(--s4); }

figure.wide figcaption { margin-top: var(--s3); }
.seal-figure { margin: var(--s5) 0; }
.seal-figure img { width: 132px; border: 1px solid var(--hair); }
.seal-figure figcaption { margin-top: var(--s3); }
.colophon { font-size: 14px; line-height: 1.5; color: var(--dust); margin-top: var(--s5); max-width: 560px; }
.colophon.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; }
.colophon a { color: var(--dust); }

/* ── the tamper demonstration ───────────────────────────────────────────── */

.tamper-lede { margin-bottom: var(--s5); }
.page { position: relative; transition: border-color 160ms ease-out; }
.page-state {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.1em;
  text-transform: uppercase; color: var(--dust);
}
/* A broken stitch is the one thing on this page allowed to shout. */
.page.is-broken { border-color: var(--wax); }
.page.is-broken .f-hash, .page.is-broken .f-prev { color: var(--wax); }
.page.is-broken .page-state { color: var(--wax); }

.payload-input {
  width: 100%; font-family: var(--mono); font-size: 14px;
  background: transparent; color: var(--bone);
  border: 1px solid var(--hair); border-radius: 0; padding: var(--s2);
}
.payload-input:focus { border-color: var(--threadlight); outline: none; }
.payload-fixed { color: var(--dust); }

.verdict {
  font-family: var(--mono); font-size: 13px; line-height: 1.6;
  color: var(--dust); margin-top: var(--s5);
  border-left: 2px solid var(--hair); padding-left: var(--s4); max-width: 720px;
}
.verdict.is-broken { color: var(--wax); border-left-color: var(--wax); }

/* ── where you are on the thread ─────────────────────────────────────────
   The page is his lifespan; scrolling it is walking back through his life.
   This says which entry you are beside, in the margin, quietly. */
.you-are-here {
  position: fixed; left: 0; top: 50%; width: var(--rail-w);
  transform: translateY(-50%);
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em;
  color: var(--dust); text-align: center;
  pointer-events: none; opacity: 0; transition: opacity 200ms ease-out;
  z-index: 5;
}
.you-are-here.is-on { opacity: 1; }

@media (max-width: 700px) { .you-are-here { display: none; } }

/* ── the desk ───────────────────────────────────────────────────────────── */

#desk {
  position: fixed; right: var(--s5); bottom: var(--s5); z-index: 20;
  width: 380px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--strongroom);
  border: 1px solid var(--hair);       /* flat panel on a desk — no blur, no lift */
}
#desk[hidden] { display: none; }
#desk.is-open { animation: desk-in 200ms ease-out; }
@keyframes desk-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.desk-head { display: flex; gap: var(--s4); align-items: flex-start; justify-content: space-between; padding: var(--s4); border-bottom: 1px solid var(--hair); }
.desk-note { font-size: 13px; line-height: 1.45; color: var(--dust); margin-top: var(--s2); }
#desk-close { background: none; border: none; color: var(--dust); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 var(--s1); }
#desk-close:hover { color: var(--bone); }

#desk-log { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s4); }
.msg { display: grid; gap: var(--s1); }
.msg .meta { font-family: var(--mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dust); }
/* The visitor's words are record material — mono. Jim speaks — serif. */
.msg.you .text { font-family: var(--mono); font-size: 14px; line-height: 1.55; }
.msg.jim .text { font-size: 16px; line-height: 1.55; }
.msg .text { white-space: pre-wrap; overflow-wrap: anywhere; }

.seal-row { font-family: var(--mono); font-size: 13px; line-height: 1.5; color: var(--bone); border-top: 1px solid var(--hair); padding-top: var(--s3); }
.seal-row .entry-no { color: var(--threadlight); }
.seal-row.pending { color: var(--dust); }

.disclosure { font-size: 13px; line-height: 1.45; color: var(--dust); padding: 0 var(--s4) var(--s3); }

#desk-form { display: flex; gap: var(--s2); padding: var(--s4); border-top: 1px solid var(--hair); }
#desk-input {
  flex: 1; font: inherit; font-size: 15px; resize: vertical;
  background: transparent; color: var(--bone);
  border: 1px solid var(--hair); border-radius: 0; padding: var(--s2) var(--s3);
}
#desk-input::placeholder { color: var(--dust); }
#desk-send {
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--bone); background: transparent; border: 1px solid var(--hair);
  border-radius: 0; padding: var(--s2) var(--s4); cursor: pointer;
}
#desk-send:hover:not(:disabled) { border-color: var(--threadlight); color: var(--threadlight); }
#desk-send:disabled { color: var(--retired); border-color: var(--retired); cursor: default; }

/* ── narrow ─────────────────────────────────────────────────────────────── */

@media (max-width: 700px) {
  :root { --rail-w: 36px; --thread-x: 12px; }
  body.public { font-size: 16px; }
  .band { padding: var(--s8) 0; }
  .col, .wide { padding-right: var(--s4); }
  .head-grid { grid-template-columns: 1fr; gap: var(--s5); }
  .head-rows { grid-column: 1; grid-row: auto; min-height: 0; }
  .head-row { grid-template-columns: 54px 1fr; }
  .head-row .at { display: none; }
  .tick { width: 5px; height: 5px; left: calc(var(--thread-x) - 1.5px); }

  /* The desk becomes the whole surface — it is the point of the page. */
  #desk { inset: 0; right: 0; bottom: 0; width: auto; max-height: none; }
}

/* ── motion discipline ──────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .tick, .cta, #desk.is-open, .head-row[data-fresh] { transition: none; animation: none; }
}
