/*
 * OCN explorer.
 *
 * The design thesis: OCN is a reference work, not a product page. It
 * should read like a well-made encyclopaedia rendered for the screen —
 * hairlines instead of cards, a real type scale, and no decoration that
 * does not carry information.
 *
 * Three type roles, each justified by the data rather than by taste:
 * opening NAMES are set in a serif because they come from books; SLUGS
 * and other identifiers are set in a monospace because they are machine
 * keys; interface furniture uses the system stack because it should not
 * compete with either.
 *
 * The one chromatic system is the five ECO classes. The class letter is
 * the only field present on every row, so colouring by it is functional:
 * you learn to read B as semi-open at a glance. Everything else is ink
 * on paper.
 *
 * The board is always a printed plate — white paper, grey squares, the
 * Cburnett diagram pieces — including in dark mode, where it reads as a
 * printed page lying on a dark desk.
 */

/* ---------------------------------------------------------------- */
/* Faces                                                             */
/* ---------------------------------------------------------------- */

@font-face {
  font-family: "Spectral"; font-style: normal; font-weight: 400;
  font-display: swap; src: url("fonts/spectral-400.woff2") format("woff2");
}
@font-face {
  font-family: "Spectral"; font-style: italic; font-weight: 400;
  font-display: swap; src: url("fonts/spectral-400i.woff2") format("woff2");
}
@font-face {
  font-family: "Spectral"; font-style: normal; font-weight: 600;
  font-display: swap; src: url("fonts/spectral-600.woff2") format("woff2");
}
@font-face {
  font-family: "Plex Mono"; font-style: normal; font-weight: 400;
  font-display: swap; src: url("fonts/plexmono-400.woff2") format("woff2");
}
@font-face {
  font-family: "Plex Mono"; font-style: normal; font-weight: 500;
  font-display: swap; src: url("fonts/plexmono-500.woff2") format("woff2");
}
@font-face {
  font-family: "Plex Mono"; font-style: normal; font-weight: 600;
  font-display: swap; src: url("fonts/plexmono-600.woff2") format("woff2");
}

/* ---------------------------------------------------------------- */
/* Tokens                                                            */
/* ---------------------------------------------------------------- */

:root {
  color-scheme: light dark;

  /* Ink and paper. Every value below 4.5:1 was measured and moved:
     --ink-3 carries labels, counts and captions, all small text, so it
     has to clear AA rather than merely look quiet. --edge is the
     boundary of an interactive control, which WCAG 1.4.11 wants at 3:1;
     --rule stays a hairline, which is decorative and exempt. */
  --paper: #f6f6f3;
  --plate: #ffffff;
  --ink: #15171a;        /* 16.6:1 */
  --ink-2: #4b5157;      /*  7.4:1 */
  --ink-3: #6b7178;      /*  4.6:1 */
  --edge: #8a8d86;       /*  3.1:1, control boundaries */
  --rule: #e3e4e0;       /*  hairline, non-text */
  --rule-2: #cbcdc7;
  --focus: #1d6fb8;

  /* The five volumes. One value family, all at AA on paper. */
  --cls-a: #3c6b8b;      /*  5.3:1 */
  --cls-b: #a13e2d;      /*  6.0:1 */
  --cls-c: #8a6512;      /*  4.9:1 */
  --cls-d: #3b6b4b;      /*  5.7:1 */
  --cls-e: #6a4a7d;      /*  6.7:1 */
  --cls: var(--ink-3);

  /* The plate keeps its own scale: a diagram is printed, never themed. */
  --sq-light: #ffffff;
  --sq-dark: #cdccc5;
  --plate-rule: #15171a;

  --serif: "Spectral", Georgia, "Times New Roman", serif;
  --mono: "Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ui: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;

  /* Type scale, seven steps and no strays. Anything that wanted an
     eighth size wanted a different job. */
  --t-micro: 0.6875rem;  /* 11px, uppercase labels only */
  --t-caption: 0.75rem;  /* 12px */
  --t-small: 0.8125rem;  /* 13px */
  --t-body: 0.9375rem;   /* 15px */
  --t-name: 1.0625rem;   /* 17px, an opening name in a list */
  --t-lead: 1.1875rem;   /* 19px */
  --t-display: clamp(1.85rem, 1.2rem + 2vw, 2.6rem);

  /* Spacing, on a four-pixel grid. */
  --s0: 0.125rem;
  --s1: 0.25rem;
  --s2: 0.5rem;
  --s3: 0.75rem;
  --s4: 1rem;
  --s5: 1.5rem;
  --s6: 2rem;
  --s7: 3rem;
  --s8: 4rem;

  /* Motion. One duration for a control, one for a panel, one curve --
     a decelerating cubic rather than `ease`, which starts too fast to
     read as deliberate. */
  --dur-1: 130ms;
  --dur-2: 220ms;
  /* Gentle in, gentle out. The previous curve spent two thirds of the
     distance in the first quarter of the time, which reads as a jump
     followed by a crawl once the distance is a few hundred pixels. */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --measure: 68ch;
  --shell: 1120px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #131416;
    --ink: #e7e8e5;
    --ink-2: #a9aeb3;
    --ink-3: #82878c;    /* 5.1:1 */
    --edge: #63676b;     /* 3.2:1 */
    --rule: #282a2d;
    --rule-2: #3b3e42;
    --focus: #6bb2ee;
    --cls-a: #78a8c8;
    --cls-b: #d9877a;
    --cls-c: #d6ab5c;
    --cls-d: #7aab8a;
    --cls-e: #a98cbb;
  }
}

/* ---------------------------------------------------------------- */
/* Base                                                              */
/* ---------------------------------------------------------------- */

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 0.9375rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 0.18em; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 1px; }

button {
  font: inherit; color: inherit; background: none;
  border: 1px solid var(--edge); border-radius: 2px; cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--ink-2); }
button:disabled { opacity: 0.35; cursor: default; }

input {
  font: inherit; color: inherit;
  background: var(--plate); border: 1px solid var(--edge); border-radius: 2px;
}
@media (prefers-color-scheme: dark) { input { background: #1b1d20; } }

.skip { position: absolute; left: -9999px; background: var(--ink); color: var(--paper); padding: 0.6rem 1rem; }
.skip:focus { left: 1rem; top: 1rem; z-index: 10; }

/* ---------------------------------------------------------------- */
/* Shell                                                             */
/* ---------------------------------------------------------------- */

.site-head {
  display: flex; align-items: center; gap: var(--s4);
  padding: var(--s4) var(--s5);
  border-bottom: 1px solid var(--rule);
}
.wordmark { display: flex; align-items: center; gap: var(--s2); }
.wordmark:hover { text-decoration: none; }
.wordmark-mark { width: 0.95rem; height: 0.95rem; flex: 0 0 auto; display: block; }
.wordmark-mark rect { fill: var(--ink); }
.wordmark-mark .frame { fill: none; stroke: var(--ink); stroke-width: 3.5; }
.wordmark-text { font-family: var(--mono); font-weight: 600; font-size: 0.9375rem; letter-spacing: 0.11em; }
.wordmark-sub { font-size: var(--t-small); color: var(--ink-3); }
@media (max-width: 560px) { .wordmark-sub { display: none; } }
.head-meta { margin-left: auto; }
.tag { font-family: var(--mono); font-size: var(--t-caption); color: var(--ink-3); }

.shell { max-width: var(--shell); margin: 0 auto; padding: 2.25rem 1.5rem 5rem; }

.site-foot {
  border-top: 1px solid var(--rule);
  padding: 1.75rem var(--s5) var(--s7);
  color: var(--ink-3); font-size: var(--t-small);
}
.site-foot p { margin: 0 auto 0.4rem; max-width: var(--shell); }
.site-foot strong { color: var(--ink-2); font-weight: 600; }
.site-foot a { color: var(--ink-2); text-decoration: underline; text-underline-offset: 0.15em; }

/* ---------------------------------------------------------------- */
/* Type primitives                                                   */
/* ---------------------------------------------------------------- */

.label { font-size: var(--t-micro); font-weight: 600; letter-spacing: 0.11em; text-transform: uppercase; color: var(--ink-3); }
.name { font-family: var(--serif); }
.ident { font-family: var(--mono); font-variant-ligatures: none; }

.display {
  font-family: var(--serif); font-weight: 600;
  font-size: var(--t-display);
  line-height: 1.08; letter-spacing: -0.015em;
  margin: var(--s2) 0 0; text-wrap: balance;
}

.section-head {
  display: flex; align-items: baseline; gap: var(--s2);
  margin: 2.75rem 0 var(--s3);
  padding-bottom: var(--s2); border-bottom: 1px solid var(--rule);
}
.section-head .count { font-family: var(--mono); font-size: var(--t-caption); color: var(--ink-3); }

/* ---------------------------------------------------------------- */
/* Class colours                                                     */
/* ---------------------------------------------------------------- */

.cls-A { --cls: var(--cls-a); }
.cls-B { --cls: var(--cls-b); }
.cls-C { --cls: var(--cls-c); }
.cls-D { --cls: var(--cls-d); }
.cls-E { --cls: var(--cls-e); }

/* ---------------------------------------------------------------- */
/* The slug path — the signature element                             */
/*                                                                   */
/* The breadcrumb IS the identifier: every segment is a link, the     */
/* literal dots of the slug are the separators, and the class letter  */
/* carries its volume colour. One line, nothing to misalign. The name */
/* of whichever segment you point at appears in a fixed slot below,   */
/* so the hierarchy teaches itself without shifting the layout.       */
/* ---------------------------------------------------------------- */

.path { display: flex; flex-direction: column; gap: var(--s0); }
.path-line {
  font-family: var(--mono);
  font-size: clamp(0.95rem, 0.8rem + 0.55vw, 1.2rem);
  font-weight: 500;
  display: flex; flex-wrap: wrap; align-items: baseline;
}
.path-seg { color: var(--ink-2); }
.path-seg:hover { color: var(--ink); text-decoration: none; }
.path-seg.here { color: var(--ink); font-weight: 600; }
.path-seg.root { color: var(--cls); font-weight: 600; }
.path-dot { color: var(--rule-2); }
.path-name {
  font-family: var(--serif); font-style: italic; font-size: 0.9375rem;
  color: var(--ink-3); min-height: 1.5em;
}

/* ---------------------------------------------------------------- */
/* Entry (row page)                                                  */
/* ---------------------------------------------------------------- */

/* The one structural line on an entry takes its volume's colour, so a
   page says which of the five it belongs to before you read a word. */
.entry-head { padding-bottom: var(--s5); border-bottom: 2px solid var(--cls); }
.entry-head .display { max-width: 26ch; }
.entry-ident { display: flex; align-items: baseline; gap: 0.75rem; flex-wrap: wrap; margin-top: 0.75rem; }

.entry-body {
  display: grid; grid-template-columns: minmax(290px, 370px) minmax(0, 1fr);
  gap: 2.75rem; align-items: start; margin-top: 2rem;
}
@media (max-width: 820px) { .entry-body { grid-template-columns: 1fr; gap: 2rem; } }

/* ---------------------------------------------------------------- */
/* Board plate                                                       */
/* ---------------------------------------------------------------- */

.plate-col { position: sticky; top: 1.5rem; }
@media (max-width: 820px) { .plate-col { position: static; } }

.board { display: block; width: 100%; height: auto; background: var(--plate); }
.board-frame { fill: none; stroke: var(--plate-rule); stroke-width: 1.25; }
.sq.light { fill: var(--sq-light); }
.sq.dark { fill: var(--sq-dark); }
.coord { font-family: var(--mono); font-size: 9px; font-weight: 500; fill: #9a9e98; }
.board-piece { transition: opacity 90ms linear; }
@media (prefers-reduced-motion: reduce) { .board-piece { transition: none; } }

.plate-caption {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: var(--s4); margin-top: var(--s2); font-size: var(--t-small); color: var(--ink-3);
}

.stepper { display: flex; align-items: center; gap: 0.3rem; margin-top: 0.85rem; }
.stepper button { width: 2.1rem; height: 1.9rem; display: grid; place-items: center; font-family: var(--mono); font-size: 0.8rem; line-height: 1; }
.stepper .ply { font-family: var(--mono); font-size: var(--t-caption); color: var(--ink-3); margin-left: 0.5rem; }

.fen {
  display: flex; align-items: flex-start; gap: var(--s2); margin-top: var(--s3);
}
.fen code {
  font-family: var(--mono); font-size: var(--t-caption); line-height: 1.55;
  color: var(--ink-3); word-break: break-all; user-select: all; flex: 1;
}
.copy {
  flex: 0 0 auto; width: 1.75rem; height: 1.75rem; display: grid; place-items: center;
  color: var(--ink-3); border-color: transparent;
}
.copy:hover:not(:disabled) { color: var(--ink); border-color: var(--edge); }
.copy svg { width: 0.9rem; height: 0.9rem; display: block; }
.copy svg path {
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
.copy.is-done { color: var(--cls-d); border-color: transparent; }
.sr {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

/* ---------------------------------------------------------------- */
/* Move list                                                         */
/* ---------------------------------------------------------------- */

.moves {
  font-family: var(--mono); font-size: var(--t-body); line-height: 1.9;
  padding-bottom: 1.25rem; border-bottom: 1px solid var(--rule);
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 var(--s0);
  margin: 0 0 var(--s6);
}
.move-no { color: var(--ink-3); margin-left: 0.45rem; }
.move-no:first-child { margin-left: 0; }
.move { padding: var(--s0) var(--s1); border-radius: 2px; color: var(--ink); cursor: pointer; }
.move:hover { background: var(--rule); text-decoration: none; }
.move.current { background: var(--ink); color: var(--paper); }
.move.current:hover { background: var(--ink); text-decoration: none; }

/* ---------------------------------------------------------------- */
/* Definition rows                                                   */
/* ---------------------------------------------------------------- */

.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); margin: 0; }
.facts > dt {
  grid-column: 1; padding: 0.75rem 1.5rem 0.75rem 0; border-top: 1px solid var(--rule);
  font-size: var(--t-micro); font-weight: 600; letter-spacing: 0.11em; text-transform: uppercase;
  color: var(--ink-3); white-space: nowrap; line-height: 1.9;
}
.facts > dd { grid-column: 2; margin: 0; padding: 0.75rem 0; border-top: 1px solid var(--rule); min-width: 0; }
.facts > dt:first-of-type, .facts > dd:first-of-type { border-top: none; padding-top: 0; }
.facts .name { font-size: var(--t-name); line-height: 1.45; }
.facts .sub { display: block; color: var(--ink-3); font-size: var(--t-small); margin-top: 0.2rem; }
.facts p { margin: 0 0 var(--s2); }
.facts p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- */
/* Chips                                                             */
/* ---------------------------------------------------------------- */

.chip {
  display: inline-block; font-family: var(--mono); font-size: var(--t-small);
  padding: var(--s0) var(--s1); border: 1px solid var(--edge); border-radius: 2px; color: var(--ink-2);
}
a.chip:hover { border-color: var(--ink-2); color: var(--ink); text-decoration: none; }
.chip.eco { letter-spacing: 0.03em; color: var(--cls); border-color: color-mix(in srgb, var(--cls) 45%, var(--edge)); }
a.chip.eco:hover { color: var(--cls); border-color: var(--cls); }
.chip.flag { color: var(--ink-3); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s1); }

/* ---------------------------------------------------------------- */
/* Lists of rows                                                     */
/* ---------------------------------------------------------------- */

.rows { list-style: none; margin: 0; padding: 0; }
.rows > li { border-top: 1px solid var(--rule); }
.rows > li:first-child { border-top: none; }

.row-link {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--s1) 1.25rem; align-items: baseline;
  padding: 0.7rem 0.5rem 0.7rem 0.7rem; border-left: 2px solid transparent;
}
.row-link:hover { background: var(--plate); border-left-color: var(--cls); text-decoration: none; }
@media (prefers-color-scheme: dark) { .row-link:hover { background: #1b1d20; } }
.row-name { font-family: var(--serif); font-size: var(--t-name); line-height: 1.35; }
.row-meta { display: flex; gap: var(--s2); align-items: baseline; flex-wrap: wrap; justify-content: flex-end; }
.row-slug { font-family: var(--mono); font-size: var(--t-small); color: var(--ink-3); }
.row-eco { font-family: var(--mono); font-size: var(--t-caption); color: var(--cls); letter-spacing: 0.03em; }

/* ---------------------------------------------------------------- */
/* Tree                                                              */
/* ---------------------------------------------------------------- */

/* An index of short labels does not want the full page width, and a
   count belongs next to the thing it counts rather than at the far
   edge of the screen. */
.tree { list-style: none; margin: 0; padding: 0; max-width: 40rem; }
.tree li { margin: 0; }
/* The spine of a subtree carries its class colour, so an expanded branch
   stays visibly attached to the volume it belongs to. */
.tree ul {
  list-style: none; margin: 0; padding: 0 0 0 var(--s4);
  border-left: 1px solid color-mix(in srgb, var(--cls) 30%, transparent);
}

/* Baseline, not centre: the mono class letter and the serif name have
   different cap heights, so centring their boxes leaves the letter
   floating. The toggle is a glyph in a box and stays optically centred. */
.node {
  display: flex; align-items: baseline; gap: var(--s2);
  padding: var(--s1) var(--s2) var(--s1) 0; border-radius: 2px;
}
.node:hover { background: var(--plate); }
@media (prefers-color-scheme: dark) { .node:hover { background: #1b1d20; } }
/* The one control in the tree, so it has to look like one: a real hit
   area and geometry rather than a glyph, because a character triangle
   carries font metrics that never line up with the text beside it.
   Quiet by default -- it should not compete with the name it labels --
   and it takes the class colour when hovered or open. */
.node-toggle {
  width: 1.5rem; height: 1.5rem; flex: 0 0 auto;
  align-self: baseline; position: relative; top: 2px;
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 2px; color: var(--ink-3);
}
.node-toggle svg { width: 0.8rem; height: 0.8rem; display: block; }
.node-toggle svg path {
  fill: currentColor;
  transition: transform var(--dur-1) var(--ease);
  transform-origin: 6px 6px;
}
.node-toggle[aria-expanded="true"] { color: var(--cls); }
.node-toggle[aria-expanded="true"] svg path { transform: rotate(90deg); }
.node-toggle:hover:not(:disabled) { color: var(--cls); background: var(--rule); border: none; }
.node-toggle:disabled { opacity: 0.25; }

/* A branch opens in one layout pass; only its rows animate, and only
   through opacity and transform. Height animation was the wrong tool:
   it re-lays-out the whole branch every frame, which measures clean on
   an idle machine and stutters on a real one.

   The stagger is short and capped, so a twenty-row branch reads as one
   movement rather than a queue. */
@keyframes row-in {
  from { opacity: 0; transform: translateY(-3px); }
  to   { opacity: 1; transform: none; }
}
.drawer.is-entering > ul > li {
  animation: row-in var(--dur-1) var(--ease) backwards;
  animation-delay: calc(var(--i, 0) * 16ms);
}
@media (prefers-reduced-motion: reduce) {
  .node-toggle svg path { transition: none; }
  .drawer.is-entering > ul > li { animation: none; }
}

.node-slug { font-family: var(--mono); font-size: var(--t-small); font-weight: 500; color: var(--ink-2); }
.node-slug.is-root { color: var(--cls); font-weight: 600; font-size: 1rem; }
.node-name { font-family: var(--serif); font-size: var(--t-body); color: var(--ink); min-width: 0; }
.node-count {
  font-family: var(--mono); font-size: var(--t-small); color: var(--ink-3);
  margin-left: var(--s2); flex: 0 0 auto; font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- */
/* Search, converter, home                                           */
/* ---------------------------------------------------------------- */

.seek { display: flex; gap: var(--s2); align-items: stretch; }
.seek input { flex: 1; padding: 0.6rem 0.75rem; font-size: 1rem; }

.hint { color: var(--ink-3); font-size: var(--t-small); margin: 0.55rem 0 0; }
.empty { color: var(--ink-3); font-style: italic; font-family: var(--serif); padding: var(--s4) 0; }

.home-lead {
  font-family: var(--serif); font-size: var(--t-lead); line-height: 1.6;
  color: var(--ink-2); max-width: 58ch; margin: 0 0 2rem;
}
.home-lead strong { color: var(--ink); font-weight: 600; }
.home-lead .ident { font-size: var(--t-name); color: var(--ink); }

.panels { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: var(--s7); }
@media (max-width: 900px) { .panels { grid-template-columns: 1fr; gap: 2.25rem; } }

.notice { padding: var(--s6) 0; }
.notice p { color: var(--ink-2); max-width: var(--measure); }
