:root {
  --navy: #0b1220;
  --navy-2: #121a2c;
  --navy-3: #1a2744;
  --ice: #e8eef6;
  --mist: #b7c4d8;
  --steel: #7a92b3;
  --live: #4fd1c5;
  --warn: #e8b86d;
  --alert: #e05a4f;
  --letter: #f7f4ee;
  --ink: #152033;
  --line: rgba(232, 238, 246, 0.12);
  --sans: "Sora", "Segoe UI", sans-serif;
  --serif: "Source Serif 4", "Palatino Linotype", serif;
  --r-shell: 16px;
  --r-inner: 12px;
  --r-ctrl: 8px;
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --move: 160ms ease-out;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--sans);
  color: var(--ice);
  background: var(--navy);
  font-size: 14px;
  line-height: 1.45;
}

.app {
  min-height: 100vh;
  width: 100%;
  margin: 0;
  padding: var(--s4);
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: var(--s4);
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s4);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
  color: inherit;
  text-decoration: none;
  border-radius: var(--r-ctrl);
}
.brand img {
  width: 36px;
  height: 36px;
  border-radius: var(--r-ctrl);
  background: var(--navy-3);
  border: 1px solid var(--line);
}
.brand strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.brand em {
  display: block;
  font-style: normal;
  font-size: 12px;
  color: var(--steel);
  font-weight: 400;
}

.live {
  display: flex;
  align-items: center;
  gap: var(--s2);
  padding: var(--s2) var(--s3);
  border: 1px solid var(--line);
  border-radius: var(--r-ctrl);
  background: var(--navy-2);
}
.live small {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--steel);
}
.live b { font-weight: 500; font-size: 12px; }
.lamp {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--alert);
}
.lamp.on { background: var(--live); }

.modes {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s1);
  border-bottom: 1px solid var(--line);
  padding-bottom: var(--s2);
}
.modes button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 36px;
  flex: 0 0 auto;
  white-space: nowrap;
  background: transparent;
  border: 0;
  border-radius: var(--r-ctrl);
  color: var(--steel);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 0 var(--s3);
  cursor: pointer;
  transition: background-color var(--move), color var(--move);
}
.modes button:hover { color: var(--ice); background: var(--navy-2); }
.modes button.on {
  color: var(--ice);
  background: var(--navy-3);
  box-shadow: inset 0 -2px 0 var(--live);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(260px, 38%) minmax(0, 1fr);
  gap: var(--s5);
  align-items: stretch;
  min-height: 0;
}
.composer, .stage, .ledger {
  background: var(--navy-2);
  border: 1px solid var(--line);
  border-radius: var(--r-shell);
  padding: var(--s4);
}
.stage { min-height: 100%; }
.step {
  margin: 0 0 var(--s2);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--live);
  font-weight: 600;
}
.row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--s3);
}
h1, h2 { margin: 0; font-weight: 600; letter-spacing: -0.03em; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
.hint { color: var(--mist); font-size: 13px; margin: var(--s2) 0 var(--s3); }
.hint.tight { margin: 0; }
.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

textarea {
  width: 100%;
  min-height: 240px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--r-inner);
  background: var(--navy);
  color: var(--ice);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.5;
  padding: var(--s3);
  outline: none;
  transition: border-color var(--move), box-shadow var(--move);
}
textarea::placeholder { color: rgba(183, 196, 216, 0.45); }

.actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: var(--s2);
  margin-top: var(--s3);
}
button.primary, button.ghost, button.text {
  font-family: inherit;
  cursor: pointer;
}
button.primary, button.ghost {
  border-radius: var(--r-ctrl);
  padding: var(--s2) var(--s4);
  font-size: 13px;
  font-weight: 600;
  border: 0;
  transition: background-color var(--move), border-color var(--move), color var(--move), transform 120ms ease-out;
}
button.primary {
  background: var(--ice);
  color: var(--navy);
}
button.primary:hover { background: #fff; }
button.ghost {
  background: transparent;
  color: var(--ice);
  border: 1px solid var(--line);
}
button.ghost:hover { border-color: var(--steel); background: var(--navy-3); }
button.ghost.danger { color: #ffb4ae; border-color: rgba(224, 90, 79, 0.4); }
button.ghost.danger:hover { background: rgba(224, 90, 79, 0.12); }
button.text {
  background: none;
  border: 0;
  color: var(--steel);
  font-size: 12px;
  padding: var(--s1);
  border-radius: var(--r-ctrl);
  transition: color var(--move);
}
button.text:hover { color: var(--ice); }

button.primary:active,
button.ghost:active,
.modes button:active { transform: translateY(1px); }

button.primary:disabled:not(.is-busy),
button.ghost:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
button.primary.is-busy {
  position: relative;
  color: transparent;
  pointer-events: none;
}
button.primary.is-busy::after {
  content: "";
  position: absolute;
  inset: 50% auto auto 50%;
  width: 14px;
  height: 14px;
  margin: -7px 0 0 -7px;
  border: 2px solid var(--navy);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

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

.empty {
  text-align: left;
}
.empty ol {
  margin: var(--s3) 0 0;
  padding-left: 18px;
  color: var(--mist);
  display: grid;
  gap: var(--s2);
}
.skeleton, .outcome, .empty { min-width: 0; }
.outcome[hidden], .empty[hidden], .skeleton[hidden] { display: none !important; }

.skel-chip {
  width: 120px;
  height: 22px;
  margin-bottom: var(--s3);
}
.skel-letter {
  background: var(--letter);
  border-radius: var(--r-inner);
  padding: var(--s5);
  display: grid;
  gap: var(--s3);
}
.skel-line {
  height: 12px;
  border-radius: 4px;
  background: rgba(21, 32, 51, 0.12);
  animation: pulse 1.1s ease-out infinite;
}
.skel-line.short { width: 42%; }
.skel-line.mid { width: 68%; }

.chips { display: flex; flex-wrap: wrap; gap: var(--s2); margin: var(--s1) 0 var(--s3); }
.chip {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: var(--s1) var(--s2);
  border-radius: var(--r-ctrl);
  border: 1px solid rgba(79, 209, 197, 0.4);
  color: var(--live);
}
.chip.warn {
  border-color: rgba(232, 184, 109, 0.45);
  color: var(--warn);
}
.masked { margin: 0 0 var(--s3); font-size: 12px; color: var(--steel); }
.letter {
  background: var(--letter);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  line-height: 1.55;
  padding: var(--s5);
  border-radius: var(--r-inner);
  white-space: pre-wrap;
  border: 1px solid rgba(21, 32, 51, 0.06);
}
.sop { font-size: 12px; color: var(--mist); margin: var(--s3) 0 0; }
.missing {
  list-style: none;
  margin: var(--s3) 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--s2);
}
.missing li {
  font-size: 12px;
  padding: var(--s2) var(--s3);
  border-radius: var(--r-ctrl);
  background: rgba(232, 184, 109, 0.12);
  color: var(--warn);
}
.status { min-height: 1.2em; margin: var(--s3) 0 0; font-size: 12px; color: var(--live); }
.status.is-error { color: #ffb4ae; }

.ledger { padding: var(--s2) var(--s4) var(--s3); }
.ledger summary {
  list-style: none;
  cursor: pointer;
  padding: var(--s2) 0;
  font-weight: 600;
  border-radius: var(--r-ctrl);
}
.ledger summary::-webkit-details-marker { display: none; }
.ledger .row { margin-bottom: var(--s2); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th, td { text-align: left; padding: var(--s2) var(--s1); border-bottom: 1px solid var(--line); }
th { color: var(--steel); font-weight: 500; }
td.hash { font-variant-numeric: tabular-nums; color: var(--mist); }

footer {
  display: flex;
  justify-content: space-between;
  gap: var(--s3);
  flex-wrap: wrap;
  color: var(--steel);
  font-size: 11px;
}

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; gap: var(--s4); }
  textarea { min-height: 180px; }
}

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

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0%, 100% { opacity: 0.45; }
  50% { opacity: 0.9; }
}
