/* SemText — vocabulary base
   Theme-independent structure: layout, spacing, the component rules, and the
   fallback-tier hide/show gating. Reads --sem-* custom properties but
   declares none — pair with a theme file such as themes/minimal-tech-light.css
   for values.

   BOTH AUTHORING FORMS FROM ONE RULE (D10). Every vocabulary selector is
   `:is(sem-x, .sem-x)`: the canonical custom element and its class-form
   alias (conventions Appendix A) render identically, before or without
   the Lit upgrade (conventions §4 rule 3). Element-form children use their
   bare tags (`<statement>`, `<highlight>`, `<name>`); the alias uses
   `.sem-*`. Parameters are read in both spellings where a rule must hold
   with NO script (`[status]`/`[data-status]`); a bare-spelling rule that
   renders `attr(<name>)` is guarded with `:not([data-<name>])` so `data-*`
   wins when both are present (conventions §2), while a value selector
   (`:is([data-status="done"], [status="done"])`) needs no guard — both
   spellings of one value yield one declaration. Rules that only apply once a tier is driving
   the element key on the `data-*` spelling alone, which the fallback core
   mirrors from the bare attribute before any handler runs.

   HIDE RULES ARE GATED (D12). Nothing in this file hides content unless a
   tier marker says a script is driving it: `[data-sem-fallback]` (vanilla
   handler) or `[data-sem-upgraded]` (Lit), on the element that owns the
   behavior — or on `<html>` for rules whose host is deliberately unmarked.
   With no script, every distractor, view, conclusion and body renders. */

body { margin: 0; }
/* Paint the element that carries the theme, not <body>: themes may mount
   on an embedded subtree (data-sem-theme on a pane div), where the tokens
   are invisible at body scope — an unguarded body rule then resolves
   var(--sem-fg) to nothing and resets page text to UA black over the
   host's dark background. [data-sem-theme] covers html/body mounts too. */
[data-sem-theme] { background: var(--sem-bg); color: var(--sem-fg); }
:is(sem-enhanced-document, .sem-enhanced-document) { font-family: system-ui, sans-serif; line-height: 1.6; }

/* Custom elements are inline by default; the vocabulary is block-level. */
sem-enhanced-document, sem-agent, sem-audiences, sem-note, sem-facts, sem-fact,
sem-details, sem-detail, sem-procedure, sem-step, sem-properties, sem-property,
sem-views, sem-view, sem-reveal, sem-progress,
sem-chronology, sem-event, sem-code, sem-references, sem-reference, sem-reader, sem-table, sem-source, sem-md,
sem-data-visualizer, sem-data-source,
sem-agent > :is(name, bio, instructions), sem-fact > :is(statement, conclusion, incorrect-statement) { display: block; }
/* The audience fallback hides with the native attribute; keep it winning
   over the block rule above for element forms. */
:is(sem-enhanced-document, .sem-enhanced-document) [hidden] { display: none !important; }

/* motion — smooth anchor scrolling only for readers who did not opt out */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  :is(highlight, .sem-highlight, .sem-occluded, .sem-revealed, .sem-target) { transition: none !important; animation: none !important; }
}

/* deep-link target (transient runtime class set by fallback/target) */
.sem-target { outline: 2px solid var(--sem-accent); outline-offset: 4px; border-radius: 8px;
  transition: outline-color .6s; }

/* metadata */
:is(sem-agent, .sem-agent) { border: 1px solid var(--sem-border); border-radius: 12px;
  padding: 1rem; margin: 1.5rem 0; background: var(--sem-surface); }
:is(sem-agent, .sem-agent) :is(name, .sem-agent-name) { font-weight: 600; }
:is(sem-agent, .sem-agent) :is(bio, .sem-agent-bio) { color: var(--sem-muted); margin: .25rem 0; }
:is(sem-agent, .sem-agent) :is(instructions, .sem-agent-instructions) { font-size: .875rem; margin: .25rem 0 0; }

/* audiences — profile declarations render as a muted metadata strip */
:is(sem-audiences, .sem-audiences) { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center;
  margin: 1rem 0; font-size: .8rem; color: var(--sem-muted); }
:is(sem-audiences, .sem-audiences)::before { content: "audiences ·"; letter-spacing: .05em; text-transform: uppercase; font-size: .7rem; }
:is(sem-profile, .sem-profile) { display: inline-block; border: 1px solid var(--sem-border); border-radius: 999px;
  padding: .1rem .6rem; background: var(--sem-surface); }
:is(sem-profile, .sem-profile)::before { content: attr(id); }
:is(sem-profile, .sem-profile)[data-label]::before { content: attr(data-label); }
:is(sem-profile, .sem-profile)[label]:not([data-label])::before { content: attr(label); }

/* note */
:is(sem-note, .sem-note) { border-left: 4px solid var(--sem-note-info); border-radius: 8px;
  padding: .75rem 1rem; margin: 1rem 0; background: var(--sem-surface); }
:is(sem-note, .sem-note):is([data-variant="warning"], [variant="warning"]) { border-color: var(--sem-note-warning); }
:is(sem-note, .sem-note):is([data-variant="tip"], [variant="tip"])     { border-color: var(--sem-note-tip); }
:is(sem-note, .sem-note):is([data-variant="danger"], [variant="danger"])  { border-color: var(--sem-note-danger); }
:is(sem-note, .sem-note)[variant]:not([data-variant])::before { content: attr(variant) " · "; }
:is(sem-note, .sem-note):is([data-variant], [variant])::before { content: attr(data-variant) " · ";
  font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--sem-muted); display: block; }
:is(sem-note, .sem-note):is([data-sem-fallback], [data-sem-upgraded])[collapsed] > .sem-note-body { display: none; }
:is(sem-note, .sem-note)[collapsed] .sem-note-summary { cursor: pointer; color: var(--sem-accent); }
/* view-as="margin": floated aside on wide viewports, inline callout
   otherwise. Floats INSIDE the container by default; a document whose
   wrapper has a gutter can push it out with
   --sem-margin-offset: calc(-1 * (var(--sem-margin-width) + 1.5rem)). */
@media (min-width: 64rem) {
  :is(sem-note, .sem-note):is([data-view-as="margin"], [view-as="margin"]) { float: right; clear: right;
    width: var(--sem-margin-width, 14rem);
    margin: 0 var(--sem-margin-offset, 0) 1rem 1.5rem;
    font-size: .875rem; }
}

/* facts */
:is(sem-facts, .sem-facts) { margin: 1.5rem 0; }
.sem-facts-chrome { display: flex; gap: .5rem; align-items: center; margin: .5rem 0; }
.sem-facts-chrome button { font: inherit; border: 1px solid var(--sem-border); background: var(--sem-surface);
  color: var(--sem-fg); border-radius: 8px; padding: .25rem .75rem; cursor: pointer; }
.sem-facts-meter { color: var(--sem-muted); font-size: .875rem; }
:is(sem-fact, .sem-fact) { border: 1px solid var(--sem-border); border-radius: 12px;
  padding: 1rem; margin: .75rem 0; background: var(--sem-surface); }
:is(sem-fact, .sem-fact) :is(statement, .sem-statement) { font-weight: 600; }
:is(sem-fact, .sem-fact) :is(conclusion, .sem-conclusion) { margin: .5rem 0 0; color: var(--sem-muted); }
/* distractors are quiz decoys: hidden once a script drives the document,
   labelled and readable when none does (D12) */
:root:is([data-sem-fallback], [data-sem-upgraded]) :is(sem-fact, .sem-fact) :is(incorrect-statement, .incorrect-statement) { display: none; }
:root:not([data-sem-fallback], [data-sem-upgraded]) :is(sem-fact, .sem-fact) :is(incorrect-statement, .incorrect-statement) {
  margin: .5rem 0 0; color: var(--sem-muted); font-size: .875rem; }
:root:not([data-sem-fallback], [data-sem-upgraded]) :is(sem-fact, .sem-fact) :is(incorrect-statement, .incorrect-statement)::before {
  content: "incorrect statement · "; font-variant-caps: all-small-caps; letter-spacing: .05em; }
/* quiz + flashcards (hide rules gated on the tier marker — JS-off stays readable) */
:is(sem-facts, .sem-facts):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="quiz"] :is(sem-fact, .sem-fact) :is(conclusion, .sem-conclusion) { display: none; }
:is(sem-facts, .sem-facts):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="flashcards"] :is(sem-fact, .sem-fact) { display: none; cursor: pointer;
  min-height: 8rem; position: relative; }
:is(sem-facts, .sem-facts):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="flashcards"] :is(sem-fact, .sem-fact).sem-current { display: block; }
:is(sem-facts, .sem-facts):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="flashcards"] :is(sem-fact, .sem-fact) :is(conclusion, .sem-conclusion) { visibility: hidden; }
:is(sem-facts, .sem-facts):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="flashcards"] :is(sem-fact, .sem-fact).sem-flipped :is(conclusion, .sem-conclusion) { visibility: visible; }
.sem-quiz-options { display: grid; gap: .5rem; margin-top: .75rem; }
.sem-quiz-options button { font: inherit; text-align: left; border: 1px solid var(--sem-border);
  background: var(--sem-surface); color: var(--sem-fg); border-radius: 8px;
  padding: .5rem .75rem; cursor: pointer; }
.sem-quiz-options button[data-correct="true"].sem-answered { border-color: var(--sem-correct); }
.sem-quiz-options button.sem-wrong-pick { border-color: var(--sem-wrong); }
.sem-score { font-size: .875rem; color: var(--sem-muted); }

/* details + highlight */
:is(sem-details, .sem-details) { margin: 1rem 0; }
:is(sem-detail, .sem-detail) { border: 1px solid var(--sem-border); border-radius: 12px;
  padding: 1rem; margin: .75rem 0; background: var(--sem-surface); cursor: pointer; }
:is(highlight, .sem-highlight) { font-style: normal; background: color-mix(in srgb, var(--sem-accent) 18%, transparent);
  border-radius: 4px; padding: 0 .2em; }
.sem-occluded { color: transparent; background: var(--sem-occluded); border-radius: 4px;
  cursor: pointer; user-select: none; transition: color .15s; min-width: 3ch; display: inline-block; }
.sem-revealed { color: inherit; background: color-mix(in srgb, var(--sem-accent) 18%, transparent); }

/* procedure */
:is(sem-procedure, .sem-procedure) { margin: 1rem 0; }
:is(sem-step, .sem-step) { counter-increment: sem-step; border-left: 3px solid var(--sem-border);
  padding: .5rem .75rem .5rem 2.25rem; margin: .25rem 0; position: relative;
  background: var(--sem-surface); border-radius: 0 8px 8px 0; }
:is(sem-step, .sem-step)::before { content: counter(sem-step); position: absolute; left: .6rem;
  top: .5rem; font-size: .75rem; color: var(--sem-muted); }
:is(sem-step, .sem-step):is([data-status="done"], [status="done"])::after { content: " ✓"; color: var(--sem-correct); }
:is(sem-step, .sem-step):is([data-status="current"], [status="current"]) { border-left-color: var(--sem-accent); }
:is(sem-step, .sem-step):is([data-status="current"], [status="current"])::after { content: " →"; color: var(--sem-accent); }
:is(sem-step, .sem-step):is([data-status="blocked"], [status="blocked"]) { border-left-color: var(--sem-wrong); color: var(--sem-muted); }
:is(sem-step, .sem-step):is([data-status="blocked"], [status="blocked"])::after { content: " ⛔"; color: var(--sem-wrong); }

/* properties */
:is(sem-properties, .sem-properties) { margin: 1rem 0; border: 1px solid var(--sem-border);
  border-radius: 12px; overflow: hidden; background: var(--sem-surface); }
:is(sem-property, .sem-property) { display: grid; grid-template-columns: minmax(8rem, 1fr) 2fr;
  gap: .75rem; padding: .5rem .9rem; }
:is(sem-property, .sem-property):nth-child(even) { background: color-mix(in srgb, var(--sem-border) 40%, transparent); }
:is(sem-property, .sem-property)::before { content: attr(data-key); color: var(--sem-muted);
  font-variant-caps: all-small-caps; }
:is(sem-property, .sem-property)[key]:not([data-key])::before { content: attr(key); }
/* narrow viewports: key above value instead of a squeezed value column */
@media (max-width: 34rem) {
  :is(sem-property, .sem-property) { grid-template-columns: minmax(0, 1fr); gap: .15rem; overflow-wrap: break-word; }
}

/* properties — glossary view (R/W1): term over definition; anchors get a
   preview from the reading bundle; :target highlight works with no script */
:is(sem-properties, .sem-properties):is([data-view-as="glossary"], [view-as="glossary"]) :is(sem-property, .sem-property) {
  display: block; padding: .6rem .9rem; }
:is(sem-properties, .sem-properties):is([data-view-as="glossary"], [view-as="glossary"]) :is(sem-property, .sem-property)::before {
  display: block; font-weight: 600; font-variant-caps: normal; color: var(--sem-fg); margin-bottom: .15rem; }
:is(sem-property, .sem-property):target { background: color-mix(in srgb, var(--sem-accent) 12%, transparent); }
:is(sem-enhanced-document, .sem-enhanced-document) dfn { font-style: normal; font-weight: 600; }
/* in-document links read against either colour scheme (citations, terms) */
:is(sem-enhanced-document, .sem-enhanced-document) a { color: var(--sem-accent); }
.sem-properties-ref { text-decoration: underline dotted; text-underline-offset: .15em; }

/* chronology — CSS-only timeline (pattern: procedure). The rail is the
   container's left border; each event's own left border carries status.
   Date label: the authored <time> child, else attr(data-when) via ::before. */
:is(sem-chronology, .sem-chronology) { margin: 1.5rem 0; padding-left: 1.25rem;
  border-left: 2px solid var(--sem-border); }
:is(sem-chronology, .sem-chronology):is([data-view-as="list"], [view-as="list"]) { border-left: 0; padding-left: 0; }
:is(sem-event, .sem-event) { position: relative; margin: 0 0 .75rem; padding: .5rem .9rem;
  background: var(--sem-surface); border: 1px solid var(--sem-border);
  border-left: 3px solid var(--sem-border); border-radius: 0 10px 10px 0; }
:is(sem-event, .sem-event) > time { display: block; font-size: .75rem; color: var(--sem-muted);
  font-variant-caps: all-small-caps; letter-spacing: .05em; }
:is(sem-event, .sem-event):not(:has(time))::before { content: attr(data-when); display: block;
  font-size: .75rem; color: var(--sem-muted); font-variant-caps: all-small-caps; letter-spacing: .05em; }
:is(sem-event, .sem-event):not(:has(time)):is([data-until], [until])::before { content: attr(data-when) " – " attr(data-until); }
:is(sem-event, .sem-event):not(:has(time))[when]:not([data-when])::before { content: attr(when); }
:is(sem-event, .sem-event):not(:has(time))[when][until]:not([data-when])::before { content: attr(when) " – " attr(until); }
:is(sem-event, .sem-event):is([data-status="done"], [status="done"]) { border-left-color: var(--sem-correct); }
:is(sem-event, .sem-event):is([data-status="done"], [status="done"])::after { content: " ✓"; color: var(--sem-correct); }
:is(sem-event, .sem-event):is([data-status="current"], [status="current"]) { border-left-color: var(--sem-accent); }
:is(sem-event, .sem-event):is([data-status="current"], [status="current"])::after { content: " →"; color: var(--sem-accent); }
:is(sem-event, .sem-event):is([data-status="blocked"], [status="blocked"]) { border-left-color: var(--sem-wrong); color: var(--sem-muted); }
:is(sem-event, .sem-event):is([data-status="blocked"], [status="blocked"])::after { content: " ⛔"; color: var(--sem-wrong); }

/* code — verbatim listing; chrome (reading bundle / Lit) is the first
   child; JS-off the filename is a CSS caption instead */
:is(sem-code, .sem-code) { margin: 1.25rem 0; border: 1px solid var(--sem-border); border-radius: 12px;
  background: var(--sem-surface); overflow: hidden; }
:is(sem-code, .sem-code) pre { margin: 0; padding: .9rem 1rem; overflow-x: auto; font-size: .875rem;
  line-height: 1.5; tab-size: 2; }
:is(sem-code, .sem-code):is([data-wrap], [wrap]) pre { white-space: pre-wrap; overflow-wrap: anywhere; }
:is(sem-code, .sem-code):not(:has(> .sem-code-chrome)):is([data-filename], [filename])::before {
  content: attr(data-filename); display: block; padding: .4rem 1rem; font-size: .75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--sem-muted);
  border-bottom: 1px solid var(--sem-border); }
:is(sem-code, .sem-code):not(:has(> .sem-code-chrome))[filename]:not([data-filename])::before { content: attr(filename); }
.sem-code-chrome { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .4rem .75rem;
  border-bottom: 1px solid var(--sem-border); font-size: .75rem; color: var(--sem-muted); }
.sem-code-filename { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.sem-code-lang { border: 1px solid var(--sem-border); border-radius: 999px; padding: 0 .5rem;
  text-transform: uppercase; letter-spacing: .05em; font-size: .7rem; }
.sem-code-chrome button { border: 1px solid var(--sem-border); background: var(--sem-bg); color: var(--sem-fg);
  border-radius: 6px; padding: .15rem .6rem; cursor: pointer; font: inherit; }
.sem-code-chrome button:first-of-type { margin-left: auto; }
.sem-code-chrome button[aria-pressed="true"] { border-color: var(--sem-accent); color: var(--sem-accent); }
.sem-code-status { min-width: 3.5rem; font-size: .7rem; }
mark.sem-code-line { display: inline-block; width: 100%; color: inherit;
  background: color-mix(in srgb, var(--sem-accent) 14%, transparent);
  box-shadow: -1rem 0 0 color-mix(in srgb, var(--sem-accent) 14%, transparent); }

/* markdown — the element's text is Markdown; the Markdown bundle (or the
   Lit wrapper) renders it into .sem-md-body and keeps the normalised
   source in a sem-code fence (.sem-md-raw). With no tier marker nothing
   was generated, so the source itself reads as pre-wrapped text. */
:is(sem-md, .sem-md) { margin: 1.25rem 0; border: 1px solid var(--sem-border); border-radius: 12px;
  background: var(--sem-surface); overflow: hidden; }
:is(sem-md, .sem-md):not([data-sem-fallback], [data-sem-upgraded]) { white-space: pre-wrap; overflow-wrap: anywhere;
  padding: .9rem 1rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .875rem; line-height: 1.5; }
:is(sem-md, .sem-md):not([data-sem-fallback], [data-sem-upgraded]):is([data-label], [label])::before {
  content: attr(data-label); display: block; margin: -.9rem -1rem .6rem; padding: .4rem 1rem; font-size: .75rem;
  font-family: system-ui, sans-serif; color: var(--sem-muted); border-bottom: 1px solid var(--sem-border); white-space: normal; }
:is(sem-md, .sem-md):not([data-sem-fallback], [data-sem-upgraded])[label]:not([data-label])::before { content: attr(label); }
.sem-md-chrome { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .4rem .75rem;
  border-bottom: 1px solid var(--sem-border); font-size: .75rem; color: var(--sem-muted); }
.sem-md-label { font-weight: 600; color: var(--sem-fg); }
.sem-md-chrome button { border: 1px solid var(--sem-border); background: var(--sem-bg); color: var(--sem-fg);
  border-radius: 6px; padding: .15rem .6rem; cursor: pointer; font: inherit; }
.sem-md-chrome button:first-of-type { margin-left: auto; }
.sem-md-chrome button[aria-pressed="true"] { border-color: var(--sem-accent); color: var(--sem-accent); }
.sem-md-status { min-width: 3.5rem; font-size: .7rem; }
.sem-md-body { padding: .75rem 1rem; }
.sem-md-body > :first-child { margin-top: 0; }
.sem-md-body > :last-child { margin-bottom: 0; }
.sem-md-body table { border-collapse: collapse; width: 100%; margin: .75rem 0; font-size: .9rem; }
.sem-md-body th, .sem-md-body td { border: 1px solid var(--sem-border); padding: .4rem .7rem; text-align: left; vertical-align: top; }
.sem-md-body th { font-variant-caps: all-small-caps; letter-spacing: .05em; color: var(--sem-muted); }
.sem-md-body blockquote { margin: .75rem 0; padding: .25rem 1rem; border-left: 4px solid var(--sem-border); color: var(--sem-muted); }
.sem-md-body pre { margin: .75rem 0; padding: .75rem 1rem; border: 1px solid var(--sem-border); border-radius: 8px;
  background: var(--sem-bg); overflow-x: auto; font-size: .875rem; line-height: 1.5; }
.sem-md-body :not(pre) > code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em;
  background: var(--sem-bg); border: 1px solid var(--sem-border); border-radius: 4px; padding: 0 .3em; }
.sem-md-body hr { border: 0; border-top: 1px solid var(--sem-border); margin: 1rem 0; }
.sem-md-body img { max-width: 100%; height: auto; }
.sem-md-raw > :is(sem-code, .sem-code) { margin: 0; border: 0; border-radius: 0; }
/* the two views (hide rules gated on the tier marker; JS-off neither exists) */
:is(sem-md, .sem-md):is([data-sem-fallback], [data-sem-upgraded]):not([data-view-as="raw"]) > .sem-md-raw { display: none; }
:is(sem-md, .sem-md):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="raw"] > .sem-md-body { display: none; }

/* references — CSS-counter numbering in every tier; previews and
   backlinks come from the reading bundle */
:is(sem-references, .sem-references) { margin: 2rem 0 1rem; padding-top: .75rem;
  border-top: 1px solid var(--sem-border); font-size: .875rem; counter-reset: sem-reference; }
:is(sem-reference, .sem-reference) { counter-increment: sem-reference; position: relative;
  padding: .2rem 0 .2rem 2.25rem; margin: .25rem 0; border-radius: 6px; }
:is(sem-reference, .sem-reference)::before { content: counter(sem-reference) "."; position: absolute;
  left: .5rem; color: var(--sem-muted); }
:is(sem-references, .sem-references):is([data-kind="bibliography"], [kind="bibliography"]) :is(sem-reference, .sem-reference) {
  padding-left: 2.75rem; }
:is(sem-reference, .sem-reference):target { background: color-mix(in srgb, var(--sem-accent) 12%, transparent); }
.sem-references-backlinks { margin-left: .4rem; }
.sem-references-backlinks a, .sem-references-link { text-decoration: none; margin-left: .3rem; color: var(--sem-accent); }
.sem-references-ref { text-decoration: none; border-bottom: 1px dotted var(--sem-accent); }

/* popover — one preview surface per document (src/shared/popover.ts);
   native `popover` where supported, fixed div otherwise. Author rules
   override the UA `inset: 0; margin: auto` of an open popover. */
.sem-popover { position: fixed; inset: auto; margin: 0; max-width: min(24rem, calc(100vw - 2rem));
  font-family: system-ui, sans-serif;
  padding: .6rem .8rem; border: 1px solid var(--sem-border); border-radius: 10px;
  background: var(--sem-surface); color: var(--sem-fg); box-shadow: 0 8px 24px rgba(0, 0, 0, .15);
  font-size: .875rem; line-height: 1.45; z-index: 50; }
.sem-popover[hidden] { display: none; }
.sem-popover-term { display: block; font-variant-caps: all-small-caps; letter-spacing: .05em; color: var(--sem-muted); }

/* views */
:is(sem-views, .sem-views) { margin: 1.5rem 0; }
.sem-views-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--sem-border); }
.sem-views-tabs button { font: inherit; border: 1px solid transparent; border-bottom: none;
  background: none; color: var(--sem-muted); border-radius: 8px 8px 0 0;
  padding: .4rem .9rem; cursor: pointer; }
.sem-views-tabs button[aria-selected="true"] { color: var(--sem-accent);
  border-color: var(--sem-border); background: var(--sem-surface); }
:is(sem-view, .sem-view) { border: 1px solid var(--sem-border); border-top: none;
  border-radius: 0 0 12px 12px; padding: 1rem; background: var(--sem-surface); }
/* one view at a time only while a script owns the tabs (D12); otherwise
   every view is stacked under its name */
:is(sem-views, .sem-views):is([data-sem-fallback], [data-sem-upgraded]) :is(sem-view, .sem-view) { display: none; }
:is(sem-views, .sem-views):is([data-sem-fallback], [data-sem-upgraded]) :is(sem-view, .sem-view)[data-active] { display: block; }
:is(sem-views, .sem-views):not([data-sem-fallback], [data-sem-upgraded]) :is(sem-view, .sem-view) { border-top: 1px solid var(--sem-border);
  border-radius: 12px; margin: .5rem 0; }
:is(sem-views, .sem-views):not([data-sem-fallback], [data-sem-upgraded]) :is(sem-view, .sem-view)::before { content: attr(data-name);
  display: block; font-variant-caps: all-small-caps; letter-spacing: .05em; color: var(--sem-muted); margin-bottom: .25rem; }
:is(sem-views, .sem-views):not([data-sem-fallback], [data-sem-upgraded]) :is(sem-view, .sem-view)[name]:not([data-name])::before { content: attr(name); }

/* reveal */
:is(sem-reveal, .sem-reveal) { margin: 1rem 0; border: 1px solid var(--sem-border);
  border-radius: 12px; background: var(--sem-surface); }
:is(sem-reveal, .sem-reveal):is([data-summary], [summary])::before { content: attr(data-summary);
  display: block; font-variant-caps: all-small-caps; color: var(--sem-muted);
  padding: .6rem .9rem 0; }
:is(sem-reveal, .sem-reveal)[summary]:not([data-summary])::before { content: attr(summary); }
:is(sem-reveal, .sem-reveal) .sem-reveal-body { padding: .5rem .9rem .75rem; }
:is(sem-reveal, .sem-reveal) details:not([open]) .sem-reveal-body { display: none; }
/* Once a script has built the <details>, its <summary> carries the
   question; the ::before caption above is the JS-off rendering of the same
   string and would duplicate it. Gated on the tier marker like every other
   rule that depends on a script having run (D12). */
:is(sem-reveal, .sem-reveal):is([data-sem-fallback], [data-sem-upgraded])[data-summary]::before { content: none; }
:is(sem-reveal, .sem-reveal) summary { padding: .6rem .9rem; cursor: pointer; font-weight: 600; }
:is(sem-reveal, .sem-reveal) summary::marker { color: var(--sem-muted); }

/* progress */
:is(sem-progress, .sem-progress) { margin: 1rem 0; color: var(--sem-muted); font-size: .875rem; }
/* JS-off: the meter is text only — `label :: value` from the attributes
   (spec/schema/sem-progress.md); no fake bar. An empty element with no
   tier marker otherwise rendered nothing at all. Plain attr() only: the
   fallback-argument form is not yet universal. */
:is(sem-progress, .sem-progress):not([data-sem-fallback], [data-sem-upgraded]):is([data-value], [value])::before {
  content: "progress :: " attr(data-value); }
:is(sem-progress, .sem-progress):not([data-sem-fallback], [data-sem-upgraded])[value]:not([data-value])::before {
  content: "progress :: " attr(value); }
:is(sem-progress, .sem-progress):not([data-sem-fallback], [data-sem-upgraded])[data-label][data-value]::before {
  content: attr(data-label) " :: " attr(data-value); }
:is(sem-progress, .sem-progress):not([data-sem-fallback], [data-sem-upgraded])[label][value]:not([data-value])::before {
  content: attr(label) " :: " attr(value); }
/* status pairs with the value (schema: done ⇔ 1); same catalog as sem-step */
:is(sem-progress, .sem-progress):is([data-status="done"], [status="done"])::after { content: " ✓"; color: var(--sem-correct); }
:is(sem-progress, .sem-progress) .sem-progress-track { display: block; height: .5rem;
  background: color-mix(in srgb, var(--sem-border) 60%, transparent);
  border-radius: 999px; overflow: hidden; margin-top: .25rem; }
:is(sem-progress, .sem-progress) .sem-progress-fill { display: block; height: 100%;
  background: var(--sem-accent); border-radius: 999px; }

/* reader — one chrome per document (R/W2, spec/schema/sem-reader.md).
   Sticky bar; the outline drops below it as a panel. The sticky rule is
   gated on the tier marker (:is([data-sem-fallback], [data-sem-upgraded]))
   a script sets when it wires the element, same as every other hide rule
   (D12). With no script running neither marker is present, so the element
   never matches this selector: it holds only an authored nav (or nothing)
   and stays static — there is no chrome to pin. */
:is(sem-reader, .sem-reader):is([data-sem-fallback], [data-sem-upgraded]) { position: sticky; top: 0; z-index: 40; }
.sem-reader-chrome { position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: .4rem;
  padding: .45rem .75rem .55rem; background: var(--sem-surface); border-bottom: 1px solid var(--sem-border);
  font-family: system-ui, sans-serif; font-size: .8rem; color: var(--sem-muted); }
.sem-reader-chrome button, .sem-reader-chrome select { font: inherit; color: var(--sem-fg);
  background: var(--sem-bg); border: 1px solid var(--sem-border); border-radius: 6px;
  padding: .2rem .55rem; cursor: pointer; }
.sem-reader-chrome button[aria-pressed="true"], .sem-reader-chrome button[aria-expanded="true"] {
  border-color: var(--sem-accent); color: var(--sem-accent); }
.sem-reader-chrome button:disabled { opacity: .45; cursor: default; }
.sem-reader-chrome > select { margin-left: auto; }
.sem-reader-chrome > select ~ select { margin-left: 0; }
.sem-reader-progress { position: absolute; left: 0; right: 0; bottom: -1px; height: 3px;
  background: color-mix(in srgb, var(--sem-border) 60%, transparent); }
.sem-reader-progress-fill { display: block; height: 100%; width: 0; background: var(--sem-accent);
  transition: width .12s linear; }
:is(sem-reader, .sem-reader) > nav[aria-label="Contents"] { font-family: system-ui, sans-serif; font-size: .875rem; }
:is(sem-reader, .sem-reader)[data-sem-fallback] > nav[aria-label="Contents"],
:is(sem-reader, .sem-reader)[data-sem-upgraded] > nav[aria-label="Contents"] {
  position: absolute; left: 0; right: 0; top: 100%; max-height: min(60vh, 24rem); overflow: auto;
  padding: .6rem 1rem; background: var(--sem-surface); border-bottom: 1px solid var(--sem-border);
  box-shadow: 0 12px 24px rgba(0, 0, 0, .12); }
:is(sem-reader, .sem-reader) > nav[aria-label="Contents"][hidden] { display: none; }
:is(sem-reader, .sem-reader) > nav :is(ol, ul) { margin: 0; padding-left: 1.1rem; }
:is(sem-reader, .sem-reader) > nav li { margin: .15rem 0; }
:is(sem-reader, .sem-reader) > nav a { color: var(--sem-fg); text-decoration: none; }
:is(sem-reader, .sem-reader) > nav a:hover { text-decoration: underline; }
:is(sem-reader, .sem-reader) > nav a[aria-current="location"] { color: var(--sem-accent); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .sem-reader-progress-fill { transition: none; } }
/* Once a script pins the bar, in-document targets (outline links, deep
   links, citations, glossary terms) stop short of it instead of landing
   underneath; --sem-reader-offset = the bar's height plus a little air. */
:is(sem-reader, .sem-reader):is([data-sem-fallback], [data-sem-upgraded]) ~ * :is(h1, h2, h3, h4, h5, h6, [id]),
:is(sem-reader, .sem-reader):is([data-sem-fallback], [data-sem-upgraded]) ~ [id] {
  scroll-margin-top: var(--sem-reader-offset, 4.5rem); }

/* reader-driven document state on <html> (session facts, never extracted) */
:root[data-sem-type="s"] :is(sem-enhanced-document, .sem-enhanced-document) { font-size: .9rem; }
:root[data-sem-type="l"] :is(sem-enhanced-document, .sem-enhanced-document) { font-size: 1.15rem; }
:root[data-sem-font="serif"] :is(sem-enhanced-document, .sem-enhanced-document) {
  font-family: Charter, Georgia, "Times New Roman", serif; }
/* color-scheme for [data-color-mode] lives in the theme file, beside its tokens */
/* focus mode: page chrome outside the root wrapper goes away, the measure
   narrows, margin notes fall back inline */
:root[data-sem-mode="focus"] body > :not(:is(sem-enhanced-document, .sem-enhanced-document), script, style, .sem-popover):not(:has(:is(sem-enhanced-document, .sem-enhanced-document))) { display: none; }
:root[data-sem-mode="focus"] :is(sem-enhanced-document, .sem-enhanced-document) {
  max-width: var(--sem-focus-measure, 42rem); margin-inline: auto; line-height: 1.75; }
:root[data-sem-mode="focus"] :is(sem-note, .sem-note):is([data-view-as="margin"], [view-as="margin"]) { float: none; width: auto; margin: 1rem 0; }

/* source — rendered/source section wrapper (spec/schema/sem-source.md).
   The fence is display:none until the reader asks for it; the hide rule
   for the rendered children is gated on a tier marker and screen-only,
   so JS-off and print always show the rendered content. */
.sem-source-chrome { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; margin: 1.5rem 0 .5rem;
  font-family: system-ui, sans-serif; font-size: .75rem; color: var(--sem-muted); }
.sem-source-label { margin-right: auto; text-transform: uppercase; letter-spacing: .05em; }
.sem-source-chrome button { font: inherit; color: var(--sem-fg); background: var(--sem-bg);
  border: 1px solid var(--sem-border); padding: .2rem .6rem; cursor: pointer; }
.sem-source-chrome button:first-of-type { border-radius: 6px 0 0 6px; }
.sem-source-chrome button:last-of-type { border-radius: 0 6px 6px 0; margin-left: -1px; }
.sem-source-chrome button[aria-pressed="true"] { border-color: var(--sem-accent); color: var(--sem-accent);
  position: relative; z-index: 1; }
.sem-source-fence { display: none; }
.sem-source-fence > :is(sem-code, .sem-code) { margin-top: 0; }
@media screen {
  :is(sem-source, .sem-source):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="source"] > .sem-source-fence { display: block; }
  :is(sem-source, .sem-source):is([data-sem-fallback], [data-sem-upgraded])[data-view-as="source"] > :not(.sem-source-chrome, .sem-source-fence) { display: none; }
}

/* table — authored <table> is the contract (R/W2, spec/schema/sem-table.md);
   sticky header and comparison first column are CSS in every tier */
:is(sem-table, .sem-table) { margin: 1.25rem 0; overflow-x: auto; border: 1px solid var(--sem-border);
  border-radius: 12px; background: var(--sem-surface); }
:is(sem-table, .sem-table) table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
:is(sem-table, .sem-table) caption { text-align: left; padding: .6rem .9rem 0; font-weight: 600; caption-side: top; }
:is(sem-table, .sem-table) th, :is(sem-table, .sem-table) td { padding: .45rem .9rem; text-align: left;
  border-bottom: 1px solid var(--sem-border); vertical-align: top; }
:is(sem-table, .sem-table) th { font-variant-caps: all-small-caps; letter-spacing: .05em; color: var(--sem-muted);
  background: var(--sem-surface); }
:is(sem-table, .sem-table) tbody tr:last-child :is(th, td) { border-bottom: 0; }
:is(sem-table, .sem-table):is([data-sticky], [sticky]) thead th { position: sticky; top: var(--sem-reader-offset, 0); z-index: 1; }
:is(sem-table, .sem-table) table:is([data-kind="comparison"], [kind="comparison"]) :is(th, td):first-child,
:is(sem-table, .sem-table):is([data-kind="comparison"], [kind="comparison"]) :is(th, td):first-child,
:is(sem-enhanced-document, .sem-enhanced-document) > table:is([data-kind="comparison"], [kind="comparison"]) :is(th, td):first-child {
  position: sticky; left: 0; background: var(--sem-surface); z-index: 1; }
:is(sem-table, .sem-table):is([data-sticky], [sticky]) table:is([data-kind="comparison"], [kind="comparison"]) thead th:first-child { z-index: 2; }
.sem-table-chrome { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; padding: .5rem .9rem;
  border-bottom: 1px solid var(--sem-border); font-size: .8rem; color: var(--sem-muted); }
.sem-table-chrome:not(:has(input)):not(:has(.sem-table-status:not(:empty))) { display: none; }
.sem-table-filter { font: inherit; color: var(--sem-fg); background: var(--sem-bg); border: 1px solid var(--sem-border);
  border-radius: 6px; padding: .25rem .5rem; min-width: 12rem; }
.sem-table-status { min-height: 1em; }
.sem-table-sort { all: unset; font: inherit; cursor: pointer; display: inline-block; padding-right: 1.1em; position: relative; }
.sem-table-sort::after { content: "↕"; position: absolute; right: 0; opacity: .5; }
th[aria-sort="ascending"] .sem-table-sort::after { content: "↑"; opacity: 1; color: var(--sem-accent); }
th[aria-sort="descending"] .sem-table-sort::after { content: "↓"; opacity: 1; color: var(--sem-accent); }
.sem-table-sort:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 2px; border-radius: 4px; }

/* data visualizer — native table rendered from an inline data source
   (spec/data-visualizer.md, phase 1); mirrors the sem-table base */
:is(sem-data-visualizer, .sem-data-visualizer) { margin: 1.25rem 0; }
:is(sem-data-source, .sem-data-source) { margin: .5rem 0; overflow-x: auto; border: 1px solid var(--sem-border);
  border-radius: 12px; background: var(--sem-surface); }
:is(sem-data-source, .sem-data-source) table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem; }
:is(sem-data-source, .sem-data-source) caption { text-align: left; padding: .6rem .9rem 0; font-weight: 600; caption-side: top; }
:is(sem-data-source, .sem-data-source) th, :is(sem-data-source, .sem-data-source) td { padding: .45rem .9rem;
  text-align: left; border-bottom: 1px solid var(--sem-border); vertical-align: top; }
:is(sem-data-source, .sem-data-source) th { font-variant-caps: all-small-caps; letter-spacing: .05em;
  color: var(--sem-muted); background: var(--sem-surface); }
:is(sem-data-source, .sem-data-source) tbody tr:last-child :is(th, td) { border-bottom: 0; }
:is(sem-data-source, .sem-data-source) .sem-data-schema { display: none; }
.sem-data-error { margin: 0; padding: .6rem .9rem; font-size: .85rem; color: var(--sem-note-danger, currentColor); }
.sem-data-sort { all: unset; font: inherit; cursor: pointer; display: inline-block; padding-right: 1.1em; position: relative; }
.sem-data-sort::after { content: "↕"; position: absolute; right: 0; opacity: .5; }
th[aria-sort="ascending"] .sem-data-sort::after { content: "↑"; opacity: 1; color: var(--sem-accent); }
th[aria-sort="descending"] .sem-data-sort::after { content: "↓"; opacity: 1; color: var(--sem-accent); }
.sem-data-sort:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 2px; border-radius: 4px; }

/* data visualizer — async loads + query/view chrome (phases 4–5) */
.sem-data-pending { margin: 0; padding: .6rem .9rem; font-size: .85rem; color: var(--sem-muted); }
.sem-data-views { display: flex; gap: .4rem; padding: .5rem .9rem 0; flex-wrap: wrap; }
.sem-data-view { all: unset; font: inherit; font-size: .8rem; cursor: pointer; padding: .15rem .7rem;
  border: 1px solid var(--sem-border); border-radius: 999px; color: var(--sem-muted); }
.sem-data-view[aria-pressed="true"] { background: var(--sem-accent); border-color: var(--sem-accent); color: var(--sem-surface); }
.sem-data-view:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 2px; }

/* phase 6 — tools row + full-page modal viewer (spec/data-visualizer.md §10) */
.sem-data-tools { display: flex; align-items: center; justify-content: flex-end; gap: .4rem;
  padding: .3rem .9rem 0; flex-wrap: wrap; }
.sem-data-expand, .sem-data-copy { all: unset; font: inherit; font-size: .8rem; cursor: pointer;
  padding: .15rem .7rem; border: 1px solid var(--sem-border); border-radius: 999px; color: var(--sem-muted); }
.sem-data-expand:focus-visible, .sem-data-copy:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 2px; }
.sem-data-copy-status { font-size: .8rem; color: var(--sem-muted); }
.sem-data-modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center;
  justify-content: center; padding: 1.5rem; background: rgb(0 0 0 / .45); }
.sem-data-modal-panel { background: var(--sem-surface); color: inherit; box-sizing: border-box;
  border: 1px solid var(--sem-border); border-radius: 16px; width: min(64rem, 100%); max-height: 100%;
  overflow: auto; padding: 1rem; }
.sem-data-modal-close { all: unset; font: inherit; font-size: .8rem; cursor: pointer; margin-bottom: .5rem;
  padding: .15rem .9rem; border: 1px solid var(--sem-border); border-radius: 999px; }
.sem-data-modal-close:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 2px; }
:is(sem-data-join, .sem-data-join) { margin: .25rem 0; }
:is(sem-data-query, .sem-data-query) { display: block; margin: .5rem 0; }
.sem-data-query-chrome { margin: .5rem 0; display: block; }
.sem-data-query-label { display: block; font-variant-caps: all-small-caps; letter-spacing: .05em;
  font-size: .85rem; color: var(--sem-muted); margin-bottom: .3rem; }
.sem-data-query-input { display: block; width: 100%; box-sizing: border-box; font: .85rem/1.5 ui-monospace, monospace;
  padding: .55rem .8rem; border: 1px solid var(--sem-border); border-radius: 10px;
  background: var(--sem-surface); color: inherit; resize: vertical; }
.sem-data-query-input:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 1px; }
.sem-data-query-controls { display: flex; align-items: center; gap: .75rem; margin: .4rem 0 .6rem; }
.sem-data-query-run { all: unset; font: inherit; font-size: .85rem; cursor: pointer; padding: .25rem 1rem;
  border: 1px solid var(--sem-border); border-radius: 999px; }
.sem-data-query-run:focus-visible { outline: 2px solid var(--sem-accent); outline-offset: 2px; }
.sem-data-query-status { font-size: .8rem; color: var(--sem-muted); }
.sem-data-query-error { margin: 0; padding: .6rem .9rem; font-size: .85rem; color: var(--sem-note-danger, currentColor); }
.sem-data-query-results table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .9rem;
  border: 1px solid var(--sem-border); border-radius: 12px; overflow: hidden; }
.sem-data-query-results :is(th, td) { padding: .45rem .9rem; text-align: left; border-bottom: 1px solid var(--sem-border); }
.sem-data-query-results th { font-variant-caps: all-small-caps; letter-spacing: .05em; color: var(--sem-muted); }
.sem-data-query-results tbody tr:last-child :is(th, td) { border-bottom: 0; }

/* print — everything a reader could open, none of the chrome. Reveal
   <details> are opened by fallback/target on `beforeprint`; CSS cannot. */
@media print {
  .sem-facts-chrome, .sem-quiz-options, .sem-views-tabs, .sem-note-summary,
  .sem-code-chrome, .sem-popover, .sem-references-backlinks, .sem-references-link,
  sem-reader, .sem-reader, .sem-table-chrome, .sem-source-chrome, .sem-source-fence,
  .sem-md-chrome, .sem-md-raw, .sem-data-tools, .sem-data-modal { display: none !important; }
  .sem-md-body { display: block !important; }
  :is(sem-table, .sem-table) { overflow: visible; }
  :is(sem-table, .sem-table) tbody tr[hidden] { display: table-row !important; }
  :is(sem-code, .sem-code) pre { white-space: pre-wrap; overflow: visible; }
  /* the href shows inside the references block only, never at the citation */
  :is(sem-reference, .sem-reference)[data-href]::after { content: " (" attr(data-href) ")"; color: var(--sem-muted); }
  :is(sem-reference, .sem-reference)[href]:not([data-href])::after { content: " (" attr(href) ")"; color: var(--sem-muted); }
  :is(sem-facts, .sem-facts) :is(sem-fact, .sem-fact) { display: block !important; min-height: 0 !important; }
  :is(sem-fact, .sem-fact) :is(conclusion, .sem-conclusion) { display: block !important; visibility: visible !important; }
  :is(sem-note, .sem-note)[collapsed] > .sem-note-body { display: block !important; }
  :is(sem-note, .sem-note):is([data-view-as="margin"], [view-as="margin"]) { float: none !important; width: auto !important; margin: 1rem 0 !important; }
  :is(sem-views, .sem-views) :is(sem-view, .sem-view) { display: block !important; border-top: 1px solid var(--sem-border);
    border-radius: 12px; margin: .5rem 0; }
  :is(sem-views, .sem-views) :is(sem-view, .sem-view)::before { content: attr(data-name); display: block;
    font-variant-caps: all-small-caps; letter-spacing: .05em; color: var(--sem-muted); margin-bottom: .25rem; }
  :is(sem-views, .sem-views) :is(sem-view, .sem-view)[name]:not([data-name])::before { content: attr(name); }
  :is(sem-reveal, .sem-reveal) summary { list-style: none; }
  .sem-occluded { color: inherit !important; background: none !important; }
  :is(sem-fact, .sem-fact), :is(sem-step, .sem-step), :is(sem-note, .sem-note), :is(sem-detail, .sem-detail),
  :is(sem-property, .sem-property), :is(sem-event, .sem-event), :is(sem-reference, .sem-reference) { break-inside: avoid; page-break-inside: avoid; }
  .sem-target { outline: none; }
}
