/*
BENRAN 本然 - tokens, primitives, components. See ../DESIGN.md.
Paper emptiness, small ink objects resting on one hairline horizon, upright
vertical type, and colour spent one seal at a time. Light is paper by day;
dark is the same sheet at night - the ground goes to inkstone and the
silhouettes turn to paper cutouts. Both are hand-authored.
*/

:root {
  /* ---- colour: paper by day ---- */
  --paper: #fcfcfa;
  --surface: #ffffff;
  --ink: #2a2a28;
  --faint: #8a8880;
  --hairline: #d5d3cd;
  --trace: #9fc4bd;
  --trace-alt: #c9a87c;
  --accent: #c25e4a;
  --on-accent: #fcfcfa;

  /* ---- type ---- */
  --font-serif: "Songti SC", "Palatino Linotype", "Book Antiqua", Palatino, "Noto Serif CJK SC", "SimSun", serif;
  --font-sans: "Avenir Next", "Futura", "Century Gothic", "Helvetica Neue", Arial, sans-serif;
  --fs-caption: 10px;
  --fs-small: 11px;
  --fs-body: 13px;
  --fs-label: 15px;
  --fs-heading: 18px;
  --fs-display: 26px;
  --fs-display-lg: 34px;
  --lh-body: 2;
  --track-caption: 0.35em;
  --track-num: 0.25em;
  --track-vertical: 0.4em;
  --track-wide: 0.5em;

  /* ---- space ---- */
  --page-max: 1060px;
  --page-pad: 40px;
  --space-section: 170px;
  --space-block: 56px;

  /* ---- form ---- */
  --rule: 1px;
  --tick: 9px;
  --tick-angle: 35deg;
  --focus-offset: 3px;

  /* ---- motion ---- */
  --t-fade: 0.3s;
  --t-ink: 0.35s;
  --ease: ease-out;
  --ease-ripple: cubic-bezier(0.16, 0.84, 0.44, 1);
  --d-ripple: 7s;
  --d-steam: 6s;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    /* the same sheet at night: inkstone ground, paper-coloured silhouettes */
    --paper: #161614;
    --surface: #1c1c1a;
    --ink: #e6e3da;
    --faint: #6f6d67;
    --hairline: #393834;
    --trace: #3e5a55;
    --trace-alt: #5f4f37;
    --accent: #c9654f;
    --on-accent: #fcfcfa;
  }
}

/* an explicit choice wins in both directions - the catalog has a toggle */
:root[data-theme="dark"] {
  --paper: #161614;
  --surface: #1c1c1a;
  --ink: #e6e3da;
  --faint: #6f6d67;
  --hairline: #393834;
  --trace: #3e5a55;
  --trace-alt: #5f4f37;
  --accent: #c9654f;
  --on-accent: #fcfcfa;
}

@media (max-width: 760px) {
  :root {
    --page-pad: 22px;
    --space-section: 120px;
  }
}

/* ---------- base ---------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html { background: var(--paper); }

body {
  font: 400 var(--fs-body) / var(--lh-body) var(--font-serif);
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: var(--rule) solid var(--ink); outline-offset: var(--focus-offset); }

::selection { background: color-mix(in srgb, var(--trace) 55%, var(--paper)); color: var(--ink); }

/* ---------- type voices ---------- */

/* vertical display: words stand upright, as on a scroll */
.v-vertical {
  writing-mode: vertical-rl;
  text-orientation: upright;
  text-transform: uppercase;
  font-family: var(--font-serif);
  font-weight: 400;
  color: var(--ink);
  letter-spacing: var(--track-vertical);
  line-height: 1;
}

/* tracked Latin caption: the small voice that names things */
.v-caption {
  font: 300 var(--fs-caption) / 1.8 var(--font-sans);
  letter-spacing: var(--track-caption);
  text-transform: uppercase;
  color: var(--ink);
}

/* decorative echo of an adjacent label; content duplicated, so faint is allowed */
.v-caption.is-echo { color: var(--faint); }

.v-body { font: 400 var(--fs-body) / var(--lh-body) var(--font-serif); color: var(--ink); max-width: 36em; }

.v-num { font: 300 var(--fs-caption) / 1.6 var(--font-sans); letter-spacing: var(--track-num); color: var(--ink); }

/* ---------- motifs ---------- */

/* horizon rule: a shelf edge with short angled end ticks */
.b-horizon { position: relative; height: var(--rule); background: var(--hairline); }
.b-horizon::before,
.b-horizon::after {
  content: "";
  position: absolute;
  top: 0;
  width: var(--rule);
  height: var(--tick);
  background: var(--hairline);
  transform-origin: top center;
}
.b-horizon::before { left: 0; transform: rotate(var(--tick-angle)); }
.b-horizon::after { right: 0; transform: rotate(calc(var(--tick-angle) * -1)); }

.b-obj { display: block; color: var(--ink); }

/* dotted trail: steam, or a path between things; dots shrink upward */
.b-trail { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.b-trail i { display: block; border-radius: 50%; background: var(--ink); }
.b-trail i:nth-child(1) { width: 1px;   height: 1px;   opacity: 0.35; }
.b-trail i:nth-child(2) { width: 1.5px; height: 1.5px; opacity: 0.5; }
.b-trail i:nth-child(3) { width: 2px;   height: 2px;   opacity: 0.65; }
.b-trail i:nth-child(4) { width: 2.5px; height: 2.5px; opacity: 0.8; }
.b-trail i:nth-child(5) { width: 3px;   height: 3px;   opacity: 1; }

@keyframes b-steam-drift {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}
.b-trail.is-live i { animation: b-steam-drift var(--d-steam) ease-in-out infinite; }
.b-trail.is-live i:nth-child(1) { animation-delay: 0s; }
.b-trail.is-live i:nth-child(2) { animation-delay: 0.7s; }
.b-trail.is-live i:nth-child(3) { animation-delay: 1.4s; }
.b-trail.is-live i:nth-child(4) { animation-delay: 2.1s; }
.b-trail.is-live i:nth-child(5) { animation-delay: 2.8s; }

/* ripple: concentric flat ellipses under an object */
.b-ripple { display: block; }
.b-ripple.is-trace { color: var(--trace); }
.b-ripple.is-trace-alt { color: var(--trace-alt); }
.b-ripple ellipse { fill: none; stroke: currentColor; stroke-width: 1; }

@keyframes b-ripple-grow {
  0% { transform: scale(0.2); opacity: 0; }
  12% { opacity: 0.9; }
  100% { transform: scale(1); opacity: 0; }
}
.b-ripple .r-live {
  transform-box: fill-box;
  transform-origin: center;
  animation: b-ripple-grow var(--d-ripple) var(--ease-ripple) infinite;
}

/* roundel: thin circle holding the mark; secondary trace by default */
.b-roundel { display: block; color: var(--trace-alt); }
.b-roundel.is-ink { color: var(--ink); }

/* seal stamp: accent ground, reversed glyph. At most one per surface. */
.b-seal { display: block; color: var(--accent); }
.b-seal-glyph { fill: none; stroke: var(--on-accent); stroke-width: 1.3; stroke-linecap: round; }

/* the x mark: a co-sign divider between two vertical columns */
.b-x { font: 300 var(--fs-small) / 1 var(--font-sans); color: var(--ink); }
.b-lockup { display: flex; align-items: flex-start; justify-content: center; gap: 14px; }
.b-lockup .b-x { padding-top: 4px; }

/* ---------- components ---------- */

/* text link: hover or focus summons a tiny seal dot */
.b-link {
  position: relative;
  display: inline-block;
  font: 400 var(--fs-caption) / 1.8 var(--font-sans);
  letter-spacing: var(--track-caption);
  text-transform: uppercase;
  color: var(--ink);
  text-decoration: none;
  padding-left: 13px;
}
.b-link::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  margin-top: -2.5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  transition: opacity var(--t-fade) var(--ease);
}
.b-link:hover::before,
.b-link:focus-visible::before,
.b-link[aria-current="true"]::before { opacity: 1; }
.b-link.is-disabled { color: var(--hairline); pointer-events: none; }

/* stamp button: upright vertical label; hover inks the whole stamp */
.b-stamp-btn {
  display: inline-block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  text-transform: uppercase;
  font: 400 var(--fs-label) / 1 var(--font-serif);
  letter-spacing: 0.45em;
  color: var(--ink);
  background: transparent;
  border: var(--rule) solid var(--hairline);
  padding: 16px 9px;
  padding-block-end: 6px; /* absorbs the trailing letter-spacing of the last glyph */
  cursor: pointer;
  text-decoration: none;
  transition: background var(--t-ink) var(--ease), color var(--t-ink) var(--ease), border-color var(--t-ink) var(--ease);
}
.b-stamp-btn:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.b-stamp-btn:disabled,
.b-stamp-btn.is-disabled {
  color: var(--hairline);
  border-color: var(--hairline);
  background: transparent;
  cursor: default;
  pointer-events: none;
}

/* chip: a tiny upright label */
.b-chip {
  display: inline-block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  text-transform: uppercase;
  font: 400 var(--fs-small) / 1 var(--font-serif);
  letter-spacing: 0.3em;
  color: var(--ink);
  border: var(--rule) solid var(--hairline);
  padding: 9px 5px;
  padding-block-end: 5px;
  background: transparent;
  cursor: pointer;
  transition: border-color var(--t-fade) var(--ease);
}
.b-chip:hover { border-color: var(--faint); }
.b-chip.is-selected { border-color: var(--ink); }
.b-chip:disabled,
.b-chip.is-disabled { color: var(--hairline); border-color: var(--hairline); cursor: default; }

/* list rows: dotted-trail entries */
.b-list { list-style: none; max-width: 30em; }
.b-list li { position: relative; padding: 6px 0 6px 24px; }
.b-list li::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 50%;
  margin-top: -1.5px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--ink);
}
.b-list li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 2px;
  top: calc(50% + 8px);
  height: calc(100% - 14px);
  width: 1px;
  background-image: radial-gradient(circle at 0.5px 1px, var(--faint) 0.8px, transparent 0.9px);
  background-size: 1px 7px;
  background-repeat: repeat-y;
}
.b-list .li-caption { margin-left: 14px; font: 300 var(--fs-caption) / 1 var(--font-sans); letter-spacing: 0.3em; text-transform: uppercase; color: var(--ink); }
.b-list .li-num { float: right; font: 300 var(--fs-small) / 2.2 var(--font-sans); letter-spacing: 0.2em; color: var(--ink); }
.b-list li.is-disabled, .b-list li.is-disabled .li-caption, .b-list li.is-disabled .li-num { color: var(--hairline); }
.b-list li.is-disabled::before { background: var(--hairline); }

/* input: a bare underline */
.b-field { display: inline-flex; flex-direction: column; gap: 6px; }
.b-field .f-label { font: 400 var(--fs-caption) / 1.8 var(--font-sans); letter-spacing: var(--track-caption); text-transform: uppercase; color: var(--ink); }
.b-input {
  font: 400 var(--fs-body) / 1.8 var(--font-serif);
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: var(--rule) solid var(--hairline);
  border-radius: 0;
  padding: 4px 1px;
  width: 15em;
  caret-color: var(--ink);
  transition: border-color var(--t-fade) var(--ease);
}
.b-input::placeholder {
  font: 300 var(--fs-caption) / 1.8 var(--font-sans);
  letter-spacing: var(--track-caption);
  text-transform: uppercase;
  color: var(--ink);
  opacity: 1;
}
.b-input:focus { border-bottom-color: var(--ink); }
.b-input:disabled { color: var(--hairline); border-bottom-color: var(--hairline); }
.b-input:disabled::placeholder { color: var(--hairline); }

/* pagination: tiny circles */
.b-pgn { display: flex; align-items: center; gap: 14px; }
.b-pgn button {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: var(--rule) solid var(--ink);
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: background var(--t-fade) var(--ease);
}
.b-pgn button:hover { background: var(--hairline); }
.b-pgn button[aria-current="page"] { background: var(--ink); }
.b-pgn button:disabled { border-color: var(--hairline); background: transparent; cursor: default; }

/* ---------- sheets ---------- */

/* poster (3:4) and bookmark (1:2.6): the two printed formats */
.b-poster,
.b-bookmark {
  position: relative;
  background: var(--surface);
  border: var(--rule) solid var(--hairline);
  overflow: hidden;
}
.b-poster { aspect-ratio: 3 / 4; }
.b-bookmark { aspect-ratio: 1 / 2.6; }

/* free placement inside a sheet */
.b-pin { position: absolute; }

/* bookmark inner flow: title, trail, object on a shelf, caption */
.b-bm-flow {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 22px 6px 14px;
  gap: 16px;
}
.b-bm-flow .bm-title { font-size: var(--fs-heading); letter-spacing: var(--track-wide); }
.b-bm-flow .bm-shelf { margin-top: auto; display: flex; flex-direction: column; align-items: center; width: 100%; }
.b-bm-flow .bm-shelf .b-horizon { width: 76%; }
.b-bm-flow .bm-caption {
  font: 300 9.5px/1.7 var(--font-sans);
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink);
  text-align: center;
  padding-top: 2px;
}

/* ---------- reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .b-ripple .r-live { animation: none; opacity: 0.6; transform: scale(0.75); }
  .b-trail.is-live i { animation: none; }
  .b-link::before, .b-stamp-btn, .b-chip, .b-input, .b-pgn button { transition: none; }
}
