/* unscratchable — archival-specimen dark.
   Two working colors: damage rust, heal green. Gold annotates. */

:root {
  --ink: #100f0d;
  --panel: #171613;
  --panel-2: #1c1a16;
  --edge: #2a2823;
  --edge-soft: #221f1a;
  --text: #e8e2d3;
  --dim: #9b9483;
  --faint: #8a8371; /* quietest text tone that still clears 4.5:1 on the panel */
  --rust: #e0533d;
  --heal: #3ddc84;
  --gold: #c8a24b;
  --serif: 'Iowan Old Style', 'Palatino Linotype', Palatino, Charter, Georgia, serif;
  --mono: ui-monospace, 'SF Mono', 'Cascadia Code', Menlo, Consolas, monospace;
  --measure: 42rem;
  --wide: 54rem;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--ink);
  color: var(--text);
  font-family: var(--serif);
  font-size: 1.14rem;
  line-height: 1.72;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--gold); color: var(--ink); }

a { color: var(--gold); text-decoration: none; border-bottom: 1px solid color-mix(in srgb, var(--gold) 40%, transparent); }
a:hover { color: var(--text); border-bottom-color: var(--text); }

em { font-style: italic; }
strong { font-weight: 600; color: #fff8e7; }

code, .mono {
  font-family: var(--mono);
  font-size: 0.82em;
  background: var(--panel-2);
  border: 1px solid var(--edge-soft);
  border-radius: 4px;
  padding: 0.1em 0.38em;
  color: var(--dim);
}

/* ---------- masthead ---------- */

header.masthead {
  max-width: var(--measure);
  margin: 0 auto;
  padding: clamp(3rem, 9vh, 6rem) 1.25rem 0;
  text-align: center;
}

.masthead .kicker {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--faint);
}

.masthead h1 {
  font-size: clamp(2.6rem, 7vw, 4.2rem);
  font-weight: 500;
  letter-spacing: -0.015em;
  margin: 0.5rem 0 0.75rem;
  color: #fdf8ea;
}

.masthead .subtitle {
  color: var(--dim);
  font-size: 1.18rem;
  font-style: italic;
  margin: 0 auto 0.4rem;
  max-width: 34rem;
}

.masthead .byline {
  font-family: var(--mono);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  color: var(--faint);
  margin-top: 1.4rem;
}
.masthead .byline a { border: none; color: var(--faint); }
.masthead .byline a:hover { color: var(--gold); }

.rule {
  width: 5rem;
  height: 1px;
  border: 0;
  margin: 2.6rem auto;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

/* ---------- essay body ---------- */

main { padding-bottom: 6rem; }

.essay {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 1.25rem;
}

.chapter { margin-top: clamp(4rem, 10vh, 7rem); }

.chapter-head { display: flex; align-items: baseline; gap: 1.1rem; margin-bottom: 1.2rem; }

.chapter-head .no {
  font-family: var(--mono);
  font-size: clamp(2.6rem, 6vw, 3.6rem);
  font-weight: 200;
  line-height: 1;
  color: var(--edge);
  -webkit-text-stroke: 1px var(--faint);
  user-select: none;
}

.chapter-head h2 {
  font-size: clamp(1.5rem, 3.4vw, 1.9rem);
  font-weight: 500;
  margin: 0;
  color: #fdf8ea;
  letter-spacing: 0.01em;
}

.chapter p { margin: 1.1rem 0; }

.aside {
  border-left: 2px solid var(--edge);
  padding-left: 1rem;
  color: var(--dim);
  font-size: 0.98rem;
}

/* ---------- figures ---------- */

figure.fig {
  margin: 2.2rem 0;
  width: min(calc(100vw - 2.5rem), var(--wide));
  /* figures breathe wider than the text column, centered on the viewport */
  position: relative;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 10px;
  padding: 0.9rem;
  box-shadow: 0 1px 0 rgba(255, 244, 214, 0.03) inset, 0 18px 48px -32px rgba(0, 0, 0, 0.9);
}

.fig-body { position: relative; }
/* touch-action is set per-figure in JS: tap-only figures allow vertical pans */
.fig-body canvas { display: block; width: 100%; border-radius: 6px; background: var(--ink); }
.fig-body canvas:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

figcaption {
  font-family: var(--mono);
  font-size: 0.74rem;
  line-height: 1.55;
  color: var(--faint);
  padding: 0.7rem 0.2rem 0.1rem;
  letter-spacing: 0.02em;
}
figcaption .fig-no { color: var(--gold); }

/* ---------- figure controls ---------- */

.fig-ui {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 1.1rem;
  padding: 0.75rem 0.2rem 0.15rem;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--dim);
}

.fig-ui .spacer { flex: 1; }

.fig-btn {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.76rem;
  letter-spacing: 0.06em;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 0.42em 0.95em;
  cursor: pointer;
  transition: border-color 120ms, color 120ms, background 120ms;
}
.fig-btn:hover { border-color: var(--gold); color: #fdf8ea; }
.fig-btn:active { transform: translateY(1px); }
.fig-btn.primary { border-color: color-mix(in srgb, var(--heal) 55%, var(--edge)); color: var(--heal); }
.fig-btn.primary:hover { background: color-mix(in srgb, var(--heal) 12%, var(--panel-2)); }
.fig-btn.danger { border-color: color-mix(in srgb, var(--rust) 45%, var(--edge)); color: var(--rust); }
.fig-btn:focus-visible, .seg button:focus-visible, input[type='range']:focus-visible, .fig-text:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.fig-field { display: inline-flex; align-items: center; gap: 0.55rem; }
.fig-field .lbl { color: var(--faint); letter-spacing: 0.05em; }
.fig-field .val { color: var(--gold); min-width: 3.2ch; text-align: right; font-variant-numeric: tabular-nums; }

input[type='range'] {
  appearance: none;
  -webkit-appearance: none;
  width: 9.5rem;
  height: 2px;
  border-radius: 1px;
  background: var(--edge);
  cursor: pointer;
}
input[type='range']::-webkit-slider-thumb {
  appearance: none;
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 1px var(--faint);
}
input[type='range']::-moz-range-thumb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--text);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 1px var(--faint);
}

.seg { display: inline-flex; border: 1px solid var(--edge); border-radius: 6px; overflow: hidden; }
.seg button {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--dim);
  background: transparent;
  border: 0;
  padding: 0.4em 0.85em;
  cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--edge); }
.seg button.on { background: var(--panel-2); color: var(--gold); }

.fig-note { font-family: var(--mono); font-size: 0.76rem; color: var(--faint); }
.fig-note.heal { color: var(--heal); }
.fig-note.rust { color: var(--rust); }

.fig-text {
  font: inherit;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text);
  background: var(--ink);
  border: 1px solid var(--edge);
  border-radius: 6px;
  padding: 0.45em 0.7em;
  min-width: 14rem;
}

/* ---------- closing map & footer ---------- */

.map { margin-top: 1.6rem; border-top: 1px solid var(--edge-soft); }
.map dl { margin: 0; }
.map .row { display: grid; grid-template-columns: 9.5rem 1fr; gap: 1rem; padding: 0.85rem 0.15rem; border-bottom: 1px solid var(--edge-soft); }
.map dt { font-family: var(--mono); font-size: 0.8rem; color: var(--gold); letter-spacing: 0.04em; padding-top: 0.15rem; }
.map dd { margin: 0; color: var(--dim); font-size: 0.98rem; }
@media (max-width: 34rem) { .map .row { grid-template-columns: 1fr; gap: 0.15rem; } }

footer.colophon {
  max-width: var(--measure);
  margin: 5rem auto 0;
  padding: 2.2rem 1.25rem 4rem;
  border-top: 1px solid var(--edge-soft);
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 2;
  color: var(--faint);
  text-align: center;
}
footer.colophon a { border: none; color: var(--dim); }
footer.colophon a:hover { color: var(--gold); }

/* ---------- misc ---------- */

.skip {
  position: absolute; left: -999px; top: 0;
  background: var(--gold); color: var(--ink);
  padding: 0.5rem 1rem; font-family: var(--mono); z-index: 10;
}
.skip:focus { left: 0.5rem; top: 0.5rem; }

noscript .fig-note { display: block; padding: 1rem; }

@media print {
  :root { --ink: #ffffff; --panel: #ffffff; --panel-2: #f4f2ec; --edge: #cfcabd; --edge-soft: #e2ddd0; --text: #1c1a16; --dim: #4a463c; --faint: #6b6557; }
  body { background: #fff; color: #1c1a16; }
  .masthead h1, .chapter-head h2, strong { color: #000; }
  .fig-body canvas, .fig-ui, .skip { display: none; }
  figure.fig::after { content: 'interactive figure — visit cleoanka.github.io/unscratchable'; font-family: var(--mono); font-size: 0.7rem; color: #6b6557; }
  a { color: #4a463c; }
}
