/* Copyright (C) 2026 Esteban Ordano
 * Copyright (C) 2020 Alexander Cobleigh — original TrustNet implementation
 *
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
/* Colour roles come from the validated reference palette. Trust rank is a
   magnitude, so it uses the sequential blue ramp; "most trusted" and
   "distrusted" are states carried by shape and stroke pattern as well as hue,
   so neither depends on colour alone. */
:root {
  color-scheme: light;

  --plane: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --hairline: #e1e0d9;
  --axis: #c3c2b7;

  --seq-100: #cde2fb;
  --seq-250: #86b6ef;
  --seq-400: #3987e5;
  --seq-550: #1c5cab;
  --seq-700: #0d366b;

  --accent: #2a78d6;
  --danger: #d03b3b;

  --radius: 10px;
  --gap: 20px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --plane: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --hairline: #2c2c2a;
    --axis: #383835;
    --accent: #3987e5;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --plane: #0d0d0d;
  --surface: #1a1a19;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --hairline: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
}

* {
  box-sizing: border-box;
}

/* A `display` rule on a class outranks the user-agent's [hidden] rule, so
   hiding has to be asserted explicitly or .layout/.wizard stay visible. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 28px 24px 56px;
}

.masthead {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

h1 {
  margin: 0 0 4px;
  font-size: 26px;
  font-weight: 620;
  letter-spacing: -0.015em;
}

.sub {
  margin: 0;
  color: var(--ink-2);
  max-width: 62ch;
  font-size: 14px;
}

h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
}

code,
.mono {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;
  font-size: 0.92em;
  font-variant-numeric: tabular-nums;
}

.boot {
  padding: 40px;
  text-align: center;
  color: var(--ink-2);
  border: 1px dashed var(--hairline);
  border-radius: var(--radius);
}

.layout {
  display: grid;
  gap: var(--gap);
  grid-template-columns: minmax(0, 1.9fr) minmax(300px, 1fr);
  grid-template-areas:
    "canvas  controls"
    "table   controls"
    "matrix  matrix"
    "derived derived";
  align-items: start;
}

.canvas-panel {
  grid-area: canvas;
}
.controls-panel {
  grid-area: controls;
}
.table-panel {
  grid-area: table;
}
.matrix-panel {
  grid-area: matrix;
}
.derived-panel {
  grid-area: derived;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "canvas" "controls" "table" "matrix" "derived";
  }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px 18px 18px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

/* ---------- wizard ---------- */

.wizard {
  max-width: 980px;
  margin: 0 auto;
  padding: 22px 26px 20px;
}

.steps {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  list-style: none;
  margin: 0 0 22px;
  padding: 0 0 16px;
  border-bottom: 1px solid var(--hairline);
}

.steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  padding: 5px 12px 5px 6px;
  border-radius: 999px;
}

.steps li.current {
  color: var(--ink);
  background: var(--plane);
}

.steps li.done {
  color: var(--ink-2);
}

.step-n {
  display: inline-grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  font-size: 11.5px;
  font-weight: 650;
  border: 1px solid var(--hairline);
  background: var(--surface);
}

.steps li.current .step-n {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.steps li.done .step-n {
  border-color: var(--axis);
  color: var(--ink-2);
}

.step-body h3 {
  margin: 0 0 6px;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.lede {
  margin: 0 0 20px;
  max-width: 74ch;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-2);
}

.count-field {
  max-width: 340px;
}

.names-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.name-field label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.name-field input {
  width: 100%;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--hairline);
  background: var(--plane);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

.name-field input:focus {
  outline: none;
  border-color: var(--accent);
}

.param-block .slider:last-child {
  margin-bottom: 0;
}

.wizard-nav {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 26px;
  padding-top: 16px;
  border-top: 1px solid var(--hairline);
}

.wiz-hint {
  font-size: 13px;
  color: var(--muted);
}

.wiz-hint.warn {
  color: var(--danger);
}

.wizard-nav .btn.primary {
  margin-left: auto;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 550;
  padding: 7px 16px;
}

.wizard-nav .btn.primary:hover {
  filter: brightness(1.08);
}

.wizard-nav .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

#matrix th.corner,
#wizard-matrix th.corner,
#derived th.corner {
  font-style: italic;
  color: var(--muted);
  font-weight: 400;
}

/* ---------- legend ---------- */

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--ink-2);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.lg-root {
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.5;
}
.lg-low {
  fill: var(--seq-250);
}
.lg-high {
  fill: var(--seq-550);
}
.lg-sel {
  fill: var(--seq-400);
  stroke: var(--ink);
  stroke-width: 2;
}
.lg-dis {
  fill: none;
  stroke: var(--danger);
  stroke-width: 1.5;
  stroke-dasharray: 3 2;
}

/* ---------- graph ---------- */

.canvas-wrap {
  position: relative;
}

#graph {
  display: block;
  width: 100%;
  height: 520px;
  border-radius: 8px;
  background: var(--surface);
  touch-action: none;
  cursor: grab;
}

#graph.dragging {
  cursor: grabbing;
}

.hint {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.hop-ring {
  fill: none;
  stroke: var(--hairline);
  stroke-width: 1;
}

.hop-label {
  font-size: 9.5px;
  fill: var(--muted);
  text-anchor: middle;
  letter-spacing: 0.04em;
}

.edge {
  stroke: var(--axis);
  fill: none;
}

.edge.backprop {
  stroke: var(--axis);
  stroke-dasharray: 2 4;
  opacity: 0.45;
}

.node-hit {
  fill: transparent;
  cursor: pointer;
}

.node {
  stroke: var(--surface);
  stroke-width: 2;
  transition: opacity 120ms ease;
}

.node.selected {
  stroke: var(--ink);
  stroke-width: 2.5;
}

.node.root {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2;
}

.node.distrusted {
  fill: none;
  stroke: var(--danger);
  stroke-width: 1.5;
  stroke-dasharray: 3 2.5;
}

.node-label {
  font-size: 11px;
  fill: var(--ink-2);
  text-anchor: middle;
  pointer-events: none;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.node-label.distrusted {
  fill: var(--muted);
  text-decoration: line-through;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: var(--surface);
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.4;
  white-space: nowrap;
  z-index: 5;
}

/* ---------- controls ---------- */

.field,
.slider {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 550;
  margin-bottom: 6px;
}

label .mono {
  float: right;
  font-weight: 500;
  color: var(--ink-2);
}

select {
  width: 100%;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--hairline);
  background: var(--plane);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  margin: 2px 0 0;
}

.note {
  margin: 5px 0 0;
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.note q {
  font-style: italic;
}

.energy-box {
  border-top: 1px solid var(--hairline);
  padding-top: 14px;
  margin-top: 4px;
}

.energy-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  font-weight: 550;
  margin-bottom: 7px;
}

.meter {
  height: 7px;
  border-radius: 4px;
  background: var(--hairline);
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 180ms ease;
}

.status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--hairline);
}

.pill {
  font-size: 11.5px;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  background: var(--plane);
}

.btn {
  font: inherit;
  font-size: 13px;
  padding: 5px 11px;
  border-radius: 7px;
  border: 1px solid var(--hairline);
  background: var(--plane);
  color: var(--ink);
  cursor: pointer;
}

.btn:hover {
  border-color: var(--axis);
}

.btn.ghost {
  margin-left: auto;
}

/* ---------- table ---------- */

.table-scroll {
  overflow-x: auto;
  max-height: 340px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th,
td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--hairline);
}

thead th {
  position: sticky;
  top: 0;
  background: var(--surface);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

tbody tr.is-distrusted td:first-child {
  text-decoration: line-through;
  color: var(--muted);
}

.swatch {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: baseline;
}

.state {
  font-size: 12px;
  color: var(--ink-2);
}

.bar-cell {
  position: relative;
}

/* ---------- matrix ---------- */

.matrix-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.matrix-scroll {
  overflow: auto;
  max-height: 420px;
}

/* The matrices are sized by their content, not stretched to the panel, and
   their headers are participant names so they must not be upper-cased. */
#matrix,
#wizard-matrix,
#derived {
  width: auto;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
}

#matrix th,
#wizard-matrix th,
#derived th {
  text-transform: none;
  letter-spacing: 0;
}

#matrix th,
#wizard-matrix th {
  position: sticky;
  background: var(--surface);
  z-index: 2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 500;
  font-size: 11px;
  color: var(--ink-2);
  padding: 3px 5px;
  border: 0;
  text-align: center;
  white-space: nowrap;
}

#matrix thead th,
#wizard-matrix thead th {
  top: 0;
}

#matrix tbody th,
#wizard-matrix tbody th {
  left: 0;
  text-align: right;
  z-index: 1;
  border-right: 1px solid var(--hairline);
}

#matrix thead th:first-child,
#wizard-matrix thead th:first-child {
  left: 0;
  z-index: 3;
}

#matrix th.is-root,
#wizard-matrix th.is-root {
  color: var(--ink);
  font-weight: 700;
}

#matrix td,
#wizard-matrix td {
  padding: 1px;
  border: 0;
  border-bottom: 1px solid var(--hairline);
}

#matrix td:last-child,
#wizard-matrix td:last-child {
  border-right: 0;
}

.cell-input {
  width: 46px;
  padding: 3px 4px;
  text-align: center;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-2);
  font: inherit;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

.cell-input::-webkit-outer-spin-button,
.cell-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.cell-input:hover {
  border-color: var(--hairline);
}

.cell-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--plane);
  color: var(--ink);
}

.cell-input.has-value {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

.cell-identity {
  width: 46px;
  padding: 3px 4px;
  text-align: center;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    var(--hairline) 3px,
    var(--hairline) 4px
  );
  border-radius: 5px;
}

.matrix-foot {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--hairline);
  max-width: 82ch;
}

.matrix-intro {
  margin: -4px 0 12px;
  max-width: 82ch;
}

.chip {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
  vertical-align: -1px;
  margin-right: 4px;
}

.chip-set {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* ---------- derived heatmap ---------- */

#derived th {
  position: sticky;
  background: var(--surface);
  z-index: 2;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 500;
  font-size: 11px;
  color: var(--ink-2);
  padding: 3px 6px;
  text-align: center;
  white-space: nowrap;
}

#derived thead th {
  top: 0;
}

#derived tbody th {
  left: 0;
  text-align: right;
  z-index: 1;
  border-right: 1px solid var(--hairline);
}

#derived thead th:first-child {
  left: 0;
  z-index: 3;
}

#derived th.is-root {
  color: var(--ink);
  font-weight: 700;
}

#derived td {
  padding: 0;
  border: 0;
}

.hcell {
  width: 50px;
  height: 25px;
  line-height: 25px;
  text-align: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-size: 10.5px;
  /* 2px surface gap between adjacent fills */
  margin: 1px;
  border-radius: 3px;
  cursor: default;
}

.hcell.identity {
  color: var(--muted);
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 3px,
    var(--hairline) 3px,
    var(--hairline) 4px
  );
}

.hcell.zero {
  color: var(--muted);
}

.hcell.selected-row {
  box-shadow: inset 0 0 0 1.5px var(--ink);
}

/* Values that are not on the shared energy scale: outlined, never filled, so
   they cannot be compared by colour against the heatmap cells. */
.hcell.offscale {
  color: var(--ink-2);
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--axis);
}

#derived th.is-firstorder {
  color: var(--muted);
}

/* ---------- prose ---------- */

.prose p {
  margin: 0 0 11px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--ink-2);
}

.prose p:last-child {
  margin-bottom: 0;
}

.credits {
  border-top: 1px solid var(--hairline);
  padding-top: 11px;
  font-size: 12.5px;
  color: var(--muted);
}

a {
  color: var(--accent);
}

.ratio-note {
  margin: -4px 0 14px;
  padding: 7px 9px;
  border-radius: 7px;
  background: var(--plane);
  border: 1px solid var(--hairline);
  font-variant-numeric: tabular-nums;
}

.ratio-note.warn {
  color: var(--danger);
  border-color: var(--danger);
}
