/* VELIN: the generative pattern, now a map of the agent's work.
   Palette from the design (navy, cobalt, lime) plus coral for failures. */

:root {
  --bg: #e8f3fd;
  --ink: #13265c;
  --muted: #53679a;
  --rule: #a9bddb;
  --paper: #ffffff;
  --field: rgba(255, 255, 255, 0.4);
  --navy: #13265c;
  --cobalt: #3565f2;
  --lime: #bfe62c;
  --coral: #ff5a3c;
  --grey: #a3adc2;

  --tone-inspected: var(--navy);
  --tone-change: var(--cobalt);
  --tone-fail: var(--coral);
  --tone-pass: var(--lime);
  --tone-running: var(--cobalt);
  --tone-error: var(--grey);
  --tone-idle: #dfe8f5;

  --add-bg: #eaf8c4;
  --del-bg: #ffe3dc;
  --solid-ink: #ffffff;

  --font: ui-monospace, 'SF Mono', 'JetBrains Mono', 'IBM Plex Mono', Menlo, Consolas, 'Liberation Mono', monospace;
  --gutter: clamp(16px, 3.4vw, 52px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #0b1531;
    --ink: #dfe8ff;
    --muted: #93a6d6;
    --rule: #2c3f72;
    --paper: #0f1d44;
    --field: rgba(255, 255, 255, 0.04);
    --tone-inspected: #c9d7ff;
    --tone-change: #6d93ff;
    --tone-idle: #1a2a57;
    --add-bg: #253816;
    --del-bg: #4a1f1a;
    --solid-ink: #0b1531;
  }
}
:root[data-theme='dark'] {
  --bg: #0b1531;
  --ink: #dfe8ff;
  --muted: #93a6d6;
  --rule: #2c3f72;
  --paper: #0f1d44;
  --field: rgba(255, 255, 255, 0.04);
  --tone-inspected: #c9d7ff;
  --tone-change: #6d93ff;
  --tone-idle: #1a2a57;
  --add-bg: #253816;
  --del-bg: #4a1f1a;
  --solid-ink: #0b1531;
}

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

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0.02em;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  line-height: 1.5;
  overflow-x: hidden;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

:focus-visible {
  outline: 2px solid var(--cobalt);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--paper);
  padding: 6px 10px;
  z-index: 10;
}
.skip:focus {
  left: 8px;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

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

hr {
  border: 0;
  border-top: 1px solid var(--rule);
  margin: 26px 0;
}

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

.top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 28px var(--gutter) 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  font-size: 26px;
  letter-spacing: 0.24em;
}

.logo {
  width: 44px;
  height: 40px;
  fill: none;
  stroke: var(--tone-inspected);
  stroke-width: 9;
  stroke-miterlimit: 4;
}
.logo .logo-outer {
  stroke: var(--cobalt);
}

.claim {
  text-align: center;
}
.claim p {
  margin: 0;
}
.claim-main {
  font-size: 15px;
  letter-spacing: 0.12em;
}
.claim-sub {
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.nav {
  justify-self: end;
  display: flex;
  gap: 14px;
  letter-spacing: 0.1em;
}
.nav a {
  text-decoration: none;
}
.nav a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ------------------------------------------------------------ layout */

.studio {
  display: grid;
  grid-template-columns: minmax(220px, 250px) minmax(0, 740px) minmax(280px, 360px);
  justify-content: center;
  gap: 0;
  padding: 16px var(--gutter) 8px;
}

.controls {
  padding-right: 40px;
  border-right: 1px solid var(--rule);
  margin: 36px 0;
}

.stage {
  padding: 0 40px;
  min-width: 0;
}

.evidence {
  padding-left: 36px;
  border-left: 1px solid var(--rule);
  margin: 36px 0;
  min-width: 0;
}

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

.field {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.field input[type='text'],
.field textarea {
  width: 100%;
  border: 1.5px solid var(--ink);
  background: var(--field);
  padding: 12px 14px;
  border-radius: 0;
  font-size: 13px;
}
.field textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.45;
}
.field input:disabled,
.field textarea:disabled {
  opacity: 0.72;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 26px;
  border: 1.5px solid var(--ink);
  background: transparent;
  text-decoration: none;
  letter-spacing: 0.12em;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover:not(:disabled):not([aria-disabled='true']) {
  background: var(--paper);
}
.btn-solid {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--solid-ink);
}
.btn-solid:hover:not([aria-disabled='true']) {
  background: var(--cobalt) !important;
  border-color: var(--cobalt);
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-block {
  width: 100%;
}

.link-btn {
  border: 0;
  background: none;
  padding: 6px 0;
  color: var(--cobalt);
  cursor: pointer;
  text-align: left;
  letter-spacing: 0.06em;
  text-decoration: underline;
  text-underline-offset: 4px;
}
.link-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
#demo-live {
  margin-top: 10px;
  font-size: 13px;
}

.note {
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}
.note:empty {
  display: none;
}
.note-warn {
  color: var(--ink);
  border-left: 3px solid var(--coral);
  padding-left: 10px;
}

.legend {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: grid;
  gap: 12px;
}
.legend-row {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 14px;
  font-size: 13px;
}
.legend-row .dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--tone);
}
.legend-row.tone-running .dot {
  background: transparent;
  border: 3px solid var(--tone);
}
.legend-row.tone-error .dot {
  background: repeating-linear-gradient(45deg, var(--tone) 0 3px, transparent 3px 6px);
  border: 1.5px solid var(--tone);
}
.legend-count {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.range span {
  font-size: 13px;
}
input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
}
input[type='range']::-webkit-slider-runnable-track {
  height: 3px;
  background: linear-gradient(90deg, var(--ink) var(--fill, 50%), var(--rule) var(--fill, 50%));
}
input[type='range']::-moz-range-track {
  height: 3px;
  background: var(--rule);
}
input[type='range']::-moz-range-progress {
  height: 3px;
  background: var(--ink);
}
input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
}
input[type='range']::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--ink);
  border: 0;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}
.switch {
  position: relative;
  width: 58px;
  height: 32px;
  border-radius: 16px;
  border: 1.5px solid var(--ink);
  background: transparent;
  cursor: pointer;
  padding: 0;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.15s ease;
}
.switch[aria-checked='true'] {
  background: var(--ink);
}
.switch[aria-checked='true']::after {
  background: var(--paper);
  transform: translateX(26px);
}

.shape-key {
  margin: 26px 0 0;
  display: grid;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
.shape-key div {
  display: flex;
  align-items: center;
  gap: 12px;
}
.shape-key dt svg {
  width: 20px;
  height: 14px;
  display: block;
  fill: none;
  stroke: var(--tone-inspected);
  stroke-width: 2;
}
.shape-key dd {
  margin: 0;
}

/* ------------------------------------------------------------ stage */

.stage-head {
  display: flex;
  align-items: baseline;
  gap: 16px;
  min-height: 30px;
  flex-wrap: wrap;
}
.run-meta {
  margin: 0;
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  min-width: 0;
  overflow-wrap: anywhere;
}
.stage-actions {
  display: flex;
  gap: 16px;
}

.canvas {
  margin-top: 10px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  padding: 12px;
}
#map-svg {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
}

#map-svg .paper {
  fill: var(--paper);
}
#map-svg path {
  fill: none;
  stroke-linecap: butt;
}
#map-svg .idle {
  stroke: var(--tone-idle);
}
#map-svg .tile {
  cursor: pointer;
  outline: none;
}
#map-svg .hit {
  fill: transparent;
}
#map-svg .tile .lines {
  stroke: var(--tone);
  transition: opacity 0.12s ease;
}
#map-svg .tile:hover .lines,
#map-svg .tile:focus-visible .lines {
  opacity: 0.72;
}
#map-svg .tile:focus-visible .hit {
  stroke: var(--cobalt);
  stroke-width: 3;
  stroke-dasharray: 6 4;
}
#map-svg .ring {
  fill: none;
  stroke: var(--ink);
  stroke-width: 3;
}
#map-svg .tag rect {
  fill: var(--paper);
  stroke: var(--ink);
  stroke-width: 1.5;
}
#map-svg .tag text {
  fill: var(--ink);
  font-family: var(--font);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
#map-svg .tone-running .lines {
  animation: pulse 0.9s ease-in-out infinite alternate;
}
#map-svg .tone-error .lines {
  stroke-dasharray: 3 5;
}

.tone-inspected { --tone: var(--tone-inspected); }
.tone-change { --tone: var(--tone-change); }
.tone-fail { --tone: var(--tone-fail); }
.tone-pass { --tone: var(--tone-pass); }
.tone-running { --tone: var(--tone-running); }
.tone-error { --tone: var(--tone-error); }

@keyframes pulse {
  from { opacity: 1; }
  to { opacity: 0.25; }
}

.phases {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 0;
  margin: 16px 0 0;
  padding: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.phase:not(:last-child)::after {
  content: '→';
  margin: 0 10px;
  color: var(--rule);
}
.phase.is-done {
  color: var(--ink);
}
.phase.is-current {
  color: var(--cobalt);
  text-decoration: underline;
  text-underline-offset: 4px;
}

.caption {
  margin: 8px 0 0;
  min-height: 1.5em;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------------ evidence */

.evidence-body {
  display: grid;
  gap: 18px;
  margin-top: 16px;
}

.card {
  display: grid;
  gap: 8px;
  width: 100%;
  padding: 16px 18px;
  border: 1.5px solid var(--ink);
  background: var(--paper);
  text-align: left;
  font-size: 12.5px;
  min-width: 0;
}
button.card {
  cursor: pointer;
}
button.card:hover {
  border-color: var(--cobalt);
}
.card-empty {
  background: transparent;
  border-style: dashed;
  border-color: var(--rule);
}
.card-empty p {
  margin: 0;
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.swatch path {
  fill: none;
  stroke: var(--tone);
}

.card-verdict p {
  margin: 0;
}
.verdict-word {
  font-size: 30px;
  line-height: 1.1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.verdict-label {
  color: var(--muted);
}
.verdict-fixed .verdict-word {
  box-shadow: inset 0 -10px 0 var(--lime);
  justify-self: start;
}
.verdict-regressed .verdict-word,
.verdict-error .verdict-word {
  box-shadow: inset 0 -10px 0 var(--coral);
  justify-self: start;
}
.verdict-running .verdict-word {
  color: var(--cobalt);
}
.reasons,
.warnings {
  margin: 4px 0 0;
  padding-left: 18px;
}
.warnings li {
  list-style: '⚠ ';
}
.summary {
  line-height: 1.55;
  border-top: 1px solid var(--rule);
  padding-top: 10px !important;
  margin-top: 4px !important;
}

.cmd {
  display: block;
  font-size: 12px;
  overflow-wrap: anywhere;
}
.exit {
  font-size: 12px;
}
.exit::before {
  content: '';
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 8px;
  background: var(--grey);
}
.exit-pass::before {
  background: var(--lime);
}
.exit-fail::before {
  background: var(--coral);
}
.failing {
  display: grid;
  gap: 2px;
  color: var(--muted);
  font-size: 11.5px;
}

.files {
  display: grid;
  gap: 4px;
}
.file {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.file .path {
  overflow-wrap: anywhere;
}
.delta {
  white-space: nowrap;
}
ins {
  text-decoration: none;
  color: #4d7a00;
}
del {
  text-decoration: none;
  color: #c2361c;
}

/* detail view */
.detail {
  display: grid;
  gap: 12px;
  min-width: 0;
}
.detail:focus {
  outline: none;
}
.detail-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.nav-buttons {
  display: flex;
  gap: 6px;
}
.icon-btn {
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}
.icon-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0;
}
.chip {
  border: 1px solid var(--rule);
  padding: 2px 8px;
  font-size: 11.5px;
}
.chip-fail {
  border-color: var(--coral);
}
.chip-pass {
  border-color: var(--lime);
  background: color-mix(in srgb, var(--lime) 25%, transparent);
}
.chip-change {
  border-color: var(--cobalt);
}
.detail-title {
  margin: 0;
  font-size: 15px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.why {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}
.detail h4 {
  margin: 8px 0 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}
.detail p {
  margin: 0;
}
.error-msg {
  border-left: 3px solid var(--coral);
  padding-left: 10px;
}
.failing-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  font-size: 12px;
}

pre.out,
pre.code,
pre.diff {
  margin: 0;
  max-height: 460px;
  overflow: auto;
  padding: 12px;
  background: var(--paper);
  border: 1px solid var(--rule);
  font-size: 11.5px;
  line-height: 1.5;
  white-space: pre;
  tab-size: 2;
}
pre .ln {
  color: var(--muted);
  user-select: none;
}
pre.diff {
  display: grid;
  grid-template-columns: minmax(100%, max-content);
}
pre.diff span {
  white-space: pre;
}
pre.diff .add {
  background: var(--add-bg);
}
pre.diff .del {
  background: var(--del-bg);
}
pre.diff .hunk {
  color: var(--cobalt);
}
pre.diff .meta {
  color: var(--muted);
}

/* ------------------------------------------------------------ actions */

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 16px 22px;
  padding: 26px var(--gutter) 40px;
}
.divider {
  width: 1px;
  height: 36px;
  background: var(--ink);
  margin: 0 8px;
}
.apply-hint {
  margin: 0;
  font-size: 12.5px;
  letter-spacing: 0.06em;
}
.apply-hint code {
  font-family: inherit;
}

/* ------------------------------------------------------------ how / scope */

.how,
.scope {
  max-width: 1120px;
  margin: 0 auto;
  padding: 40px var(--gutter);
  border-top: 1px solid var(--rule);
}
.lede {
  max-width: 760px;
  font-size: 15px;
  line-height: 1.6;
  margin: 18px 0 30px;
}
.steps {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 20px;
}
.steps li {
  border-top: 3px solid var(--ink);
  padding-top: 14px;
}
.steps .n {
  color: var(--cobalt);
  font-size: 12px;
}
.steps h3 {
  margin: 6px 0;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.1em;
}
.steps p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
}
.example {
  margin: 32px 0 0;
  padding: 16px 20px;
  border-left: 4px solid var(--lime);
  background: var(--field);
  max-width: 900px;
  line-height: 1.6;
}
.example strong {
  font-weight: 500;
}
.scope-list {
  margin: 18px 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
  font-size: 14px;
}
.scope-list span {
  color: var(--muted);
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 20px var(--gutter) 0;
  padding: 18px 0 26px;
  border-top: 1.5px solid var(--ink);
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1180px) {
  .studio {
    grid-template-columns: minmax(220px, 250px) minmax(0, 1fr);
  }
  .evidence {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--rule);
    padding: 26px 0 0;
    margin: 24px 0 0;
  }
  .evidence-body {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    align-items: start;
  }
  .evidence-body .detail {
    grid-column: 1 / -1;
  }
  .steps {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .top {
    grid-template-columns: 1fr auto;
  }
  .claim {
    grid-column: 1 / -1;
    grid-row: 2;
    text-align: left;
  }
  .nav {
    font-size: 12px;
    gap: 8px;
  }
  .studio {
    grid-template-columns: minmax(0, 1fr);
    padding-top: 0;
  }
  .controls {
    border-right: 0;
    padding: 0;
    margin: 12px 0 24px;
  }
  .stage {
    padding: 0;
  }
  .canvas {
    padding: 6px;
  }
  .steps {
    grid-template-columns: minmax(0, 1fr);
  }
  .divider {
    display: none;
  }
  .actions .btn {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #map-svg .tone-running .lines {
    animation: none;
  }
  .switch::after {
    transition: none;
  }
}
