/* The register: one grammar for everything you can press (design/05-interaction-system.md).
   Loaded after every other stylesheet, so it wins.

   Four signals, each with one job, each mapped to real HTML:
   1. GO     <a>       a destination. Text carries an underline (edge tone at rest, paper tone and 2px on hover).
   2. OPEN   <a>       a box that opens a whole record (a paper, an ink, a work, a guide). Its top-right corner is
                       trimmed like mount board, visible at rest. A box without the cut is never a link.
   3. ACT    <button>  an operation on this page (zoom, change view, go deeper, submit). A square closed box.
   4. HERE   state     where you are or what you chose, and only that: a small chamber inverted to paper. Hover never
                       uses it, so a pointer passing over something never looks like a choice.

   Precedence: default, then hover (a neutral brightening), then HERE (persistent inversion), then focus (a square
   2px paper-tone outline, always drawn, never replaced by HERE), then active (a brief pressed state).
   Colour: cyan means measured and amber means Neon; neither marks hover, focus or HERE.
   The rule tone (#2d2b28, 1.3:1) only divides; every edge that says "press here" uses --edge (3.96:1).
   Painting frames are never trimmed and never change on hover. */

:root {
  --edge: #77736a;          /* resting edge of anything you can press: 3.96:1 on the ground, 3.72:1 on raised */
  --cut: 10px;              /* the trimmed corner on OPEN boxes */
  --behind: var(--ground);  /* what shows through the cut */
}

/* ---------- focus: one outline, never a signal colour ---------- */
a:focus-visible, button:focus-visible, summary:focus-visible, .tile:focus-visible, [tabindex]:focus-visible,
.os-deep summary:focus-visible, .os-conbtn:focus-visible, .os-depth a:focus-visible, .os-start:focus-visible,
.constellation .toggle button:focus-visible {
  outline: 2px solid var(--text); outline-offset: 3px; border-radius: 0;
}
.eq-form input:focus-visible, .eq-form select:focus-visible, .eq-form textarea:focus-visible,
.works-filters input:focus { outline: 2px solid var(--text); outline-offset: 1px; border-color: var(--text); }

/* ---------- 1. GO ---------- */
.deep a, .details a, .step-text p a, .xref, .lead-p a, .faq a, .prose a, p a:not([class]), dd a:not([class]) {
  border-bottom: 0; text-decoration: underline; text-decoration-color: var(--edge); text-decoration-thickness: 1px;
  text-underline-offset: 4px; transition: text-decoration-color .15s;
}
.deep a:hover, .details a:hover, .step-text p a:hover, .xref:hover, .lead-p a:hover, .faq a:hover, .prose a:hover,
p a:not([class]):hover, dd a:not([class]):hover { text-decoration-color: var(--text); text-decoration-thickness: 2px; }
header.top nav a, footer.foot a, .trail a { text-decoration: none; }

/* contents lines */
.toc a, .method-toc a { color: var(--text); border-bottom: 1px solid var(--edge); padding-bottom: 3px; }
.toc a:hover, .method-toc a:hover { border-bottom: 2px solid var(--text); padding-bottom: 2px; }

/* top navigation: the current section (HERE) is underlined in paper tone; hover draws an edge-tone line */
header.top nav a::after { background: var(--text); }
header.top nav a:not([aria-current]):not(.within):hover::after { background: var(--edge); }
.nav-item:hover > a::before, .nav-item:focus-within > a::before { color: var(--text); }
.menu-sheet a[aria-current="page"] { color: var(--text); box-shadow: inset 3px 0 0 var(--text); padding-left: 12px; }
.nav-enquire { border-color: var(--edge) !important; } .nav-enquire:hover { border-color: var(--text) !important; background: var(--raise); }

/* rows that lead elsewhere */
.see a, .doors a, .cards a, .layer-index li a { transition: background-color .15s; }
.see a:hover, .cards a:hover, .layer-index li a:hover { background: var(--raise); }
.doors b, .cards b, .route-index b {
  text-decoration: underline; text-decoration-color: var(--edge); text-decoration-thickness: 1px; text-underline-offset: 5px;
  border-bottom: 0; box-shadow: none;
}
.doors a:hover b, .cards a:hover b, .route-index a:hover b, .route-index a:focus-visible b {
  text-decoration-color: var(--text); text-decoration-thickness: 2px; box-shadow: none;
}
.see a .mono { color: var(--text); }

/* Where next: a ledger. The destination (underlined), a leader rule, the reason. The whole row is the link. */
.next-routes a {
  display: flex; align-items: baseline; gap: 16px; min-height: 48px; padding: 13px 0; grid-template-columns: none;
  transition: background-color .15s;
}
.next-routes a b { order: 1; flex: none; max-width: 60%; font-size: 18px;
  text-decoration: underline; text-decoration-color: var(--edge); text-decoration-thickness: 1px; text-underline-offset: 5px; box-shadow: none; }
.next-routes a::before { content: ""; order: 2; flex: 1; min-width: 24px; align-self: center; height: 1px; background: var(--line); transition: background-color .15s; }
.next-routes a span { order: 3; flex: 0 1 auto; max-width: 46%; text-align: right; }
.next-routes a:hover b { text-decoration-color: var(--text); text-decoration-thickness: 2px; box-shadow: none; }
.next-routes a:hover::before { background: var(--text); }
.next-routes a:hover span { color: var(--text); }
@media (max-width: 760px) {
  .next-routes a { display: grid; gap: 4px; } .next-routes a::before { display: none; }
  .next-routes a b, .next-routes a span { max-width: none; text-align: left; }
}

/* the Details register: open sides, a spine between label and value; only linked values respond */
.basics { border-top: 1px solid var(--edge); }
.basics dt { padding-right: 18px; border-right: 1px solid var(--line); }
.basics dd { padding-left: 20px; }

/* ---------- 3. ACT ---------- */
.button, .zoom-bar button, .hero-views button {
  display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 18px; margin-top: 22px;
  border: 1px solid var(--edge); border-radius: 0; background: var(--ground); color: var(--text);
  font: 500 15px/1.2 var(--sans); letter-spacing: .01em; text-decoration: none; cursor: pointer;
  transition: background-color .12s, border-color .12s, color .12s;
}
.hero-tools .button, .hero-views button, .zoom-bar button { margin-top: 0; }
.button:hover, .zoom-bar button:hover, .hero-views button:hover { border-color: var(--text); background: var(--raise); }
.button:active, .zoom-bar button:active, .hero-views button:active { background: var(--text); color: var(--ground); border-color: var(--text); }
/* the submit at the end of a form is the one filled button: it sits under the form, never beside a painting */
.button.solid { background: var(--text); color: var(--ground); border-color: var(--text); font-weight: 600; }
.button.solid:hover { background: var(--ground); color: var(--text); border-color: var(--text); }
.button.solid:active { background: var(--muted); border-color: var(--muted); color: var(--ground); }

/* choices in a row: a strip of joined cells; the chosen one (HERE) fills its small square chamber */
.arrange, .hero-views { gap: 0 !important; }
.arrange button, .arrange a.arr, .hero-views button {
  display: inline-flex; align-items: center; gap: 9px; min-height: 40px; padding: 0 14px; border: 1px solid var(--edge); margin-left: -1px;
  color: var(--muted); background: var(--ground); box-shadow: none !important; transition: background-color .12s, color .12s;
}
.arrange button::before, .arrange a.arr::before, .hero-views button::before {
  content: ""; width: 9px; height: 9px; border: 1px solid var(--edge); flex: none;
}
.arrange button:hover, .arrange a.arr:hover, .hero-views button:hover { color: var(--text); background: var(--raise); position: relative; z-index: 1; }
.arrange button[aria-pressed=true], .arrange a.arr[aria-pressed=true], .hero-views button[aria-pressed="true"] {
  color: var(--text); background: var(--raise); border-color: var(--edge);
}
.arrange button[aria-pressed=true]::before, .arrange a.arr[aria-pressed=true]::before, .hero-views button[aria-pressed="true"]::before {
  background: var(--text); border-color: var(--text);
}
.arrange > .mono { margin-right: 14px; }

/* filter cells: label, then a count chamber (always the number of shown works it would leave); chosen = count inverted */
.chip { display: inline-flex; align-items: stretch; min-height: 38px; padding: 0; border: 1px solid var(--edge); margin: 0 -1px 0 0;
  color: var(--muted); background: var(--ground); font-size: 14.5px; transition: background-color .12s, color .12s; }
.chip > span { display: flex; align-items: center; padding: 0 12px; }
.chip > i { display: flex; align-items: center; min-width: 3.4ch; justify-content: center; padding: 0 8px; border-left: 1px solid var(--line);
  font: 400 12.5px var(--mono); font-style: normal; color: var(--muted); }
.chip:not(:has(> span)) { padding: 0 12px; align-items: center; }
.chip:hover { color: var(--text); background: var(--raise); position: relative; z-index: 1; }
.chip.on { color: var(--text); border-color: var(--edge); background: var(--raise); position: relative; z-index: 2; }
.chip.on > i { background: var(--text); color: var(--ground); border-left-color: var(--text); font-weight: 500; }
.chip.on:not(:has(> i)) { box-shadow: inset 0 -3px 0 var(--text); }
.chip.zero { color: var(--dim); } .chip.zero > i { color: var(--dim); }
.works-filters > div { row-gap: 8px; }
.wt-more summary .chip::after { margin-left: 8px; align-self: center; }

/* Go deeper: a full-width ACT button into the next depth (it reveals, it does not navigate) */
.descend {
  position: relative; background: var(--ground); border: 1px solid var(--edge);
  padding: 22px 26px 22px 84px; transform: none !important; transition: background-color .15s, border-color .15s;
}
.descend::before {
  content: attr(data-step); position: absolute; left: 22px; top: 22px; width: 40px; height: 40px; display: grid; place-items: center;
  border: 1px solid var(--edge); font: 500 16px var(--mono); color: var(--text); transition: border-color .15s;
}
.descend span { color: var(--muted); }
.descend b::after { content: none; }
.descend:hover { background: var(--raise); border-color: var(--text); }
.descend:hover::before { border-color: var(--text); }
.descend:active { background: var(--text); color: var(--ground); } .descend:active * { color: var(--ground); }

/* ---------- 2. OPEN: the trimmed corner, drawn over the box so focus outlines stay whole ---------- */
.specimen, a.out, .guide-cards a, .route-cards a, .margin-card, .one-page, .work-nav a {
  --b: var(--edge);
  position: relative; border: 1px solid var(--b) !important; border-radius: 0;
  transform: none !important; transition: border-color .15s, background-color .15s;
}
.specimen::before, a.out::before, .guide-cards a::before, .route-cards a::before, .margin-card::before, .one-page::before, .work-nav a::before {
  content: ""; position: absolute; top: -1px; right: -1px; width: calc(var(--cut) + 1px); height: calc(var(--cut) + 1px); pointer-events: none;
  background: linear-gradient(to bottom left, var(--behind) calc(50% - .6px), var(--b) calc(50% - .6px), var(--b) calc(50% + .7px), transparent calc(50% + .7px));
}
.specimen:hover, a.out:hover, .guide-cards a:hover, .route-cards a:hover, .margin-card:hover, .one-page:hover, .work-nav a:hover {
  --b: var(--text); background: var(--raise);
}
.one-page { border-left-width: 1px !important; }
.margin-card:hover i { transform: none; }
.work-nav a { display: grid; align-content: center; gap: 2px; padding: 12px 18px; min-height: 60px; color: var(--text); }

/* the paper specimens (/papers) */
.specimen { background: var(--ground); padding: 0; gap: 0; }
.specimen > * { padding-left: 22px; padding-right: 22px; }
.sp-head { padding-top: 20px; }
.sp-head span.mono { display: inline-block; font-size: 14px; letter-spacing: .04em; color: var(--text); border: 1px solid var(--edge); padding: 3px 8px 2px; }
.specimen:hover .sp-head span.mono { border-color: var(--text); }
.sp-head b { margin-top: 12px; font-size: 23px; }
.specimen > :not(.sp-head):not(.sp-foot) { margin-top: 16px; }
.sp-use { border-top: 1px solid var(--line); padding-top: 12px; padding-bottom: 2px; }
.sp-foot { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px 14px; margin-top: 10px; padding-bottom: 16px; }
.sp-strip { display: flex; flex-wrap: wrap; gap: 3px 2px; align-items: flex-end; min-width: 0; }
.sp-strip i { display: block; height: 9px; background: var(--empty); box-shadow: inset 0 0 0 1px #3a3833; }
.sp-strip i.s { background: #b9b3a6; box-shadow: none; }
.sp-key { grid-column: 1; font: 400 11.5px var(--mono); letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.sp-open { grid-column: 2; grid-row: 1 / span 2; align-self: end; font: 500 14px var(--sans); color: var(--text);
  text-decoration: underline; text-decoration-color: var(--edge); text-underline-offset: 4px; }
.specimen:hover .sp-open { text-decoration-color: var(--text); text-decoration-thickness: 2px; }
/* a paper registered but never painted on says so in words; the dashed edge is secondary */
.specimen.unused { opacity: 1; border-style: dashed !important; }
.specimen.unused .sp-head b { color: var(--muted); }

/* figures at the head of a page are facts, not doors: no box */
.method-stats { background: none; border: 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); gap: 0; }
.method-stats div { background: none; padding: 22px 26px 22px 0; }
.method-stats div + div { padding-left: 26px; border-left: 1px solid var(--line); }

/* ---------- 4. HERE: the depth gauge on a work page. Static, equal cells, named. ---------- */
.js-depth .gauge, .js-depth .gauge:hover {
  position: fixed; left: 50%; right: auto; top: auto; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); z-index: 30; display: grid; grid-template-columns: auto repeat(var(--n, 4), minmax(124px, 1fr));
  gap: 0; margin: 0; padding: 0; border: 1px solid var(--edge); border-radius: 0; background: var(--ground);
  box-shadow: 0 0 0 6px rgba(19, 18, 17, .85), 0 18px 50px rgba(0, 0, 0, .55); backdrop-filter: none; -webkit-backdrop-filter: none;
  animation: none;
}
.gauge .g-lab { display: flex; align-items: center; padding: 0 16px; border-right: 1px solid var(--edge);
  font: 500 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.js-depth .gauge button, .js-depth .gauge button:not(:last-child) {
  display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 0 18px 0 12px; margin: 0;
  border: 0; border-radius: 0; background: none; color: var(--muted); grid-template-columns: none; transition: background-color .12s, color .12s;
}
.js-depth .gauge button + button { border-left: 1px solid var(--line); }
.js-depth .gauge button::before, .js-depth .gauge button::after { display: none !important; }
.js-depth .gauge i { display: grid; place-items: center; width: 26px; height: 26px; flex: none; margin: 0; border: 1px solid var(--edge); border-radius: 0;
  background: none; box-shadow: none !important; font: 500 13px var(--mono); font-style: normal; color: var(--muted); }
.js-depth .gauge b, .js-depth .gauge button b { display: block; font: 500 16px var(--sans); color: inherit; }
.js-depth .gauge small { display: none; }
.js-depth .gauge button.done { color: var(--text); }
.js-depth .gauge button.done i { border-color: var(--text); color: var(--text); background: none; }
.js-depth .gauge button:hover { background: var(--raise); color: var(--text); }
.js-depth .gauge button:hover i { border-color: var(--text); color: var(--text); }
.js-depth .gauge button[aria-current] { background: var(--raise); color: var(--text); }
.js-depth .gauge button[aria-current] i { background: var(--text); border-color: var(--text); color: var(--ground); }
.gauge .lv-tip { border-color: var(--edge); border-radius: 0; color: var(--text); bottom: calc(100% + 14px); }
@media (max-width: 760px) {
  .js-depth .gauge, .js-depth .gauge:hover { left: 8px; right: 8px; transform: none; grid-template-columns: repeat(var(--n, 4), minmax(0, 1fr)); }
  .gauge .g-lab { grid-column: 1 / -1; padding: 5px 10px 4px; border-right: 0; border-bottom: 1px solid var(--line); font-size: 10.5px; }
  .js-depth .gauge button, .js-depth .gauge button:not(:last-child) { justify-content: center; gap: 6px; padding: 0 4px; min-height: 48px; }
  .js-depth .gauge button:nth-of-type(1) { border-left: 0; }
  .js-depth .gauge b, .js-depth .gauge button b { font-size: 13.5px; }
  .js-depth .gauge i { width: 22px; height: 22px; font-size: 12px; }
}

/* ---------- smaller places cyan used to mark a state ---------- */
.im-chip.on { box-shadow: inset 0 -2px 0 var(--text); } .im-chip.on i { color: var(--text); }
.im-item.on { box-shadow: inset 3px 0 0 var(--text); } .im-item.on span::after { color: var(--text); }
.os-depth a[aria-current] i { background: var(--text); border-color: var(--text); }
.ptable a:hover { background: #24221f; }
.mnav a { border-color: var(--edge); } .mnav a:hover { border-color: var(--text); }
.lad-row > span.on { background: var(--text); color: var(--ground); }

/* Windows High Contrast and other forced colours: keep every edge and every HERE chamber */
@media (forced-colors: active) {
  .js-depth .gauge button[aria-current] i, .chip.on > i, .arrange [aria-pressed=true]::before, .hero-views [aria-pressed="true"]::before {
    forced-color-adjust: none; background: Highlight; color: HighlightText; border-color: Highlight;
  }
  .specimen::before, a.out::before, .guide-cards a::before, .route-cards a::before, .margin-card::before, .one-page::before, .work-nav a::before { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .button, .specimen, .descend, .gauge button, .chip, .next-routes a::before { transition: none; }
}

/* the fixed depth gauge must never cover the page's last lines */
.js-depth body { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
