/*
  Endpaper: journaling app page (Screenery template)
  The page is a marbler's workbench and the books it binds: a size bath of floated ink, a drying rack,
  an open notebook on indigo book cloth, a specimen book, a red colophon, ochre plan labels, a green question page.

  Contents
   1. Tokens (the seven pigments, size and paper, type, space)
   2. Base and browser surfaces
   3. Components: buttons, icon buttons, fields, checks, alerts
   4. Header
   5. Hero: bath, label, tray, pulled sheet, fallbacks
   6. Drying rack
   7. Journal: book, pages, search, tags, calendar, list, editor
   8. Specimen book
   9. Colophon
  10. Plans
  11. Sign-up
  12. Questions, footer
  13. Motion
  14. Narrow screens
*/

/* ---------- 1. Tokens ---------- */
:root {
  /* Pigments, named as a marbler would */
  --indigo: #24427d;
  --indigo-deep: #1d3568;     /* book cloth */
  --madder: #b63a2e;          /* Turkey red */
  --madder-deep: #9a2e25;     /* red grounds carrying cream text */
  --ochre: #e0a43a;
  --verdigris: #3a8b78;
  --verdigris-deep: #1f5a4e;  /* the question page */
  --rose: #e29aa4;
  --lamp: #221f26;            /* lamp black: text */

  /* Size and paper */
  --size: #f3ead6;            /* the carrageenan bath, and the paper colour of plates */
  --paper: #fbf6ea;           /* journal pages, labels */
  --paper-shade: #e9dec6;     /* rules and wells on paper */
  --ink-soft: #4f4552;        /* secondary text on paper and size */
  --rule: #cbbd9f;

  /* Text on dark grounds */
  --on-dark: #fbf6ea;
  --on-dark-soft: #e3dccd;

  /* Type */
  --display: 'Hahmlet', 'Iowan Old Style', Georgia, serif;
  --text: 'Sintony', 'Segoe UI', system-ui, sans-serif;
  --fs-xs: 0.78rem;
  --fs-s: 0.9rem;
  --fs-m: 1rem;
  --fs-l: clamp(1.15rem, 0.9rem + 0.6vw, 1.35rem);
  --fs-h3: clamp(1.25rem, 1rem + 0.7vw, 1.55rem);
  --fs-h2: clamp(1.9rem, 1.2rem + 2.4vw, 3.1rem);
  --fs-h1: clamp(2.2rem, 1.3rem + 3vw, 3.9rem);

  /* Space */
  --s1: 0.25rem; --s2: 0.5rem; --s3: 0.75rem; --s4: 1rem; --s5: 1.5rem; --s6: 2rem; --s7: 3rem; --s8: 4.5rem; --s9: 6.5rem;
  --gutter: clamp(1rem, 0.5rem + 2.5vw, 3rem);
  --max: 1240px;

  /* Shape and depth */
  --r-s: 4px;
  --r-m: 8px;
  --shadow-sheet: 0 1px 1px rgba(34, 31, 38, .12), 0 8px 22px -6px rgba(34, 31, 38, .32);
  --shadow-book: 0 2px 2px rgba(10, 14, 30, .25), 0 26px 50px -18px rgba(5, 8, 20, .7);
  --header-h: 64px;
  --ease: cubic-bezier(.16, 1, .3, 1);
}

/* ---------- 2. Base and browser surfaces ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h) + 8px); -webkit-text-size-adjust: 100%; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }
body {
  margin: 0;
  background: var(--paper);
  color: var(--lamp);
  font: 400 var(--fs-m)/1.6 var(--text);
  caret-color: var(--madder);
  accent-color: var(--indigo);
  scrollbar-color: var(--indigo) var(--size);
  overflow-x: clip;
}
::selection { background: var(--ochre); color: var(--lamp); }
h1, h2, h3 { font-family: var(--display); font-weight: 650; line-height: 1.08; letter-spacing: -0.015em; margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; text-decoration-thickness: 1px; text-underline-offset: 0.2em; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 3px solid var(--ochre); outline-offset: 3px; border-radius: 2px; }
.vh { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.defs { position: absolute; width: 0; height: 0; }
.ic { width: 1.15em; height: 1.15em; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.skip { position: absolute; left: var(--s4); top: -100px; z-index: 50; background: var(--lamp); color: var(--paper); padding: var(--s2) var(--s4); border-radius: var(--r-s); }
.skip:focus { top: var(--s2); }
mark { background: color-mix(in srgb, var(--ochre) 60%, transparent); color: inherit; border-radius: 2px; padding: 0 1px; }
[hidden] { display: none !important; }

/* ---------- 3. Components ---------- */
.btn {
  --bg: var(--paper); --fg: var(--lamp); --bd: var(--lamp);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 46px; padding: 0 var(--s5);
  font: 700 var(--fs-s)/1 var(--text); letter-spacing: .01em;
  color: var(--fg); background: var(--bg); border: 1.5px solid var(--bd); border-radius: 999px;
  text-decoration: none; cursor: pointer;
  transition: background-color .2s var(--ease), color .2s var(--ease), transform .2s var(--ease), box-shadow .2s var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px -6px rgba(34, 31, 38, .5); text-decoration: none; }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-sm { min-height: 40px; padding: 0 var(--s4); }
.btn-ink { --bg: var(--indigo); --fg: var(--paper); --bd: var(--indigo); }
.btn-ink:hover { --bg: var(--indigo-deep); }
.btn-red { --bg: var(--madder-deep); --fg: var(--paper); --bd: var(--madder-deep); }
.btn-red:hover { --bg: #85271f; }
.btn-line { --bg: transparent; }
.btn-line:hover { --bg: var(--paper); }
.btn-wide { width: 100%; min-height: 52px; font-size: var(--fs-m); }
.btn:disabled { cursor: progress; opacity: .85; transform: none; box-shadow: none; }

.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0;
  color: inherit; background: transparent; border: 1px solid transparent; border-radius: 50%; cursor: pointer;
}
.icon-btn:hover { border-color: currentColor; }
.link-btn {
  padding: 0; min-height: 28px; font: 700 var(--fs-s)/1.3 var(--text); color: inherit;
  background: none; border: 0; cursor: pointer; text-decoration: underline; text-underline-offset: .22em; text-decoration-thickness: 1px;
}
.link-btn:hover { text-decoration-thickness: 2px; }

.field { display: grid; gap: var(--s2); border: 0; margin: 0; padding: 0; min-width: 0; }
.field > label, .field > legend { font: 700 var(--fs-s)/1.3 var(--text); padding: 0; margin-bottom: var(--s1); }
.field input:not([type=radio]):not([type=checkbox]) {
  width: 100%; min-height: 48px; padding: 0 var(--s4);
  font: 400 var(--fs-m)/1.3 var(--text); color: var(--lamp);
  background: var(--paper); border: 1.5px solid var(--rule); border-radius: var(--r-s);
  transition: border-color .2s, box-shadow .2s;
}
.field input::placeholder, .j-search input::placeholder, .j-title::placeholder, .j-body::placeholder, .j-tag-field input::placeholder { color: #5e5462; }
.field input:hover { border-color: var(--ink-soft); }
.field input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 22%, transparent); }
.field.bad input { border-color: var(--madder-deep); }
.field.good input { border-color: var(--verdigris); }
.field-hint { font-size: var(--fs-s); color: var(--ink-soft); }
.field-err { display: flex; gap: var(--s2); align-items: flex-start; font-size: var(--fs-s); font-weight: 700; color: var(--madder-deep); line-height: 1.4; }
.field-err .ic { margin-top: .1em; }
.check { display: flex; gap: var(--s3); align-items: flex-start; font-size: var(--fs-s); cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; }
.check.bad span { color: var(--madder-deep); }

.form-alert { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-s); font-size: var(--fs-s); line-height: 1.45; border: 1.5px solid; }
.form-alert.warn { background: color-mix(in srgb, var(--ochre) 22%, var(--paper)); border-color: #b9842a; }
.form-alert.error { background: color-mix(in srgb, var(--madder) 10%, var(--paper)); border-color: var(--madder-deep); color: #7d241d; }
.form-alert .ic { margin-top: .15em; }

/* ---------- 4. Header ---------- */
.top {
  position: sticky; top: 0; z-index: 30; height: var(--header-h);
  display: flex; align-items: center; gap: var(--s5); padding: 0 var(--gutter);
  background: var(--paper);
  border-bottom: 3px double var(--lamp);
}
.brand { display: inline-flex; align-items: center; gap: var(--s2); font: 700 1.35rem/1 var(--display); letter-spacing: -0.01em; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; }
.nav { display: flex; gap: var(--s5); margin-left: auto; }
.nav a { font-size: var(--fs-s); font-weight: 700; text-decoration: none; padding: var(--s2) 0; border-bottom: 2px solid transparent; }
.nav a:hover { border-bottom-color: var(--madder); }

/* ---------- 5. Hero ---------- */
.hero {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: max(660px, calc(100svh - var(--header-h)));
  max-height: 1000px;
  background: var(--size);
}
.bath { position: relative; overflow: hidden; grid-row: 1; grid-column: 1; background: var(--size); }
.bath-fallback { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.bath-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; opacity: 0; }
.bath.live .bath-canvas { opacity: 1; }
.bath.live .bath-fallback { display: none; }
.bath-canvas:focus-visible { outline: 3px solid var(--ochre); outline-offset: -6px; }
/* A faint paper grain over the bath so the canvas reads as a surface, not a screen */
.bath::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .32; mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .45 0 0 0 0 .38 0 0 0 0 .3 0 0 0 .5 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E");
}
.crosshair {
  position: absolute; left: -14px; top: -14px; width: 28px; height: 28px; pointer-events: none; opacity: 0; z-index: 2;
  border: 2px solid var(--lamp); border-radius: 50%; box-shadow: 0 0 0 2px var(--paper);
}
.crosshair::before, .crosshair::after { content: ''; position: absolute; background: var(--lamp); }
.crosshair::before { left: 50%; top: -9px; bottom: -9px; width: 2px; margin-left: -1px; }
.crosshair::after { top: 50%; left: -9px; right: -9px; height: 2px; margin-top: -1px; }
.crosshair.on { opacity: 1; }
.hint {
  position: absolute; right: var(--gutter); top: var(--s5); z-index: 2; pointer-events: none;
  padding: var(--s2) var(--s4); font-size: var(--fs-s); font-weight: 700;
  background: var(--paper); border: 1px solid var(--lamp); border-radius: 999px;
  transition: opacity .6s var(--ease), transform .6s var(--ease);
}
.hint.gone { opacity: 0; transform: translateY(-6px); }
html:not(.js) .hint, .no-canvas .hint { display: none; }

/* The book label pasted on the marbled cover: notched corners, double rule */
.label {
  grid-row: 1; grid-column: 1; align-self: center; justify-self: start; z-index: 3;
  margin-left: clamp(1rem, 6vw, 6rem); width: min(540px, calc(100% - 2rem));
  pointer-events: none;
  filter: drop-shadow(0 10px 18px rgba(34, 31, 38, .28)) drop-shadow(0 1px 1px rgba(34, 31, 38, .2));
}
.label-inner {
  pointer-events: auto;
  --notch: 18px;
  clip-path: polygon(var(--notch) 0, calc(100% - var(--notch)) 0, 100% var(--notch), 100% calc(100% - var(--notch)), calc(100% - var(--notch)) 100%, var(--notch) 100%, 0 calc(100% - var(--notch)), 0 var(--notch));
  background:
    linear-gradient(var(--paper), var(--paper)) padding-box;
  padding: clamp(1.6rem, 1rem + 2vw, 2.6rem) clamp(1.4rem, 1rem + 1.6vw, 2.4rem);
  position: relative;
  display: grid; gap: var(--s4);
}
.label-inner::before {
  content: ''; position: absolute; inset: 9px; pointer-events: none;
  border: 1px solid var(--lamp); outline: 1px solid var(--lamp); outline-offset: -5px;
  clip-path: polygon(12px 0, calc(100% - 12px) 0, 100% 12px, 100% calc(100% - 12px), calc(100% - 12px) 100%, 12px 100%, 0 calc(100% - 12px), 0 12px);
}
.label h1 { font-size: var(--fs-h1); font-weight: 700; letter-spacing: -0.025em; }
.label p { color: var(--ink-soft); max-width: 46ch; }
.label-actions { display: flex; flex-wrap: wrap; gap: var(--s3); margin-top: var(--s2); }
.label-foot { font-size: var(--fs-s); }

/* The tray: pigments, tools, actions */
.tray {
  grid-row: 2; z-index: 4;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s4) var(--s6);
  padding: var(--s4) var(--gutter);
  background: var(--paper);
  border-top: 3px double var(--lamp);
}
.tray fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
.tray legend { font: 700 var(--fs-xs)/1 var(--text); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); margin-bottom: var(--s2); padding: 0; }
.pot-row, .tool-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pot input, .tool input, .period input, .plan-pick input, .cover-opt input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pot span { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; cursor: pointer; }
.pot i { width: 30px; height: 30px; border-radius: 50%; background: var(--c); box-shadow: inset 0 -3px 5px rgba(0, 0, 0, .2), 0 0 0 1px rgba(34, 31, 38, .35); transition: transform .25s var(--ease); }
.pot-gall i { box-shadow: inset 0 -3px 5px rgba(0, 0, 0, .08), 0 0 0 1px var(--ink-soft); }
.pot b { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.pot span:hover i { transform: scale(1.08); }
.pot input:checked + span { box-shadow: 0 0 0 2px var(--lamp); }
.pot input:checked + span i { transform: scale(.86); }
.pot input:focus-visible + span { outline: 3px solid var(--ochre); outline-offset: 2px; }
.tool span {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s3);
  font-size: var(--fs-s); font-weight: 700; border: 1.5px solid var(--rule); border-radius: var(--r-s); cursor: pointer; background: var(--paper);
}
.tool span:hover { border-color: var(--lamp); }
.tool input:checked + span { background: var(--lamp); color: var(--paper); border-color: var(--lamp); }
.tool input:focus-visible + span { outline: 3px solid var(--ochre); outline-offset: 2px; }
.acts { display: flex; flex-wrap: wrap; gap: var(--s2); align-self: flex-end; }
.tray-status { flex: 1 1 260px; font-size: var(--fs-s); color: var(--ink-soft); align-self: flex-end; padding-bottom: .55rem; min-width: 0; }
/* keep the status line clear of the gallery badge in the bottom-right corner (the badge is hidden on phones) */
@media (min-width: 641px) { .tray-status { padding-right: 150px; } }
.tray-nocanvas { display: none; font-size: var(--fs-s); max-width: 70ch; }
html:not(.js) .tray > :not(.tray-nocanvas), .no-canvas .tray > :not(.tray-nocanvas) { display: none; }
html:not(.js) .tray-nocanvas, .no-canvas .tray-nocanvas { display: block; }

/* The pulled sheet */
.sheet {
  position: absolute; z-index: 5; left: 68%; top: 50%; width: min(46vh, 40vw, 380px); aspect-ratio: 3 / 4;
  translate: -50% -50%; display: none; pointer-events: none;
}
.sheet.on { display: block; }
.sheet-face { position: absolute; inset: 0; background: var(--paper) center / cover no-repeat; box-shadow: var(--shadow-sheet); }
.sheet-face::after { content: "";  position: absolute; inset: 0; background: var(--paper); }

/* ---------- 6. Drying rack ---------- */
.shelf {
  padding: var(--s7) var(--gutter) var(--s6);
  background: var(--size);
  display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: var(--s6); align-items: start;
  border-top: 1px solid var(--rule);
}
.shelf-head h2 { font-size: var(--fs-h3); margin-bottom: var(--s3); }
.shelf-head p { font-size: var(--fs-s); color: var(--ink-soft); }
.rack {
  list-style: none; margin: 0; padding: var(--s5) 0 0; position: relative;
  display: flex; align-items: flex-start; gap: var(--s5); overflow-x: auto; overscroll-behavior-x: contain; min-height: 230px;
  scrollbar-width: thin;
}
/* The line the sheets hang from */
.rack::before { content: ''; position: absolute; left: 0; right: 0; top: 12px; height: 2px; background: linear-gradient(90deg, #8b7a5f, #6d5f49 50%, #8b7a5f); border-radius: 2px; min-width: 100%; }
.rack-empty { align-self: center; color: var(--ink-soft); font-size: var(--fs-s); padding: var(--s6) var(--s5); border: 1.5px dashed var(--rule); border-radius: var(--r-m); margin-top: var(--s4); max-width: 46ch; }
.peg { flex: none; width: 140px; display: grid; gap: var(--s1); position: relative; padding-top: 8px; }
.peg-clip { position: absolute; left: 50%; top: -4px; width: 12px; height: 26px; margin-left: -6px; background: #b99b6b; border-radius: 3px; box-shadow: inset -3px 0 0 rgba(0, 0, 0, .15), 0 1px 2px rgba(0, 0, 0, .3); z-index: 1; }
.peg-sheet { display: block; aspect-ratio: 3 / 4; background: var(--paper) center / cover; box-shadow: var(--shadow-sheet); transform-origin: 50% 0; rotate: -1deg; }
.peg:nth-child(even) .peg-sheet { rotate: 1.2deg; }
.peg-name { font: 700 var(--fs-s)/1.2 var(--display); margin-top: var(--s2); }
.peg-note { font-size: var(--fs-xs); color: var(--ink-soft); }
.peg-acts { display: flex; align-items: center; justify-content: space-between; }
.peg-next .peg-sheet { rotate: none; box-shadow: none; border: 1.5px dashed var(--rule); background: transparent; display: grid; place-items: center; padding: var(--s3); text-align: center; font-size: var(--fs-xs); color: var(--ink-soft); }

/* ---------- 7. Journal ---------- */
.journal {
  padding: var(--s8) var(--gutter) var(--s9);
  color: var(--on-dark);
  background-color: var(--indigo-deep);
  /* Book cloth: a fine woven grain */
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, .08) 0 1px, transparent 1px 3px);
}
.journal-head { max-width: var(--max); margin: 0 auto var(--s6); display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: var(--s3) var(--s7); align-items: end; }
.journal-head h2 { font-size: var(--fs-h2); grid-column: 1; }
.journal-head p { grid-column: 1; color: var(--on-dark-soft); max-width: 58ch; }
.bind-with { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; align-self: end; }
.bind-chip {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 44px; padding: 4px var(--s3) 4px 4px;
  font: 700 var(--fs-xs)/1.2 var(--text); color: var(--on-dark); background: rgba(255, 255, 255, .06);
  border: 1.5px solid rgba(251, 246, 234, .35); border-radius: var(--r-s); cursor: pointer;
}
.bind-chip i { width: 26px; height: 34px; border-radius: 2px; background: var(--size) center / cover; box-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.bind-chip[aria-checked="true"] { background: var(--paper); color: var(--lamp); border-color: var(--paper); }
.bind-chip:hover { border-color: var(--paper); }

.book {
  max-width: var(--max); margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
  padding: clamp(10px, 1.4vw, 18px);
  border-radius: 6px 12px 12px 6px;
  /* Cover paper (replaced by the chosen sheet) */
  background:
    var(--size) center / cover no-repeat;
  background-image: repeating-linear-gradient(105deg, var(--indigo) 0 14px, var(--ochre) 14px 22px, var(--madder) 22px 38px, var(--size) 38px 44px, var(--verdigris) 44px 58px);
  box-shadow: var(--shadow-book);
}
.page {
  background: var(--paper); color: var(--lamp); min-width: 0;
  padding: clamp(1.1rem, .8rem + 1.4vw, 2.2rem);
}
.page-left { border-radius: 3px 0 0 3px; box-shadow: inset -22px 0 26px -22px rgba(60, 40, 20, .45); display: flex; flex-direction: column; gap: var(--s4); }
.page-right { border-radius: 0 3px 3px 0; box-shadow: inset 22px 0 26px -22px rgba(60, 40, 20, .45); display: flex; flex-direction: column; gap: var(--s4); }

.pastedown { padding-bottom: var(--s3); border-bottom: 3px double var(--rule); }
.pastedown-owner { font: 400 var(--fs-l)/1.3 var(--display); }
.pastedown-owner strong { font-weight: 700; }
.pastedown-meta { font-size: var(--fs-s); color: var(--ink-soft); font-variant-numeric: tabular-nums; }

.j-search { position: relative; }
.j-search .ic { position: absolute; left: 12px; top: 50%; translate: 0 -50%; color: var(--ink-soft); }
.j-search input {
  width: 100%; min-height: 44px; padding: 0 var(--s4) 0 2.4rem; font: 400 var(--fs-m) var(--text); color: var(--lamp);
  background: var(--size); border: 1.5px solid var(--rule); border-radius: 999px;
}
.j-search input:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px color-mix(in srgb, var(--indigo) 22%, transparent); }
.j-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px;
  font: 700 var(--fs-xs)/1 var(--text); color: var(--lamp); background: transparent;
  border: 1.5px solid var(--rule); border-radius: 999px; cursor: pointer;
}
.tag span { color: var(--ink-soft); font-weight: 400; font-variant-numeric: tabular-nums; }
.tag:hover { border-color: var(--lamp); }
.tag[aria-pressed="true"] { background: var(--lamp); color: var(--paper); border-color: var(--lamp); }
.tag[aria-pressed="true"] span { color: var(--on-dark-soft); }

.cal { border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: var(--s3) 0; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s2); }
.cal-head h3 { font-size: var(--fs-m); font-weight: 700; letter-spacing: 0; }
.cal-grid { display: grid; gap: 2px; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.cal-dow span { text-align: center; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-soft); padding: 2px 0; }
.cal-dow abbr { text-decoration: none; }
.cal-row > span { display: grid; }
.cal-day {
  position: relative; min-height: 34px; padding: 0; font: 400 var(--fs-s)/1 var(--text); font-variant-numeric: tabular-nums;
  color: var(--lamp); background: transparent; border: 1.5px solid transparent; border-radius: var(--r-s); cursor: pointer;
}
.cal-day:hover { border-color: var(--rule); }
.cal-day.has { font-weight: 700; }
.cal-day.has::after { content: ''; position: absolute; left: 50%; bottom: 4px; width: 6px; height: 6px; margin-left: -3px; border-radius: 50%; background: var(--dot, var(--indigo)); box-shadow: 0 0 0 1px rgba(34, 31, 38, .3); }
.cal-day.today { border-color: var(--madder-deep); }
.cal-day[aria-pressed="true"] { background: var(--indigo); color: var(--paper); border-color: var(--indigo); }
.cal-day[aria-pressed="true"]::after { box-shadow: 0 0 0 1.5px var(--paper); }

.j-filter { font-size: var(--fs-s); color: var(--ink-soft); }
.j-filter b { color: var(--lamp); }
.j-list { list-style: none; margin: 0; padding: 0; display: grid; max-height: 440px; overflow-y: auto; border-top: 1px solid var(--rule); scrollbar-width: thin; }
.j-list li { border-bottom: 1px solid var(--paper-shade); }
.j-item {
  width: 100%; text-align: left; display: grid; grid-template-columns: 4.6rem minmax(0, 1fr); gap: 2px var(--s3);
  padding: var(--s3) var(--s2); font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; border-radius: var(--r-s);
}
.j-item:hover { background: var(--size); }
.j-item[aria-current="true"] { background: color-mix(in srgb, var(--ochre) 24%, var(--paper)); }
.j-item-date { grid-row: 1 / span 3; font-size: var(--fs-xs); font-weight: 700; color: var(--ink-soft); padding-top: 3px; font-variant-numeric: tabular-nums; }
.j-item-title { font: 700 var(--fs-m)/1.3 var(--display); }
.j-item-snip { font-size: var(--fs-s); color: var(--ink-soft); line-height: 1.45; overflow-wrap: anywhere; }
.j-item-tags { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 2px; }
.j-item-tags i { font-style: normal; font-size: var(--fs-xs); color: var(--ink-soft); display: inline-flex; align-items: center; gap: 5px; }
.j-item-tags i::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--dot); }
.j-static { display: grid; gap: 2px; padding: var(--s3) var(--s2); }
.j-static b { font: 700 var(--fs-m)/1.3 var(--display); }
.j-static span { font-size: var(--fs-s); color: var(--ink-soft); }
.j-nojs { font-size: var(--fs-s); color: var(--ink-soft); }
.js .j-nojs { display: none; }
html:not(.js) .cal, html:not(.js) .j-search, html:not(.js) .j-toolbar, html:not(.js) .j-foot, html:not(.js) .bind-with { display: none; }
.j-empty { padding: var(--s5) var(--s2); font-size: var(--fs-s); color: var(--ink-soft); }
.j-empty b { display: block; color: var(--lamp); font: 700 var(--fs-m)/1.3 var(--display); margin-bottom: var(--s1); }

.j-toolbar { display: flex; justify-content: flex-end; }
.j-editor { display: flex; flex-direction: column; gap: var(--s3); flex: 1; }
.j-date { font-size: var(--fs-s); font-weight: 700; color: var(--madder-deep); letter-spacing: .02em; }
.j-title {
  width: 100%; padding: 0 0 var(--s2); font: 700 var(--fs-h3)/1.2 var(--display); color: var(--lamp);
  background: transparent; border: 0; border-bottom: 1.5px solid var(--rule); border-radius: 0;
}
.j-title:focus, .j-body:focus, .j-tag-field input:focus { outline: none; border-color: var(--indigo); }
.j-body {
  width: 100%; flex: 1; min-height: 330px; resize: vertical; padding: 4px 0 0;
  font: 400 var(--fs-m)/32px var(--text); color: var(--lamp);
  background: transparent repeating-linear-gradient(transparent 0 31px, var(--paper-shade) 31px 32px) local;
  border: 0; border-bottom: 1.5px solid transparent;
}
.j-tag-field { display: grid; gap: 4px; }
.j-tag-field label { font-size: var(--fs-s); font-weight: 700; }
.j-tag-field label span { font-weight: 400; color: var(--ink-soft); }
.j-tag-field input { min-height: 42px; padding: 0 var(--s3); font: 400 var(--fs-m) var(--text); color: var(--lamp); background: var(--size); border: 1.5px solid var(--rule); border-radius: var(--r-s); }
.j-title[aria-invalid="true"], .j-body[aria-invalid="true"] { border-bottom-color: var(--madder-deep); }
.j-tag-field input[aria-invalid="true"] { border-color: var(--madder-deep); }
.j-foot { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; padding-top: var(--s2); }
.j-count { margin-right: auto; font-size: var(--fs-s); color: var(--ink-soft); font-variant-numeric: tabular-nums; }
#j-delete.armed { --bg: var(--madder-deep); --fg: var(--paper); --bd: var(--madder-deep); }
.j-saved { font-size: var(--fs-s); color: var(--ink-soft); display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; min-height: 1.6em; }
.j-saved .ic { color: var(--verdigris-deep); }

/* ---------- 8. Specimen book ---------- */
.specimens { padding: var(--s9) var(--gutter); background: var(--size); }
.spec-head { max-width: var(--max); margin: 0 auto var(--s7); display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s6); align-items: end; }
.spec-head h2 { font-size: var(--fs-h2); }
.spec-head p { color: var(--ink-soft); max-width: 60ch; }
.plates { max-width: var(--max); margin: 0 auto; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s7) clamp(1.2rem, 3vw, 3rem); }
.plate { margin: 0; display: grid; gap: var(--s4); align-content: start; }
.plate:nth-child(3n + 2) { translate: 0 var(--s7); }
/* Tipped-in specimen: the marbled sheet on a paper mount with a printed rule */
.plate-img {
  aspect-ratio: 3 / 4; background-color: var(--paper); background-size: cover; background-position: center;
  border: 10px solid var(--paper); outline: 1px solid var(--rule); box-shadow: var(--shadow-sheet);
}
/* Before the canvas draws them (or without one), each plate shows a printed stand-in */
.plate:not(.drawn) .plate-img { background-image: repeating-linear-gradient(var(--a, 100deg), var(--indigo) 0 10px, var(--ochre) 10px 16px, var(--madder) 16px 28px, var(--size) 28px 32px, var(--verdigris) 32px 42px); }
.plate-b { --a: 80deg; } .plate-c { --a: 0deg; } .plate-d { --a: 45deg; } .plate-e { --a: 135deg; } .plate-f { --a: 170deg; }
.plate figcaption { display: grid; gap: var(--s2); justify-items: start; }
.plate h3 { font-size: var(--fs-h3); }
.plate p { font-size: var(--fs-s); color: var(--ink-soft); max-width: 40ch; }
.no-canvas .plate .link-btn, html:not(.js) .plate .link-btn { display: none; }

/* ---------- 9. Colophon ---------- */
.colophon { padding: var(--s9) var(--gutter); background: var(--madder-deep); }
.colo-sheet {
  max-width: 980px; margin: 0 auto; background: var(--paper); padding: clamp(1.6rem, 1rem + 4vw, 4.5rem);
  box-shadow: var(--shadow-book); position: relative;
}
.colo-sheet::before { content: ''; position: absolute; inset: 12px; border: 1px solid var(--madder-deep); pointer-events: none; }
.colophon h2 { font-size: var(--fs-h2); text-align: center; }
.colo-lede { text-align: center; color: var(--ink-soft); margin: var(--s3) auto var(--s6); }
.colo-list { margin: 0; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s5) var(--s7); }
.colo-list div { display: grid; grid-template-columns: 6.5rem minmax(0, 1fr); gap: var(--s4); padding-top: var(--s4); border-top: 1px solid var(--rule); }
.colo-list dt { font: 700 var(--fs-m)/1.4 var(--display); color: var(--madder-deep); }
.colo-list dd { margin: 0; font-size: var(--fs-s); line-height: 1.6; }

/* ---------- 10. Plans ---------- */
.plans { padding: var(--s9) var(--gutter); background: var(--ochre); }
.plans-head { max-width: 980px; margin: 0 auto var(--s6); display: flex; flex-wrap: wrap; justify-content: space-between; align-items: end; gap: var(--s4); }
.plans-head h2 { font-size: var(--fs-h2); }
.period { display: inline-flex; padding: 4px; background: var(--paper); border: 1.5px solid var(--lamp); border-radius: 999px; }
.period span { display: inline-flex; align-items: center; min-height: 38px; padding: 0 var(--s4); border-radius: 999px; font-size: var(--fs-s); font-weight: 700; cursor: pointer; }
.period input:checked + span { background: var(--lamp); color: var(--paper); }
.period input:focus-visible + span { outline: 3px solid var(--indigo); outline-offset: 2px; }
.plan-pair { max-width: 980px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: var(--s5); align-items: stretch; }
.plan {
  --notch: 16px;
  clip-path: polygon(var(--notch) 0, calc(100% - var(--notch)) 0, 100% var(--notch), 100% calc(100% - var(--notch)), calc(100% - var(--notch)) 100%, var(--notch) 100%, 0 calc(100% - var(--notch)), 0 var(--notch));
  padding: clamp(1.5rem, 1rem + 2vw, 2.6rem); display: flex; flex-direction: column; gap: var(--s4);
  background: var(--paper);
}
.plan-bound { background: var(--indigo-deep); color: var(--on-dark); }
.plan h3 { font-size: var(--fs-h3); }
.price { display: flex; align-items: baseline; gap: var(--s2); flex-wrap: wrap; }
.price strong { font: 700 clamp(2.4rem, 1.6rem + 2.4vw, 3.4rem)/1 var(--display); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.price span { font-size: var(--fs-s); }
.price-note { font-size: var(--fs-s); color: var(--on-dark-soft); margin-top: calc(var(--s3) * -1); }
.plan ul { margin: 0; padding: 0; list-style: none; display: grid; gap: var(--s2); flex: 1; align-content: start; }
.plan li { padding-left: 1.3rem; position: relative; font-size: var(--fs-s); }
.plan li::before { content: ''; position: absolute; left: 0; top: .5em; width: 9px; height: 9px; border-radius: 50%; background: var(--madder); box-shadow: 0 0 0 2px var(--paper), 0 0 0 3px var(--madder); }
.plan-bound li::before { background: var(--ochre); box-shadow: 0 0 0 2px var(--indigo-deep), 0 0 0 3px var(--ochre); }
.plan .btn { align-self: flex-start; }
.plan-bound .btn-ink { --bg: var(--paper); --fg: var(--lamp); --bd: var(--paper); }
.plan-why { font-size: var(--fs-s); color: var(--on-dark-soft); border-top: 1px solid rgba(251, 246, 234, .3); padding-top: var(--s3); }

/* ---------- 11. Sign-up ---------- */
.join { display: grid; grid-template-columns: clamp(48px, 9vw, 150px) minmax(0, 1fr); background: var(--paper); }
.join-edge { background: var(--indigo) center / cover; background-image: repeating-linear-gradient(8deg, var(--indigo) 0 12px, var(--ochre) 12px 18px, var(--madder) 18px 30px, var(--size) 30px 34px); box-shadow: inset -10px 0 14px -10px rgba(0, 0, 0, .5); }
.join-body { padding: var(--s9) var(--gutter); display: grid; grid-template-columns: minmax(0, 0.9fr) minmax(0, 1.1fr); gap: var(--s5) var(--s8); max-width: calc(var(--max) + 120px); }
.join-intro { display: grid; gap: var(--s4); align-content: start; position: sticky; top: calc(var(--header-h) + var(--s6)); align-self: start; }
.join-intro h2 { font-size: var(--fs-h2); }
.join-intro p { color: var(--ink-soft); max-width: 46ch; }
/* A drawn notebook: the chosen sheet as the cover, a leather spine, a pasted label */
.join-cover, .done-book {
  position: relative; width: min(260px, 70%); aspect-ratio: 3 / 4; margin-top: var(--s4);
  background: var(--size) center / cover;
  background-image: repeating-linear-gradient(105deg, var(--indigo) 0 14px, var(--ochre) 14px 22px, var(--madder) 22px 38px, var(--size) 38px 44px);
  border-radius: 3px 8px 8px 3px; box-shadow: var(--shadow-book);
  display: grid; place-items: center;
}
.join-cover::before, .done-book::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 18%;
  background: linear-gradient(90deg, #5a2a1f, #7a3a2a 40%, #5a2a1f); border-radius: 3px 0 0 3px; box-shadow: 2px 0 4px rgba(0, 0, 0, .3);
}
.join-cover span, .done-book span {
  position: relative; margin-left: 18%; max-width: 64%; padding: var(--s2) var(--s3); text-align: center;
  font: 700 var(--fs-s)/1.25 var(--display); background: var(--paper); border: 1px solid var(--lamp); outline: 1px solid var(--paper); outline-offset: 2px;
  overflow-wrap: anywhere;
}
.form { display: grid; gap: var(--s5); align-content: start; max-width: 560px; }
.form.busy .field, .form.busy .check { opacity: .6; pointer-events: none; }
.pass-wrap { position: relative; }
.pass-wrap input { padding-right: 5rem !important; }
.pass-toggle { position: absolute; right: 6px; top: 50%; translate: 0 -50%; min-height: 36px; padding: 0 var(--s3); font: 700 var(--fs-xs) var(--text); color: var(--lamp); background: var(--size); border: 1px solid var(--rule); border-radius: var(--r-s); cursor: pointer; }
.cover-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.cover-opt span { display: grid; gap: 6px; padding: 6px; border: 1.5px solid var(--rule); border-radius: var(--r-s); cursor: pointer; background: var(--paper); height: 100%; }
.cover-opt i { aspect-ratio: 3 / 4; background: var(--size) center / cover; background-image: repeating-linear-gradient(105deg, var(--indigo) 0 8px, var(--ochre) 8px 12px, var(--madder) 12px 20px); border-radius: 2px; }
.cover-opt i[style] { background-repeat: no-repeat; }
.cover-opt b { font-size: var(--fs-xs); line-height: 1.25; }
.cover-opt input:checked + span { border-color: var(--lamp); box-shadow: 0 0 0 1.5px var(--lamp); }
.cover-opt input:focus-visible + span { outline: 3px solid var(--ochre); outline-offset: 2px; }
.plan-pick { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.plan-pick span { display: flex; flex-direction: column; justify-content: center; min-height: 56px; padding: var(--s2) var(--s4); border: 1.5px solid var(--rule); border-radius: var(--r-s); cursor: pointer; font-size: var(--fs-s); }
.plan-pick em { font-style: normal; }
.plan-pick input:checked + span { border-color: var(--indigo); background: color-mix(in srgb, var(--indigo) 8%, var(--paper)); box-shadow: 0 0 0 1.5px var(--indigo); }
.plan-pick input:focus-visible + span { outline: 3px solid var(--ochre); outline-offset: 2px; }
.form-small { font-size: var(--fs-s); color: var(--ink-soft); }
/* Loading: a drop spreading into rings, on the button */
.spin { display: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--paper); box-shadow: inset 0 0 0 3px var(--madder-deep), inset 0 0 0 5px var(--ochre); }
.btn.loading .spin { display: inline-block; }
.done { align-self: start; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s6); align-items: center; align-content: start; padding: var(--s5); border: 3px double var(--lamp); background: var(--size); outline: none; }
.done .done-book { width: 150px; margin: 0; }
.done h3 { font-size: var(--fs-h3); margin-bottom: var(--s2); }
.done p { margin-bottom: var(--s4); }

/* ---------- 12. Questions, footer ---------- */
.faq { padding: var(--s9) var(--gutter); background: var(--verdigris-deep); color: var(--on-dark); display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.4fr); gap: var(--s6); }
.faq h2 { font-size: var(--fs-h2); }
.faq-list { border-top: 1px solid rgba(251, 246, 234, .4); }
.faq details { border-bottom: 1px solid rgba(251, 246, 234, .4); }
.faq summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: var(--s4); padding: var(--s4) 0; min-height: 56px; font: 600 var(--fs-l)/1.3 var(--display); }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: ''; flex: none; width: 14px; height: 14px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; rotate: 45deg; translate: 0 -3px; transition: rotate .3s var(--ease); }
.faq details[open] summary::after { rotate: 225deg; translate: 0 3px; }
.faq details p { padding: 0 0 var(--s5); max-width: 66ch; color: var(--on-dark-soft); }

.foot { background: var(--lamp); color: var(--on-dark); }
.foot-band { height: 84px; background: var(--size) center / cover; background-image: repeating-linear-gradient(90deg, var(--indigo) 0 10px, var(--ochre) 10px 16px, var(--madder) 16px 28px, var(--size) 28px 32px, var(--verdigris) 32px 42px); }
.foot-body { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr); gap: var(--s6); padding: var(--s7) var(--gutter) var(--s5); }
.foot-brand p { margin-top: var(--s3); color: var(--on-dark-soft); font-size: var(--fs-s); max-width: 40ch; }
.foot address { font-style: normal; font-size: var(--fs-s); line-height: 1.8; color: var(--on-dark-soft); }
.foot nav { display: grid; gap: 2px; align-content: start; }
.foot nav a { font-size: var(--fs-s); text-decoration: none; min-height: 28px; display: inline-flex; align-items: center; }
.foot nav a:hover { text-decoration: underline; }
.foot-fine { padding: var(--s4) var(--gutter) var(--s6); font-size: var(--fs-xs); color: var(--on-dark-soft); border-top: 1px solid rgba(251, 246, 234, .2); margin: 0 var(--gutter); padding-left: 0; padding-right: 0; }

/* ---------- 13. Motion (all from a visible default) ---------- */
@media (prefers-reduced-motion: no-preference) {
  .btn.loading .spin { animation: spread 1.1s var(--ease) infinite; }
  @keyframes spread { 0% { transform: scale(.4); opacity: .4; } 70% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.05); opacity: .8; } }
  @supports (animation-timeline: view()) {
    .plate-img { animation: settle linear both; animation-timeline: view(); animation-range: entry 0% entry 60%; }
    @keyframes settle { from { rotate: -1.5deg; scale: .97; } to { rotate: 0deg; scale: 1; } }
  }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ---------- 14. Narrow screens ---------- */
@media (max-width: 1100px) {
  .plates { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plate:nth-child(3n + 2) { translate: none; }
  .plate:nth-child(even) { translate: 0 var(--s7); }
  .colo-list { grid-template-columns: 1fr; }
  .join-body { grid-template-columns: 1fr; }
  .join-intro { position: static; }
  .join-cover { width: 200px; }
}
@media (max-width: 900px) {
  .nav { display: none; }
  .top .btn { margin-left: auto; }
  .hero { height: auto; max-height: none; grid-template-rows: auto auto auto; }
  .label { grid-row: 1; justify-self: stretch; align-self: start; margin: 0; width: auto; filter: none; border-bottom: 3px double var(--lamp); }
  .label-inner { clip-path: none; padding: var(--s6) var(--gutter) var(--s5); }
  .label-inner::before { display: none; }
  .sheet { left: 50%; width: min(42vh, 62vw, 320px); }
  .bath { grid-row: 2; height: min(62svh, 560px); min-height: 340px; }
  .tray { grid-row: 3; }
  .shelf { grid-template-columns: 1fr; gap: var(--s3); }
  .journal-head { grid-template-columns: 1fr; }
  .bind-with { grid-column: 1; grid-row: auto; justify-content: flex-start; }
  .spec-head { grid-template-columns: 1fr; gap: var(--s3); }
  .faq { grid-template-columns: 1fr; }
  .foot-body { grid-template-columns: 1fr 1fr; }
  .foot-brand { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .book { grid-template-columns: 1fr; border-radius: 8px; }
  .page-left { border-radius: 3px 3px 0 0; box-shadow: inset 0 -22px 26px -22px rgba(60, 40, 20, .45); }
  .page-right { border-radius: 0 0 3px 3px; box-shadow: inset 0 22px 26px -22px rgba(60, 40, 20, .45); }
  .j-list { max-height: 420px; }
  .plan-pair { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  :root { --header-h: 58px; }
  .brand { font-size: 1.2rem; }
  .top .btn { padding: 0 var(--s3); }
  .tray { gap: var(--s3) var(--s4); }
  .acts { width: 100%; }
  .acts .btn { flex: 1 1 auto; padding: 0 var(--s3); }
  .tray-status { flex-basis: 100%; padding-bottom: 0; }
  .plates { gap: var(--s6) var(--s3); }
  .plate:nth-child(even) { translate: 0 var(--s6); }
  .plate-img { border-width: 6px; }
  .plate h3 { font-size: var(--fs-l); }
  .plate p { font-size: var(--fs-xs); }
  .label-inner { padding: var(--s5) var(--gutter) var(--s4); gap: var(--s3); }
  .label h1 { font-size: 2rem; }
  .label-foot { display: none; }
  .label-actions .btn { padding: 0 var(--s4); }
  .tool-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; width: 100%; }
  .tools { width: 100%; }
  .tool span { justify-content: center; padding: 0 4px; gap: 4px; }
  .pot-row { gap: 4px; }
  .colo-list div { grid-template-columns: 1fr; gap: var(--s1); }
  .join { grid-template-columns: 1fr; grid-template-rows: 56px auto; }
  .join-edge { box-shadow: inset 0 -10px 14px -10px rgba(0, 0, 0, .5); }
  .plan-pick { grid-template-columns: 1fr; }
  .done { grid-template-columns: 1fr; }
  .foot-body { grid-template-columns: 1fr; }
  .j-item { grid-template-columns: 1fr; }
  .j-item-date { grid-row: auto; padding: 0; }
}
