/* =========================================================================
 * SignalScribe — AI-text likelihood reviewer
 *
 * Shares the visual family of PyOptimize / SchemaShift / TestGapFinder with a
 * slate blue accent to distinguish it, a diverging score axis instead of a
 * radial ring, and a native <table> for the thirteen signal readings.
 *
 * Accessibility decisions honoured (per accessibility-lead handoff):
 *   • Band communicated redundantly: colour + text label + icon + integer.
 *   • Mixed band uses amber, NEVER red — it is ambiguity, not an error.
 *   • Ethical banner is <aside aria-labelledby>, NOT a live region.
 *   • Refusal routes through #status role="status", NOT #error role="alert".
 *   • Diverging axis: role="img" + computed <title>, plus sr-only sentence.
 *   • Signal table: native <table> + caption + scope="col"/"row" + vote
 *     cells carry text labels, not colour alone.
 *   • Two-layer focus ring (outline + box-shadow).
 *   • prefers-reduced-motion disables marker transitions.
 *   • forced-colors: decorative fills collapse to system colours.
 * ========================================================================= */

@import url("https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,600;0,9..144,700;1,9..144,600&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

:root {
  color-scheme: light dark;

  --bg: #f1f3f7;
  --bg-2: #e7eaf1;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-raised: #ffffff;
  --border: #cbd5e1;
  --border-strong: #64748b;
  --text: #0f172a;
  --text-muted: #475569;
  --text-inverse: #ffffff;

  --link: #1e3a8a;
  --link-hover: #0f1e52;
  --accent: #475569;
  --accent-strong: #1e293b;

  --grad-1: #0a1f44;
  --grad-2: #1e293b;
  --grad-3: #475569;

  --slate: #475569;
  --amber: #b45309;

  /* Bands ------------------------------------------------------------------ */
  --band-human-text: #166534;
  --band-human-fill: #f0fdf4;
  --band-human-dot: #86efac;
  --band-human-border: #86efac;

  --band-mixed-text: #92400e;
  --band-mixed-fill: #fffbeb;
  --band-mixed-stripe: #fcd34d;
  --band-mixed-border: #fcd34d;

  --band-ai-text: #991b1b;
  --band-ai-fill: #fef2f2;
  --band-ai-border: #fca5a5;

  --warn-text: #92400e;
  --warn-fill: #fffbeb;
  --warn-border: #fcd34d;

  --axis-line: #334155;
  --axis-marker: #0f172a;
  --axis-label: #334155;

  --focus-outer: #475569;
  --focus-inner: #ffffff;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 8px 20px -10px rgba(15, 23, 42, 0.25),
    0 2px 6px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 24px 48px -24px rgba(15, 23, 42, 0.35),
    0 4px 12px rgba(15, 23, 42, 0.1);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --space-8: 3rem;
  --space-10: 4rem;

  --serif: "Fraunces", "Source Serif Pro", Georgia, serif;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
    monospace;
}

[data-theme="dark"] {
  --bg: #020617;
  --bg-2: #0b1220;
  --surface: #0f172a;
  --surface-2: #0b1220;
  --surface-raised: #1e293b;
  --border: #1e293b;
  --border-strong: #64748b;
  --text: #f1f5f9;
  --text-muted: #cbd5e1;
  --text-inverse: #020617;

  --link: #93c5fd;
  --link-hover: #dbeafe;
  --accent: #94a3b8;
  --accent-strong: #cbd5e1;

  --grad-1: #0a1f44;
  --grad-2: #334155;
  --grad-3: #94a3b8;

  --slate: #94a3b8;

  --band-human-text: #86efac;
  --band-human-fill: #052e16;
  --band-human-dot: #166534;
  --band-human-border: #166534;

  --band-mixed-text: #fcd34d;
  --band-mixed-fill: #1c1917;
  --band-mixed-stripe: #92400e;
  --band-mixed-border: #92400e;

  --band-ai-text: #fca5a5;
  --band-ai-fill: #450a0a;
  --band-ai-border: #991b1b;

  --warn-text: #fcd34d;
  --warn-fill: #1c1917;
  --warn-border: #92400e;

  --axis-line: #cbd5e1;
  --axis-marker: #f1f5f9;
  --axis-label: #cbd5e1;

  --focus-outer: #cbd5e1;
  --focus-inner: #020617;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

a {
  color: var(--link);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-thickness: 0.08em;
}

a:hover {
  color: var(--link-hover);
}

*:focus-visible {
  outline: 3px solid var(--focus-outer);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px var(--focus-inner);
  border-radius: var(--radius-sm);
}

/* Skip link --------------------------------------------------------------- */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.skip-link:focus {
  position: fixed;
  left: var(--space-4);
  top: var(--space-4);
  width: auto;
  height: auto;
  padding: var(--space-3) var(--space-4);
  background: var(--accent-strong);
  color: var(--text-inverse);
  font-weight: 600;
  border-radius: var(--radius);
  z-index: 1000;
}

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

/* Header ------------------------------------------------------------------ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}

.site-title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.site-title__mark {
  color: var(--accent-strong);
}

.theme-toggle {
  margin-left: auto;
  font: inherit;
  font-size: 0.9rem;
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.theme-toggle[aria-pressed="true"] {
  background: var(--accent-strong);
  color: var(--text-inverse);
  border-color: var(--accent-strong);
}

/* Hero -------------------------------------------------------------------- */
.hero {
  background: linear-gradient(
    135deg,
    var(--grad-1) 0%,
    var(--grad-2) 55%,
    var(--grad-3) 100%
  );
  color: #f8fafc;
  padding: var(--space-10) var(--space-6);
}

.hero__inner {
  max-width: 1080px;
  margin: 0 auto;
}

.hero__eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.78rem;
  font-weight: 600;
  opacity: 0.85;
  display: inline-block;
  margin-bottom: var(--space-3);
}

.hero__title {
  font-family: var(--serif);
  font-size: clamp(1.8rem, 3.4vw, 2.6rem);
  line-height: 1.15;
  margin: 0 0 var(--space-4) 0;
  max-width: 30ch;
}

.hero__lede {
  font-size: 1.08rem;
  line-height: 1.55;
  margin: 0;
  max-width: 60ch;
  opacity: 0.92;
}

/* Main layout ------------------------------------------------------------- */
.site-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: var(--space-8) var(--space-6) var(--space-10);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.site-main:focus {
  outline: none;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  position: relative;
}

.panel::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -1px;
  right: -1px;
  height: 4px;
  background: linear-gradient(
    90deg,
    var(--grad-1) 0%,
    var(--grad-2) 50%,
    var(--grad-3) 100%
  );
  border-top-left-radius: var(--radius);
  border-top-right-radius: var(--radius);
}

.panel h2 {
  margin-top: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
}

.lede {
  color: var(--text-muted);
  margin-top: 0;
  margin-bottom: var(--space-4);
}

/* Ethical banner ---------------------------------------------------------- */
.ethical-banner {
  background: var(--warn-fill);
  border: 1px solid var(--warn-border);
  border-left: 6px solid var(--warn-border);
  border-radius: var(--radius);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-sm);
}

.ethical-banner__title {
  margin: 0 0 var(--space-2) 0;
  font-family: var(--serif);
  font-size: 1.05rem;
  color: var(--warn-text);
}

.ethical-banner p {
  margin: var(--space-2) 0 0 0;
  color: var(--text);
  line-height: 1.55;
}

.ethical-banner code {
  font-family: var(--mono);
  background: color-mix(in srgb, var(--warn-border) 40%, transparent);
  padding: 0 0.3em;
  border-radius: 3px;
  font-size: 0.92em;
}

/* Upload panel ------------------------------------------------------------ */
.upload-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.upload-label {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.text-input {
  font-family: var(--mono);
  font-size: 0.92rem;
  line-height: 1.55;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  resize: vertical;
  min-height: 10em;
  width: 100%;
  tab-size: 2;
}

.upload-hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  margin-top: var(--space-3);
}

.button {
  font: inherit;
  font-weight: 600;
  padding: var(--space-3) var(--space-5);
  background: var(--accent-strong);
  color: var(--text-inverse);
  border: 1px solid var(--accent-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.button:hover {
  background: var(--grad-2);
  border-color: var(--grad-2);
}

.button--ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

.button--ghost:hover {
  background: var(--bg-2);
  color: var(--text);
}

.upload-file-label {
  position: relative;
}

.upload-file {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-file:focus-visible + span,
.upload-file-label:focus-within {
  outline: 3px solid var(--focus-outer);
  outline-offset: 2px;
}

/* Status / error ---------------------------------------------------------- */
.status {
  min-height: 1.5em;
  color: var(--text-muted);
  font-style: italic;
  padding: 0 var(--space-1);
}

.alert {
  background: var(--band-ai-fill);
  border: 1px solid var(--band-ai-border);
  border-left: 6px solid var(--band-ai-border);
  color: var(--band-ai-text);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
}

/* Results ----------------------------------------------------------------- */
.results-panel h2 {
  margin-bottom: var(--space-4);
}

.band-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: var(--space-5);
  align-items: center;
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.band-card[data-band="likely_human"] {
  background: var(--band-human-fill);
  border-color: var(--band-human-border);
  color: var(--band-human-text);
}

.band-card[data-band="mixed"] {
  background: var(--band-mixed-fill);
  border-color: var(--band-mixed-border);
  color: var(--band-mixed-text);
}

.band-card[data-band="likely_ai"] {
  background: var(--band-ai-fill);
  border-color: var(--band-ai-border);
  color: var(--band-ai-text);
}

.band-card[data-band="refused"] {
  background: var(--warn-fill);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.band-card__glyph {
  width: 56px;
  height: 56px;
  color: currentColor;
}

.band-card__glyph svg {
  width: 100%;
  height: 100%;
}

.band-card__meta {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.band-card__label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.band-card[data-band] .band-card__label {
  color: inherit;
  opacity: 0.85;
}

.band-card__title {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: inherit;
}

.band-card__summary {
  margin: 0;
  color: var(--text);
  font-size: 0.98rem;
}

.band-card[data-band] .band-card__summary {
  color: inherit;
}

.band-card__score {
  text-align: center;
  padding: var(--space-3) var(--space-4);
  border-left: 1px solid currentColor;
  border-left-color: color-mix(in srgb, currentColor 40%, transparent);
}

.band-card__score-num {
  display: block;
  font-family: var(--serif);
  font-size: 2.2rem;
  font-weight: 700;
  line-height: 1;
  color: inherit;
}

.band-card__score-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.8;
}

/* Diverging axis ---------------------------------------------------------- */
.score-axis {
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

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

.score-axis text {
  font-family: var(--sans);
  font-size: 11px;
  fill: var(--axis-label);
}

.axis-tick-strong {
  font-weight: 700;
}

.axis-labels text {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 10px;
  font-weight: 600;
  fill: var(--axis-label);
}

.axis-marker {
  transition: transform 400ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .axis-marker {
    transition: none;
  }
}

/* Warnings block ---------------------------------------------------------- */
.warnings {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--warn-fill);
  border: 1px solid var(--warn-border);
  border-left: 6px solid var(--warn-border);
  border-radius: var(--radius-sm);
  color: var(--text);
}

.warnings strong {
  color: var(--warn-text);
}

/* Signal table ------------------------------------------------------------ */
.signals-desc {
  color: var(--text-muted);
  margin-top: 0;
}

.signal-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.signal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.signal-table caption {
  text-align: left;
  padding: var(--space-2);
}

.signal-table th,
.signal-table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.signal-table thead th {
  background: var(--bg-2);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
}

.signal-table tbody th {
  font-weight: 600;
  color: var(--text);
  font-family: var(--sans);
  width: 22%;
}

.signal-table tbody tr:last-child td,
.signal-table tbody tr:last-child th {
  border-bottom: none;
}

.signal-table tbody tr:nth-child(even) {
  background: var(--surface-2);
}

.signal-value {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: var(--text);
  white-space: nowrap;
}

.vote {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  font-family: var(--mono);
  font-weight: 600;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  border: 1px solid currentColor;
  font-size: 0.85rem;
  white-space: nowrap;
}

.vote--human {
  color: var(--band-human-text);
  background: var(--band-human-fill);
}

.vote--ambiguous {
  color: var(--text-muted);
  background: var(--bg-2);
}

.vote--ai {
  color: var(--band-ai-text);
  background: var(--band-ai-fill);
}

.vote__glyph {
  font-family: var(--sans);
  font-weight: 700;
  font-size: 0.95em;
}

.signal-interp {
  color: var(--text);
  line-height: 1.5;
  max-width: 48ch;
}

/* Passage display --------------------------------------------------------- */
.passage-hint {
  color: var(--text-muted);
}

.passage-display {
  font-family: var(--mono);
  font-size: 0.9rem;
  line-height: 1.55;
  padding: var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-height: 30em;
  overflow-y: auto;
  color: var(--text);
}

.passage-display code {
  font-family: inherit;
}

.flag {
  background: color-mix(in srgb, var(--warn-fill) 85%, transparent);
  border-bottom: 2px solid var(--warn-border);
  padding: 0 0.15em;
  border-radius: 2px;
}

/* Footer ------------------------------------------------------------------ */
.site-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-6);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.92rem;
  background: var(--surface);
}

.site-footer__link {
  color: var(--link);
}

/* Responsive -------------------------------------------------------------- */
@media (max-width: 720px) {
  .band-card {
    grid-template-columns: auto 1fr;
  }

  .band-card__score {
    grid-column: 1 / -1;
    border-left: none;
    border-top: 1px solid color-mix(in srgb, currentColor 40%, transparent);
    padding-top: var(--space-3);
    text-align: left;
  }

  .signal-table tbody th {
    width: auto;
  }
}

/* Forced colors ---------------------------------------------------------- */
@media (forced-colors: active) {
  .panel::before,
  .hero {
    forced-color-adjust: none;
    background: Canvas !important;
    color: CanvasText !important;
  }

  .band-card,
  .ethical-banner,
  .warnings,
  .alert {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }

  .axis-marker line,
  .axis-marker circle {
    stroke: Highlight !important;
    fill: Highlight !important;
  }

  .axis-line,
  .score-axis text,
  .signal-table th,
  .signal-table td {
    color: CanvasText;
    fill: CanvasText;
    stroke: CanvasText;
    border-color: CanvasText;
  }

  .vote {
    border-color: CanvasText;
    background: Canvas;
    color: CanvasText;
  }
}
