:root {
  --bg: #0d1015;
  --rail: #11151c;
  --ink: #ece8df;
  --muted: #98a0af;
  --faint: #5d6575;
  --line: #262c38;
  --card: rgba(19, 23, 31, 0.97);
  --amber: #f2c14e;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Avenir Next", Avenir, "Segoe UI", system-ui, -apple-system, sans-serif;
  --rail-w: 300px;
  --panel-w: 380px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--sans); overflow: hidden; }
body { font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
button:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }
.pill, #topbar button, .panel-head button, .railfoot button, #btn-back, .guide-nav button {
  padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; background: rgba(19, 23, 31, 0.85); font-size: 13.5px; color: var(--ink); }
#topbar button:hover, .panel-head button:hover, .railfoot button:hover, #btn-back:hover, .guide-nav button:hover { border-color: var(--faint); }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }

.label { position: absolute; left: 0; top: 0; white-space: nowrap; font-size: 12.5px; letter-spacing: 0.02em;
  color: var(--ink); text-shadow: 0 1px 6px var(--bg), 0 0 2px var(--bg); transition: opacity 0.18s; will-change: transform; }
.label.breed { font-weight: 600; font-size: 12px; }
.label.breed.on { font-size: 13.5px; background: var(--ink); color: var(--bg); text-shadow: none; padding: 2px 8px; border-radius: 5px; }
.label.tick { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.label.axis { color: var(--muted); font-size: 12.5px; letter-spacing: 0.08em; text-transform: uppercase; }
.label.axis.lit { color: var(--amber); }
.label.ref { color: var(--amber); font-size: 12px; }

/* ---------- left rail: solid, so nothing from the chart can show through it ---------- */
#rail { position: fixed; left: 0; top: 0; bottom: 0; width: var(--rail-w); background: var(--rail); border-right: 1px solid var(--line);
  padding: 20px 18px 14px; display: flex; flex-direction: column; z-index: 3; }
#rail h1 { font-family: var(--serif); font-weight: 600; font-size: 27px; line-height: 1.08; margin: 0 0 8px; letter-spacing: -0.01em; text-wrap: balance; }
#rail .dek { margin: 0 0 14px; font-size: 14px; color: var(--muted); }
.key { list-style: none; margin: 0 0 14px; padding: 12px 0 0; border-top: 1px solid var(--line); display: grid; gap: 9px; font-size: 14px; }
.key li { display: grid; grid-template-columns: 20px auto 1fr; align-items: center; gap: 8px; }
.key b { font-weight: 600; }
.swatches { display: flex; align-items: center; gap: 5px; justify-content: flex-end; font-size: 12px; color: var(--muted); }
.sizebar { display: block; width: 52px; height: 12px; background:
  linear-gradient(#6f6a5e, #6f6a5e) 4px 100% / 6px 3px no-repeat, linear-gradient(#9c9584, #9c9584) 16px 100% / 6px 6px no-repeat,
  linear-gradient(#cfc8b6, #cfc8b6) 28px 100% / 6px 9px no-repeat, linear-gradient(#fff6dc, #fff6dc) 40px 100% / 6px 12px no-repeat; }
.rule { display: block; width: 52px; height: 9px; background:
  radial-gradient(circle 3.2px at 9px 50%, #d9d4c7 98%, transparent) , radial-gradient(circle 3.2px at 27px 50%, #f2c14e 98%, transparent), radial-gradient(circle 3.2px at 41px 50%, #f08a4b 98%, transparent),
  linear-gradient(var(--ink), var(--ink)) 0 50% / 100% 1.5px no-repeat; }
.rampbar { display: block; width: 64px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #d9d4c7, #f2c14e 25%, #f08a4b 62.5%, #ff5a4f); }
.glyph { display: block; width: 18px; height: 18px; position: relative; }
.glyph::before { content: ""; position: absolute; background: var(--ink); }
.gx::before { left: 0; right: 0; top: 8px; height: 2px; }
.gy::before { top: 0; bottom: 0; left: 8px; width: 2px; }
.gz::before { left: 1px; right: 1px; top: 8px; height: 2px; transform: rotate(-38deg); }
.find { font-size: 11.5px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding-top: 12px; border-top: 1px solid var(--line); margin-bottom: 6px; }
#find { width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: #0d1015; color: var(--ink); font: inherit; font-size: 14.5px; }
#find:focus { outline: 2px solid var(--amber); outline-offset: 1px; }
#pick { display: none; width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: #0d1015; color: var(--ink); font: inherit; }
#list { flex: 1; min-height: 80px; overflow-y: auto; margin: 8px -8px 10px; padding: 0 8px; scrollbar-width: thin; scrollbar-color: #2b3240 transparent; }
.item { display: grid; grid-template-columns: 12px 1fr auto; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 6px 8px; border-radius: 8px; font-size: 14px; color: var(--ink); }
.item i { width: 10px; height: 10px; border-radius: 2px; display: block; }
.item small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.item:hover { background: #1a1f29; }
.item.on { background: var(--ink); color: var(--bg); }
.item.on small { color: #4a4f5a; }
.item[hidden] { display: none; }
.railfoot { display: flex; flex-wrap: wrap; gap: 6px; }
.railfoot button { padding: 7px 12px; font-size: 13px; }

#btn-back { position: fixed; left: calc(var(--rail-w) + 18px); top: 18px; z-index: 2; display: none; font-size: 14.5px; padding: 9px 16px; background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }
body.focus #btn-back { display: block; }
#topbar { position: fixed; right: 22px; top: 18px; display: flex; gap: 8px; transition: right 0.35s; z-index: 2; }
body.focus #topbar { display: none; }

#hint { position: fixed; left: var(--rail-w); right: 0; bottom: 22px; text-align: center; pointer-events: none; transition: opacity 0.4s; font-size: 14px; color: var(--muted); }
body.touched #hint, body.focus #hint, body.guiding #hint { opacity: 0; }

/* ---------- the click-through guide ---------- */
#guide { position: fixed; left: calc(var(--rail-w) + 50%); bottom: 26px; transform: translateX(calc(-50% - var(--rail-w) / 2)); width: min(560px, calc(100vw - var(--rail-w) - 48px));
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px 12px; z-index: 3; }
#guide[hidden] { display: none; }
#guide-text { margin: 0 0 12px; font-family: var(--serif); font-size: 20px; line-height: 1.3; }
#guide-text b { color: var(--amber); font-weight: 600; }
.guide-nav { display: flex; align-items: center; gap: 8px; }
.guide-nav span { margin-right: auto; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.guide-nav button { padding: 6px 13px; }
#guide-next { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 600; }

/* ---------- right panel: one breed ---------- */
#panel { position: fixed; top: 0; right: 0; bottom: 0; width: var(--panel-w); background: var(--card); border-left: 1px solid var(--line);
  overflow-y: auto; padding: 18px 22px 24px; z-index: 3; scrollbar-width: thin; scrollbar-color: #2b3240 transparent; }
#panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.panel-head .step { display: flex; gap: 6px; }
#panel h2 { font-family: var(--serif); font-size: 31px; line-height: 1.08; margin: 0 0 14px; font-weight: 600; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.fact { border: 1px solid var(--line); border-radius: 12px; padding: 10px 13px; }
.fact.wide { grid-column: 1 / -1; }
.fact span { display: block; font-size: 11.5px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); }
.fact b { display: block; font-family: var(--serif); font-weight: 600; font-size: 24px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.fact em { display: block; font-style: normal; font-size: 14px; color: var(--ink); margin-top: 1px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: -6px 0 12px; }
.tags span { font-size: 12px; letter-spacing: 0.04em; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); }
.stands { margin-top: 18px; }
.stands .head { font-size: 11.5px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--muted); padding-bottom: 8px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.stand { margin-bottom: 12px; }
.stand .cap { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 14px; margin-bottom: 5px; }
.stand .cap span { font-weight: 600; }
.stand .cap em { font-style: normal; color: var(--muted); font-size: 13px; text-align: right; }
.strip { position: relative; height: 18px; border-bottom: 1px solid #39414f; }
.strip i { position: absolute; bottom: 0; width: 1px; height: 8px; background: #6b7384; opacity: 0.75; }
.strip s { position: absolute; bottom: 0; width: 2px; margin-left: -1px; height: 13px; background: var(--amber); }
.strip u { position: absolute; bottom: -1px; width: 4px; margin-left: -2px; height: 18px; border-radius: 2px 2px 0 0; box-shadow: 0 0 8px rgba(255, 255, 255, 0.35); }
.stands .legend { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--muted); }
.stands .legend s { display: block; width: 2px; height: 12px; background: var(--amber); }
.fine { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--line); }
.fine p { margin: 0 0 7px; font-size: 13px; line-height: 1.4; color: var(--muted); }

#tooltip { position: fixed; left: 0; top: 0; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 12px; font-size: 13px; min-width: 200px; will-change: transform; z-index: 4; }
#tooltip[hidden] { display: none; }
#tooltip b { display: block; font-size: 14.5px; margin-bottom: 3px; }
#tooltip div { display: flex; justify-content: space-between; gap: 16px; color: var(--muted); font-variant-numeric: tabular-nums; }
#tooltip div span:last-child { color: var(--ink); text-align: right; }

dialog#sources { border: 1px solid var(--line); border-radius: 16px; background: #12161d; color: var(--ink); padding: 0; max-width: 680px; width: calc(100% - 40px); max-height: 86vh; overflow: hidden; }
dialog#sources::backdrop { background: rgba(5, 7, 10, 0.72); }
.dialog-inner { padding: 26px 30px 30px; overflow-y: auto; max-height: 86vh; }
#btn-sources-close { float: right; padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px; font-size: 13.5px; }
#sources-body h2 { font-family: var(--serif); font-size: 26px; margin: 0 0 14px; font-weight: 600; }
#sources-body h3 { font-size: 12px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); margin: 22px 0 8px; }
#sources-body p, #sources-body li { font-size: 15px; margin: 0 0 9px; }
#sources-body ul { padding-left: 20px; margin: 0; }
#sources-body a { color: var(--amber); }
#sources-body details { margin: 0 0 9px; font-size: 15px; }
#sources-body summary { cursor: pointer; color: var(--amber); }
#sources-body details ul { margin-top: 8px; }
#sources-body details li { font-size: 14px; margin-bottom: 4px; color: var(--muted); }

/* ---------- mid-width windows: the rail steps aside while a breed is open, so the chart keeps its room ---------- */
@media (min-width: 821px) and (max-width: 1180px) {
  body.focus #rail { display: none; }
  body.focus #btn-back { left: 18px; }
}
/* the narrowest desktop windows: with so little room beside the rail the two end words would crowd the ruler, so the ruler's own ticks carry it */
@media (min-width: 821px) and (max-width: 900px) { .label.end { display: none; } }

/* ---------- phone: the rail becomes a top block with a dropdown ---------- */
@media (max-width: 820px) {
  #rail { right: 0; bottom: auto; width: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 14px; display: grid; grid-template-columns: 1fr; gap: 8px; }
  #rail h1 { font-size: 21px; margin: 0; }
  #rail .dek, .key, .find, #find, #list { display: none; }
  #pick { display: block; }
  #topbar, #btn-back { display: none !important; }
  #hint { left: 0; }
  #guide { left: 12px; right: 12px; width: auto; transform: none; bottom: 14px; }
  #guide-text { font-size: 17px; }
  #panel { top: auto; left: 0; right: 0; width: auto; height: 54vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0; padding: 14px 16px 22px; }
  .label.end { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- film mode (?film=1): a fixed 1080 square, no interface. Three looks of text: statements, explaining lines, and text attached to the chart. Type is sized for a phone. ---------- */
body.film { width: 1080px; height: 1080px; transform-origin: 0 0; transform: scale(var(--film-scale, 1)); }
body.film #rail, body.film #topbar, body.film #hint, body.film #panel, body.film #btn-back, body.film #guide, body.film #tooltip { display: none !important; }
body.film #scene { pointer-events: none; }
body.film #labels, body.film .label { display: none; }   /* the film draws its own words in the scene and on the glass */
body.film::after { content: ""; position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background: radial-gradient(ellipse at 50% 52%, rgba(13, 16, 21, 0) 55%, rgba(13, 16, 21, 0.55) 100%); }
#ftext { position: fixed; inset: 0; z-index: 2; pointer-events: none; }
.ft { position: fixed; left: 0; top: 0; visibility: hidden; font-family: var(--serif); font-weight: 600; color: var(--ink); text-shadow: 0 2px 16px var(--bg), 0 0 5px var(--bg); }
.ft .w { display: inline-block; opacity: 0; will-change: transform, opacity; }
.ft .w.n { color: var(--amber); }
.ft.stmt, .ft.line { width: 972px; text-align: center; text-wrap: balance; }
.ft.hook { font-size: 112px; line-height: 1.06; }
.ft.twist { font-size: 92px; line-height: 1.08; }
.ft.end { font-size: 104px; line-height: 1.05; }
.ft.addr { font-size: 60px; color: var(--amber); font-weight: 500; }
.ft.src { font-family: var(--sans); font-size: 40px; color: var(--muted); font-weight: 500; }
.ft.line { font-size: 56px; line-height: 1.14; }
.ft.att { white-space: nowrap; }
.ft.name { font-size: 78px; line-height: 1.05; }
.ft.num { font-size: 52px; line-height: 1.1; }
.ft.fig { font-size: 56px; line-height: 1.12; white-space: normal; width: 580px; }
.ft.sub { font-family: var(--sans); font-weight: 500; font-size: 38px; line-height: 1.15; color: var(--muted); }
.ft.figline { font-size: 56px; line-height: 1.12; }
/* rough cut 3: a named breed is its name in white, a gap, then its years in amber and heavier; "Let's look" under the hook; the count-up keeps its digits steady */
.ft.lab { font-size: 54px; line-height: 1.1; }
.ft.lab .w.n { font-weight: 800; }
.ft.lab .w:not(.n) + .w.n { margin-left: 0.4em; }
.ft.sub2 { font-size: 72px; line-height: 1.1; color: var(--muted); }
.ft .w.n { font-variant-numeric: tabular-nums; }
