@scope (main#top) {
  :scope {
    --control-line: color-mix(in srgb, var(--line) 65%, var(--muted));
    --selected-surface: color-mix(in srgb, var(--accent) 10%, var(--surface));
    width: min(1216px, calc(100% - 104px));
    margin-inline: auto;
    padding-bottom: 40px;
    font-family: var(--pixel);
    line-height: 1.55;
  }
  *, *::before, *::after { box-sizing: border-box; }
  h1, h2, h3, p, dl, dd { margin: 0; }
  button, input, code, output { font: inherit; color: inherit; }
  button, summary { cursor: pointer; }
  button:disabled { opacity: .4; cursor: default; }
  :is(button, input, a, summary):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
  [hidden] { display: none !important; }
  .sr { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); overflow: hidden; }

  .tree-intro, .stats, .views, .drawing-head, .drawing-foot, .legend, .identity, .routehead,
  .sectionhead, .listbar, .pager, .verifyrow { display: flex; align-items: center; }
  .tree-intro, .views, .drawing-head, .drawing-foot, .routehead, .sectionhead, .listbar { justify-content: space-between; }
  .tree-intro { gap: 28px; padding: clamp(34px, 3.2vw, 54px) 0 28px; }
  .tree-intro > div { min-width: 0; }
  .project-name { font-size: 1.09rem; font-weight: 445; letter-spacing: .012em; color: var(--accent); margin-bottom: 10px; }
  .tree-intro h1 { font: 490 clamp(2.85rem, 5.25vw, 4.85rem)/1 var(--display); letter-spacing: .008em; }
  .intro-copy { font-size: 1rem; color: #c6c4be; line-height: 1.65; margin-top: 10px; max-width: 41em; }
  .stats { flex-shrink: 0; }
  .stats > div { padding: 0 20px; border-left: 1px solid var(--line); }
  .stats > div:last-child { padding-right: 0; }
  .stats dd { font: 475 clamp(1.55rem, 2.4vw, 2.15rem)/1.1 var(--pixel); letter-spacing: -.015em; }
  .stats dt { font-size: .875rem; color: var(--muted); margin-top: 5px; }

  .views { gap: 12px; margin-bottom: 13px; }
  .switch { display: flex; gap: 3px; padding: 3px; border: 1px solid var(--line); background: var(--surface); border-radius: 4px; }
  .switch button { background: transparent; color: var(--muted); border: 0; padding: 7px 15px; border-radius: 3px; font-size: .92rem; white-space: nowrap; }
  .switch button[aria-pressed="true"] { background: var(--accent); color: var(--bg); font-weight: 510; }
  .views p, .listbar { font-size: .9rem; color: var(--muted); }
  .tree-exhibit { display: grid; grid-template-columns: minmax(0, 1fr) clamp(250px, 24%, 325px); background: var(--surface); border: 1px solid var(--line); border-radius: 5px; overflow: hidden; }
  .drawing { display: flex; flex-direction: column; min-width: 0; background: radial-gradient(color-mix(in srgb, var(--line) 58%, transparent) .7px, transparent .95px) 0 0 / 15px 15px, var(--bg); }
  .drawing-head { padding: 18px 22px 0; align-items: center; }
  .micro, .kicker, .figuretag { font: 465 .875rem/1.2 var(--pixel); letter-spacing: .035em; color: var(--muted); }
  .micro, .kicker { display: flex; align-items: center; gap: 10px; }
  .micro, .kicker { color: var(--accent); }
  .kicker i { height: 2px; width: 17px; background: var(--accent); }
  .line { background: var(--line); height: 1px; flex: 1; }
  .tree-label { text-transform: uppercase; }
  #plotname { font-size: 1.3rem; font-weight: 510; line-height: 1.4; margin-top: 3px; }
  .figuretag { border: 1px solid var(--line); border-radius: 3px; padding: 4px 7px; white-space: nowrap; }
  #tree { display: block; width: 100%; height: auto; flex: 1; min-height: 0; overflow: hidden; }
  #tree text { font-family: var(--pixel); font-weight: 475; letter-spacing: 0; }
  #tree .mint-route {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3.2;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 1 1;
    stroke-dashoffset: 0;
  }
  #tree .route-tracer {
    visibility: hidden;
    fill: #fff5df;
    stroke: var(--bg);
    stroke-width: 1.5;
  }
  #tree[data-route-state="playing"] .route-tracer { visibility: visible; }
  @media (max-width: 539px) {
    #tree[data-mode="catalog"] .mint-route { stroke-width: 5; }
    #tree[data-mode="catalog"] .route-tracer { r: 8px; }
  }
  .drawing-foot { margin: 0 22px; padding: 10px 0 12px; border-top: 1px solid var(--line); }
  .legend { font-size: .84rem; color: var(--muted); gap: 14px; }
  .legend span { display: flex; align-items: center; gap: 7px; }
  .trace { height: 2px; width: 17px; background: var(--accent); }
  .node { width: 6px; height: 6px; border: 1px solid var(--muted); }
  .bare { font-size: .87rem; background: none; color: var(--accent); border: 0; padding: 3px 0; }
  .bare:hover { text-decoration: underline; }

  .specimen { display: flex; flex-direction: column; min-width: 0; background: var(--surface); border-left: 1px solid var(--line); padding: 20px; }
  .identity { gap: 14px; margin: 19px 0; }
  .identity #portrait { width: 78px; height: 78px; image-rendering: pixelated; outline: 1px solid var(--line); }
  .mini, .routehead span, .meta dt { font-size: .85rem; color: var(--muted); }
  .identity h2 { font-size: clamp(1.8rem, 2.6vw, 2.5rem); line-height: 1.04; font-weight: 500; }
  .tier { color: var(--accent); font-size: .92rem; text-transform: uppercase; }
  .routehead { padding-top: 12px; border-top: 1px solid var(--line); }
  .routehead code { font-size: 1rem; letter-spacing: .12em; color: var(--accent); }
  #minipath { width: 100%; height: 43px; margin: 2px 0 4px; }
  .meta { flex: 1; }
  .meta dt { margin-top: 8px; }
  .meta dd { font-size: 1rem; line-height: 1.36; overflow-wrap: anywhere; color: var(--text); }
  .meta dd.human { font-size: .92rem; }
  .verifyrow { gap: 8px; flex-wrap: wrap; margin-top: 14px; }
  button.verify, form button, .pager button { border: 1px solid var(--control-line); background: transparent; color: var(--text); border-radius: 3px; padding: 7px 11px; font-size: .9rem; }
  button.verify:hover, form button:hover, .pager button:enabled:hover { border-color: var(--accent); color: var(--accent); }
  #verified { font-size: .86rem; color: var(--accent); }

  .directory, .mechanism { padding-top: 38px; scroll-margin-top: 20px; }
  .sectionhead { gap: 18px; align-items: flex-end; }
  .sectionhead h2 { font-size: 1.8rem; font-weight: 510; line-height: 1.35; margin-top: 6px; }
  .sectionhead form { display: flex; align-items: center; gap: 6px; }
  .sectionhead input { min-width: 0; width: 200px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); padding: 7px 10px; font-size: .96rem; }
  .listbar { min-height: 34px; }
  .picks { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
  .picks:empty { display: none; }
  .pick { padding: 12px; border: 0; background: var(--surface); color: var(--text); display: grid; grid-template-columns: 34px minmax(0, 1fr); column-gap: 10px; align-items: center; text-align: left; min-width: 0; }
  .pick:hover, .pick[aria-pressed="true"] { background: var(--selected-surface); }
  .pick[aria-pressed="true"] b { color: var(--accent); }
  .pick .sprite { grid-row: span 2; width: 34px; height: 34px; image-rendering: pixelated; }
  .pick b { font-size: 1.12rem; font-weight: 500; line-height: 1.1; }
  .pick small { font-size: .82rem; line-height: 1.32; color: var(--muted); overflow-wrap: anywhere; }
  .pick .pick-address { grid-column: 1 / -1; margin-top: 6px; color: var(--text); }
  .pager { gap: 12px; justify-content: flex-end; padding-top: 10px; color: var(--muted); font-size: .95rem; }
  .pager button { padding: 4px 8px; }
  .steps { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 18px 0; padding: 0; list-style: none; counter-reset: steps; gap: 20px; }
  .steps li { border-top: 1px solid var(--line); padding: 12px 0; counter-increment: steps; }
  .steps h3 { font: 490 1.1875rem/1.35 var(--pixel); color: var(--accent); margin-bottom: 8px; }
  .steps h3::before { content: "0" counter(steps); font: 500 1rem/1 var(--pixel); color: var(--accent); margin-right: 9px; }
  .steps p { font: 445 1.125rem/1.55 var(--pixel); letter-spacing: .012em; color: color-mix(in srgb, var(--text) 65%, var(--muted)); }
  summary { font-size: .98rem; }

  @media (max-width: 1099px) {
    :scope { width: calc(100% - 64px); }
    .stats > div { padding-inline: 12px; }
    .specimen { padding: 16px; }
    .identity #portrait { width: 64px; height: 64px; }
    .drawing-head { padding-inline: 14px; }
    .drawing-foot { margin-inline: 14px; }
  }
  @media (max-width: 800px) {
    :scope { width: calc(100% - 38px); }
    .tree-intro { align-items: flex-start; flex-direction: column; gap: 16px; }
    .stats > div { border: 0; padding: 0 20px 0 0; }
    .stats dd { font-size: 1.55rem; }
    .views { align-items: flex-start; flex-direction: column; gap: 6px; }
    .tree-exhibit { grid-template-columns: 1fr; }
    .specimen { border: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: minmax(120px, 1fr) minmax(0, 1.25fr); gap: 3px 18px; }
    .specimen .micro, .verifyrow { grid-column: 1 / -1; }
    .identity { grid-column: 1; grid-row: 2 / 4; margin: 8px 0; }
    .routehead { padding: 0; border: 0; grid-area: 4 / 1; }
    #minipath { grid-area: 5 / 1; }
    .meta { grid-column: 2; grid-row: 2 / 6; }
    .meta dt { margin-top: 5px; }
    .verifyrow { margin-top: 8px; }
    .steps { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
    .picks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (max-width: 650px) {
    :scope { width: calc(100% - 32px); }
    .tree-intro { padding: 28px 0 18px; }
    .tree-intro h1 { font-size: clamp(2.4rem, 10vw, 3.8rem); }
    .intro-copy { font-size: .96rem; }
    .stats dt { margin-top: 1px; }
    .directory, .mechanism { padding-top: 28px; }
  }
  @media (max-width: 480px) {
    .switch { width: 100%; }
    .switch button { flex: 1; padding: 7px 3px; }
    .sectionhead { display: block; }
    .sectionhead form { margin-top: 10px; }
    .sectionhead input { flex: 1; }
    .picks { grid-template-columns: minmax(0, 1fr); }
    .steps { grid-template-columns: 1fr; gap: 0; }
    .specimen { padding: 14px 11px; gap: 3px 9px; }
    .identity { flex-wrap: wrap; gap: 7px; }
    .identity #portrait { width: 47px; height: 47px; }
    .identity h2 { font-size: 1.6rem; }
    .tier { font-size: .82rem; }
    .meta dd { font-size: .88rem; }
    .drawing-head { padding: 12px 10px 0; }
    #plotname { font-size: 1.08rem; }
    .drawing-foot { margin-inline: 10px; }
    .legend, .bare { font-size: .77rem; }
    .legend { gap: 8px; }
    .figuretag { font-size: .8rem; }
  }
}

@scope (main#top) {
  .tree-exhibit { grid-template-columns: minmax(0, 1fr) clamp(310px, 30%, 375px); }
  .plot-tools, .zoom-control, .log-head { display:flex; align-items:center; }
  .plot-tools { gap:10px; justify-content:flex-end; flex-wrap:wrap; }
  .zoom-control { padding:2px; gap:4px; border:1px solid var(--control-line); border-radius:4px; background:var(--surface); }
  .zoom-control button { display:grid; place-content:center; color:var(--text); width:36px; height:32px; font:500 1.7rem/1 var(--pixel); padding:0; background:none; border:0; border-radius:2px; }
  .zoom-control button:enabled:hover { color:var(--bg); background:var(--accent); }
  #zoom-level { min-width:3.1em; text-align:center; color:var(--text); font-size:.9rem; }
  .figuretag { border:0; }
  .leaf-references { margin-top:12px; border-top:1px solid var(--line); }
  .leaf-references summary { padding-top:8px; font-size:.94rem; color:var(--muted); }
  .verify { border-color:var(--control-line); }
  .verifyrow { align-items:baseline; }
  .verifyrow button { color:var(--text); }
  #verified { font-size:.89rem; }
  #evidence-terminal { margin-top:13px; background:var(--bg); color:var(--text); border:1px solid var(--control-line); border-radius:4px; min-width:0; }
  .replaying .meta, .replaying .routehead, .replaying #minipath { display:none; }
  .replaying .identity { margin:12px 0; }
  .replaying .identity #portrait { width:52px; height:52px; }
  .replaying .verifyrow { margin-top:0; }
  .log-head { gap:8px; justify-content:space-between; padding:8px 11px; background:var(--surface); border-bottom:1px solid var(--line); font-size:.94rem; }
  .log-scope { font-size:.74rem; letter-spacing:.035em; color:var(--accent); }
  .log-command { padding:9px 11px 5px; color:var(--accent); font-size:.96rem; }
  .log-rows { padding:0 11px; max-height:24rem; overflow:auto; scrollbar-color:var(--control-line) var(--bg); }
  .log-entry { display:grid; grid-template-columns:1.25em minmax(0,1fr); gap:5px; padding:5px 0; border-bottom:1px solid var(--line); }
  .log-index { color:var(--muted); font:.8rem/1.35 var(--pixel); }
  .log-entry dt { font:445 .85rem/1.25 var(--pixel); color:var(--muted); }
  .log-value { font:485 .99rem/1.28 var(--pixel); margin:1px 0 0; color:var(--text); overflow-wrap:anywhere; }
  .log-value.compact { font-size:.85rem; }
  .log-value small { display:block; color:var(--muted); font:.77rem/1.3 var(--pixel); margin-top:1px; }
  .log-value a { text-decoration:underline; text-decoration-color:var(--accent); text-underline-offset:2px; }
  .log-proof { padding:8px 11px 0; color:var(--muted); font-size:.85rem; }
  .log-proof code { display:block; color:var(--accent); }
  .log-proof progress { display:block; appearance:none; width:100%; height:3px; margin:4px 0 6px; border:0; background:var(--line); }
  .log-proof progress::-webkit-progress-bar { background:var(--line); }
  .log-proof progress::-webkit-progress-value { background:var(--accent); }
  .log-proof progress::-moz-progress-bar { background:var(--accent); }
  .log-proof[data-verdict="pass"] { color:var(--accent); }
  .log-proof[data-verdict="fail"] { color:#ffc185; }
  .log-back { margin:6px 11px 8px; font-size:.79rem; }
  @media (prefers-reduced-motion:no-preference) {
    .log-entry { animation:write-log .16s ease-out both; }
  }
  @media (max-width:800px) {
    .tree-exhibit { grid-template-columns:minmax(0,1fr); }
    #evidence-terminal { grid-column:1 / -1; margin-top:4px; }
    .replaying .identity { grid-area:2 / 1; }
    .replaying .verifyrow { grid-area:2 / 2; align-self:center; }
  }
  @media (max-width:540px) {
    .plot-tools { gap:2px; }
    .plot-tools .figuretag { display:none; }
    .drawing-head { gap:6px; }
    #plotname { max-width:13em; }
    .zoom-control button { width:39px; height:39px; }
    #zoom-level { font-size:.82rem; min-width:2.7em; }
    .log-rows { max-height:26rem; }
  }
}
@keyframes write-log {
  from { opacity:.2; transform:translateY(4px); }
  to { opacity:1; transform:translateY(0); }
}

@scope (main#top) {
  #portrait { flex: none; }
  #view-status { margin: auto; padding: 32px 20px; text-align: center; color: var(--muted); }
  .drawing:has(#view-status:not([hidden])) { min-height: 270px; }
  .drawing-foot { flex-wrap: wrap; gap: 8px; }
  .group-nav { display: flex; gap: 8px; align-items: center; font-size: .88rem; }
  .group-nav button { border: 1px solid var(--line); border-radius: 3px; color: var(--accent); }
  .tree-exhibit:has(.specimen[hidden]) { grid-template-columns: minmax(0, 1fr); }
}
