/* styles.css — Topomol showcase on the Academic register's dotted page (canon in BRAND.md).
   The grid is the coordinate system, not a texture (Bradley, 2026-11-17: "all components
   should snap directly to the grid"). Rules this file keeps:
   - a dot every 40 px, at the cell corners; every box's corners sit on dots;
   - widths are whole cells (CSS round()), heights are whole cells (snap.js rounds `.snap` and
     `.snap-x` blocks up), gaps are whole cells;
   - text runs on a 20 px line, half a cell, inside 20 px of padding, so lines sit in the grid;
   - text sits on a white backing that blanks the dots; the render box carries the same dots
     (backdrop.js), so the grid runs through the figure unbroken.
   Colour values mirror the register's spec; they are not canon here. */

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

:root {
  --ground: #FFFFFF;
  --hairline: #E6E6E6;
  --ink: #111111;
  --grey: #5A5A5A;
  --dot: #B8B8B8;
  --purple: #875CA5; --purple-deep: #513465; --purple-light: #E0D0ED;
  --green: #008767;  --green-deep: #00513B;  --green-light: #BEE1D3;
  --rose: #AB5061;   --rose-deep: #682C38;   --rose-light: #F1CDD1;
  --sky: #007DAA;    --sky-deep: #004A68;    --sky-light: #BDDDEE;
  --error: var(--rose-deep);
  --font-text: 'Newsreader', Georgia, serif;
  --font-ui: 'Schibsted Grotesk', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: ui-monospace, 'Cascadia Mono', Consolas, Menlo, monospace;
  --cell: 40px;
  --half: 20px;
  --pad-x: 40px;  /* page margin: one cell, so the first box starts on a dot column */
  --text-w: 720px;
}

html { background: var(--ground); }
body {
  background-color: var(--ground);
  background-image: radial-gradient(circle at 0 0, var(--dot) 2px, transparent 2.6px);
  background-size: var(--cell) var(--cell);
  background-position: 0 0;
  color: var(--ink); font-family: var(--font-text); font-size: 16px; line-height: var(--half);
  font-optical-sizing: auto;
}
h1, h2, h3, h4 { font-family: var(--font-ui); color: var(--ink); font-size: 14px; line-height: var(--half); }
ul, ol { list-style: none; }
a { color: var(--ink); text-underline-offset: 3px; }
button, input { font-family: var(--font-ui); color: var(--ink); line-height: var(--half); }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }
input[type="checkbox"], input[type="range"] { accent-color: var(--purple-deep); }
[id$="-readout"]:empty, #legend:empty { display: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* A block: white backing, text inset half a cell, corners on dots. */
.block, .gloss, #caption, #layers-section, #readouts-section, .family, #gallery-section > h2,
.sourced li, #motion-list figure { background: var(--ground); padding: var(--half); }

/* ---- Header: one cell tall, on the second dot row; mark and name left, the way home right ---- */
.site-header {
  display: flex; align-items: center; flex-wrap: wrap; column-gap: var(--cell); row-gap: 0;
  width: round(down, calc(100% - 2 * var(--pad-x)), var(--cell));
  margin: var(--cell) var(--pad-x);
}
.site-header .home-link { margin-left: auto; }
.brand-line { display: flex; align-items: center; height: var(--cell); background: var(--ground); }
.mark { display: block; height: var(--cell); width: auto; }
#wordmark { font-size: 33px; line-height: var(--cell); font-weight: 700; padding: 0 var(--half) 0 0; }
.version { font-family: var(--font-ui); font-size: 14px; color: var(--grey); padding-right: var(--half); }
.home-link {
  display: flex; align-items: center; justify-content: center; height: var(--cell); padding: 0 var(--half);
  background: var(--ground); font-family: var(--font-ui); font-size: 14px; font-weight: 500;
  text-decoration: underline; text-decoration-color: var(--purple); text-underline-offset: 5px; white-space: nowrap;
}
.home-link:hover { text-decoration-thickness: 2px; }

/* ---- Tabs: in line with the name, one cell tall; the open tab's rule takes the main colour ---- */
.tabs { display: flex; flex-wrap: wrap; column-gap: var(--cell); padding: 0 var(--half); background: var(--ground); }
.tab { font-size: 16px; font-weight: 500; color: var(--grey); background: none; border: none; border-bottom: 2px solid transparent; height: var(--cell); padding: 0; cursor: pointer; white-space: nowrap; }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--purple); }

.panel { padding: 0 var(--pad-x) var(--cell); }
.panel-text { display: flex; flex-direction: column; gap: var(--cell); }
.panel-text .sourced, #motion-list { display: flex; flex-direction: column; gap: var(--cell); }
.sourced li, #motion-list figure { width: round(down, min(var(--text-w), 100%), var(--cell)); }

/* ---- Explore: the render box and what reads it on the left, the inspector beside it ---- */
.explore {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  grid-template-columns: round(down, calc(100% - 360px), var(--cell)) 320px;
  grid-template-areas: "strip strip" "stage inspector" "form inspector" "caption inspector" "gallery gallery";
  column-gap: var(--cell); row-gap: var(--cell); align-items: start;
}
#stage {
  grid-area: stage; position: relative; overflow: hidden; background: var(--ground);
  height: max(360px, round(nearest, min(66vh, 720px), var(--cell)));
  outline: 1px solid var(--hairline); outline-offset: -1px;  /* a frame that takes no space: the canvas fills the cells */
}
#stage.is-loading .viewer { opacity: 0.6; }
#smiles-form { grid-area: form; }
#caption { grid-area: caption; width: round(down, min(var(--text-w), 100%), var(--cell)); }
#inspector { grid-area: inspector; display: flex; flex-direction: column; gap: var(--cell); }
#gallery-section { grid-area: gallery; display: flex; flex-direction: column; gap: var(--cell); }
#strip-section { grid-area: strip; background: var(--ground); padding: var(--half); }
.strip-list { row-gap: var(--half); }

#inspector h2 { font-weight: 700; box-shadow: inset 0 -1px 0 var(--purple); margin-bottom: var(--half); }

/* ---- Why these molecules: below the render box, full width, families two to a row ---- */
.explain-head { background: var(--ground); padding: var(--half); width: round(down, min(var(--text-w), 100%), var(--cell)); }
.explain-head h2 { font-size: 16px; font-weight: 700; box-shadow: inset 0 -1px 0 var(--purple); margin-bottom: var(--half); }
#gallery { display: grid; grid-template-columns: repeat(2, round(down, calc((100% - var(--cell)) / 2), var(--cell))); gap: var(--cell); align-items: start; }
.why { margin-bottom: var(--half); }
.explained-list { display: flex; flex-direction: column; gap: var(--half); }
.explained .mol { margin-bottom: 0; }
.explained .shows { margin-top: 0; }
.explained .fails { font-style: italic; }

/* ---- Stage internals: overlays sit half a cell in, one line tall ---- */
.viewer { position: absolute; inset: 0; }
#viewer-v1 { display: none; }
body.is-comparing #viewer-v1 { display: block; }
body.is-comparing #viewer-main, body.is-comparing #viewer-v1 { width: 50%; }
body.is-comparing #viewer-v1 { left: 0; right: auto; }
body.is-comparing #viewer-main { left: auto; right: 0; }
#stage-labels { position: absolute; inset: 0; display: none; pointer-events: none; }
body.is-comparing #stage-labels { display: block; }
#stage-labels span { position: absolute; top: var(--half); font-family: var(--font-ui); font-size: 14px; background: var(--ground); padding: 0 8px; }
#label-v1 { left: var(--half); }
#label-v11 { right: var(--half); }
#stage-status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-family: var(--font-ui); font-size: 14px; text-align: center; pointer-events: none; }
#stage-status.is-error { color: var(--error); }
#legend { position: absolute; left: var(--half); bottom: var(--half); font-family: var(--font-ui); font-size: 12px; background: var(--ground); padding: 0 8px; }
#stage-hint { position: absolute; left: var(--half); top: var(--half); font-family: var(--font-ui); font-size: 12px; color: var(--grey); background: var(--ground); padding: 0 8px; pointer-events: none; }
body.is-comparing #stage-hint { display: none; }
.swatch { display: inline-block; width: 10px; height: 10px; border: 1px solid var(--ink); vertical-align: middle; margin-right: 5px; }
#hover-readout { position: absolute; right: var(--half); bottom: var(--half); font-family: var(--font-ui); font-size: 12px; background: var(--ground); padding: 0 8px; text-align: right; }

/* ---- SMILES form, directly under the render box: one cell tall ---- */
#smiles-form { display: flex; align-items: stretch; height: var(--cell); background: var(--ground); }
#smiles-form label { display: flex; align-items: center; padding: 0 var(--half); font-family: var(--font-ui); font-size: 14px; font-weight: 500; }
#smiles-input { font-family: var(--font-mono); font-size: 14px; flex: 1; min-width: 0; padding: 0 var(--half); border: 1px solid var(--hairline); border-bottom-color: var(--ink); background: var(--ground); color: var(--ink); }
#render-btn { width: 120px; font-size: 14px; font-weight: 500; background: var(--purple-deep); color: var(--ground); border: none; cursor: pointer; }
#render-btn:hover { background: var(--ink); }

/* ---- Caption: reads as the figure's caption, one 20 px line at a time ---- */
#caption-name { font-size: 18px; font-weight: 700; }
#caption-smiles { font-family: var(--font-mono); font-size: 13px; color: var(--grey); margin-bottom: var(--half); }
#caption-text { margin-bottom: var(--half); }
#caption-notshown { font-style: italic; margin-bottom: var(--half); }
#caption-notshown:empty { display: none; }
#caption-source { font-family: var(--font-ui); font-size: 12px; color: var(--grey); }

/* ---- Molecule families: colour follows subject, in order of appearance ---- */
.family { --fam: var(--purple); --fam-light: var(--purple-light); }
.family[data-colour="green"] { --fam: var(--green); --fam-light: var(--green-light); }
.family[data-colour="rose"] { --fam: var(--rose); --fam-light: var(--rose-light); }
.family[data-colour="sky"] { --fam: var(--sky); --fam-light: var(--sky-light); }
.family-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; margin-bottom: var(--half); }
.family-title .ring { width: 12px; height: 12px; border: 2px solid var(--fam); border-radius: 50%; flex: none; }
.family-title .count { font-size: 14px; font-weight: 400; color: var(--grey); }
.subgroup + .subgroup { margin-top: var(--half); }
.subgroup h4 { font-weight: 500; color: var(--grey); }
.mol-list { display: flex; flex-wrap: wrap; column-gap: 4px; row-gap: 0; }
.mol { font-size: 13px; line-height: 18px; color: var(--ink); background: var(--ground); border: 1px solid var(--hairline); padding: 0 8px; cursor: pointer; }
.mol:hover { background: var(--fam-light); border-color: var(--fam); }
.mol.is-active { background: var(--fam-light); border-color: var(--fam); box-shadow: inset 0 0 0 1px var(--fam); }
/* In the flat strip each chip carries its family's colour on its left edge. */
.mol { --fam: var(--purple); --fam-light: var(--purple-light); }
.mol[data-colour="green"] { --fam: var(--green); --fam-light: var(--green-light); }
.mol[data-colour="rose"] { --fam: var(--rose); --fam-light: var(--rose-light); }
.mol[data-colour="sky"] { --fam: var(--sky); --fam-light: var(--sky-light); }
.strip-list .mol { box-shadow: inset 3px 0 0 var(--fam); padding-left: 10px; }
.strip-list .mol.is-active { box-shadow: inset 3px 0 0 var(--fam), inset 0 0 0 1px var(--fam); }

/* ---- Layers and readouts: one 20 px line per row ---- */
.layer, .control { display: flex; align-items: center; gap: 8px; font-family: var(--font-ui); font-size: 14px; flex-wrap: wrap; }
.layer-note { display: block; flex-basis: 100%; padding-left: 21px; font-size: 12px; color: var(--grey); }
.layer-note:empty { display: none; }
.control { margin: var(--half) 0 0; }
#readouts, #atom-readout dl { display: grid; grid-template-columns: auto 1fr; column-gap: var(--half); }
#readouts dt, #atom-readout dt { font-family: var(--font-ui); font-size: 14px; }
#readouts dd, #atom-readout dd { font-family: var(--font-mono); font-size: 13px; text-align: right; }
#atom-readout { margin-top: var(--half); box-shadow: inset 0 1px 0 var(--hairline); padding-top: var(--half); }

/* ---- Text tabs: each claim with its source ---- */
small.source { display: block; font-family: var(--font-ui); font-size: 12px; color: var(--grey); }
#motion-list img { max-width: 100%; height: auto; display: block; margin-top: var(--half); }
details > summary { font-family: var(--font-ui); font-size: 14px; font-weight: 500; cursor: pointer; }

footer { padding: 0 var(--pad-x) var(--cell); font-family: var(--font-ui); font-size: 14px; color: var(--grey); }
footer p { display: inline-block; max-width: 100%; padding: 10px var(--half); background: var(--ground); }

/* ---- Narrow screens: one column; the grid shifts half a cell so a 20 px margin is on a dot ---- */
@media (max-width: 899px) {
  :root { --pad-x: 20px; }
  body { background-position: 20px 0; }
  .explore { grid-template-columns: round(down, 100%, var(--cell)); grid-template-areas: "strip" "stage" "form" "inspector" "caption" "gallery"; }
  #gallery { grid-template-columns: round(down, 100%, var(--cell)); }
  #stage { height: max(320px, round(nearest, 60vh, var(--cell))); }
  .site-header { column-gap: 0; }
  .site-header .version { display: none; }
  #wordmark { font-size: 27px; }
  .tabs { order: 3; column-gap: var(--half); }
  .tab { font-size: 15px; }
  #render-btn { width: 80px; }
  body.is-comparing #viewer-main, body.is-comparing #viewer-v1 { width: 100%; height: 50%; top: auto; bottom: auto; }
  body.is-comparing #viewer-v1 { top: 0; }
  body.is-comparing #viewer-main { bottom: 0; }
  /* Scoped via the parent id: plain #label-v11 loses on specificity to #stage-labels span. */
  #stage-labels #label-v11 { top: calc(50% + var(--half)); right: var(--half); }
  #stage-hint .hint-desktop { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  html { scroll-behavior: auto; }
}
