/* The demo pages: the example shop, the widget playground and the switching
   page. Loaded after /site/site.css, which brings the tokens, the top bar, the
   page head, buttons, code blocks and the footer; this file holds only what
   the demo pages have of their own. The shop's form sits inside a browser
   frame, so it still reads as a customer's page. */

:root {
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --code-muted: #94a3b8;
  --dark-figure: #0f172a;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --dark-figure: #000000;
  }
}

.demo-main {
  padding: 48px 0 88px;
}

.demo-main h2 {
  margin: 0;
}

.demo-section + .demo-section {
  margin-top: 56px;
}

.demo-section__head {
  margin-bottom: 18px;
}

.demo-section__head h2 {
  font-size: 1.5rem;
}

.demo-section__head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel {
  padding: 24px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 1.125rem;
}

.panel .lead {
  margin: 4px 0 0;
  color: var(--muted);
}

/* A code block without the copy button: logs and answers. */
.out {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  color: var(--code-ink);
  white-space: pre-wrap;
  background: var(--code-bg);
  border: 1px solid #1e293b;
  border-radius: var(--radius);
  font-variant-numeric: tabular-nums;
}

.code .hl {
  color: var(--ins);
}

.mt {
  margin-top: 16px;
}

.mt-lg {
  margin-top: 24px;
}

/* ── The example shop: a browser frame around a customer's form ─────────── */

.split2 {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  gap: 32px;
  align-items: start;
}

.browser {
  overflow: hidden;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.browser__head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.browser__dots {
  display: inline-flex;
  gap: 6px;
}

.browser__dots i {
  width: 10px;
  height: 10px;
  background: var(--line-strong);
  border-radius: 999px;
}

.browser__url {
  flex: 1;
  padding: 3px 10px;
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.shop {
  padding: 28px 32px 32px;
}

.shop__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
  font-weight: 700;
  color: var(--ink-strong);
}

.shop__logo {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 0.875rem;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b, #ea580c);
  border-radius: 8px;
}

.shop__brand small {
  margin-left: auto;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form h1 {
  margin: 0;
  font-size: 1.5rem;
}

.form .lead {
  margin: -6px 0 4px;
  font-size: 0.9375rem;
  color: var(--muted);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--ink-strong);
}

.field input,
.field textarea {
  min-height: 40px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 400;
  color: var(--ink-strong);
  background: var(--raised);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.form .btn {
  align-self: stretch;
  min-height: 44px;
}

.note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.note--ok {
  color: var(--accent);
}

.note--fail {
  color: var(--danger);
}

/* ── "What happens": the steps light up with the widget's events ───────── */

.flow-steps {
  margin: 18px 0 0;
  padding: 0;
  list-style: none;
}

.step {
  position: relative;
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 14px;
  padding-bottom: 20px;
}

.step:last-child {
  padding-bottom: 0;
}

.step::before {
  content: '';
  position: absolute;
  top: 34px;
  bottom: 2px;
  left: 15px;
  width: 2px;
  background: var(--line);
}

.step:last-child::before {
  display: none;
}

.step__dot {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: 0.8125rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.step h3 {
  margin: 4px 0 0;
  font-size: 0.9375rem;
}

.step p {
  margin: 2px 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}

.step.is-active .step__dot {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--highlight);
  animation: pulse 1.2s ease-in-out infinite;
}

.step.is-done .step__dot {
  color: #fff;
  background: var(--emerald);
  border-color: var(--emerald);
}

.step.is-done::before {
  background: var(--emerald);
}

.step.is-fail .step__dot {
  color: var(--danger);
  background: var(--danger-soft);
  border-color: var(--danger);
}

@keyframes pulse {
  50% {
    box-shadow: 0 0 0 6px var(--highlight);
  }
}

@media (prefers-reduced-motion: reduce) {
  .step.is-active .step__dot {
    animation: none;
  }
}

.flow__code {
  margin-top: 24px;
}

.flow__code h3 {
  margin: 0 0 8px;
  font-size: 0.875rem;
}

.demo-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 40px;
}

.demo-fact {
  padding: 18px 20px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.demo-fact strong {
  display: block;
  font-size: 0.9375rem;
  color: var(--ink-strong);
}

.demo-fact span {
  font-size: 0.875rem;
  color: var(--muted);
}

/* ── Result page ────────────────────────────────────────────────────────── */

.verdict {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 1.375rem;
}

.verdict::before {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  font-size: 1.125rem;
  border-radius: 999px;
}

.verdict--ok::before {
  content: '✓';
  color: #fff;
  background: var(--emerald);
}

.verdict--fail::before {
  content: '✕';
  color: var(--danger);
  background: var(--danger-soft);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ── Playground ─────────────────────────────────────────────────────────── */

.figs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(332px, 1fr));
  gap: 16px;
}

.figs figure {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 16px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.figs figcaption {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--ink-strong);
}

.chip {
  padding: 1px 8px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.figs .figure--dark {
  background: var(--dark-figure);
  border-color: #1e293b;
}

.figs .figure--dark figcaption {
  color: #fff;
}

.figure--dark .chip {
  color: #94a3b8;
  background: #0b1222;
  border-color: #1e293b;
}

.figs .btn {
  align-self: stretch;
}

.preview {
  border: 0;
}

.preview--normal {
  width: 300px;
  height: 66px;
}

.preview--pill {
  width: 300px;
  height: 42px;
}

.preview--compact {
  width: 150px;
  height: 140px;
}

.log {
  min-height: 160px;
  max-height: 320px;
  overflow: auto;
}

.log:empty::before {
  content: attr(data-empty);
  color: var(--code-muted);
}

/* ── Switching page ─────────────────────────────────────────────────────── */

.vendors {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 24px;
}

.vendor {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.vendor .code-box {
  margin: 0;
}

.vendor__label {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
}

.live {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}

.callback {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.callback output {
  font-family: var(--mono);
  color: var(--ink-strong);
  font-variant-numeric: tabular-nums;
}

.callback output.is-set {
  color: var(--accent);
}

/* ── The demo's own bar: shop · playground · switching, always in one place ─ */

.areanav {
  background: #0b0d2c;
  border-bottom: 1px solid var(--navy-line);
}

.areanav__in {
  display: flex;
  gap: 4px;
  overflow-x: auto;
}

.areanav a {
  padding: 12px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--on-navy-muted);
  white-space: nowrap;
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.areanav a:hover {
  color: var(--on-navy);
}

.areanav a[aria-current='page'] {
  color: var(--on-navy);
  border-bottom-color: var(--brand-green, #28d567);
}

/* ── Configurator (example shop) ────────────────────────────────────────── */

.config {
  margin-bottom: 32px;
}

.config__head {
  margin-bottom: 16px;
}

.config__form {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px 24px;
}

.config fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.config legend {
  margin-bottom: 8px;
  padding: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.segs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.seg {
  position: relative;
}

.seg input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.seg > span {
  display: inline-block;
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.seg > span:hover {
  border-color: var(--accent);
}

.seg input:checked + span {
  color: #fff;
  background: var(--emerald);
  border-color: var(--emerald);
}

.seg input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.config__range,
.near__control {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.875rem;
  color: var(--ink);
}

.config__range input,
.near__control input {
  flex: 1;
  max-width: 220px;
  accent-color: var(--emerald);
}

.config__range output,
.near__control output {
  min-width: 52px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

/* ── Playground: notes, and the approach ring ───────────────────────────── */

.fig-note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--muted);
}

.figure--dark .fig-note {
  color: #94a3b8;
}

#fig-near {
  overflow: hidden;
}

/* Room for the ring at the default distance; a wider one is cut by the card. */
.near {
  position: relative;
  align-self: center;
  width: fit-content;
  margin: 72px 0;
}

.near__ring {
  position: absolute;
  inset: 0;
  border-radius: 8px;
  outline: 1.5px dashed var(--accent);
  outline-offset: var(--d, 120px);
  pointer-events: none;
  opacity: 0.7;
}

/* ── Narrow screens ─────────────────────────────────────────────────────── */

@media (max-width: 960px) {
  .config__form,
  .split2,
  .vendors,
  .demo-facts {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .shop {
    padding: 22px 18px 24px;
  }

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