/*
 * Dark by default: the renderer draws additive light on a dark ground, so a
 * light chrome around it would make the canvas look like a hole in the page.
 *
 * The Python/Browser tags on each panel are load-bearing, not decoration —
 * the point of this demo is which half of the work happens where, and the
 * colour split is the fastest way to read that.
 */

:root {
  --bg: #0b0d12;
  --bg-panel: #12151d;
  --bg-inset: #0e1117;
  --line: #232838;
  --line-soft: #1a1e2a;
  --text: #e6e9f0;
  --text-dim: #949bad;
  --text-faint: #646c80;
  --accent: #5b8cff;
  --accent-soft: rgba(91, 140, 255, 0.14);
  --py: #6fd08c;
  --js: #f0c674;
  --danger: #ff6b6b;
  --radius: 10px;
  --rail-width: 340px;
}

* {
  box-sizing: border-box;
}

/*
 * The `hidden` attribute is only a `display: none` in the UA stylesheet, so
 * any author rule that sets `display` outranks it. Both overlays below are
 * `display: grid`, which left them painted on top of a finished render even
 * after the script had set `hidden`. Restore the attribute's meaning once,
 * globally, rather than remembering it per rule.
 */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font:
    14px/1.5 ui-sans-serif,
    system-ui,
    -apple-system,
    'Segoe UI',
    Roboto,
    sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}

code {
  font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;
  font-size: 0.92em;
  color: var(--text-dim);
}

/* ── Top bar ─────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-panel);
  flex: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2.5px solid var(--accent);
  border-right-color: transparent;
  position: relative;
}

.brand-mark::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 13px;
  height: 2.5px;
  background: var(--accent);
  transform: translateY(-50%);
}

.topbar h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-sub {
  margin: 0;
  font-size: 11.5px;
  color: var(--text-faint);
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-dim);
  background: var(--bg-inset);
  white-space: nowrap;
}

.pill-ok {
  color: var(--py);
  border-color: rgba(111, 208, 140, 0.3);
}

.pill-bad {
  color: var(--danger);
  border-color: rgba(255, 107, 107, 0.35);
}

.pill-link {
  text-decoration: none;
}

.pill-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

/* ── Layout ──────────────────────────────────────────────────────── */

.layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--rail-width) 1fr;
}

/*
 * The rail is a fixed-height dock, not a scroll of everything at once. Only
 * the panel body inside it scrolls, and the tabs are cut so that in practice
 * it does not need to: the whole point is to be able to reach any parameter
 * without losing sight of the render.
 */
.rail {
  border-right: 1px solid var(--line);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  background: var(--bg);
}

.rail-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.rail-body::-webkit-scrollbar {
  width: 8px;
}

.rail-body::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 8px;
}

/* ── Source panel ────────────────────────────────────────────────── */

.panel-source {
  flex: none;
  padding: 10px;
}

/* ── Python / Browser split ──────────────────────────────────────── */

.modes {
  flex: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-inset);
}

.mode {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 8px;
  border: 0;
  border-radius: 7px;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s;
}

.mode:hover {
  color: var(--text);
}

.mode[aria-selected='true'] {
  background: var(--bg-panel);
  color: var(--text);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.35);
}

.mode-note {
  flex: none;
  margin: -4px 2px 0;
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-faint);
}

/* ── Group tabs ──────────────────────────────────────────────────── */

.tabs {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tab {
  padding: 4px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
  transition:
    background 0.15s,
    color 0.15s,
    border-color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected='true'] {
  background: var(--accent-soft);
  border-color: rgba(91, 140, 255, 0.32);
  color: var(--accent);
}

/*
 * One explanation line, fed by whatever control is under the pointer. Help
 * text under every control is what made the rail a scroll in the first place.
 */
.hint-strip {
  flex: none;
  margin: 0;
  padding: 9px 10px;
  min-height: 52px;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  background: var(--bg-panel);
  font-size: 11px;
  line-height: 1.45;
  color: var(--text-dim);
}

.hint-strip.is-idle {
  color: var(--text-faint);
  font-style: italic;
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
}

.panel-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-note {
  margin: -2px 0 12px;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.45;
}

.tag {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: uppercase;
}

.tag-py {
  color: var(--py);
  background: rgba(111, 208, 140, 0.12);
}

.tag-js {
  color: var(--js);
  background: rgba(240, 198, 116, 0.12);
}

/* ── Dropzone ────────────────────────────────────────────────────── */

.dropzone {
  position: relative;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius);
  background: var(--bg-inset);
  min-height: 88px;
  display: grid;
  place-items: center;
  cursor: pointer;
  overflow: hidden;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone-hint {
  display: grid;
  gap: 3px;
  text-align: center;
  padding: 12px;
  pointer-events: none;
}

.dropzone-hint strong {
  font-size: 13px;
  font-weight: 600;
}

.dropzone-hint span {
  font-size: 11px;
  color: var(--text-faint);
}

.preview {
  width: 100%;
  max-height: 190px;
  object-fit: contain;
  display: block;
  /* Letterbox in the panel colour, not black: a black surround around a
     light image reads as part of the artwork. */
  background: var(--bg-inset);
}

/*
 * Once an image is chosen the dropzone collapses to a strip.
 *
 * A generous drop target is right while it is the thing being asked for, and
 * wrong afterwards: every pixel it keeps comes off the controls below it, and
 * the panel budget is what stops those from needing a scrollbar. The thumbnail
 * stays big enough to confirm which image is loaded, which is all it is for
 * once the stage is showing the render.
 */
.panel-source.has-file .dropzone {
  min-height: 0;
  place-items: stretch;
}

.panel-source.has-file .preview {
  height: 54px;
  max-height: 54px;
  object-fit: cover;
}

.file-meta {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-faint);
  word-break: break-all;
  min-height: 1em;
}

/* ── Controls ────────────────────────────────────────────────────── */

.controls {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.group {
  border-top: 1px solid var(--line-soft);
  padding-top: 8px;
  margin-top: 4px;
}

.group:first-child {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.group-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 2px;
}

.group-help {
  font-size: 10.5px;
  color: var(--text-faint);
  margin-bottom: 8px;
  line-height: 1.4;
}

/*
 * Tight on purpose. A tab has to fit without scrolling, and the difference
 * between 5px and 3px of padding here is a whole extra control on the tabs
 * that expand as options are switched on.
 */
.field {
  display: grid;
  gap: 2px;
  padding: 3px 0;
}

/*
 * The always-visible half of a description. Clamped to one line: a short form
 * that wrapped would cost the height the tab layout is budgeted against, and
 * anything that does not fit belongs in the long tier anyway.
 */
.field-short {
  margin: 0;
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-short {
  margin-left: 6px;
  font-weight: 400;
  font-size: 10.5px;
  color: var(--text-faint);
}

.field-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.field label {
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

.field-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.field-help {
  font-size: 10.5px;
  color: var(--text-faint);
  line-height: 1.4;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
  height: 16px;
  cursor: pointer;
}

select,
input[type='number'],
input[type='text'] {
  width: 100%;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 6px;
  padding: 5px 7px;
  font: inherit;
  font-size: 12px;
}

select:focus,
input:focus {
  outline: 1.5px solid var(--accent);
  outline-offset: -1px;
}

input[type='color'] {
  width: 100%;
  height: 26px;
  background: var(--bg-inset);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
  cursor: pointer;
}

.field-check {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}

.field-check input {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

.field-inline {
  display: flex;
  gap: 6px;
  align-items: center;
}

.field-inline input[type='number'] {
  flex: 1;
}

.btn-tiny {
  font-size: 10.5px;
  padding: 4px 8px;
  border-radius: 5px;
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text-dim);
  cursor: pointer;
  white-space: nowrap;
}

.btn-tiny:hover {
  color: var(--text);
  border-color: var(--accent);
}

.loading {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 0;
}

/* ── Stage ───────────────────────────────────────────────────────── */

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.stage-canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: radial-gradient(ellipse at 50% 45%, #10131b 0%, #07080c 75%);
}

#stage {
  display: block;
  width: 100%;
  height: 100%;
}

.stage-empty,
.stage-busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  pointer-events: none;
}

.stage-empty p {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}

.stage-empty-sub {
  max-width: 40ch;
  font-size: 12px !important;
  color: var(--text-faint) !important;
  line-height: 1.5;
}

.stage-busy {
  background: rgba(7, 8, 12, 0.6);
  color: var(--text-dim);
  font-size: 13px;
  grid-auto-flow: column;
  align-content: center;
}

.spinner {
  width: 15px;
  height: 15px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.stage-bar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 10px 16px;
  border-top: 1px solid var(--line);
  background: var(--bg-panel);
}

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

.btn {
  border: 1px solid var(--line);
  background: var(--bg-inset);
  color: var(--text);
  border-radius: 7px;
  padding: 7px 14px;
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s,
    opacity 0.15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08111f;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: #6f9bff;
}

.btn-quiet {
  color: var(--text-dim);
}

.stats {
  display: flex;
  gap: 18px;
  margin: 0;
}

.stats div {
  display: grid;
  gap: 1px;
}

.stats dt {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
}

.stats dd {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

/* ── Messages ────────────────────────────────────────────────────── */

.message {
  flex: none;
  padding: 10px 16px;
  font-size: 12.5px;
  border-top: 1px solid var(--line);
  background: rgba(255, 107, 107, 0.08);
  color: #ffb3b3;
}

.message.is-info {
  background: var(--accent-soft);
  color: #b8ccff;
}

.message ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

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

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .rail {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-y: visible;
    order: 2;
  }

  .stage {
    order: 1;
  }

  .stage-canvas-wrap {
    min-height: 58vh;
  }
}

/* ── Presets ─────────────────────────────────────────────────────── */

/*
 * A preset sets both halves at once — extraction *and* render — because the
 * two are not independent: tracing a photograph and tracing a line drawing
 * want different importance maps as much as they want different particles.
 */
.presets {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.preset {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-panel);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition:
    border-color 0.15s,
    background 0.15s;
}

.preset:hover {
  border-color: var(--accent);
}

.preset[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.preset b {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
}

.preset span {
  font-size: 10.5px;
  line-height: 1.4;
  color: var(--text-faint);
}

/* ── Corner gradient editor ──────────────────────────────────────── */

/*
 * Five wells sitting on a live preview of the blend they produce, painted
 * with the same maths the renderer uses. A row of swatches would not show
 * what the corners do to each other, which is the only interesting part.
 */
.grad {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.grad-stage {
  position: relative;
  /* A fixed height, not an aspect ratio: the preview is a legend for the five
     wells, and letting it grow with the rail width spends height that the
     controls under it are budgeted against. */
  height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.grad-stage canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.grad-stage input[type='color'] {
  position: absolute;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.grad-stage input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0;
}

.grad-stage input[type='color']::-webkit-color-swatch {
  border: 0;
  border-radius: 999px;
}

.grad-stage input[type='color']::-moz-color-swatch {
  border: 0;
  border-radius: 999px;
}

.grad-tl {
  top: 7px;
  left: 7px;
}

.grad-tr {
  top: 7px;
  right: 7px;
}

.grad-bl {
  bottom: 7px;
  left: 7px;
}

.grad-br {
  bottom: 7px;
  right: 7px;
}

.grad-c {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* ── Stale-extraction marker ─────────────────────────────────────── */

.tag-quiet {
  color: var(--text-faint);
  background: rgba(255, 255, 255, 0.05);
}

.tag-live {
  color: var(--py);
  background: rgba(111, 208, 140, 0.12);
}

.cloud-tags {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

/* ── Compare wipe ────────────────────────────────────────────────── */

.compare-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.compare-layer img {
  position: absolute;
  display: block;
  object-fit: fill;
}

.compare-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 0;
  z-index: 5;
  border-left: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: 0 0 12px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.grip {
  position: absolute;
  bottom: 14px;
  left: 0;
  width: 34px;
  height: 34px;
  margin-left: -17px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 999px;
  background: rgba(11, 13, 18, 0.85);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  color: var(--text);
  font-size: 11px;
  letter-spacing: -1px;
  cursor: ew-resize;
  pointer-events: auto;
  touch-action: none;
}

/* Along the bottom: the top corners of the stage are busy already. */
.compare-tag {
  position: absolute;
  bottom: 20px;
  z-index: 5;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 9.5px;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.72);
  pointer-events: none;
}

.compare-tag-left {
  left: 12px;
}

.compare-tag-right {
  right: 12px;
}

.wipe-bar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--text-dim);
}

.wipe-bar[data-on='false'] #compare-range,
.wipe-bar[data-on='false'] .wipe-readout {
  opacity: 0.35;
}

.wipe-bar input[type='range'] {
  flex: 1;
  max-width: 320px;
}

.wipe-readout {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  white-space: nowrap;
}

.check:has(input:disabled) {
  cursor: not-allowed;
  color: var(--text-faint);
}
