@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;1,400&family=IBM+Plex+Mono:wght@400;500&family=Crimson+Pro:ital,wght@0,400;0,600;1,400;1,600&display=swap");

/* ------------------------------------------------------------------ tokens */
/* Ink on paper, with a red-pen accent for the relations of T. Neutrals are
   pulled very slightly toward the indigo used for orbits, so nothing reads as
   default grey. */

:root {
  --paper: #f7f7fa;
  --surface: #ffffff;
  --surface-sunk: #f0f1f5;
  --ink: #14161c;
  --ink-soft: #4d5462;
  --ink-faint: #848b9b;
  --rule: #dcdee6;
  --rule-strong: #c2c6d2;

  --accent: #b3351c;
  --accent-soft: #e0a596;
  --accent-wash: #fbeeea;
  --orbit: #3f3a9c;
  --orbit-wash: #ecebf7;
  --good: #1c6f47;
  --warn: #8a5a0b;

  --cell-off: #d8dbe6;
  --cell-diag: #b9bfcd;
  --shadow: 0 1px 2px rgb(20 22 28 / 6%), 0 4px 14px rgb(20 22 28 / 5%);

  --font-ui: "IBM Plex Sans", ui-sans-serif, system-ui, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;
  --font-math: "Crimson Pro", "Iowan Old Style", Georgia, serif;

  --rail: 340px;
  --step: 0.35rem;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0e1015;
    --surface: #161920;
    --surface-sunk: #11141a;
    --ink: #e7e9f0;
    --ink-soft: #a2a9b9;
    --ink-faint: #6d7486;
    --rule: #272c37;
    --rule-strong: #39404f;

    --accent: #f07a5c;
    --accent-soft: #7e3826;
    --accent-wash: #2a1712;
    --orbit: #9d95f2;
    --orbit-wash: #1b1930;
    --good: #56c98d;
    --warn: #d9a441;

    --cell-off: #232936;
    --cell-diag: #333b4b;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
  }
}

:root[data-theme="dark"] {
  --paper: #0e1015;
  --surface: #161920;
  --surface-sunk: #11141a;
  --ink: #e7e9f0;
  --ink-soft: #a2a9b9;
  --ink-faint: #6d7486;
  --rule: #272c37;
  --rule-strong: #39404f;

  --accent: #f07a5c;
  --accent-soft: #7e3826;
  --accent-wash: #2a1712;
  --orbit: #9d95f2;
  --orbit-wash: #1b1930;
  --good: #56c98d;
  --warn: #d9a441;

  --cell-off: #232936;
  --cell-diag: #333b4b;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
}

/* ------------------------------------------------------------------ shell */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  min-height: 0;
}

:focus-visible {
  outline: 2px solid var(--orbit);
  outline-offset: 2px;
  border-radius: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}

/* ----------------------------------------------------------------- header */

header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}

.wordmark {
  font-weight: 600;
  font-size: 0.82rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
}

.current {
  font-family: var(--font-math);
  font-size: 1.32rem;
  line-height: 1;
  padding-left: 1rem;
  border-left: 1px solid var(--rule);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: var(--step);
  align-items: center;
  flex-wrap: wrap;
}

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

button,
select,
input,
textarea {
  font: inherit;
  color: inherit;
}

.btn {
  background: var(--surface);
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  padding: 0.32rem 0.66rem;
  cursor: pointer;
  font-size: 0.82rem;
  white-space: nowrap;
  transition: background 120ms ease, border-color 120ms ease;
}

.btn:hover:not(:disabled) {
  background: var(--surface-sunk);
  border-color: var(--ink-faint);
}

.btn:disabled {
  opacity: 0.42;
  cursor: default;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  overflow: hidden;
}

.segmented button {
  background: var(--surface);
  border: 0;
  border-right: 1px solid var(--rule-strong);
  padding: 0.32rem 0.7rem;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--ink-soft);
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button[aria-pressed="true"] {
  background: var(--ink);
  color: var(--paper);
}

/* ------------------------------------------------------------------- body */

.body {
  display: grid;
  grid-template-columns: var(--rail) 1fr;
  min-height: 0;
}

@media (max-width: 900px) {
  .body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    overflow-y: auto;
  }
}

.rail {
  border-right: 1px solid var(--rule);
  background: var(--surface);
  overflow-y: auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.panel {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.panel:last-child {
  border-bottom: 0;
}

.panel h2 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* ------------------------------------------------------------------- tabs */

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--rule);
  background: var(--surface-sunk);
}

.tabs button {
  flex: 1;
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 0.6rem 0.4rem;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.tabs button[aria-selected="true"] {
  color: var(--ink);
  font-weight: 500;
  border-bottom-color: var(--accent);
  background: var(--surface);
}

.tabpane {
  display: none;
  flex-direction: column;
  gap: 0.6rem;
}

.tabpane[data-active="true"] {
  display: flex;
}

select,
input[type="text"],
textarea {
  width: 100%;
  background: var(--surface-sunk);
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}

textarea {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.5;
  resize: vertical;
  min-height: 8rem;
}

.id-lookup {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.id-lookup input[type="number"] {
  width: 4.5rem;
  background: var(--surface-sunk);
  border: 1px solid var(--rule-strong);
  border-radius: 5px;
  padding: 0.4rem 0.5rem;
  font-size: 0.85rem;
}

.id-lookup span {
  color: var(--ink-faint);
}

.hint {
  font-size: 0.76rem;
  color: var(--ink-faint);
  margin: 0;
}

.hint code {
  font-family: var(--font-mono);
  font-size: 0.94em;
  color: var(--ink-soft);
}

.status {
  font-size: 0.78rem;
  padding: 0.4rem 0.55rem;
  border-radius: 5px;
  border-left: 3px solid;
  display: none;
}

.status[data-kind="error"] {
  display: block;
  background: var(--accent-wash);
  border-color: var(--accent);
  color: var(--ink);
}

.status[data-kind="ok"] {
  display: block;
  background: var(--orbit-wash);
  border-color: var(--good);
  color: var(--ink);
}

/* ------------------------------------------------------------- properties */

.readout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.18rem 0.75rem;
  font-size: 0.82rem;
}

.readout dt {
  color: var(--ink-soft);
}

.readout dd {
  margin: 0;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--step);
}

.chip {
  font-size: 0.72rem;
  padding: 0.12rem 0.45rem;
  border-radius: 99px;
  border: 1px solid var(--rule-strong);
  color: var(--ink-faint);
  letter-spacing: 0.02em;
}

.chip[data-on="true"] {
  border-color: var(--good);
  color: var(--good);
  font-weight: 500;
}

/* ------------------------------------------------------------- navigation */

.navlist {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 13rem;
  overflow-y: auto;
}

.navlist button {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  background: var(--surface-sunk);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.28rem 0.45rem;
  cursor: pointer;
  font-size: 0.79rem;
}

.navlist button:hover {
  border-color: var(--accent-soft);
  background: var(--accent-wash);
}

.navlist .arrowlabel {
  font-family: var(--font-math);
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.navlist .delta {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--ink-faint);
  flex: none;
}

.empty {
  font-size: 0.78rem;
  color: var(--ink-faint);
  font-style: italic;
}

/* ----------------------------------------------------------------- canvas */

.canvas {
  display: grid;
  grid-template-rows: 1fr auto;
  min-height: 0;
  min-width: 0;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--paper);
}

.stage svg {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
  touch-action: none;
}

.stage svg.dragging {
  cursor: grabbing;
}

.stage-note {
  position: absolute;
  left: 0.85rem;
  bottom: 0.75rem;
  font-size: 0.74rem;
  color: var(--ink-faint);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  pointer-events: none;
  max-width: 60%;
}

.stage-tools {
  position: absolute;
  right: 0.75rem;
  top: 0.75rem;
  display: flex;
  gap: var(--step);
}

/* diagram marks */

.edge-base {
  stroke: var(--rule-strong);
  stroke-width: 1.4;
  fill: none;
}

.edge-extra {
  stroke: var(--rule);
  stroke-width: 1;
  stroke-dasharray: 3 4;
  fill: none;
}

.edge-in {
  stroke: var(--accent);
  stroke-width: 2.6;
  fill: none;
}

.edge-gen {
  stroke: var(--accent);
  stroke-width: 3.4;
  fill: none;
}

.edge-hit {
  stroke: transparent;
  stroke-width: 14;
  fill: none;
  cursor: pointer;
}

.edge-hit:hover + .edge-draw,
.edge-hit:focus-visible + .edge-draw {
  stroke: var(--orbit);
}

.node circle {
  fill: var(--surface);
  stroke: var(--ink-soft);
  stroke-width: 1.4;
}

.node text {
  font-family: var(--font-math);
  font-style: italic;
  font-size: 15px;
  fill: var(--ink);
  text-anchor: middle;
}

.node.is-bottom circle,
.node.is-top circle {
  fill: var(--ink);
  stroke: var(--ink);
}

.orbit-ring {
  fill: none;
  stroke: var(--orbit);
  stroke-width: 1.2;
  stroke-dasharray: 2 3;
}

.gen-dot {
  fill: var(--accent);
}

.forced-mark {
  fill: var(--paper);
  stroke: var(--orbit);
  stroke-width: 2;
}

g.orbit-hot .edge-draw {
  stroke: var(--orbit);
}

g.orbit-hot > rect,
g.orbit-hot > circle {
  stroke: var(--orbit);
  stroke-width: 2.2;
}

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

.drawer {
  border-top: 1px solid var(--rule);
  background: var(--surface);
  max-height: 42vh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.drawer-head {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.45rem 1rem;
  cursor: pointer;
  user-select: none;
}

.drawer-head h2 {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.drawer-head .spacer {
  flex: 1;
}

.drawer-body {
  overflow: auto;
  padding: 0 1rem 1rem;
  min-height: 0;
}

.drawer[data-open="false"] .drawer-body {
  display: none;
}

table.matrix {
  border-collapse: collapse;
  font-size: 11px;
}

table.matrix th {
  font-family: var(--font-math);
  font-style: italic;
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-soft);
  padding: 1px 4px;
  white-space: nowrap;
  position: sticky;
  background: var(--surface);
}

table.matrix thead th {
  top: 0;
  z-index: 2;
  vertical-align: bottom;
}

table.matrix tbody th {
  left: 0;
  z-index: 1;
  text-align: right;
}

table.matrix td {
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1px solid var(--rule);
}

td.cell-none {
  background: transparent;
  border-color: color-mix(in srgb, var(--rule) 40%, transparent);
}

td.cell-off {
  background: var(--cell-off);
  cursor: pointer;
}

td.cell-off:hover {
  background: var(--accent-wash);
}

td.cell-on {
  background: var(--accent-soft);
  cursor: pointer;
}

td.cell-gen {
  background: var(--accent);
  cursor: pointer;
}

td.cell-diag {
  background: var(--cell-diag);
}

td.orbit-hot {
  box-shadow: inset 0 0 0 2px var(--orbit);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.9rem;
  font-size: 0.75rem;
  color: var(--ink-soft);
  padding: 0.5rem 0 0.3rem;
}

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

.swatch {
  width: 13px;
  height: 13px;
  border-radius: 3px;
  border: 1px solid var(--rule-strong);
  flex: none;
}

/* ------------------------------------------------------------------ notes */

.note {
  font-size: 0.78rem;
  color: var(--ink-soft);
  background: var(--orbit-wash);
  border-left: 3px solid var(--orbit);
  padding: 0.45rem 0.6rem;
  border-radius: 0 5px 5px 0;
}

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

.math {
  font-family: var(--font-math);
  font-style: italic;
}
