/*
 * Styles for the in-browser demo section embedded in index.html. Loaded after
 * styles.css and built entirely on its custom properties so both themes work
 * without additional overrides.
 */

/*
 * The demo section is the page's one interactive feature, so it breaks out of
 * the paper flow as a full-bleed highlight band: a strong accent wash with a
 * glow at the top and solid accent edges. Everything derives from the theme
 * variables, so the band stays distinct in both light and dark mode.
 */

.section-demo {
  position: relative;
  max-width: none;
  margin: 0 0 var(--section-space);
  padding: clamp(2.4rem, 5vw, 3.6rem) var(--gutter) clamp(2.6rem, 5.5vw, 4rem);
  background:
    radial-gradient(
      110% 75% at 50% 0%,
      color-mix(in srgb, var(--accent) 18%, transparent),
      transparent 65%
    ),
    color-mix(in srgb, var(--accent) 11%, var(--bg));
  border-top: 2px solid color-mix(in srgb, var(--accent) 75%, transparent);
  border-bottom: 2px solid color-mix(in srgb, var(--accent) 75%, transparent);
}

.section-demo > h2 {
  font-size: clamp(1.6rem, 3vw, 1.9rem);
}

.demo-eyebrow {
  max-width: var(--col-text);
  margin: 0 auto 0.9rem;
}

.demo-eyebrow-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, var(--bg));
  padding: 0.28rem 0.8rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.demo-disclaimer {
  max-width: var(--col-text);
  margin: 1rem auto 0;
  border: 1px solid var(--line-strong);
  border-left: 2px solid var(--accent);
  background: var(--bg-raised);
  padding: 0.7rem 1rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.demo-noscript {
  max-width: var(--col-text);
  margin: 1.4rem auto 0;
  color: var(--text-muted);
  font-style: italic;
}

.demo-app {
  max-width: var(--col-text);
  margin: 1.6rem auto 0;
}

/* The state machine drives visibility through data-state + [data-panel]. */

.demo-app[data-state="idle"] [data-panel="stage"],
.demo-app[data-state="idle"] [data-panel="progress"],
.demo-app[data-state="idle"] [data-panel="error"] {
  display: none;
}

/* Input panel */

.demo-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: 2px dashed var(--line-strong);
  border-radius: 1rem;
  background: var(--bg-raised);
  padding: 2.4rem 1.5rem;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: border-color 160ms ease, background 160ms ease;
}

.demo-dropzone:hover,
.demo-dropzone.is-dragover {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 7%, var(--bg-raised));
}

.demo-dropzone-icon {
  color: var(--accent);
  font-size: 1.6rem;
  line-height: 1;
}

.demo-dropzone-title {
  font-size: 1.05rem;
  font-weight: 600;
}

.demo-dropzone-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

.demo-samples {
  margin-top: 1.1rem;
}

.demo-samples-label {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.demo-samples-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  margin-top: 0.55rem;
}

.demo-sample {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--line-strong);
  border-radius: 0.6rem;
  background: var(--bg-raised);
  padding: 0.45rem;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.75rem;
  transition: border-color 160ms ease, color 160ms ease;
}

.demo-sample:hover {
  border-color: var(--accent);
  color: var(--text);
}

.demo-sample img {
  width: 4.6rem;
  aspect-ratio: 1;
  border-radius: 0.35rem;
  object-fit: cover;
  background: #000;
}

.demo-model-note {
  margin-top: 1.1rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* Progress panel */

.demo-progress {
  margin-top: 1.4rem;
}

.demo-progress-label {
  color: var(--text);
  font-size: 0.9rem;
}

.demo-progress-track {
  height: 0.5rem;
  margin-top: 0.6rem;
  border-radius: 0.25rem;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  overflow: hidden;
}

.demo-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 160ms ease;
}

/* Indeterminate phases pulse the full track instead of filling it. */
.demo-progress-track.is-indeterminate .demo-progress-fill {
  width: 100%;
  animation: demo-progress-pulse 1.4s ease-in-out infinite;
}

@keyframes demo-progress-pulse {
  0%,
  100% {
    opacity: 0.25;
  }

  50% {
    opacity: 0.85;
  }
}

.demo-progress .copy-button {
  margin-top: 0.8rem;
}

/* Error panel */

.demo-error {
  margin-top: 1.4rem;
  border: 1px solid color-mix(in srgb, #ff5470 55%, var(--line-strong));
  border-radius: 0.6rem;
  background: color-mix(in srgb, #ff5470 8%, var(--bg-raised));
  padding: 1rem 1.2rem;
}

.demo-error .copy-button {
  margin-top: 0.8rem;
}

/* Stage: toolbar, views, run button */

.demo-stage {
  margin-top: 1.4rem;
}

.demo-stage-toolbar {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  min-height: 2.2rem;
}

.demo-backend {
  border: 1px solid var(--line-strong);
  border-radius: 1rem;
  padding: 0.18rem 0.65rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.demo-backend.is-webgpu {
  border-color: var(--accent);
  color: var(--accent);
}

.demo-runtime {
  flex: 1 1 auto;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.demo-views {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-top: 1rem;
}

.demo-view {
  margin: 0;
}

.demo-view-frame {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 0.6rem;
  background: #000;
}

.demo-view-frame canvas {
  display: block;
  width: 100%;
  height: auto;
}

.demo-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.demo-view figcaption {
  padding-top: 0.45rem;
  text-align: center;
}

.demo-run-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.7rem 1rem;
  margin-top: 1.2rem;
}

.demo-quality {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.demo-quality-select {
  border: 1px solid var(--line-strong);
  border-radius: 2rem;
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  padding: 0.45rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.demo-quality-select:hover,
.demo-quality-select:focus-visible {
  border-color: var(--accent);
}

.demo-quality-select:disabled {
  cursor: wait;
  opacity: 0.6;
}

.demo-reset-button {
  border: 1px solid var(--line-strong);
  border-radius: 2rem;
  background: var(--bg-raised);
  color: var(--text);
  cursor: pointer;
  padding: 0.62rem 1.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  transition: border-color 160ms ease, color 160ms ease;
}

.demo-reset-button:hover,
.demo-reset-button:focus-visible {
  border-color: var(--accent);
  color: var(--accent);
}

.demo-run-button {
  border: 1px solid var(--accent);
  border-radius: 2rem;
  background: var(--accent);
  color: var(--accent-contrast);
  cursor: pointer;
  padding: 0.65rem 2.4rem;
  font-size: 1rem;
  font-weight: 600;
  transition: filter 160ms ease;
}

.demo-run-button:hover {
  filter: brightness(1.12);
}

.demo-run-button:disabled {
  filter: grayscale(0.6);
  cursor: wait;
}

/* Results: controls + legend */

.demo-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  margin-top: 1.3rem;
}

.demo-opacity {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.demo-opacity input[type="range"] {
  width: 9rem;
  accent-color: var(--accent);
}

.demo-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.demo-legend {
  margin-top: 1.5rem;
}

.demo-legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.demo-legend-header h3 {
  font-size: 1.05rem;
}

.demo-legend-list {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  margin-top: 0.8rem;
  padding: 0;
  list-style: none;
}

.demo-legend-group-header {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.demo-legend-group-header input[type="checkbox"] {
  accent-color: var(--accent);
}

.demo-legend-group-header label {
  cursor: pointer;
}

.demo-legend-group-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
  gap: 0.3rem 1rem;
  margin: 0.45rem 0 0 1.45rem;
  padding: 0;
  list-style: none;
}

.demo-legend-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.88rem;
}

.demo-legend-item input[type="checkbox"] {
  accent-color: var(--accent);
}

.demo-legend-swatch {
  width: 0.85rem;
  height: 0.85rem;
  flex: 0 0 auto;
  border-radius: 0.2rem;
  border: 1px solid rgba(0, 0, 0, 0.35);
}

.demo-legend-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.demo-legend-count {
  color: var(--text-muted);
  font-size: 0.75rem;
}

@media (max-width: 640px) {
  .demo-views {
    grid-template-columns: 1fr;
  }

  .demo-dropzone {
    padding: 1.8rem 1rem;
  }
}
