:root {
  --bg: #1B1621; --card: #251E2C; --edge: #4D2D49; --pink: #E663B5; --gold: #C9A45C;
  --ink: #ECE5F1; --muted: #9686A2; --ok: #7FC79A; --blue: #7FA8D9; --red: #E07A6F;
  /* The panel and overlays are read as prose, so they set in a proportional face; the bar, labels and strip keep Iosevka. */
  --read: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.5 "Iosevka Aile", "Iosevka", ui-sans-serif, system-ui, sans-serif; }
button { font: inherit; color: inherit; }
a { color: var(--pink); }
code { font-family: "Iosevka", ui-monospace, monospace; font-size: 13px; background: #14101A; padding: 1px 5px; border-radius: 4px; }

/* Written for the phone first: one column that scrolls as a page. The path stays at the top; the view,
   its actions and the catalogues come first, then the panel to read. Wider screens put the panel beside the view
   (see "Side by side" below). */
.ev { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* top bar: flush to the window edge, one hairline below. The path scrolls sideways and the title cuts off,
   so the bar never widens the page. On a phone its parts become rows of the page. */
.ev-bar { display: contents; }
.ev-head { order: 0; position: sticky; top: 0; z-index: 3; display: flex; align-items: stretch; flex: none; height: 44px; min-width: 0; background: var(--bg); border-bottom: 1px solid var(--edge); }
.ev-crumbs { display: flex; align-items: center; gap: 4px; padding: 0 12px 0 10px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; white-space: nowrap; }
.ev-crumbs::-webkit-scrollbar { display: none; }
.ev-crumbs a { color: var(--muted); text-decoration: none; padding: 11px 4px; }
.ev-crumbs a:hover { color: var(--ink); }
.ev-crumbs a[aria-current="page"] { color: var(--ink); font-weight: 700; }
.ev-crumbs .sep { color: var(--edge); }
/* The site's mark leads home, the teardown's title leads to its root: both sit left of the path. */
.ev-mark { order: -2; display: inline-flex; align-items: center; justify-content: center; flex: 0 0 44px; color: var(--ink); border-right: 1px solid var(--edge); transition: background 0.15s, color 0.15s; }
.ev-mark svg { width: 26px; height: 26px; }
.ev-mark:hover, .ev-mark:focus-visible { color: var(--pink); background: var(--card); }
.ev-mark:focus-visible, .ev-title > a:focus-visible { outline: 2px solid var(--pink); outline-offset: -2px; }
.ev-title { order: -1; display: flex; align-items: center; gap: 8px; max-width: 50%; padding: 0 14px 0 16px; color: var(--muted); white-space: nowrap; min-width: 0; flex: 0 1 auto; border-right: 1px solid var(--edge); }
.ev-title > a { color: var(--ink); flex: 0 1 auto; overflow: hidden; text-overflow: ellipsis; font-weight: 700; text-decoration: none; }
.ev-title > a:hover { color: var(--pink); }
.ev-title span { display: none; overflow: hidden; text-overflow: ellipsis; }
.ev-actions { order: 2; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 1px solid var(--edge); }
.ev-actions button { border: 0; border-left: 1px solid var(--edge); background: none; min-height: 46px; padding: 0 4px; cursor: pointer; }
.ev-actions button:first-child { border-left: 0; }
.ev-actions button[aria-pressed="true"] { background: var(--card); color: var(--pink); }
.ev-actions button:disabled { color: var(--muted); cursor: default; }

/* stage */
.ev-stage { order: 1; position: relative; overflow: hidden; flex: none; height: 62vh; height: 62svh; min-height: 300px; }
.ev-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.ev-labels { position: absolute; inset: 0; pointer-events: none; z-index: 1; }
.ev-label { position: absolute; left: 0; top: 0; pointer-events: auto; cursor: pointer; white-space: nowrap; color: inherit; text-decoration: none;
  background: rgba(27, 22, 33, 0.82); border: 1px solid var(--edge); border-radius: 6px; padding: 1px 8px 2px; font-size: 13px; }
.ev-label .dot, .ev-chip .dot, .ev-terms .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; background: var(--k); vertical-align: 1px; }
.ev-label.focus { font-size: 16px; font-weight: 700; padding: 2px 10px 3px; }
.ev-label.hover { border-color: var(--pink); color: #fff; }
.ev-hint { position: absolute; left: 16px; bottom: 12px; right: 16px; color: var(--muted); font-size: 13px; pointer-events: none; }

/* panel: one measure, one left edge; the name, then the lede, then sections parted by a rule and space */
.ev-panel { order: 4; border-top: 1px solid var(--edge); padding: 28px 16px 48px; font: 16px/1.6 var(--read); }
.ev-panel h2 { margin: 10px 0 10px; font-size: clamp(34px, 3.3vw, 54px); line-height: 1.04; letter-spacing: -0.025em; font-weight: 700; text-wrap: balance; }
.ev-panel h3, .ev-facts dt { margin: 0 0 8px; font-size: 12px; line-height: 1.4; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.ev-panel section, .ev-facts { margin-top: 28px; padding-top: 22px; border-top: 1px solid var(--edge); }
.ev-panel section p { margin: 0 0 10px; }
/* A folded section: its whole heading line is the control, a full-height target for a thumb */
.ev-fold summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; margin: -13px 0 -13px; cursor: pointer; list-style: none; }
.ev-fold summary::-webkit-details-marker { display: none; }
.ev-fold summary h3 { margin: 0; }
.ev-fold summary::after { content: "+"; color: var(--muted); font-size: 20px; line-height: 1; }
.ev-fold details[open] > summary { margin-bottom: 0; }
.ev-fold details[open] > summary::after { content: "−"; }
@media (hover: hover) { .ev-fold summary:hover h3, .ev-fold summary:hover::after { color: var(--ink); } }
.ev-fold summary:focus-visible { outline: 2px solid var(--pink); outline-offset: 2px; border-radius: 4px; }
/* A long paragraph in one column: cut to six lines until the reader asks for the rest */
.ev-clamp:not(.open) { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 6; overflow: hidden; }
.ev-more { display: inline-flex; align-items: center; min-height: 44px; padding: 0; background: none; border: 0; color: var(--pink); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.ev-more[hidden] { display: none; }
.ev-kind { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--k); font-weight: 600; }
.ev-aka { margin: 0 0 18px; color: var(--muted); font-size: 14px; }
.ev-plain { max-width: 42ch; margin: 0; font-size: clamp(17px, 1.25vw, 20px); line-height: 1.5; text-wrap: pretty; }
.ev-facts { margin-bottom: 0; }
.ev-facts dd { margin: 0 0 18px; }
.ev-facts dd:last-child { margin-bottom: 0; }
/* Connections: each relation sits above its chips, like the facts, so the chips get the panel's full width */
.ev-panel dl.ev-links { margin: 0; }
.ev-links dt { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.ev-links dd { margin: 0 0 14px; }
.ev-links dd:last-child { margin-bottom: 0; }
.ev-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.ev-chip { color: inherit; text-decoration: none; border: 1px solid var(--edge); border-radius: 999px; padding: 2px 12px 3px; cursor: pointer; font-size: 14px; }
.ev-panel, .ev-overlay { overflow-wrap: anywhere; }
.ev-chain { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ev-chain .arrow { color: var(--muted); }
.ev-why { color: var(--ink); font-style: italic; }
.ev-note { margin: 40px 0 0; padding-top: 18px; border-top: 1px solid var(--edge); color: var(--muted); font-size: 13px; }
.ev-note a { color: inherit; }
.ev-cues { margin: 0; padding-left: 22px; }
.ev-cues li { margin: 6px 0; padding-left: 4px; }
.ev-sources ol { margin: 0; padding-left: 22px; font-size: 14px; line-height: 1.5; }
.ev-sources li { margin: 0 0 14px; }
.ev-sources .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ev-sources .page { color: var(--muted); }
.ev-sources .quote { display: block; color: var(--muted); font-style: italic; font-size: 13.5px; margin-top: 4px; }
.ev-sources .flag { color: var(--gold); font-size: 13px; }
.unverified { color: var(--red); font-size: 14px; }
/* a prompt to copy: one block of code with its button under it, not a code span broken across lines */
.ev-ask { font-size: 13px; }
.ev-ask code { display: block; padding: 10px 12px; border-radius: 6px; line-height: 1.5; white-space: pre-wrap; }
.ev-copy { display: inline-block; margin-top: 8px; background: none; border: 1px solid var(--edge); border-radius: 6px; cursor: pointer; font-size: 13px; padding: 3px 12px; }
.ev-plot { margin: 0; }
.ev-plot svg { width: 100%; height: auto; display: block; }
.ev-plot figcaption { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

/* bottom strip: catalogues and flatpack steps; cells share hairlines and wrap instead of hiding off-screen.
   The catalogue's name is the first cell of its row, so its options get the full width to wrap in.
   Each cell draws its right edge, so a wrapped line starts on the screen's own edge. */
.ev-strip { order: 3; border-top: 1px solid var(--edge); }
.ev-row { display: flex; align-items: stretch; flex-wrap: wrap; row-gap: 1px; }
.ev-row + .ev-row { border-top: 1px solid var(--edge); }
.ev-rowlabel { display: flex; align-items: center; min-height: 44px; padding: 0 12px 0 16px; border-right: 1px solid var(--edge); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; white-space: nowrap; }
.ev-cells { display: contents; }
/* the top shadow lands on the row's own top edge on the first line, and fills the 1px gap between wrapped lines */
.ev-row button, .ev-row a { border: 0; border-right: 1px solid var(--edge); box-shadow: 0 -1px 0 var(--edge); background: none; min-height: 44px; padding: 0 16px; cursor: pointer; white-space: nowrap; }
/* a flatpack step is a link to its own URL, drawn like the buttons beside it */
.ev-row a { display: flex; align-items: center; color: inherit; text-decoration: none; }
/* hover colours only where there is hover: on a touch screen they stick after a tap and look selected */
@media (hover: hover) {
  .ev-actions button:hover:not(:disabled), .ev-row button:hover:not(:disabled), .ev-row a:hover, .ev-terms li a:hover { background: var(--card); }
  .ev-label:hover { border-color: var(--pink); color: #fff; }
  .ev-chip:hover { border-color: var(--pink); }
}
.ev-row button[aria-pressed="true"], .ev-row a[aria-current="step"] { background: var(--card); color: var(--pink); }
.ev-row button:disabled { color: var(--muted); cursor: default; }
/* Flatpack in one column: the steps scroll sideways on one line, the current one in the middle;
   Back, Next and Play share the line below in equal thirds. */
.ev-flatpack { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px 0; }
.ev-flatpack .ev-rowlabel { display: none; }
.ev-steps { grid-column: 1 / -1; grid-row: 1; display: flex; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none; }
.ev-steps::-webkit-scrollbar { display: none; }
.ev-steps a { flex: none; scroll-snap-align: center; }
.ev-flatpack > .ev-cells > button { grid-row: 2; justify-content: center; }
.ev-flatpack > .ev-cells > button:last-child { border-right: 0; }

/* overlays (index, sources): fill the screen on a phone; typing in them does not zoom the page */
.ev-overlay { position: fixed; inset: 0; z-index: 10; background: var(--bg); overflow-y: auto; overscroll-behavior: contain; scroll-padding-top: 64px; padding: 0 0 12px; font-family: var(--read); }
.ev-overlay-head { position: sticky; top: 0; z-index: 1; display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--edge); }
.ev-overlay-head b { flex: 1; min-width: 0; }
.ev-overlay input { order: 1; flex: 1 1 100%; min-width: 0; background: var(--card); border: 1px solid var(--edge); border-radius: 6px; color: var(--ink); font: inherit; font-size: 16px; padding: 6px 10px; }
.ev-close { background: none; border: 1px solid var(--edge); border-radius: 6px; padding: 3px 12px; cursor: pointer; }
.ev-overlay ul { list-style: none; margin: 0; padding: 0; }
.ev-terms li a { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; width: 100%; color: inherit; text-decoration: none; border-bottom: 1px solid #2c2333; padding: 9px 16px; cursor: pointer; }
.ev-terms .term { font-weight: 600; }
.ev-terms .kind { color: var(--muted); font-size: 12.5px; }
.ev-terms .plain { grid-column: 1 / -1; color: var(--muted); font-size: 13.5px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ev-terms .plain b { color: var(--gold); font-weight: 600; }
.ev-terms .ev-note { padding: 8px 16px; color: var(--muted); font-size: 13px; border-bottom: 1px solid #2c2333; }
.ev-works .ev-group { padding: 18px 16px 6px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--gold); font-weight: 600; border-bottom: 1px solid var(--edge); }
.ev-work { padding: 10px 16px 12px; border-bottom: 1px solid #2c2333; }
.ev-work-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 2px 12px; }
.ev-work-head a { color: var(--ink); font-weight: 600; text-decoration: none; }
.ev-work-head a:hover { color: var(--pink); text-decoration: underline; }
.ev-work-head .count { color: var(--muted); font-size: 12.5px; white-space: nowrap; }
.ev-work-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.ev-cites { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; }
.ev-cite { display: inline-flex; align-items: baseline; gap: 6px; }
.ev-cite .page { color: var(--muted); font-size: 12.5px; }
.ev-cite .page:hover { color: var(--pink); }
.ev-work-why { margin: 4px 0 2px; font-size: 13.5px; }

/* Side by side: a wide screen, or a phone on its side. The page stops scrolling; the view fills the window and
   the panel scrolls beside it, taking about a third of the window so a definition reads as prose. */
@media (width > 900px), (width > 600px) and (orientation: landscape) {
  html, body { height: 100%; }
  body { overflow: hidden; }
  .ev { display: grid; grid-template-columns: minmax(0, 1fr) clamp(360px, 34vw, 640px); grid-template-rows: 44px minmax(0, 1fr) auto; height: 100vh; height: 100dvh; }
  .ev-bar { grid-column: 1 / -1; display: flex; align-items: stretch; border-bottom: 1px solid var(--edge); min-width: 0; }
  .ev-head { position: static; flex: 1; height: auto; border-bottom: 0; }
  .ev-crumbs { padding: 0 0 0 16px; }
  .ev-crumbs a { padding: 0 2px; }
  .ev-mark { flex-basis: 48px; }
  .ev-title { max-width: none; padding: 0 16px; }
  .ev-title > a { flex: none; }
  .ev-title span { display: inline; }
  .ev-actions { display: flex; flex: none; border-top: 0; }
  .ev-actions button, .ev-actions button:first-child { border-left: 1px solid var(--edge); min-height: 0; padding: 0 18px; }
  .ev-stage { height: auto; min-height: 0; }
  .ev-strip { grid-column: 1; }
  .ev-panel { grid-column: 2; grid-row: 2 / 4; border-top: 0; border-left: 1px solid var(--edge); overflow-y: auto; padding: 32px clamp(24px, 2.8vw, 44px) 56px; }
  .ev-row { flex-wrap: nowrap; }
  .ev-rowlabel { min-width: 92px; min-height: 0; padding: 0 14px 0 16px; border-right: 0; }
  .ev-cells { flex: 1; display: flex; flex-wrap: wrap; row-gap: 1px; }
  .ev-row button, .ev-row a { min-height: 40px; border-right: 0; border-left: 1px solid var(--edge); }
  .ev-overlay-head { flex-wrap: nowrap; }
  .ev-overlay-head b { flex: 0 1 auto; }
  .ev-overlay input { order: 0; flex: 1; }
  .ev-terms li a { grid-template-columns: 220px 90px 1fr; gap: 12px; padding: 6px 16px; }
  .ev-terms .plain { grid-column: auto; display: block; white-space: nowrap; text-overflow: ellipsis; }
  .ev-work-head { flex-wrap: nowrap; gap: 16px; }
  .ev-clamp:not(.open) { display: block; -webkit-line-clamp: none; overflow: visible; }
  .ev-flatpack { display: flex; gap: 0; }
  .ev-flatpack .ev-rowlabel { display: flex; }
  .ev-steps { display: contents; }
}

/* Phone on its side: too short for the full panel, so it narrows and its type steps down;
   catalogues keep to one line each and scroll sideways. In the flatpack only the steps scroll,
   between Back and Next, so the controls stay in reach. */
@media (width > 600px) and (orientation: landscape) and (height <= 500px) {
  .ev { grid-template-columns: minmax(0, 1fr) min(340px, 42vw); }
  .ev-title { display: none; }
  .ev-actions button, .ev-actions button:first-child { padding: 0 12px; }
  .ev-panel { padding: 16px 16px 32px; }
  .ev-panel h2 { font-size: 26px; }
  .ev-plain { font-size: 17px; }
  .ev-cells { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .ev-cells::-webkit-scrollbar { display: none; }
  .ev-row button, .ev-row a { flex: none; }
  .ev-flatpack .ev-rowlabel { display: none; }
  .ev-flatpack .ev-cells { overflow: visible; min-width: 0; }
  .ev-steps { display: flex; flex: 1; min-width: 0; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; scrollbar-width: none; }
  .ev-flatpack > .ev-cells > button:first-child { border-left: 0; }
}

/* A screen tall and wide enough: the Index and Sources float over the view and draw their own edge.
   On a phone on its side they still fill the screen, and typing in them still does not zoom the page. */
@media (width > 900px) and (height > 500px), (width > 600px) and (orientation: landscape) and (height > 500px) {
  .ev-overlay { position: absolute; inset: 14px; z-index: 2; background: rgba(27, 22, 33, 0.97); border: 1px solid var(--edge); border-radius: 10px; overscroll-behavior: auto; }
  .ev-overlay input { font-size: inherit; padding: 4px 10px; }
}

/* Fingers: bigger targets; quick taps on buttons and links do not zoom the page; and a drag or pinch
   that starts on a label still reaches the view (viewer.js picks the tapped label) */
@media (pointer: coarse) {
  .ev button, .ev a { touch-action: manipulation; }
  .ev-label { pointer-events: none; }
  .ev-chips, .ev-chain { gap: 8px; }
  .ev-chip { padding: 5px 12px 6px; }
  .ev-close { padding: 6px 14px; }
}
