/* PostSheet Services — Section 508-Ready Document Publishing Stylesheet
 * Verified WCAG 2.1/2.2 AA/AAA contrast across Moonlight, High Contrast AAA, Paper, and Blue-Glare Shield.
 * Strict 320px (400% zoom) zero-horizontal-overflow reflow & >=44px interactive target floor.
 */

:root {
  color-scheme: dark;
  --bg: #07131a;
  --surface: #0c1d27;
  --surface-alt: #112734;
  --border: #3a6073;
  --border-strong: #67a8c4;
  --text: #eef6f8;
  --text-muted: #b7cfd9;
  --accent: #38e59a;
  --accent-ink: #04130d;
  --focus: #ffd60a;
  --badge-bg: #133140;
  --badge-text: #d7f4ff;
  --btn-bg: #123142;
  --btn-hover: #1a455d;
  --btn-text: #f3fbff;
  --btn-active-bg: #38e59a;
  --btn-active-text: #04130d;
  --warn-bg: #3a2a04;
  --warn-border: #ffd60a;
  --font-main: "CrrSharedMetric", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

body[data-theme="aaa"] {
  color-scheme: dark;
  --bg: #000000;
  --surface: #000000;
  --surface-alt: #0f0f0f;
  --border: #ffffff;
  --border-strong: #ffd60a;
  --text: #ffffff;
  --text-muted: #f5f5f5;
  --accent: #ffd60a;
  --accent-ink: #000000;
  --focus: #ffd60a;
  --badge-bg: #000000;
  --badge-text: #ffffff;
  --btn-bg: #000000;
  --btn-hover: #222222;
  --btn-text: #ffffff;
  --btn-active-bg: #ffd60a;
  --btn-active-text: #000000;
  --warn-bg: #1a1500;
  --warn-border: #ffd60a;
}

body[data-theme="paper"] {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #faf8f3;
  --surface-alt: #ebe6da;
  --border: #556268;
  --border-strong: #1e3a46;
  --text: #141c20;
  --text-muted: #34444c;
  --accent: #0b5d42;
  --accent-ink: #ffffff;
  --focus: #9a4700;
  --badge-bg: #e2ddd0;
  --badge-text: #141c20;
  --btn-bg: #e7e2d6;
  --btn-hover: #d8d1c2;
  --btn-text: #141c20;
  --btn-active-bg: #0b5d42;
  --btn-active-text: #ffffff;
  --warn-bg: #fff5d6;
  --warn-border: #8a5a00;
}

body[data-theme="blue_shield"] {
  color-scheme: dark;
  --bg: #14110b;
  --surface: #1d1810;
  --surface-alt: #272015;
  --border: #7a6544;
  --border-strong: #e6a84c;
  --text: #f4ead6;
  --text-muted: #d6c5a7;
  --accent: #e6a84c;
  --accent-ink: #171108;
  --focus: #ffd666;
  --badge-bg: #2a2114;
  --badge-text: #f7e6c4;
  --btn-bg: #2f2517;
  --btn-hover: #423420;
  --btn-text: #faf0dc;
  --btn-active-bg: #e6a84c;
  --btn-active-text: #171108;
  --warn-bg: #3b2b0e;
  --warn-border: #ffd666;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  font-size: 16px;
  line-height: 1.5;
  overflow-x: clip;
}

body.a11y-text-spacing,
body.a11y-text-spacing p,
body.a11y-text-spacing li,
body.a11y-text-spacing td,
body.a11y-text-spacing th,
body.a11y-text-spacing button,
body.a11y-text-spacing input,
body.a11y-text-spacing select {
  line-height: 1.55 !important;
  letter-spacing: 0.12em !important;
  word-spacing: 0.16em !important;
}
body.a11y-text-spacing p { margin-bottom: 2em !important; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

body.a11y-reduced-motion *,
body.a11y-reduced-motion *::before,
body.a11y-reduced-motion *::after {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.4rem 0.75rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.skip-link {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  max-width: 100%;
  padding: 0.45rem 0.75rem;
  color: var(--btn-text);
  background: var(--btn-bg);
  border: 2px solid var(--border);
  border-radius: 6px;
  text-decoration: underline;
  font-weight: 600;
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.site-header {
  padding: 1rem 1.25rem;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.hero-block h1 {
  margin: 0 0 0.4rem 0;
  font-size: clamp(1.25rem, 2.5vw, 1.7rem);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.hero-sub {
  margin: 0;
  color: var(--text-muted);
  max-width: 72ch;
  font-size: 0.98rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.adapt-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.adapt-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
}

button, select, input[type="search"], input[type="number"] {
  min-height: 44px;
  min-width: 44px;
  max-width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: inherit;
  font-size: 0.95rem;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--btn-bg);
  color: var(--btn-text);
  overflow-wrap: anywhere;
}

button { cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { background: var(--btn-hover); border-color: var(--border-strong); }
button:disabled { opacity: 0.58; cursor: not-allowed; }
button[aria-pressed="true"] {
  background: var(--btn-active-bg);
  color: var(--btn-active-text);
  border-color: var(--focus);
}

input[type="search"], input[type="number"], select {
  background: var(--bg);
  color: var(--text);
}

input[type="search"] { flex: 1 1 180px; min-width: 0; width: 100%; }
input[type="number"] { width: 78px; }

.live-banner {
  margin: 0;
  padding: 0.6rem 1.25rem;
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

main.workspace {
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.panel {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.panel-head h2 { margin: 0; font-size: 1.15rem; overflow-wrap: anywhere; }
.helper-note { margin: 0; color: var(--text-muted); font-size: 0.92rem; overflow-wrap: anywhere; }

.sample-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.sample-card {
  text-align: left;
  padding: 0.85rem;
  border-radius: 10px;
  border: 2px solid var(--border-strong);
  background: var(--surface-alt);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.sample-card strong { font-size: 1rem; }
.sample-card span { font-size: 0.86rem; font-weight: 400; color: var(--text-muted); }
.sample-card[aria-pressed="true"] span { color: var(--btn-active-text); }

.search-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
}

/* NEVER display:none — preserves WebGPU swapchain while 1x1 when headless */
.gpu-stage-wrap {
  position: relative;
  width: 100%;
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  background: var(--bg);
  overflow: hidden;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
}

#canvas {
  display: block;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

#canvas.spatial-open {
  width: 100%;
  height: 220px;
  opacity: 1;
  pointer-events: auto;
}

#gpu-cpu-stage { display: block; width: 100%; height: 220px; }
#gpu-cpu-stage[hidden] { display: none; }

.metrics-strip {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 0.45rem 0.65rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.aom-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.6rem;
}

.aom-row { display: contents; }

.aom-cell {
  min-height: 60px;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  cursor: pointer;
  min-width: 0;
  overflow-wrap: anywhere;
}

.aom-cell[aria-selected="true"],
.aom-cell:focus-visible {
  border-color: var(--focus);
  box-shadow: inset 0 0 0 2px var(--focus);
  background: var(--btn-hover);
}

.aom-cell-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  font-weight: 700;
  font-size: 0.92rem;
}

.aom-rank-tag {
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.aom-cell[data-rank="0"] .aom-rank-tag {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--focus);
}

.aom-score-bar {
  height: 7px;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.aom-score-fill { height: 100%; background: var(--accent); }
.aom-meta { font-size: 0.8rem; color: var(--text-muted); }

.doc-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
}

.doc-controls label { font-weight: 600; font-size: 0.9rem; }
.doc-controls select { flex: 1 1 200px; min-width: 0; width: 100%; }

.split-plane {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
  gap: 1rem;
  align-items: start;
}

.crr-stage-box {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-width: 0;
}

#crr-doc-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  cursor: pointer;
}

#reading-island {
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  min-width: 0;
}

.island-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.45rem;
}

.island-header h3 { margin: 0; font-size: 1.02rem; overflow-wrap: anywhere; }

.sem-node {
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.55rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  overflow-wrap: anywhere;
}

.sem-node.selected { border: 2px solid var(--focus); background: var(--surface-alt); }
.sem-node.low-conf { background: var(--warn-bg); border-color: var(--warn-border); }
.sem-node h4, .sem-node h5, .sem-node h6, .sem-node p { margin: 0 0 0.35rem 0; }

.sem-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.4rem;
}

.badge-tag {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.18rem 0.42rem;
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--badge-text);
  border: 1px solid var(--border);
}

.action-mini { min-height: 44px; padding: 0.35rem 0.65rem; font-size: 0.84rem; }

.table-scroll { width: 100%; overflow-x: auto; max-width: 100%; }

table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.35rem 0;
  font-size: 0.88rem;
}

caption { text-align: left; font-weight: 700; margin-bottom: 0.35rem; color: var(--text); }
th, td { border: 1px solid var(--border); padding: 0.4rem 0.5rem; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
th { background: var(--surface-alt); color: var(--text); font-weight: 700; }

.transpose-card {
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  margin-bottom: 0.5rem;
  background: var(--surface-alt);
}

.code-box {
  margin: 0;
  padding: 0.55rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow-x: auto;
  font-size: 0.84rem;
}

details#artifact-drawer {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
}

details#artifact-drawer summary {
  cursor: pointer;
  font-weight: 700;
  min-height: 44px;
  display: flex;
  align-items: center;
}

dialog#source-dialog {
  max-width: min(720px, 94vw);
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--focus);
  border-radius: 12px;
  padding: 1rem;
}
dialog#source-dialog::backdrop { background: rgba(0, 0, 0, 0.75); }
dialog#source-dialog pre {
  max-height: 340px;
  overflow: auto;
  background: var(--bg);
  color: var(--text);
  padding: 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.82rem;
}
#ocr-crop-img { max-width: 100%; height: auto; border: 1px solid var(--border); border-radius: 6px; }

footer.site-footer {
  max-width: 1440px;
  margin: 0 auto 2rem;
  padding: 0.85rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--border);
  overflow-wrap: anywhere;
}

/* Strict 320px (400% zoom) Reflow Safety */
@media (max-width: 900px) {
  .split-plane, .sample-cards {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 520px) {
  .site-header, main.workspace, .live-banner, footer.site-footer {
    padding-left: 0.55rem;
    padding-right: 0.55rem;
  }
  .panel { padding: 0.65rem; }
  .aom-grid { grid-template-columns: minmax(0, 1fr); }
  .search-row button, .doc-controls select { width: 100%; }
}
