:root {
  color-scheme: dark;
  --ink: #eef5ee;
  --ink-dim: #b8c5bb;
  --ink-muted: #7f8d84;
  --coal: #080b0a;
  --coal-2: #0e1412;
  --coal-3: #141d19;
  --line: #2a3831;
  --line-strong: #496255;
  --paper: #e9dfc7;
  --cyan: #54d6c7;
  --cyan-quiet: #143f3b;
  --amber: #f0bc55;
  --amber-quiet: #3b2c12;
  --green: #87d68d;
  --green-quiet: #17391e;
  --red: #ff7a7a;
  --red-quiet: #431b1b;
  --focus: #fff2a8;
  --shadow: rgba(0, 0, 0, 0.36);
  --radius: 18px;
  --mono: "Berkeley Mono", "IBM Plex Mono", "Menlo", "Consolas", monospace;
  --body: "Aptos", "Gill Sans", "Trebuchet MS", sans-serif;
  --display: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
}

* {
  box-sizing: border-box;
}

*,
*::before,
*::after {
  min-width: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--coal);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
}

button,
input,
textarea {
  font: inherit;
  min-width: 0;
}

button {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--coal-3);
  color: var(--ink);
  padding: 0.68rem 1rem;
  cursor: pointer;
  transition: border-color 150ms ease, transform 150ms ease, background-color 150ms ease;
}

button:hover {
  border-color: var(--cyan);
  transform: translateY(-1px);
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
pre:focus-visible,
.token-button:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
  transform: none;
}

button.primary {
  border-color: var(--cyan);
  background: var(--cyan);
  color: #06211f;
  font-weight: 800;
}

button.quiet {
  border-color: var(--line);
  background: transparent;
  color: var(--ink-dim);
}

textarea,
input {
  width: 100%;
  max-width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #050807;
  color: var(--ink);
  padding: 0.9rem;
  overflow-wrap: anywhere;
}

input[readonly] {
  color: var(--paper);
  border-style: dashed;
}

textarea {
  resize: vertical;
}

label {
  display: block;
  color: var(--ink);
  font-weight: 800;
}

code,
pre,
.cover-output,
.secret-output,
.engine-facts dd,
.fingerprint,
.bit-chip {
  font-family: var(--mono);
}

code,
pre,
dd,
.engine-status,
.help,
.notice,
.empty-state,
.compatibility-box,
.pipeline-step span,
.token-button,
.badge {
  overflow-wrap: anywhere;
  word-break: break-word;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

h1 {
  font-size: clamp(3.4rem, 9vw, 8rem);
}

h2 {
  font-size: clamp(2rem, 4vw, 3.35rem);
}

h3 {
  font-size: clamp(1.35rem, 2vw, 1.9rem);
}

p {
  margin: 0;
}

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

.skip-link {
  position: absolute;
  left: 1rem;
  top: 1rem;
  z-index: 10;
  transform: translateY(-140%);
  background: var(--focus);
  color: #111;
  padding: 0.75rem 1rem;
  border-radius: 999px;
}

.skip-link:focus {
  transform: translateY(0);
}

.masthead,
.workspace {
  width: min(1540px, calc(100% - 2rem));
  max-width: 100%;
  margin-inline: auto;
}

.masthead {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 2rem;
  padding: 2rem 0 1rem;
  align-items: end;
}

.masthead__copy {
  max-width: 980px;
}

.lede {
  max-width: 760px;
  color: var(--ink-dim);
  font-size: clamp(1.05rem, 1.7vw, 1.35rem);
}

.eyebrow {
  margin-bottom: 0.55rem;
  color: var(--cyan);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.engine-card,
.panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(14, 20, 18, 0.96);
  box-shadow: 0 24px 70px var(--shadow);
}

.engine-card {
  padding: 1rem;
}

.engine-status {
  color: var(--amber);
  font-weight: 800;
}

.engine-status.ok {
  color: var(--green);
}

.engine-status.bad {
  color: var(--red);
}

.engine-facts {
  display: grid;
  gap: 0.6rem;
  margin: 1rem 0 0;
}

.engine-facts div,
.model-facts div,
.metric-row,
.compatibility-box {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(8rem, 0.4fr) minmax(0, 1fr);
  gap: 0.7rem;
  align-items: start;
}

.engine-facts dt,
.model-facts dt,
.metric-row dt {
  color: var(--ink-muted);
}

.engine-facts dd,
.model-facts dd,
.metric-row dd {
  margin: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.workspace-nav {
  display: flex;
  min-width: 0;
  gap: 0.5rem;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--coal-2);
  padding: 0.35rem;
  position: sticky;
  top: 0.75rem;
  z-index: 4;
}

.nav-tab {
  min-width: 0;
  flex: 1;
  border-color: transparent;
  background: transparent;
  color: var(--ink-dim);
  font-weight: 900;
}

.nav-tab.is-active {
  background: var(--paper);
  color: #15110a;
}

.view {
  min-width: 0;
  display: none;
  padding: 1rem 0 2rem;
}

.view.is-active {
  display: block;
}

.two-column {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(320px, 0.85fr) minmax(360px, 1.15fr);
  gap: 1rem;
  align-items: start;
}

.panel {
  padding: clamp(1rem, 2vw, 1.35rem);
}

.browser-llm-card {
  min-width: 0;
  display: grid;
  gap: 1rem;
  border: 1px solid var(--cyan-quiet);
  border-radius: var(--radius);
  background: var(--coal-2);
  padding: 1rem;
}

#browser-llm-status.ok {
  color: var(--green);
}

#browser-llm-status.bad {
  color: var(--red);
}

.model-facts {
  min-width: 0;
  display: grid;
  gap: 0.5rem;
  margin: 0;
}

.reference-box {
  min-width: 0;
  display: grid;
  gap: 0.7rem;
  margin-top: 1rem;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: #050807;
  padding: 1rem;
}

.reference-box [role="status"] {
  color: var(--ink-dim);
  font-weight: 800;
}

.reference-box [role="status"].ok {
  color: var(--green);
}

.reference-box [role="status"].bad {
  color: var(--amber);
}

.form-panel,
.result-panel,
.checklist-panel {
  min-width: 0;
  min-height: 100%;
}

.decode-side {
  min-width: 0;
  display: grid;
  gap: 1rem;
}

.section-heading {
  min-width: 0;
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1.15rem;
}

.section-heading p:not(.eyebrow),
.help {
  color: var(--ink-dim);
}

.split-heading {
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 1rem;
}

.field {
  min-width: 0;
  display: grid;
  gap: 0.45rem;
  margin: 1rem 0;
}

.help {
  font-size: 0.92rem;
}

.key-control {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: start;
}

.action-row {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  align-items: center;
}

.action-row.compact button {
  min-height: 38px;
  padding: 0.45rem 0.75rem;
}

.empty-state,
.notice,
.compatibility-box {
  min-width: 0;
  max-width: 100%;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  color: var(--ink-dim);
  padding: 1rem;
}

.cover-output,
.secret-output {
  min-width: 0;
  max-width: 100%;
  max-height: 380px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #050807;
  color: var(--paper);
  padding: 1rem;
}

.result-stack {
  min-width: 0;
  display: grid;
  gap: 1rem;
}

.status-line {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 0.35rem 0.7rem;
  font-weight: 900;
}

.badge.ok {
  border-color: var(--green);
  background: var(--green-quiet);
  color: var(--green);
}

.badge.warn {
  border-color: var(--amber);
  background: var(--amber-quiet);
  color: var(--amber);
}

.badge.bad {
  border-color: var(--red);
  background: var(--red-quiet);
  color: var(--red);
}

.inspect-grid,
.learn-grid {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

.span-all {
  min-width: 0;
  grid-column: 1 / -1;
}

.mode-switch {
  min-width: 0;
  display: flex;
  gap: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.25rem;
  background: #050807;
}

.mode-button {
  min-height: 38px;
  border-color: transparent;
  background: transparent;
  color: var(--ink-dim);
  padding: 0.45rem 0.8rem;
}

.mode-button.is-active {
  background: var(--cyan-quiet);
  color: var(--cyan);
}

.pipeline {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(110px, 1fr));
  gap: 0.55rem;
}

.pipeline-step {
  min-width: 0;
  min-height: 112px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--coal-3);
  padding: 0.85rem;
}

.pipeline-step strong {
  display: block;
  margin-bottom: 0.45rem;
}

.pipeline-step span {
  color: var(--ink-dim);
  overflow-wrap: anywhere;
}

.anatomy,
.tail-auth {
  min-width: 0;
  display: grid;
  gap: 0.7rem;
}

.metric-row {
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.55rem;
}

.metric-row:last-child {
  border-bottom: 0;
}

.bit-river {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 0.45rem;
  min-height: 120px;
}

.bit-chip {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #050807;
  color: var(--cyan);
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

.timeline-shell {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 1rem;
}

.token-timeline {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.45rem;
  max-height: 430px;
  overflow: auto;
  padding-right: 0.2rem;
}

.token-button {
  min-height: auto;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--coal-3);
  color: var(--ink);
  padding: 0.7rem;
  text-align: left;
}

.token-button.is-active {
  border-color: var(--cyan);
  background: var(--cyan-quiet);
}

.token-button small {
  display: block;
  color: var(--ink-muted);
}

.step-detail {
  min-width: 0;
  min-height: 240px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #050807;
  padding: 1rem;
}

.detail-grid,
.error-ledger,
.checklist {
  min-width: 0;
  display: grid;
  gap: 0.7rem;
}

.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-grid div,
.error-ledger div {
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.55rem;
}

.detail-grid dt,
.error-ledger dt {
  color: var(--ink-muted);
  font-weight: 800;
}

.detail-grid dd,
.error-ledger dd {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
}

.candidate-table {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
}

.candidate-table table {
  width: 100%;
  border-collapse: collapse;
}

.candidate-table th,
.candidate-table td {
  border-bottom: 1px solid var(--line);
  padding: 0.65rem;
  text-align: left;
  vertical-align: top;
}

.candidate-table th {
  color: var(--ink-muted);
}

.bar-cell {
  min-width: 170px;
}

.bar {
  display: block;
  height: 0.65rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--coal);
  overflow: hidden;
}

.bar span {
  display: block;
  height: 100%;
  background: var(--cyan);
}

pre {
  min-width: 0;
  max-width: 100%;
  max-height: 520px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #050807;
  color: var(--paper);
  padding: 1rem;
  white-space: pre-wrap;
}

.expert-only {
  display: none;
}

body.expert-mode .expert-only {
  display: block;
}

body.expert-mode .inspect-grid .expert-only {
  display: block;
}

.checklist {
  margin: 0;
  padding-left: 1.2rem;
}

.checklist li::marker {
  color: var(--cyan);
  font-weight: 900;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(420px, calc(100% - 2rem));
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--paper);
  color: #15110a;
  padding: 0.75rem 1rem;
  box-shadow: 0 20px 50px var(--shadow);
  transform: translateY(160%);
  transition: transform 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
}

.warning-text {
  color: var(--amber);
}

.error-text {
  color: var(--red);
}

.success-text {
  color: var(--green);
}

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

@media (max-width: 1180px) {
  .masthead,
  .two-column,
  .timeline-shell {
    grid-template-columns: 1fr;
  }

  .pipeline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .masthead,
  .workspace {
    width: min(100% - 1rem, 1540px);
  }

  .workspace-nav {
    position: static;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    border-radius: 18px;
  }

  .nav-tab {
    border-radius: 14px;
  }

  .inspect-grid,
  .learn-grid,
  .split-heading,
  .key-control,
  .detail-grid,
  .engine-facts div,
  .model-facts div,
  .metric-row,
  .compatibility-box {
    grid-template-columns: 1fr;
  }

  .action-row {
    align-items: stretch;
  }

  .action-row button {
    flex: 1 1 100%;
  }

  .candidate-table,
  pre,
  .cover-output,
  .secret-output,
  .token-timeline {
    max-width: 100%;
  }

  h1 {
    font-size: 4rem;
  }
}
