.demo {
  --seen: #7c3aed;
  --seen-soft: #ede9fe;
  --unseen: #0891b2;
  --unseen-soft: #cffafe;
  --dolma: #059669;
  --dolma-soft: #d1fae5;
  --unknown: #94a3b8;
  --unchanged: #94a3b8;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --helped: #2563eb;
  --hurt: #ea580c;
  --match: #fef3c7;
  --match-strong: #fcd34d;
  --span: #f59e0b;
  font-family: 'Inter', sans-serif;
}

.demo-intro {
  text-align: center;
  color: var(--text-secondary);
  max-width: 44rem;
  margin: -0.5rem auto 2rem;
}

.demo-step {
  background: var(--background-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  transition: opacity .3s ease;
}

.demo-step.is-locked {
  opacity: .45;
  pointer-events: none;
}

.demo-step-head {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.demo-step-num {
  flex: none;
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  background: var(--text-primary);
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
}

.demo-step-title {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-primary);
}

.demo-step-sub {
  color: var(--text-secondary);
  font-size: .92rem;
  flex-basis: 100%;
  margin-left: 2.65rem;
}

.demo-group-label {
  font-size: .75rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin: .25rem 0 .5rem;
}

.demo-chips {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: .9rem;
}

.demo-chip {
  border: 1.5px solid var(--border-color);
  background: var(--background-primary);
  border-radius: 999px;
  padding: .4rem .95rem;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}

.demo-chip small {
  font-weight: 500;
  color: var(--text-secondary);
}

.demo-chip:hover { border-color: var(--text-secondary); }
.demo-chip.pile.is-active { background: var(--seen-soft); border-color: var(--seen); }
.demo-chip.dolma.is-active { background: var(--dolma-soft); border-color: var(--dolma); }
.demo-chip.unseen.is-active { background: var(--unseen-soft); border-color: var(--unseen); }
.demo-chip.model.is-active { background: var(--text-primary); border-color: var(--text-primary); color: #fff; }
.demo-chip.model.is-active small { color: #cbd5e1; }

.demo-dot {
  width: .6rem;
  height: .6rem;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}
.demo-dot.pile, .demo-dot.seen { background: var(--seen); }
.demo-dot.dolma { background: var(--dolma); }
.demo-dot.unseen { background: var(--unseen); border: none; }

.demo-docnav {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .9rem;
  color: var(--text-secondary);
}

.demo-btn {
  border: none;
  border-radius: 10px;
  background: var(--text-primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  font-size: .92rem;
  padding: .55rem 1.1rem;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: .45rem;
}
.demo-btn:hover { background: var(--primary-color); }
.demo-btn:disabled { opacity: .5; cursor: default; background: var(--text-primary); }
.demo-btn.is-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1.5px solid var(--border-color);
  padding: .3rem .7rem;
}
.demo-btn.is-ghost:hover { border-color: var(--text-secondary); background: var(--background-accent); }

.demo-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.demo-status {
  font-size: .88rem;
  color: var(--text-secondary);
}

.demo-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.demo-panel {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  background: var(--background-secondary);
  min-width: 0;
}

.demo-panel-head {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  padding: .6rem .9rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  gap: .5rem;
}

.demo-text {
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .76rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
  padding: .75rem .9rem;
  max-height: 22rem;
  overflow-y: auto;
  position: relative;
  color: #334155;
}

.demo-ctxdoc + .demo-ctxdoc {
  border-top: 1px dashed var(--border-color);
  margin-top: .6rem;
  padding-top: .6rem;
}

.demo-ctxlabel {
  display: block;
  font-family: 'Inter', sans-serif;
  font-size: .7rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: .2rem;
}

.tk {
  border-radius: 3px;
  transition: background-color .25s ease, box-shadow .25s ease, color .25s ease;
}
.tk.is-scan { box-shadow: inset 0 -2px 0 var(--primary-color); }
.tk.m1 { background: var(--match); }
.tk.m2 { background: var(--match-strong); }
.tk.is-src { background: var(--span); color: var(--text-primary); }
.tk.is-pick {
  background: var(--text-primary);
  color: #fff;
  position: relative;
}
.tk.is-pick.flash { animation: demo-pop .45s ease; }
.tk.is-pick[data-n]::after {
  content: attr(data-n);
  position: absolute;
  top: -.85em;
  right: -.35em;
  font-family: 'Inter', sans-serif;
  font-size: .55rem;
  font-weight: 700;
  line-height: 1;
  background: var(--primary-color);
  color: #fff;
  border-radius: 999px;
  padding: .12em .35em;
  white-space: nowrap;
  pointer-events: none;
}
.tk.is-pick.helped { background: var(--helped); }
.tk.is-pick.hurt { background: var(--hurt); }
.tk.is-pick.same { background: var(--unchanged); }
.tk.is-pick { cursor: pointer; }
.tk.is-pick.is-focus { box-shadow: 0 0 0 2px #fff, 0 0 0 3.5px var(--text-primary); }

.demo-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(1.35rem, 1fr));
  gap: 4px;
  margin-bottom: .75rem;
}
.demo-cell {
  height: 1.35rem;
  border-radius: 4px;
  border: none;
  padding: 0;
  background: var(--background-accent);
  cursor: pointer;
  font: inherit;
  font-size: .6rem;
  color: transparent;
  transition: background-color .25s ease, transform .2s ease;
}
.demo-cell:disabled { cursor: default; }
.demo-cell.is-done { color: rgba(255, 255, 255, .85); }
.demo-cell.is-current { box-shadow: 0 0 0 2px var(--text-primary); transform: scale(1.12); }

.demo-tally {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: .35rem 1.3rem;
  font-size: .88rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
  font-variant-numeric: tabular-nums;
}
.demo-tally b { font-size: 1.1rem; color: var(--text-primary); }
.demo-tally .helped b { color: var(--helped); }
.demo-tally .hurt b { color: var(--hurt); }
.demo-tally .score b { font-size: 1.3rem; }

.demo-info {
  margin-top: .75rem;
  min-height: 2.6rem;
  padding: .6rem .9rem;
  border-radius: var(--border-radius);
  background: var(--background-accent);
  font-size: .85rem;
  color: var(--text-secondary);
}
.demo-info b { color: var(--text-primary); }

@keyframes demo-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.demo-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: .8rem;
  color: var(--text-secondary);
  margin-top: .75rem;
}
.demo-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.demo-swatch { width: .9rem; height: .9rem; border-radius: 3px; display: inline-block; }


.demo-score {
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 1rem 1.1rem;
  background: var(--background-secondary);
}
.demo-score h4 {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: .6rem;
  color: var(--text-primary);
}
.demo-trained {
  font-size: .75rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-left: .3rem;
}

.demo-counts {
  display: flex;
  gap: 1.2rem;
  font-size: .85rem;
  color: var(--text-secondary);
  margin-bottom: .4rem;
}
.demo-counts b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
.demo-counts .helped b { color: var(--helped); }
.demo-counts .hurt b { color: var(--hurt); }

.demo-formula {
  font-size: .85rem;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.demo-formula .big {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text-primary);
}

.demo-axis {
  position: relative;
  height: 2.6rem;
  margin: 1rem .4rem .2rem;
}
.demo-axis-line {
  position: absolute;
  left: 0;
  right: 0;
  top: 1rem;
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(90deg, #dbeafe, #ffedd5);
}
.demo-axis-tick {
  position: absolute;
  top: 1.55rem;
  font-size: .65rem;
  color: var(--text-light);
  transform: translateX(-50%);
}
.demo-axis-dot {
  position: absolute;
  top: calc(1rem - 4px);
  width: 12px;
  height: 12px;
  margin-left: -6px;
  border-radius: 50%;
  opacity: .55;
  transition: left .9s cubic-bezier(.4, 0, .2, 1), opacity .3s;
}
.demo-axis-dot.seen { background: var(--seen); }
.demo-axis-dot.dolma { background: var(--dolma); }
.demo-axis-dot.unknown { background: #fff; border: 2px solid var(--unknown); }
.demo-axis-dot.unseen { background: var(--unseen); }
.demo-axis-dot.is-current {
  opacity: 1;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  top: calc(1rem - 7px);
  box-shadow: 0 0 0 3px #fff, 0 0 0 4.5px var(--text-primary);
  z-index: 2;
}
.demo-axis-caption {
  font-size: .75rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
}

.demo-verdict {
  margin-top: 1rem;
  padding: .8rem 1rem;
  border-radius: var(--border-radius);
  background: var(--background-accent);
  font-size: .9rem;
  color: var(--text-primary);
}

.demo-note {
  font-size: .8rem;
  color: var(--text-light);
  margin-top: .75rem;
}

@media screen and (max-width: 768px) {
  .demo-panels { grid-template-columns: 1fr; }
  .demo-step { padding: 1rem; }
  .demo-step-sub { margin-left: 0; }
  .demo-text { max-height: 16rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tk, .demo-axis-dot, .demo-cell { transition: none; }
  .tk.is-pick.flash { animation: none; }
}

.demo-pred {
  display: inline-block;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: .78rem;
  padding: .05rem .4rem;
  border-radius: 5px;
  white-space: pre;
}
.demo-pred.ok { background: var(--ok-soft); color: #166534; }
.demo-pred.bad { background: var(--bad-soft); color: #991b1b; }

.demo-outcome {
  display: inline-block;
  font-size: .68rem;
  font-weight: 700;
  border-radius: 999px;
  padding: .1rem .5rem;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.demo-outcome.helped { background: #dbeafe; color: var(--helped); }
.demo-outcome.hurt { background: #ffedd5; color: var(--hurt); }
.demo-outcome.same { background: #f1f5f9; color: #64748b; }
