:root {
  --bg: #0f1115;
  --bg-deep: #090b0f;
  --panel: #151922;
  --panel-2: #1a1f2a;
  --ink: #e9e2d2;
  --ink-dim: #b8b2a4;
  --muted: #87909f;
  --gold: #c8a45c;
  --gold-bright: #e5c47c;
  --cyan: #69c2c9;
  --cyan-bright: #9fe3e7;
  --red: #c96d5f;
  --line: rgba(200, 164, 92, 0.22);
  --line-soft: rgba(233, 226, 210, 0.08);
  --serif: "Bodoni 72", "Didot", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --mono: "SFMono-Regular", "Cascadia Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

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

[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 78% -10%, rgba(200, 164, 92, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 30%, rgba(105, 194, 201, 0.06), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.28;
  background-image:
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(90deg, rgba(0, 0, 0, 0.12) 0 1px, transparent 1px 4px);
  mix-blend-mode: overlay;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(1280px, calc(100% - 64px));
  margin: 0 auto;
}

a { color: var(--gold-bright); }

button, input, select { font: inherit; }

button { color: inherit; }

.mono,
.mono-label,
.formula,
.matrix,
.result-id,
.footer-meta,
.tooltip-index {
  font-family: var(--mono);
}

.masthead {
  padding: 44px 0 34px;
  border-bottom: 1px solid var(--line);
}

.masthead-top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: baseline;
  border-bottom: 1px solid var(--line-soft);
  padding-bottom: 10px;
}

.kicker,
.eyebrow,
.folio,
.mono-label {
  margin: 0;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--gold);
}

.kicker { display: flex; align-items: center; gap: 9px; }

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 12px var(--gold);
  display: inline-block;
}

.folio { color: var(--muted); letter-spacing: 0.12em; }

.masthead h1 {
  margin: 26px 0 26px;
  font-family: var(--serif);
  font-size: clamp(58px, 9.4vw, 132px);
  line-height: 0.82;
  letter-spacing: -0.035em;
  font-weight: 500;
  color: var(--ink);
  text-transform: uppercase;
}

.masthead h1 em {
  display: inline-block;
  font-style: normal;
  background: linear-gradient(100deg, var(--gold-bright), #f2dfb2 45%, var(--gold) 80%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 26px rgba(200, 164, 92, 0.18));
}

.masthead-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(300px, 1fr);
  gap: 40px;
  align-items: end;
}

.deck {
  max-width: 60ch;
  margin: 0;
  color: var(--ink-dim);
  font-size: clamp(16px, 1.4vw, 20px);
  line-height: 1.55;
}

.deck strong { color: var(--ink); font-weight: 600; }

.corpus-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  margin: 0;
  background: var(--line);
  border: 1px solid var(--line);
}

.corpus-stats div {
  background: rgba(15, 17, 21, 0.86);
  padding: 12px 14px;
}

.corpus-stats dt {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.corpus-stats dd {
  margin: 3px 0 0;
  font-family: var(--mono);
  font-size: clamp(13px, 1.3vw, 18px);
  color: var(--gold-bright);
  white-space: nowrap;
}

main { padding: 30px 0 52px; }

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 390px) minmax(0, 1fr);
  gap: 30px;
  align-items: start;
}

.console,
.evidence,
.empty-state {
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.025), transparent 30%),
    var(--panel);
  box-shadow: var(--shadow);
}

.console {
  position: sticky;
  top: 22px;
  padding: 22px;
}

.panel-head { border-bottom: 1px solid var(--line-soft); padding-bottom: 14px; margin-bottom: 18px; }

h2 {
  margin: 4px 0 0;
  font-family: var(--serif);
  font-size: clamp(26px, 2.4vw, 34px);
  line-height: 1.05;
  font-weight: 500;
  letter-spacing: -0.015em;
}

.field { display: block; margin: 0 0 15px; }

.field > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.field > span i {
  color: var(--muted);
  font-style: normal;
  letter-spacing: 0.06em;
  text-transform: none;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--bg-deep);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.04em;
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.field input::placeholder { color: #555e6c; }

.field input:focus,
.field select:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(200, 164, 92, 0.12);
  background: #0b0e13;
}

.field small {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.02em;
}

.range-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field.compact { margin-bottom: 15px; }

.actions-row { display: grid; grid-template-columns: 1.3fr 1fr; gap: 10px; margin-top: 18px; }

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 16px;
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold-bright);
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.btn:hover { background: rgba(200, 164, 92, 0.12); border-color: var(--gold-bright); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }
.btn:disabled { opacity: 0.55; cursor: wait; }

.btn.primary {
  background: var(--gold);
  color: #14110a;
  border-color: var(--gold);
  font-weight: 700;
}

.btn.primary:hover { background: var(--gold-bright); }

.btn.ghost { border-color: var(--line); color: var(--ink-dim); }
.btn.ghost:hover { border-color: var(--gold); color: var(--gold-bright); }

.btn-spinner {
  width: 12px;
  height: 12px;
  border: 1.5px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  display: none;
  animation: spin 700ms linear infinite;
}

.is-busy .btn-spinner { display: inline-block; }
.is-busy .btn-label { opacity: 0.7; }

.form-error {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-left: 2px solid var(--red);
  background: rgba(201, 109, 95, 0.08);
  color: #e9b5ab;
  font-family: var(--mono);
  font-size: 11px;
}

.presets-block {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line-soft);
}

.presets-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 10px; }
.presets-note { font-family: var(--mono); font-size: 9px; color: var(--muted); }

.presets { display: grid; gap: 7px; }

.preset-chip {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 12px;
  text-align: left;
  padding: 9px 10px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, 0.015);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease;
}

.preset-chip:hover,
.preset-chip.is-active {
  border-color: var(--gold);
  background: rgba(200, 164, 92, 0.08);
}

.preset-chip strong {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink);
  font-weight: 600;
}

.preset-chip span {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--muted);
  grid-row: 2;
}

.preset-chip em {
  grid-row: 1 / span 2;
  align-self: center;
  font-family: var(--mono);
  font-style: normal;
  font-size: 10px;
  color: var(--gold);
}

.status-block { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.status-line { display: flex; gap: 9px; align-items: flex-start; }
.status-line p { margin: 0; color: var(--muted); font-family: var(--mono); font-size: 10px; line-height: 1.5; }

.status-dot {
  width: 6px;
  height: 6px;
  margin-top: 4px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.status-dot.ok { background: var(--cyan); box-shadow: 0 0 10px rgba(105, 194, 201, 0.55); }
.status-dot.busy { background: var(--gold); box-shadow: 0 0 10px rgba(200, 164, 92, 0.6); animation: pulse 1.1s ease-in-out infinite; }
.status-dot.error { background: var(--red); }

.progress { height: 1px; margin-top: 10px; background: var(--line-soft); overflow: hidden; }
.progress span { display: block; height: 100%; width: 0; background: var(--gold); transition: width 180ms ease; }

.evidence { padding: 24px; min-width: 0; animation: rise 360ms ease both; }

.evidence-head {
  display: flex;
  justify-content: space-between;
  gap: 26px;
  align-items: flex-start;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line-soft);
}

#result-title {
  margin: 5px 0 4px;
  font-size: clamp(30px, 3.6vw, 52px);
  line-height: 0.98;
}

.result-subtitle { margin: 0; color: var(--muted); font-family: var(--mono); font-size: 11px; letter-spacing: 0.04em; }

.result-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 1px;
  margin: 0;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  flex: 0 0 auto;
}

.result-metrics div { background: var(--panel); padding: 9px 11px; }
.result-metrics dt { font-family: var(--mono); font-size: 8px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.result-metrics dd { margin: 2px 0 0; font-family: var(--mono); font-size: 14px; color: var(--gold-bright); white-space: nowrap; }

.matrix-card {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  background:
    radial-gradient(700px 400px at 50% 0%, rgba(200, 164, 92, 0.06), transparent 70%),
    #0b0e13;
}

.matrix-toolbar { display: flex; justify-content: space-between; gap: 14px; align-items: baseline; margin-bottom: 10px; }
.matrix-hint { font-family: var(--mono); font-size: 9px; color: var(--muted); }

.matrix-wrap {
  position: relative;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  aspect-ratio: 1;
  border: 1px solid rgba(200, 164, 92, 0.38);
  background: #080a0e;
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.65);
}

.matrix {
  position: relative;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(21, 1fr);
  grid-template-rows: repeat(21, 1fr);
  outline: none;
}

.matrix-row { display: contents; }

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid rgba(233, 226, 210, 0.045);
  border-bottom: 1px solid rgba(233, 226, 210, 0.045);
  color: #c7ced9;
  font-family: var(--mono);
  font-size: clamp(7.5px, 1.55vw, 16px);
  line-height: 1;
  user-select: none;
  cursor: default;
  position: relative;
  transition: background 100ms ease, color 100ms ease;
}

.cell:nth-child(21n) { border-right: 0; }
.matrix-row:last-child .cell { border-bottom: 0; }

.cell.void { color: rgba(135, 144, 159, 0.18); background: rgba(0, 0, 0, 0.18); }

.cell.primary {
  background: var(--gold);
  color: #100d07;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(255, 244, 215, 0.24);
  z-index: 2;
}

.cell.secondary {
  background: var(--cyan);
  color: #061013;
  font-weight: 800;
  box-shadow: inset 0 0 0 1px rgba(220, 255, 255, 0.2);
  z-index: 2;
}

.cell.both { background: linear-gradient(135deg, var(--gold) 0 50%, var(--cyan) 50% 100%); color: #071010; }

.cell:hover,
.cell.cursor { outline: 1px solid var(--gold-bright); outline-offset: -2px; z-index: 4; }

#connectors {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  pointer-events: none;
  z-index: 3;
}

.connector {
  fill: none;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  opacity: 0.88;
  filter: drop-shadow(0 0 4px rgba(0, 0, 0, 0.8));
}

.connector.primary { stroke: #f6da9c; stroke-width: 3; }
.connector.secondary { stroke: var(--cyan-bright); stroke-width: 2.2; }
.connector.secondary.s1 { stroke: #d68b7d; }
.connector.secondary.s2 { stroke: #a6b7e8; }

.connector {
  stroke-dasharray: 1;
  stroke-dashoffset: 1;
  animation: draw-line 700ms ease forwards;
}

.tooltip {
  position: absolute;
  z-index: 8;
  max-width: 250px;
  padding: 9px 11px;
  border: 1px solid var(--gold);
  background: #0a0c10;
  color: var(--ink);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.5;
}

.tooltip strong { display: block; color: var(--gold-bright); font-size: 12px; letter-spacing: 0.08em; }
.tooltip span { display: block; color: var(--muted); }
.tooltip .tooltip-doc { margin-top: 5px; color: var(--ink-dim); }

.legend { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 12px; font-family: var(--mono); font-size: 9px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend-note { margin-left: auto; }
.swatch { width: 9px; height: 9px; display: inline-block; }
.swatch.gold { background: var(--gold); }
.swatch.cyan { background: var(--cyan); }
.swatch.both { background: linear-gradient(135deg, var(--gold) 0 50%, var(--cyan) 50% 100%); }

.result-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.result-id { margin-left: auto; color: var(--muted); font-size: 9px; letter-spacing: 0.06em; }

.doc-panel { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 9px; margin-top: 14px; }

.doc-card {
  border: 1px solid var(--line-soft);
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.018);
}

.doc-card.main { border-color: rgba(200, 164, 92, 0.5); background: rgba(200, 164, 92, 0.06); }
.doc-card .doc-role { font-family: var(--mono); font-size: 8px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--muted); }
.doc-card .doc-title { margin: 4px 0 3px; color: var(--ink); font-size: 14px; line-height: 1.25; }
.doc-card .doc-meta { font-family: var(--mono); font-size: 9px; color: var(--muted); }
.doc-card .doc-word { color: var(--cyan); }

.method { margin-top: 18px; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.method summary { cursor: pointer; font-family: var(--mono); font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--gold); }
.method summary:focus-visible { outline: 2px solid var(--cyan); outline-offset: 4px; }
.method-body { max-width: 78ch; color: var(--ink-dim); font-size: 14px; line-height: 1.65; }
.formula { padding: 10px 14px; border-left: 2px solid var(--gold); background: rgba(200, 164, 92, 0.06); font-family: var(--mono); color: var(--gold-bright); }
.caveat { border-top: 1px solid var(--line-soft); padding-top: 12px; color: var(--ink-dim); }
.caveat strong { color: var(--ink); }

.empty-state { padding: 42px 30px; min-height: 320px; display: flex; flex-direction: column; justify-content: center; }
.empty-state h2 { font-size: clamp(32px, 4vw, 52px); max-width: 14ch; }
.empty-state p:last-child { max-width: 50ch; color: var(--muted); }

.footer {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  padding: 26px 0 40px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.footer p { margin: 0 0 5px; }
.footer-mark { font-family: var(--mono); font-size: 9px; letter-spacing: 0.18em; color: var(--gold); }
.footer-meta { text-align: right; font-family: var(--mono); font-size: 9px; }
.footer-meta .mono { color: var(--ink-dim); }
.footer-meta .credit { margin-top: 8px; color: var(--gold); letter-spacing: 0.08em; }
.footer-meta .credit span { color: var(--gold-bright); }

.noscript { padding: 20px; border: 1px solid var(--red); margin: 20px; color: var(--ink); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes draw-line { to { stroke-dashoffset: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 1040px) {
  .layout { grid-template-columns: 1fr; }
  .console { position: static; }
  .masthead-bottom { grid-template-columns: 1fr; gap: 22px; }
  .matrix-wrap { max-width: 700px; }
}

@media (max-width: 700px) {
  .shell { width: min(100% - 28px, 1280px); }
  .masthead { padding-top: 28px; }
  .masthead h1 { font-size: clamp(52px, 17vw, 92px); }
  .masthead-top { display: block; }
  .folio { margin-top: 6px; }
  .corpus-stats { grid-template-columns: 1fr 1fr; }
  .corpus-stats div:last-child { grid-column: 1 / -1; }
  main { padding-top: 18px; }
  .console, .evidence { padding: 16px; }
  .actions-row { grid-template-columns: 1fr; }
  .result-metrics { grid-template-columns: repeat(3, 1fr); }
  .evidence-head { display: block; }
  .result-metrics { margin-top: 14px; }
  .matrix-card { padding: 9px; }
  .matrix-toolbar { gap: 8px; }
  .matrix-hint { display: none; }
  .cell { font-size: clamp(8.5px, 2.2vw, 13px); }
  .legend { gap: 9px; font-size: 8px; }
  .legend-note { margin-left: 0; }
  .footer { display: block; }
  .footer-meta { text-align: left; margin-top: 16px; }
  .tooltip { max-width: 210px; }
}

@media (max-width: 390px) {
  .shell { width: calc(100% - 20px); }
  .cell { font-size: 8.5px; }
  .matrix-card { padding: 6px; }
  .console, .evidence { padding: 13px; }
  .result-metrics dd { font-size: 12px; }
}

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