@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-padding-top: calc(var(--masthead-h, 46px) + 14px); }
  html, body { margin: 0; padding: 0; background: var(--bg-canvas); color: var(--text-primary); }
  body { font-family: var(--font-sans); font-size: var(--ts-base); line-height: 1.5; min-block-size: 100dvh; overflow-x: clip; }
  h1, h2, h3, h4, p, dl, dt, dd { margin: 0; }
  button, input, select { font: inherit; color: inherit; }
  button { cursor: pointer; background: none; border: none; padding: 0; }
  :focus-visible { outline: 2px solid var(--accent-primary); outline-offset: 2px; }
  .va-nums { font-variant-numeric: var(--font-nums); font-feature-settings: "tnum" 1, "zero" 1; }
}

@layer shell {
  .bc-plus-btn {
    display: inline-flex; align-items: center; gap: 5px; background: var(--bg-surface); border: 1px solid var(--border-hairline);
    border-radius: var(--r-sm); padding: 3px 9px; font: inherit; color: var(--text-primary); cursor: pointer; white-space: nowrap;
    transition: background-color 0.14s ease, border-color 0.14s ease;
  }
  .bc-plus-btn:hover, .bc-plus-btn:focus-visible, .bc-plus-btn[aria-expanded="true"] { background: var(--bg-sunken); border-color: var(--border-subtle); }
  .bc-plus-quiet { background: transparent; border-color: transparent; }
  .bc-plus-quiet:hover, .bc-plus-quiet:focus-visible, .bc-plus-quiet[aria-expanded="true"] { background: var(--bg-sunken); border-color: var(--border-hairline); }
  .bc-plus-caret { font-size: 11px; color: var(--text-muted); line-height: 1; flex: none; }

  .bc-popover[popover] {
    position: fixed; inset: auto; margin: 0; padding: 6px; min-width: 248px; max-width: min(360px, calc(100vw - 24px));
    max-height: min(65vh, 420px); overflow-y: auto; overscroll-behavior: contain; background: var(--bg-elevated);
    border: 1px solid var(--border-subtle); border-radius: var(--r-md); box-shadow: var(--shadow-md);
    color: var(--text-primary); z-index: 80; display: none; flex-direction: column; gap: 2px;
  }
  .bc-popover[popover]:is(:popover-open, .\:popover-open, .is-open, .is-popover-open) { display: flex; }
  @media (min-width: 768px) {
    @supports (position-area: block-end) {
      #passage-picker-btn { anchor-name: --bc-passage; }
      #passage-picker-popover { position-anchor: --bc-passage; position-area: block-end span-inline-end; position-try-fallbacks: flip-block, flip-inline; margin-block-start: 6px; }
      #source-picker-btn { anchor-name: --bc-source; }
      #source-picker-popover { position-anchor: --bc-source; position-area: block-end span-inline-end; position-try-fallbacks: flip-block, flip-inline; margin-block-start: 6px; }
    }
  }
  .bc-option {
    display: flex; flex-direction: column; align-items: stretch; gap: 2px; inline-size: 100%; min-height: 38px; padding: 7px 10px;
    border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--text-primary);
    text-align: start; cursor: pointer; transition: background-color 0.12s ease, border-color 0.12s ease;
  }
  .bc-option:hover, .bc-option:focus-visible { background: var(--bg-sunken); }
  .bc-option.is-active, .bc-option[aria-selected="true"], .bc-option[aria-current="true"] { background: var(--bg-sunken); border-color: var(--border-subtle); font-weight: 600; }
  .bc-option-main { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-size: var(--ts-sm); line-height: 1.35; }
  .bc-option-sub { font-size: var(--ts-xs); line-height: 1.35; font-weight: 400; color: var(--text-muted); }

  .select-wrap { position: relative; display: inline-flex; align-items: center; min-inline-size: 0; max-inline-size: 100%; }
  .va-select {
    appearance: none; -webkit-appearance: none; inline-size: 100%; min-inline-size: 0; padding-inline: 10px 28px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; background: var(--bg-canvas);
    border: 1px solid var(--border-strong); border-radius: var(--radius-ui); color: var(--text-primary); cursor: pointer;
  }
  .va-select:hover:not(:disabled) { border-color: var(--border-ink); }
  .select-chevron { position: absolute; inset-inline-end: 8px; pointer-events: none; inline-size: 14px; block-size: 14px; color: var(--text-muted); }
  .va-icon { inline-size: 15px; block-size: 15px; flex: none; }
  .va-kicker-icon, .footnote-bar .va-icon { inline-size: 0.875rem; block-size: 0.875rem; flex: none; vertical-align: -0.1em; }

  .info-i-btn {
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    inline-size: 1.5rem; block-size: 1.5rem; min-inline-size: 1.5rem;
    border-radius: 999px; border: 1px solid var(--border-strong);
    background: var(--bg-card); color: var(--text-secondary); cursor: pointer; flex: none; vertical-align: middle;
    transition: border-color 0.14s ease, color 0.14s ease, background-color 0.14s ease;
  }
  .info-i-btn:hover, .info-i-btn:focus-visible, .info-i-btn[aria-expanded="true"] { border-color: var(--accent-primary); color: var(--accent-primary); background: var(--bg-elevated); }
  .info-i-glyph { font-family: var(--font-serif); font-style: italic; font-weight: 700; font-size: 0.875rem; line-height: 1; user-select: none; }
  @media (pointer: coarse) { .info-i-btn::after { content: ""; position: absolute; inset: -0.625rem; } }

  .info-popover {
    position: fixed; inset: auto; margin: 0; z-index: 95;
    inline-size: min(23rem, calc(100dvw - 1rem)); max-block-size: min(28rem, calc(100dvh - 1.5rem));
    overflow-y: auto; overscroll-behavior: contain; background: var(--bg-card); color: var(--text-primary);
    border: 1px solid var(--border-strong); border-radius: var(--radius-lg, 12px);
    padding: 0.9rem 1rem; box-shadow: var(--shadow-lg, var(--shadow-popover));
    display: none; flex-direction: column; gap: 0.5rem;
  }
  .info-popover:is(:popover-open, .\:popover-open, [data-open="true"]) { display: flex; }
  .info-pop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 0.5rem; padding-block-end: 0.45rem; border-block-end: 1px solid var(--border-hairline); }
  .info-pop-title { font-family: var(--font-serif); font-size: var(--ts-md, 0.96rem); font-weight: 700; color: var(--text-primary); line-height: 1.3; }
  .info-pop-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 0.4rem; font-size: var(--ts-xs); color: var(--text-muted); }
  .info-pop-code { font-family: var(--font-mono); font-size: var(--ts-xs); font-weight: 700; padding: 1px 6px; border-radius: var(--radius-pill, 999px); background: var(--lane-cobalt-bg); color: var(--lane-cobalt-fg); }
  .info-pop-breakdown { display: flex; flex-direction: column; gap: 0.25rem; padding: 0.5rem 0.65rem; background: var(--bg-elevated); border-radius: var(--radius-sm); font-size: var(--ts-xs); color: var(--text-secondary); line-height: 1.48; }
  .info-code-key { font-family: var(--font-mono); font-weight: 700; color: var(--text-primary); }
  .info-pop-summary { font-size: var(--ts-sm); color: var(--text-secondary); line-height: 1.52; }
  .info-pop-link {
    display: inline-flex; align-items: center; justify-content: space-between; gap: 0.4rem;
    min-block-size: 2.25rem; padding: 0.35rem 0.7rem; align-self: flex-start;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--bg-elevated); color: var(--accent-primary);
    font-size: var(--ts-sm); font-weight: 600; text-decoration: none;
    transition: border-color 0.14s ease, background-color 0.14s ease;
  }
  .info-pop-link:hover { border-color: var(--accent-primary); background: var(--lane-cobalt-bg); }

  .va-kicker { font-family: var(--font-mono); font-size: var(--ts-xs); font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); }
  .va-meta-inline { font-family: var(--font-mono); font-size: var(--ts-xs); color: var(--text-muted); }
  .va-serial-id {
    font-family: var(--font-mono); font-size: 11px; line-height: 1.2; font-weight: 400;
    color: var(--text-muted); letter-spacing: 0.01em; white-space: nowrap; flex-shrink: 0;
  }

  .va-btn-ghost {
    min-block-size: 30px; padding: 0.22rem 0.62rem; border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); background: var(--bg-canvas); color: var(--text-secondary);
    font-size: var(--ts-xs); font-weight: 600; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  }
  .va-btn-ghost:hover:not(:disabled) { border-color: var(--border-ink); color: var(--text-primary); background: var(--bg-elevated); }
  .va-btn-ghost:disabled { opacity: 0.45; cursor: not-allowed; }
  .va-btn-bridge {
    min-block-size: 30px; padding: 0.22rem 0.65rem; border: 1px solid var(--lane-cobalt-fg);
    border-radius: var(--radius-sm); background: var(--lane-cobalt-bg); color: var(--lane-cobalt-fg);
    font-size: var(--ts-xs); font-weight: 700; display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  }
  .va-btn-bridge:hover { border-color: var(--accent-primary); }

  .va-tb-group { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg-canvas); }
  .va-tb-btn { min-block-size: 28px; padding: 0.16rem 0.55rem; font-size: var(--ts-xs); font-weight: 600; color: var(--text-secondary); border-inline-end: 1px solid var(--border-strong); white-space: nowrap; }
  .va-tb-btn:last-child { border-inline-end: none; }
  .va-tb-btn[aria-pressed="true"] { background: var(--pill-active-bg); color: var(--pill-active-fg); font-weight: 700; }

  /* Open-Page Single-Scroll Spread in Parallel Study; Full-Corpus Time Lens + Inspector */
  .workbench-shell {
    display: grid; grid-template-columns: minmax(0, 1fr);
    inline-size: 100%; min-block-size: calc(100dvh - var(--masthead-h, 46px));
    background: var(--bg-canvas);
  }
  .workbench-shell:not([data-entry="focal"]) .study-sidebar { display: none; }
  .workbench-shell[data-entry="focal"] {
    grid-template-columns: minmax(0, 1fr) var(--sidebar-w, 396px);
    max-inline-size: min(1720px, 100%); margin-inline: auto;
  }
  .stage-main { min-inline-size: 0; display: flex; flex-direction: column; }
  .study-sidebar {
    min-inline-size: 0; border-inline-start: 1px solid var(--border-strong); background: var(--bg-elevated);
    display: flex; flex-direction: column; position: sticky; inset-block-start: var(--masthead-h, 46px);
    block-size: calc(100dvh - var(--masthead-h, 46px)); overflow: hidden;
  }

  dialog.va-modal-sheet[open] {
    display: flex; flex-direction: column; inline-size: min(34rem, calc(100dvw - 1.5rem));
    max-block-size: min(88dvh, 46rem); background: var(--bg-surface);
    border: 1px solid var(--border-strong); border-radius: var(--radius-card); overflow: clip; padding: 0;
  }
  dialog.va-story-modal[open] { inline-size: min(54rem, calc(100dvw - 1.5rem)); max-block-size: min(90dvh, 52rem); }
  dialog.va-study-modal[open] { inline-size: min(46rem, calc(100dvw - 1.5rem)); max-block-size: min(90dvh, 52rem); }
  dialog.va-modal-sheet:modal { overscroll-behavior: contain; }
  dialog.va-modal-sheet::backdrop, dialog.va-footnote-tray::backdrop { background: var(--bg-scrim); }

  dialog.va-footnote-tray {
    margin: auto 0 0 0; inline-size: 100%; max-inline-size: 100%; padding: 0;
    border: none; border-block-start: 1px solid var(--border-strong);
    border-radius: var(--radius-card) var(--radius-card) 0 0;
    background: var(--bg-surface); color: var(--text-primary); box-shadow: var(--shadow-popover); overflow: clip;
  }
  dialog.va-footnote-tray[open] { display: flex; flex-direction: column; max-block-size: min(74dvh, 300px); overscroll-behavior: contain; }
  @media (prefers-reduced-motion: no-preference) {
    dialog.va-footnote-tray[open] { transition: transform 0.18s ease-out, opacity 0.18s ease-out; transform: translateY(0); opacity: 1; }
    @starting-style { dialog.va-footnote-tray[open] { transform: translateY(28px); opacity: 0; } }
  }

  .va-modal-hdr {
    display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap;
    padding: 0.68rem 0.95rem; background: var(--bg-elevated); border-block-end: 1px solid var(--border-strong);
  }
  .va-modal-hdr > div:has(> button) { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
  .va-study-modal .sb-card-hdr { flex-wrap: wrap; }
  .va-modal-body { padding: 0.9rem 0.95rem; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; font-size: var(--ts-sm); line-height: 1.55; }
  .va-modal-actions { display: flex; align-items: center; justify-content: flex-end; gap: 0.5rem; }

  .va-shell-footer {
    padding: 0.5rem max(16px, calc((100% - 1280px) * 0.5 + 16px)) calc(var(--footnote-h, 40px) + 0.6rem);
    border-block-start: 1px solid var(--border-hairline);
    background: var(--bg-canvas); font-size: var(--ts-xs); color: var(--text-muted);
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0.4rem;
  }
  .workbench-shell:not([data-entry="parallel"]) ~ .va-shell-footer { padding-block-end: 0.55rem; }
}

@media print {
  @layer utilities { .study-sidebar, .footnote-bar, .phone-bottom-bar, .va-shell-footer { display: none; } }
}

@layer utilities {
  .hidden,
  [hidden]:not([hidden="until-found"]) { display: none; }
}
