/* YoGlyph — dark creative-tool interface.
   Design vocabulary lifted from the reference screenshots in docs/: uppercase
   micro-labels, full-width sliders, collapsible sections, numbered rows.
   Phase 3's tonal-state editor should reuse .section / .ctrl / .swatch as-is. */

:root {
  --bg-app: #08080a;
  --bg-panel: #0e0e11;
  --bg-raised: #17171b;
  --bg-input: #1c1c21;
  --bg-stage: #060607;

  --line: #232329;
  --line-soft: #1a1a1f;

  --fg: #e6e5e3;
  --fg-dim: #9c9ba3;
  --fg-faint: #6a6971;

  --accent: #d8ff4a;
  --accent-dim: #97b230;
  --danger: #ff6b5e;

  --h-top: 44px;
  --h-status: 26px;
  --w-panel: 274px;

  --r-sm: 3px;
  --r-md: 5px;

  --font-ui: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Shared motion system: one easing curve and two durations, everywhere.
     Overridden to 0 under prefers-reduced-motion below, which is what makes
     every transition and press-scale in this file respect that preference
     for free — nothing further to opt in, just don't hardcode a duration
     outside these variables. */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 100ms;
  --dur-base: 150ms;
}

@media (prefers-reduced-motion: reduce) {
  :root { --dur-fast: 0ms; --dur-base: 0ms; }
}

* { box-sizing: border-box; }

/* The browser's own [hidden]{display:none} rule lives in the user-agent
   stylesheet, the lowest-priority origin in the cascade — ANY author rule
   that sets display on the same element wins over it regardless of
   selector specificity. Once a class like .stack (display:flex, used for
   several toggled panels) matches an element that also gets hidden=true
   toggled from JS, the element silently stops hiding: the DOM property is
   correctly true, but it keeps rendering anyway. Confirmed directly on
   #single-mark-block after the tonal-map hide broke this way. Restated here
   as an author rule with !important so [hidden] is always absolute,
   regardless of what other classes an element carries — the one thing every
   other rule in this file must never be allowed to win against. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg-app);
  color: var(--fg);
  font: 400 12px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-columns: var(--w-panel) 1fr;
  /* The timeline row is auto so it collapses to nothing for image sources. */
  grid-template-rows: var(--h-top) 1fr auto var(--h-status);
  grid-template-areas:
    "top   top"
    "panel stage"
    "panel timeline"
    "status status";
  height: 100vh;
}

/* ── top bar ──────────────────────────────────────────────────── */

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 10px 0 12px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-right: 14px;
  border-right: 1px solid var(--line);
  height: 100%;
}

.brand__mark { display: block; height: 20px; width: auto; }

.brand__name {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
}

.brand__phase {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 1px 4px;
}

.topbar__group { display: flex; align-items: center; gap: 6px; }
.topbar__group--end { margin-left: auto; }

.viewtabs {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: var(--bg-app);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.viewtab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  font: 600 10px/1 var(--font-ui);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

.viewtab:hover { color: var(--fg); }

.viewtab.is-active {
  background: var(--bg-raised);
  color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* ── buttons & inputs ─────────────────────────────────────────── */

.btn {
  appearance: none;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg);
  font: 500 11px/1 var(--font-ui);
  padding: 7px 11px;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease);
}

.btn:hover { background: #202027; border-color: #2e2e36; }
.btn:active { background: #14141a; transform: scale(0.96); }

.btn:focus-visible,
.viewtab:focus-visible,
.chip:focus-visible,
.select:focus-visible,
.input:focus-visible,
.dropzone:focus-visible,
.section__head:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.btn--primary {
  background: transparent;
  border-color: #34342f;
  color: var(--accent);
  font-weight: 600;
}

.btn--primary:hover { background: rgba(216, 255, 74, 0.08); border-color: var(--accent-dim); }

.btn--icon { padding: 6px 8px; line-height: 1; }

.btn[disabled] { opacity: 0.4; pointer-events: none; }

.select, .input {
  appearance: none;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg);
  font: 400 11px/1 var(--font-ui);
  padding: 7px 8px;
}

.select {
  background-image: linear-gradient(45deg, transparent 50%, var(--fg-dim) 50%),
                    linear-gradient(135deg, var(--fg-dim) 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 9px) 50%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
  padding-right: 24px;
  cursor: pointer;
}

.select--compact { width: auto; padding: 6px 22px 6px 8px; }

.input { font-family: var(--font-mono); }
.input--num { width: 78px; text-align: right; }
.input::-webkit-outer-spin-button,
.input::-webkit-inner-spin-button { appearance: none; margin: 0; }

.swatch {
  appearance: none;
  width: 30px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: transparent;
  cursor: pointer;
}
.swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.swatch::-webkit-color-swatch { border: 0; border-radius: 2px; }
.swatch::-moz-color-swatch { border: 0; border-radius: 2px; }

/* ── left panel ───────────────────────────────────────────────── */

.panel {
  grid-area: panel;
  background: var(--bg-panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
}

.panel::-webkit-scrollbar { width: 9px; }
.panel::-webkit-scrollbar-track { background: transparent; }
.panel::-webkit-scrollbar-thumb {
  background: #26262d;
  border: 3px solid var(--bg-panel);
  border-radius: 5px;
}
.panel::-webkit-scrollbar-thumb:hover { background: #34343d; }

.section { border-bottom: 1px solid var(--line-soft); }

.section__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--fg-dim);
  cursor: pointer;
  user-select: none;
  list-style: none;
  transition: color var(--dur-fast) var(--ease);
}

.section__head::-webkit-details-marker { display: none; }

.section__head::after {
  content: '+';
  font-size: 13px;
  font-weight: 400;
  color: var(--fg-faint);
}

.section[open] > .section__head { color: var(--fg); }
.section[open] > .section__head::after { content: '–'; }
.section__head:hover { color: var(--fg); }

.section__body {
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 2px 12px 14px;
}

/* ── controls ─────────────────────────────────────────────────── */

.ctrl {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.ctrl__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.ctrl__label em {
  font-style: normal;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0;
  color: var(--fg);
}

.ctrl--inline {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.ctrl--inline .ctrl__label { flex: 0 0 auto; }

.ctrl--check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--fg-dim);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease);
}

.ctrl--check:hover { color: var(--fg); }

.ctrl.is-disabled { opacity: 0.35; pointer-events: none; }

input[type='checkbox'] {
  appearance: none;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
  margin: 0;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  transition: background var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

input[type='checkbox']:checked {
  background: var(--accent);
  border-color: var(--accent);
}

input[type='checkbox']:checked::after {
  content: '';
  position: absolute;
  left: 4px;
  top: 1px;
  width: 3px;
  height: 7px;
  border: solid #0a0a06;
  border-width: 0 2px 2px 0;
  transform: rotate(42deg);
}

input[type='range'] {
  appearance: none;
  width: 100%;
  height: 16px;
  margin: 0;
  background: transparent;
  cursor: ew-resize;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 2px;
  background: #2b2b33;
  border-radius: 1px;
}

input[type='range']::-webkit-slider-thumb {
  appearance: none;
  width: 11px;
  height: 11px;
  margin-top: -4.5px;
  background: var(--fg);
  border-radius: 50%;
  border: 0;
  transition: background var(--dur-fast) var(--ease);
}

input[type='range']:hover::-webkit-slider-thumb { background: var(--accent); }

input[type='range']::-moz-range-track {
  height: 2px;
  background: #2b2b33;
  border-radius: 1px;
}

input[type='range']::-moz-range-thumb {
  width: 11px;
  height: 11px;
  background: var(--fg);
  border: 0;
  border-radius: 50%;
  transition: background var(--dur-fast) var(--ease);
}

input[type='range']:hover::-moz-range-thumb { background: var(--accent); }

/* ── presets / chips ──────────────────────────────────────────── */

.presets { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }

.chip {
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg-dim);
  font: 500 10px/1 var(--font-ui);
  letter-spacing: 0.04em;
  padding: 6px 0;
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}

.chip:hover { color: var(--fg); border-color: #2e2e36; }

.chip.is-active {
  background: rgba(216, 255, 74, 0.1);
  border-color: var(--accent-dim);
  color: var(--accent);
}

/* ── segmented control ────────────────────────────────────────── */

.segmented--3 { grid-template-columns: repeat(3, 1fr); }
.segmented--3 .segmented__opt { padding: 7px 0; letter-spacing: 0.04em; }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 2px;
  background: var(--bg-app);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}

.segmented__opt {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--fg-dim);
  font: 600 10px/1 var(--font-ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 7px 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

.segmented__opt:hover { color: var(--fg); }

.segmented__opt.is-active {
  background: var(--bg-raised);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* ── mark library ─────────────────────────────────────────────── */

.marks {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 4px;
}

.mark {
  position: relative;
  appearance: none;
  aspect-ratio: 1;
  padding: 0;
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: grab;
  display: grid;
  place-items: center;
  overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease),
    opacity var(--dur-base) var(--ease);
}

.mark:hover { border-color: #34343d; }

.mark.is-active {
  border-color: var(--accent-dim);
  background: rgba(216, 255, 74, 0.09);
}

.mark canvas { display: block; width: 100%; height: 100%; }

.mark.is-dragging { opacity: 0.35; cursor: grabbing; }
.mark.is-drop-target { box-shadow: inset 2px 0 0 0 var(--accent); }

.mark__del {
  position: absolute;
  top: 1px;
  right: 1px;
  width: 13px;
  height: 13px;
  display: none;
  place-items: center;
  padding: 0;
  background: var(--bg-app);
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--fg-dim);
  font: 400 10px/1 var(--font-ui);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.mark:hover .mark__del { display: grid; }
.mark__del:hover { color: var(--danger); border-color: var(--danger); }

.btn--wide { width: 100%; }

.hint {
  margin: 0;
  font-size: 10px;
  line-height: 1.4;
  color: var(--fg-faint);
}

.rule {
  border: 0;
  border-top: 1px solid var(--line-soft);
  margin: 2px 0;
}

/* ── credit ───────────────────────────────────────────────────── */

.credit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px 12px;
  border-top: 1px solid var(--line-soft);
  font-size: 10px;
}

.credit__link {
  color: var(--fg-faint);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}

.credit__link:hover { color: var(--accent); }

.credit__link:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

.credit__sep { color: var(--line); }

/* ── tonal states ─────────────────────────────────────────────── */

.states { display: flex; flex-direction: column; gap: 4px; }

.state {
  background: var(--bg-input);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 5px;
  transition: opacity var(--dur-base) var(--ease);
}

.state__head {
  display: grid;
  grid-template-columns: 12px 26px 1fr auto auto auto;
  align-items: center;
  gap: 6px;
}

.state__n {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-faint);
  text-align: center;
}

.state__preview {
  width: 26px;
  height: 26px;
  background: var(--bg-stage);
  border: 1px solid var(--line-soft);
  border-radius: 2px;
  display: block;
  cursor: grab;
}

.state__preview:active { cursor: grabbing; }

.state.is-dragging { opacity: 0.4; }
.state.is-drop-target { box-shadow: inset 2px 0 0 0 var(--accent), inset -2px 0 0 0 var(--accent); }

.state__label {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.07em;
  color: var(--fg-dim);
  overflow: hidden;
}

.state__label em {
  font: 400 9px/1 var(--font-mono);
  letter-spacing: 0;
  color: var(--fg-faint);
  font-style: normal;
}

.state__btn {
  appearance: none;
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--fg-dim);
  font: 400 11px/1 var(--font-ui);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.state__btn:hover { color: var(--fg); border-color: #34343d; }
.state__btn--del:hover { color: var(--danger); border-color: var(--danger); }

.state__more {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding: 8px 2px 2px;
  margin-top: 6px;
  border-top: 1px solid var(--line-soft);
}

.state.is-open .state__more { display: flex; }

/* Always visible — this is how a state gets its mark, so it must never sit
   behind a disclosure toggle. */
.state__marks { display: flex; gap: 4px; margin-top: 5px; }
.state__marks .select { flex: 1; min-width: 0; }

.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }

.kernel-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  max-width: 160px;
}

.kernel-grid .input--num { width: 100%; text-align: center; }

.kernel-grid__px {
  display: grid;
  place-items: center;
  color: var(--accent);
  font-size: 10px;
}
.stack { display: flex; flex-direction: column; gap: 11px; }

/* ── palette editor ───────────────────────────────────────────── */

.palette { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }

.palette__slot { position: relative; }

.palette__slot .swatch { width: 100%; height: 26px; }

.palette__del {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 13px;
  height: 13px;
  display: none;
  place-items: center;
  padding: 0;
  background: var(--bg-app);
  border: 1px solid var(--line);
  border-radius: 2px;
  color: var(--fg-dim);
  font: 400 10px/1 var(--font-ui);
  cursor: pointer;
  transition: color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease);
}

.palette__slot:hover .palette__del { display: grid; }
.palette__del:hover { color: var(--danger); border-color: var(--danger); }

/* ── dropzone & meta ──────────────────────────────────────────── */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  width: 100%;
  padding: 16px 10px;
  background: transparent;
  border: 1px dashed #2c2c34;
  border-radius: var(--r-md);
  color: var(--fg-faint);
  font: 400 11px/1.3 var(--font-ui);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.dropzone:hover { border-color: var(--accent-dim); color: var(--fg-dim); }
.dropzone__icon { font-size: 14px; }

.meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 10px;
}

.meta__row { display: flex; justify-content: space-between; gap: 10px; }

.meta dt {
  color: var(--fg-faint);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-ui);
  font-size: 9px;
  padding-top: 1px;
}

.meta dd {
  margin: 0;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── ramp preview ─────────────────────────────────────────────── */

.ramp {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  letter-spacing: 0.12em;
  color: var(--fg);
  background: var(--bg-stage);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
}

/* ── stage ────────────────────────────────────────────────────── */

.stage {
  grid-area: stage;
  position: relative;
  background: var(--bg-stage);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.016) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.016) 1px, transparent 1px);
  background-size: 32px 32px;
  overflow: hidden;
}

.stage__canvas { display: block; width: 100%; height: 100%; }

.stage__empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  text-align: center;
}

.stage__empty[hidden] { display: none; }

.stage__empty-title {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

.stage__empty-hint {
  margin: 0;
  font-size: 11px;
  color: var(--fg-faint);
}

.stage__badge {
  position: absolute;
  left: 50%;
  bottom: 12px;
  transform: translateX(-50%);
  padding: 5px 10px;
  background: rgba(8, 8, 10, 0.82);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--fg-dim);
  pointer-events: none;
  white-space: nowrap;
}

.stage__badge[hidden] { display: none; }

.stage__drop {
  position: absolute;
  inset: 8px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--accent);
  border-radius: var(--r-md);
  background: rgba(216, 255, 74, 0.05);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--accent);
  pointer-events: none;
}

.stage__drop[hidden] { display: none; }

/* ── timeline ─────────────────────────────────────────────────── */

.timeline {
  grid-area: timeline;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line);
}

.timeline[hidden] { display: none; }

.timeline .btn--icon { font-size: 10px; padding: 6px 9px; }

.timeline__scrub {
  flex: 1;
  min-width: 60px;
  cursor: pointer;
}

.timeline__scrub::-webkit-slider-runnable-track { height: 3px; }
.timeline__scrub::-webkit-slider-thumb { margin-top: -4px; background: var(--accent); }
.timeline__scrub::-moz-range-track { height: 3px; }
.timeline__scrub::-moz-range-thumb { background: var(--accent); }

.timeline__time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-faint);
  white-space: nowrap;
}

.timeline__time em { font-style: normal; color: var(--fg); }

.timeline__rate {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-dim);
}

/* ── status bar ───────────────────────────────────────────────── */

.statusbar {
  grid-area: status;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg-panel);
  border-top: 1px solid var(--line);
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-faint);
}

.statusbar__spacer { flex: 1; }
.statusbar__msg.is-error { color: var(--danger); }
.statusbar__perf { color: var(--fg-faint); }
