/* PostBench Editorial Research-Lab Design System
   Inspired by wasm-vs-js.com and port-authority.dev */

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

:root {
  color-scheme: light dark;
  --page: #faf8f4;
  --surface: #f1eee7;
  --surface-hover: #e7e3d9;
  --surface-subtle: #f6f4ee;
  --raised: #ffffff;
  --ink: #141413;
  --muted: #4b4942;
  --rule: #d8d3c8;
  --accent: #1e4b7a;
  --accent-ink: #ffffff;
  --teal: #0f766e;
  --teal-soft: #e6f4f1;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --crimson: #9f1239;
  --crimson-soft: #fdf2f4;
  --focus: #175cd3;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, monospace;
  --sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --measure: 72ch;
  --wide: min(96vw, 88rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --page: #161513;
    --surface: #22201d;
    --surface-hover: #2c2925;
    --surface-subtle: #1c1a17;
    --raised: #272420;
    --ink: #ebe7df;
    --muted: #bbb5aa;
    --rule: #3f3b35;
    --accent: #7eb3f2;
    --accent-ink: #0a1524;
    --teal: #5eead4;
    --teal-soft: #132d2a;
    --amber: #fbbf24;
    --amber-soft: #362507;
    --crimson: #fb7185;
    --crimson-soft: #3b131d;
    --focus: #93c5fd;
  }
}

html {
  background: var(--page);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 100%;
  line-height: 1.55;
}

body {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 0.18em;
}

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -5rem;
  background: var(--ink);
  color: var(--page);
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-weight: 600;
  z-index: 100;
}

.skip-link:focus {
  top: 0.75rem;
}

.num,
code,
pre,
.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

code {
  font-size: 0.9em;
  background: var(--surface);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

pre {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.9rem 1rem;
  overflow-x: auto;
  font-size: 0.85rem;
  line-height: 1.45;
}

/* Header */
.masthead {
  border-bottom: 1px solid var(--rule);
  background: var(--page);
}

.masthead-inner {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1.5rem;
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.primary-nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 1rem;
}

.primary-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 500;
  padding: 0.25rem 0.45rem;
  border-radius: 6px;
}

.primary-nav a:hover {
  color: var(--ink);
  background: var(--surface);
}

.primary-nav a[aria-current="page"] {
  color: var(--ink);
  font-weight: 700;
  background: var(--surface);
}

.mode-switch {
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--ink);
  text-decoration: none;
}

.mode-switch:hover {
  background: var(--surface-hover);
}

/* Layout */
.container {
  max-width: var(--wide);
  margin: 0 auto;
  padding: 1.75rem 1.25rem 4rem;
}

.prose {
  max-width: var(--measure);
}

.eyebrow {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 0.4rem;
}

h1 {
  font-size: clamp(1.75rem, 3.2vw, 2.55rem);
  line-height: 1.15;
  letter-spacing: -0.025em;
  margin: 0 0 0.85rem;
}

h2 {
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  letter-spacing: -0.015em;
  margin: 2.25rem 0 0.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--rule);
}

h3 {
  font-size: 1.05rem;
  margin: 1.25rem 0 0.45rem;
}

.lede {
  font-size: 1.08rem;
  color: var(--muted);
  max-width: 68ch;
  margin: 0 0 1rem;
}

.quote-callout {
  border-left: 3px solid var(--accent);
  background: var(--surface-subtle);
  padding: 0.85rem 1.1rem;
  margin: 1rem 0 1.4rem;
  border-radius: 0 8px 8px 0;
  max-width: 68ch;
}

.quote-callout p {
  margin: 0;
  font-size: 0.96rem;
}

.quote-callout cite {
  display: block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: var(--muted);
  font-style: normal;
}

/* Panels & Banners */
.panel {
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1.1rem 1.25rem;
  margin: 1rem 0;
}

.banner {
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  font-size: 0.94rem;
}

.banner-warn {
  background: var(--amber-soft);
  border-color: var(--amber);
}

.banner-error {
  background: var(--crimson-soft);
  border-color: var(--crimson);
  color: var(--crimson);
}

.banner-ok {
  background: var(--teal-soft);
  border-color: var(--teal);
}

/* Environment Strip */
.env-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.9rem 1rem;
  margin: 1.15rem 0;
}

.env-stat {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.env-stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 600;
}

.env-stat-value {
  font-size: 0.96rem;
  font-weight: 700;
}

.cap-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(195px, 1fr));
  gap: 0.45rem 0.75rem;
  margin-top: 0.75rem;
}

.cap-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.6rem;
  background: var(--surface-subtle);
  border: 1px solid var(--rule);
  border-radius: 6px;
  font-size: 0.85rem;
}

/* Badges */
.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-ok {
  background: var(--teal-soft);
  color: var(--teal);
  border-color: color-mix(in srgb, var(--teal) 35%, transparent);
}

.badge-warn {
  background: var(--amber-soft);
  color: var(--amber);
  border-color: color-mix(in srgb, var(--amber) 35%, transparent);
}

.badge-error {
  background: var(--crimson-soft);
  color: var(--crimson);
  border-color: color-mix(in srgb, var(--crimson) 35%, transparent);
}

.badge-muted {
  background: var(--surface);
  color: var(--muted);
  border-color: var(--rule);
}

/* Controls */
.controls-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.85rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin: 1rem 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.86rem;
  font-weight: 600;
}

select,
input[type="text"],
input[type="search"] {
  font: inherit;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: var(--raised);
  color: var(--ink);
}

.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.75rem;
  align-items: center;
}

.category-pills label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 0.32rem 0.6rem;
}

.btn {
  appearance: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 0.5rem 0.95rem;
  border-radius: 7px;
  border: 1px solid var(--rule);
  background: var(--raised);
  color: var(--ink);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
  background: var(--accent);
}

.btn-danger {
  background: var(--crimson);
  color: #ffffff;
  border-color: var(--crimson);
}

.btn-sm {
  font-size: 0.84rem;
  padding: 0.36rem 0.72rem;
}

.btn-highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}

.manual-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  flex-basis: 100%;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--rule);
  font-size: 0.88rem;
}

.manual-note {
  flex-basis: 100%;
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

/* Progress */
.progress-wrap {
  margin: 1rem 0;
}

.progress-track {
  width: 100%;
  height: 10px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 150ms ease;
}

.progress-status {
  display: flex;
  justify-content: space-between;
  font-size: 0.86rem;
  color: var(--muted);
  margin-top: 0.35rem;
}

/* Hypothesis & Charts */
.hypothesis-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
  margin: 1rem 0;
}

.stat-card {
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 0.9rem 1rem;
}

.stat-card-label {
  font-size: 0.8rem;
  color: var(--muted);
  font-weight: 600;
}

.stat-card-num {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0.25rem 0;
}

.stat-card-note {
  font-size: 0.83rem;
  color: var(--muted);
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.chart-panel {
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem;
}

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

.chart-head h3 {
  margin: 0;
  font-size: 1rem;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.65rem;
  font-size: 0.8rem;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 2px;
  display: inline-block;
}

/* Real-world Cards */
.realworld-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.rw-card {
  background: var(--raised);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.1rem;
}

.rw-card h3 {
  margin: 0 0 0.35rem;
  font-size: 1rem;
}

.rw-bar-row {
  margin: 0.55rem 0;
}

.rw-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.84rem;
  margin-bottom: 0.2rem;
}

.rw-bar-track,
.rw-bar-svg {
  width: 100%;
  height: 9px;
  display: block;
  background: var(--surface);
  border-radius: 4px;
  overflow: hidden;
}

.rw-bar-fill {
  height: 100%;
  background: var(--accent);
}

.rw-bar-fill.fast {
  background: var(--teal);
}

.rw-bar-fill.slow {
  background: var(--amber);
}

/* Tables with layout containment for complex updates */
.contain-section {
  content-visibility: auto;
  contain-intrinsic-size: auto 900px;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--raised);
  margin: 0.75rem 0 1.25rem;
}

table.bench-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.bench-table caption {
  text-align: left;
  padding: 0.65rem 0.9rem;
  font-weight: 700;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

table.bench-table th,
table.bench-table td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--rule);
  text-align: left;
  vertical-align: middle;
}

table.bench-table th.num,
table.bench-table td.num {
  text-align: right;
  white-space: nowrap;
}

table.bench-table thead th {
  background: var(--surface-subtle);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

table.bench-table tbody tr.clickable {
  cursor: pointer;
}

table.bench-table tbody tr.clickable:hover {
  background: var(--surface-subtle);
}

/* Native Dialog */
dialog.detail-dialog {
  max-width: min(92vw, 48rem);
  width: 100%;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--raised);
  color: var(--ink);
  padding: 1.25rem 1.4rem;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.22);
}

dialog.detail-dialog::backdrop {
  background: rgba(15, 15, 14, 0.55);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.dialog-head h2 {
  margin: 0;
  padding: 0;
  border: 0;
  font-size: 1.2rem;
}

/* Submit & Footer */
.submit-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  margin: 1.25rem 0;
}

.submit-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.site-footer {
  border-top: 1px solid var(--rule);
  padding: 1.5rem 1.25rem 2.5rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.site-footer-inner {
  max-width: var(--wide);
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.75rem;
}

.popup-shell {
  max-width: 34rem;
  margin: 2rem auto;
  padding: 1.25rem;
}

@media (max-width: 640px) {
  .chart-grid,
  .realworld-grid {
    grid-template-columns: 1fr;
  }
}
