/* ---------------------------------------------------------------------------
   Motif — pattern engine
   Aesthetic reference: Patternly (Gavin Potenza) + Feral UI gradient dials
--------------------------------------------------------------------------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #16181d;
  --ink-soft: #5c626e;
  --label: #9aa0ab;
  --line: #e8e8e6;
  --paper: #fdfdfc;
  --accent: #5b7fe8;
  --radius-frame: 26px;
  --sidebar-w: 292px;
  --ui-ink: #101318;
  --ui-surface: #f7f6f2;
  --ui-accent: #5b7fe8;
  --ui-field-ink: #101318;
  --ui-page: #dfe4ec;
  --ui-font: "Helvetica Neue", Helvetica, Inter, Arial, sans-serif;
  --ui-radius: 12px;
  --motion-period: 8s;
  --motion-ease: cubic-bezier(0.77, 0, 0.175, 1);
  --motion-travel: 12%;
  --motion-orbit: 1.14;
  --motion-glow: 0.72;
  /* motion vocabulary (emil-design-eng): strong curves, UI under 300ms */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  font-size: 16px;
}

html, body { height: 100%; }

body {
  font-family: "Inter", "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(120% 90% at 15% 10%, #cfe0f7 0%, transparent 55%),
    radial-gradient(110% 80% at 90% 15%, #e8d9ef 0%, transparent 50%),
    radial-gradient(120% 100% at 80% 95%, #f6d9d3 0%, transparent 55%),
    linear-gradient(175deg, #b6cdf2 0%, #cddcf5 45%, #e3d3e0 100%);
  display: grid;
  place-items: center;
  padding: 34px;
  overflow: hidden;
}

/* film grain over the page bg */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='140' height='140'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.06 0'/%3E%3C/filter%3E%3Crect width='140' height='140' filter='url(%23n)'/%3E%3C/svg%3E");
}

.app-frame {
  position: relative;
  width: min(1240px, 100%);
  height: min(760px, 100%);
  background: var(--paper);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: var(--radius-frame);
  box-shadow:
    0 30px 80px -20px rgba(38, 55, 100, 0.35),
    0 2px 6px rgba(38, 55, 100, 0.12);
  display: grid;
  grid-template-columns: 1fr var(--sidebar-w);
  overflow: hidden;
}

/* ------------------------------- sidebar -------------------------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--paper);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #d8d8d5 transparent;
}

.brand-mark {
  width: 22px;
  height: 22px;
  color: var(--ink);
  flex: none;
}

.tagline {
  margin-top: 1px;
  font-size: 0.55rem;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--label);
}

/* ------------------------------- looks + controls accordions ------------------------------- */

.looks-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px 4px;
}

.looks-head h1 {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* Looks + Controls share one nav as native accordions */
.acc {
  border-bottom: 1px solid var(--line);
  flex: none;
}
.acc[open]:last-of-type {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.acc[open]:last-of-type .acc-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.acc > summary {
  list-style: none;
  cursor: pointer;
  padding: 11px 18px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary::after {
  content: "";
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--label);
  border-bottom: 1.5px solid var(--label);
  transform: rotate(45deg);
  transition: transform 160ms var(--ease-out);
}
.acc[open] > summary::after {
  transform: rotate(225deg);
  margin-top: 4px;
}
.acc-body { padding: 0 12px 12px; }
.acc:not([open]) .acc-body { display: none; }
#controlsAcc[open] .acc-body { overflow: auto; }

.gen-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin: 0 0 10px;
  padding: 0;
  background: transparent;
}

.gen-grid .seg-btn {
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 2px 6px;
  font-size: 0.55rem;
  letter-spacing: 0.02em;
  border: 1.4px solid var(--line);
  background: #fff;
  border-radius: 10px;
}

.gen-grid .seg-btn svg {
  width: 15px;
  height: 15px;
}

.gen-grid .seg-btn[hidden] { display: none; }

.gen-grid .seg-btn.active {
  background: #fff;
  box-shadow: 0 0 0 1.5px var(--ink) inset;
  color: var(--ink);
}

.harmony-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.harmony-chips button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 7px;
  font-family: inherit;
  font-size: 0.58rem;
  font-weight: 650;
  color: var(--ink-soft);
  background: #fff;
  border: 1.4px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
}

.harmony-chips button.active {
  color: var(--ink);
  border-color: var(--ink);
}

.set-dots {
  display: inline-flex;
  gap: 2px;
}
.set-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ccc;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.12) inset;
}

.look-suggest-label { margin: 8px 0 5px; }
.look-suggest .solid-swatch { width: 22px; height: 22px; }
/* stage column: framed canvas + Application bar */

.stage-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: #ecece8;
}

.stage-well {
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: 12px 12px 0;
  container-type: size;
}

/* layer tabs */

.layer-tabs {
  display: flex;
  gap: 3px;
  margin: 2px 0 12px;
  padding: 3px;
  background: #f0f0ee;
  border-radius: 11px;
}

.layer-tab {
  flex: 1;
  padding: 7px 1px;
  font-family: inherit;
  font-size: 0.52rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 160ms var(--ease-out);
}

.layer-tab:active { transform: scale(0.97); }

/* panels fade in on tab/generator switch — fast enough to stay invisible */
.panel {
  opacity: 1;
  transform: none;
  transition: opacity 140ms var(--ease-out), transform 140ms var(--ease-out);
}

@starting-style {
  .panel {
    opacity: 0;
    transform: translateY(4px);
  }
}

.layer-tab.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 25, 45, 0.12);
}

.panel { display: flex; flex-direction: column; flex: 1; }
.panel[hidden] { display: none; }

/* preset chips */

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  justify-content: center;
  padding: 2px 18px 18px;
  border-bottom: 1px solid var(--line);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px 5px 8px;
  font-size: 0.72rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1.4px solid var(--line);
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 160ms var(--ease-out);
}

@media (hover: hover) and (pointer: fine) {
  .chip:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(30, 40, 80, 0.08); }
}
.chip:active { transform: scale(0.97); }
.chip.active { border-color: var(--chip, var(--accent)); box-shadow: 0 0 0 1px var(--chip, var(--accent)) inset; }
.chip svg { width: 13px; height: 13px; color: var(--chip, var(--accent)); }

/* controls */

.controls { padding: 16px 22px 14px; flex: 1; }

.control-row { margin-bottom: 16px; }

.controls label,
.slider-head label,
.section-label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--label);
}

.section-label { display: block; margin-bottom: 10px; }

.hint {
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--ink-soft);
  margin: -4px 0 12px;
}

.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: 18px -22px 18px;
}

/* sliders (pattern panel — thin Patternly style) */

.slider-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
}

.val { font-size: 0.7rem; font-weight: 500; color: var(--ink-soft); font-variant-numeric: tabular-nums; }

input[type="range"]:not(.dial) {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}

input[type="range"]:not(.dial)::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--ink) var(--fill), #ececea var(--fill));
}

input[type="range"]:not(.dial)::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 17px;
  height: 17px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #d3d3d0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

input[type="range"]:not(.dial)::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--ink) var(--fill), #ececea var(--fill));
}

input[type="range"]:not(.dial)::-moz-range-thumb {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #d3d3d0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

/* dials (background panel — chunky Feral UI style) */

.dial-row {
  display: grid;
  grid-template-columns: 72px 1fr 62px;
  align-items: center;
  gap: 10px;
  margin-bottom: 11px;
}

.dial-row label { white-space: nowrap; }

.dial-val {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"].dial {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 24px;
  background: transparent;
  cursor: pointer;
  --fill: 50%;
}

input[type="range"].dial::-webkit-slider-runnable-track {
  height: 24px;
  border-radius: 8px;
  background: linear-gradient(to right, #a8a49c var(--fill), #eceae5 var(--fill));
}

input[type="range"].dial::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 4px;
  height: 24px;
  border-radius: 2px;
  background: #7c786f;
  opacity: 0;
}

input[type="range"].dial::-moz-range-track {
  height: 24px;
  border-radius: 8px;
  background: linear-gradient(to right, #a8a49c var(--fill), #eceae5 var(--fill));
}

input[type="range"].dial::-moz-range-thumb {
  width: 4px;
  height: 24px;
  border: none;
  border-radius: 2px;
  background: #7c786f;
  opacity: 0;
}

/* nested row group */

.sub-controls {
  margin: 0 0 0 8px;
  padding-left: 12px;
  border-left: 1px solid var(--line);
}

/* toggles */

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.toggle {
  position: relative;
  width: 36px;
  height: 21px;
  border-radius: 999px;
  border: none;
  background: #e4e4e1;
  cursor: pointer;
  transition: background 180ms ease;
  flex-shrink: 0;
}

.toggle::after {
  content: "";
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 180ms var(--ease-out);
}

.toggle[aria-checked="true"] { background: var(--ink); }
.toggle[aria-checked="true"]::after { transform: translateX(15px); }

/* selects */

.select-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.select-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 6px;
}

.select-wrap select {
  appearance: none;
  -webkit-appearance: none;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--ink);
  background: transparent;
  border: none;
  padding: 4px 18px 4px 4px;
  cursor: pointer;
  text-align: right;
  direction: rtl;
}
.select-wrap select option { direction: ltr; }

.select-wrap::after {
  content: "";
  position: absolute;
  right: 4px;
  top: 50%;
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--label);
  border-bottom: 1.5px solid var(--label);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}

.swatch {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  background: var(--accent);
  flex-shrink: 0;
}

.custom-color-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

input[type="color"] {
  width: 44px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: none;
  padding: 2px;
  cursor: pointer;
}

.shuffle-row { text-align: right; margin-top: -6px; }

/* segmented control (background mode) */

.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  background: #f0f0ee;
  border-radius: 11px;
  margin-bottom: 18px;
}

.seg-btn {
  flex: 1;
  padding: 6px 0;
  font-family: inherit;
  font-size: 0.71rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease, transform 160ms var(--ease-out);
}

.seg-btn:active { transform: scale(0.96); }

.seg-btn.active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 25, 45, 0.12);
}

/* generator segmented control (looks rail overrides .seg) */

.gen-seg { margin: 0; flex-wrap: wrap; }
.gen-seg .seg-btn { font-size: 0.66rem; padding: 6px 0; flex: 1 1 calc(25% - 4px); }

.suggest-swatches { margin-top: 8px; }
.solid-swatch.best { outline: 2px solid var(--ink); outline-offset: 2px; }
#colorWarn { margin-top: 10px; color: #a33; }

.gen-suggest-row { margin: 8px 0 2px; }

#genControls { padding-top: 4px; }

/* text inputs (ribbons / type) */

.text-input {
  width: 100%;
  padding: 8px 10px;
  font-family: "SF Mono", "Menlo", "Consolas", monospace;
  font-size: 0.74rem;
  color: var(--ink);
  background: #fff;
  border: 1.4px solid var(--line);
  border-radius: 9px;
  resize: vertical;
  outline: none;
}
.text-input:focus { border-color: var(--accent); }

.randomize-btn {
  width: 100%;
  margin-top: 6px;
  padding: 9px;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1.4px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}
.randomize-btn { transition: border-color 0.15s ease, transform 160ms var(--ease-out); }
.randomize-btn:hover { border-color: var(--ink-soft); }
.randomize-btn:active { transform: scale(0.97); }

.format-row { margin-bottom: 12px; }
.format-row .select-wrap select { font-size: 0.71rem; }

.sub-label {
  font-size: 0.56rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #b8bdc6;
  margin: 10px 0 8px;
}

/* gradient preset pies */

.pie-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px 6px;
}

.pie-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.58rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  line-height: 1.2;
  text-align: center;
}

.pie {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 1px 4px rgba(20, 25, 45, 0.18);
  transition: transform 160ms var(--ease-out), border-color 0.12s ease;
}

@media (hover: hover) and (pointer: fine) {
  .pie-btn:hover .pie { transform: scale(1.08); }
}
.pie-btn:active .pie { transform: scale(0.94); }
.pie-btn.active .pie { border-color: var(--ink); }
.pie-btn.active { color: var(--ink); }

/* colour spot list */

.spots-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.spots-head .section-label { margin-bottom: 0; }
.spots-actions { display: flex; gap: 6px; }
.spots-actions .mini-btn { flex: none; padding: 4px 10px; }

.color-list { display: flex; flex-direction: column; gap: 7px; }

.color-item {
  display: grid;
  grid-template-columns: 26px 1fr 56px 18px;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  background: #f6f6f4;
  border: 1px solid var(--line);
  border-radius: 11px;
}

.color-item input[type="color"] {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.12);
  padding: 0;
  overflow: hidden;
}
.color-item input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.color-item input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }

.color-item .hex {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink);
  text-transform: uppercase;
  font-variant-numeric: tabular-nums;
}

.color-item input[type="range"].dial { height: 16px; }
.color-item input[type="range"].dial::-webkit-slider-runnable-track { height: 16px; border-radius: 6px; }
.color-item input[type="range"].dial::-moz-range-track { height: 16px; border-radius: 6px; }
.color-item input[type="range"].dial::-webkit-slider-thumb { height: 16px; }

.color-remove {
  background: none;
  border: none;
  color: var(--label);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.color-remove:hover { color: var(--ink); }

.add-color {
  width: 100%;
  margin-top: 9px;
  padding: 8px;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: none;
  border: 1.4px dashed #d5d5d2;
  border-radius: 11px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.add-color { transition: border-color 0.15s ease, color 0.15s ease, transform 160ms var(--ease-out); }
.add-color:hover { border-color: var(--ink-soft); color: var(--ink); }
.add-color:active { transform: scale(0.98); }

.add-color.danger { margin-top: 12px; color: #b04545; border-color: #e5c9c9; }
.add-color.danger:hover { border-color: #b04545; color: #8f2f2f; }

.btn-pair {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

/* single colour picker row inside dynamic controls */
.color-single-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* image + solid modes */

.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  width: 100%;
  padding: 10px;
  font-family: inherit;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 1.4px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: border-color 0.15s;
  margin-bottom: 10px;
}
.upload-btn:hover { border-color: #c9c9c6; }

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

.solid-swatch {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1.5px solid rgba(0, 0, 0, 0.12);
  cursor: pointer;
  transition: transform 160ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
  .solid-swatch:hover { transform: scale(1.12); }
}
.solid-swatch:active { transform: scale(0.94); }

/* export footer */

.export {
  padding: 14px 22px 20px;
  border-top: 1px solid var(--line);
  background: var(--paper);
  position: sticky;
  bottom: 0;
  margin-top: auto;
}

.primary-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 11px;
  cursor: pointer;
  transition: filter 0.15s ease, transform 160ms var(--ease-out);
}

.primary-btn:hover { filter: brightness(1.07); }
.primary-btn:active { transform: scale(0.97); }

.export-secondary {
  display: flex;
  gap: 6px;
  margin-top: 9px;
}

.export-hint {
  margin: 8px 0 0;
  font-size: 0.62rem;
  line-height: 1.4;
  color: var(--label);
}

.mini-btn {
  flex: 1;
  padding: 7px 8px;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: #fff;
  border: 1.4px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 160ms var(--ease-out);
  white-space: nowrap;
}

.mini-btn:hover { border-color: #c9c9c6; color: var(--ink); }
.mini-btn:active { transform: scale(0.96); }

/* ------------------------------- canvas --------------------------------- */

.canvas {
  position: relative;
  overflow: hidden;
  background: #dfe7f5;
  container-type: size;
  aspect-ratio: var(--art-w, 1080) / var(--art-h, 1080);
  width: min(100cqi, calc(100cqh * var(--art-w, 1080) / var(--art-h, 1080)));
  height: auto;
  max-height: 100%;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(20, 28, 50, 0.14);
}

.canvas[data-motion="glide"] .pattern-host {
  perspective: 1100px;
}

.pattern-host .motif-unit {
  transform-box: fill-box;
  transform-origin: center;
}

.backdrop {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: center;
  opacity: 1;
  transition: opacity 200ms var(--ease-out);
}

.bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 1;
  transition: opacity 200ms var(--ease-out);
}

/* soften the swap when the background mode changes */
@starting-style {
  .backdrop,
  .bg-canvas {
    opacity: 0;
  }
}

.grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0.5 0'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
  opacity: 0.1;
}

.pattern-host {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  z-index: 3;
}

.pattern-host svg {
  width: 100%;
  height: auto;
  max-height: 100%;
  display: block;
}

/* full-canvas generators (beams / tiles / ribbons / type) */
.pattern-host.full { justify-content: center; }
.pattern-host.full svg {
  width: 100%;
  height: 100%;
}

.pattern-host.blend-multiply {
  mix-blend-mode: multiply;
}

/* Contour on media — Sobel crosses over photo/video (Application) */
.contour-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
  overflow: hidden;
}
.contour-layer[hidden] { display: none !important; }
.contour-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
  background: #0a0a0a;
}
.contour-layer.has-image.show-media .contour-image { display: block; }
.contour-layer.has-video.show-media .contour-video { display: block; }
.contour-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}
.contour-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  text-align: center;
  font: 500 0.85rem/1.35 var(--ui-font, system-ui, sans-serif);
  color: rgba(255, 255, 255, 0.55);
  background: rgba(12, 14, 18, 0.55);
  pointer-events: none;
}
.contour-layer.has-source .contour-empty { display: none; }
.canvas.contour-on .pattern-host { opacity: 0; pointer-events: none; }
.canvas.contour-on.contour-keep-pattern .pattern-host { opacity: 1; }

.check-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0.65rem 0 0.35rem;
  font-size: 0.8rem;
  color: var(--ink-muted, #5a5f6a);
}
.check-row input { margin: 0; }

/* colour spot rings */

.spots-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
}
.spots-layer[hidden] { display: none; }

.spot-ring {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 8px rgba(15, 20, 40, 0.35);
  cursor: grab;
  display: grid;
  place-items: center;
  touch-action: none;
}

.spot-ring::after {
  content: "";
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--spot);
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.spot-ring { transition: transform 160ms var(--ease-out); }
.spot-ring:active { cursor: grabbing; transform: scale(1.1); }

.spot-label {
  position: absolute;
  left: 30px;
  top: 50%;
  transform: translateY(-50%);
  padding: 3px 9px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border-radius: 999px;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(15, 20, 40, 0.2);
}

/* draggable art-element handles (ribbons / type) */

.art-handles {
  position: absolute;
  pointer-events: none;
}
.art-handles[hidden] { display: none; }

.art-handle {
  position: absolute;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.9);
  background: rgba(20, 25, 45, 0.25);
  box-shadow: 0 1px 6px rgba(15, 20, 40, 0.35);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  transition: transform 0.1s;
}
@media (hover: hover) and (pointer: fine) {
  .art-handle:hover { transform: scale(1.15); }
}
.art-handle:active { cursor: grabbing; }

/* role select inside brand colour rows */

.role-select {
  font-family: inherit;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px 4px;
  cursor: pointer;
}

/* contrast pairing matrix */

.matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
}

.matrix th, .matrix td {
  padding: 5px 4px;
  text-align: center;
  border: 1px solid var(--line);
}

.matrix th { font-weight: 600; color: var(--ink-soft); }

.matrix .chipdot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
  vertical-align: -1px;
}

.matrix td.subtle { background: #f4f4f2; color: #7a7f88; }
.matrix td.balanced { background: #eef4fb; color: #2c5a8f; font-weight: 600; }
.matrix td.bold { background: #edf7ee; color: #2c6b34; font-weight: 600; }
.matrix td.clash { background: #fbeeee; color: #a33; font-weight: 600; }
.matrix td small { display: block; font-size: 0.54rem; letter-spacing: 0.04em; }

.matrix-empty {
  font-size: 0.68rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

/* toast */

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translate(-50%, 16px);
  padding: 9px 18px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  background: var(--ink);
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out);
  z-index: 10;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Pattern / UI application bar — Light Rails sizebar, Motif-native scenes */

.sizebar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 10px 12px 12px;
  flex: none;
}

.sb-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(20, 28, 50, 0.08);
}

.sb-card label {
  font-size: 0.58rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--label);
}

.sb-card select {
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink);
  background: #f4f4f2;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 5px 8px;
  cursor: pointer;
  max-width: 18rem;
}

.sw {
  width: 36px;
  height: 20px;
  padding: 2px;
  border: 0;
  border-radius: 999px;
  background: #d8d8d4;
  cursor: pointer;
  position: relative;
}
.sw span {
  display: block;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 160ms var(--ease-out);
}
.sw[aria-checked="true"] { background: var(--ink); }
.sw[aria-checked="true"] span { transform: translateX(16px); }

.ui-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
  overflow: hidden;
  border-radius: 14px;
  font-family: var(--ui-font);
}
.ui-layer.off { display: none; }
.ui-layer .scene {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 420ms var(--ease-out);
  pointer-events: none;
}
.ui-layer .scene.on { opacity: 1; }
.ui-layer .scene.on [data-k] { pointer-events: auto; cursor: text; }

.pause {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 6;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,0.88);
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  cursor: pointer;
  display: grid;
  place-items: center;
  gap: 3px;
  grid-auto-flow: column;
}
.pause[hidden] { display: none; }
.pause span {
  width: 3px;
  height: 11px;
  background: var(--ink);
  border-radius: 1px;
}
.pause.is-paused span:first-child {
  width: 0;
  height: 0;
  border-left: 8px solid var(--ink);
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  background: none;
  border-radius: 0;
}
.pause.is-paused span:last-child { display: none; }

/* question bar */
.ui-layer [data-k] { white-space: pre-line; }

#uiAsk .bar2 {
  position: relative;
  background: var(--ui-surface);
  color: var(--ui-ink);
  max-width: 86%;
  padding: 14px 40px 14px 18px;
  font-size: clamp(15px, 3.2cqh, 28px);
  letter-spacing: -0.02em;
  font-weight: 500;
  box-shadow: 0 10px 40px rgba(10, 16, 32, 0.18);
  border-radius: var(--ui-radius);
}
#uiAsk .bar2 i {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 10px;
  background: var(--ui-accent);
  border-radius: 0 var(--ui-radius) var(--ui-radius) 0;
}

/* brand spread: ink panel left, live pattern is the photograph on the right */
#uiBrand { display: flex !important; align-items: stretch; }
#uiBrand .bl, #uiBrand .br {
  flex: 1 1 50%;
  height: 100%;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  padding: 7% 6%;
  position: relative;
}
#uiBrand .bl { background: var(--ui-ink); color: var(--ui-surface); }
#uiBrand .br { color: var(--ui-field-ink); }
#uiBrand .vert {
  position: absolute;
  left: 4%;
  top: 50%;
  transform: translateY(-50%) rotate(180deg);
  writing-mode: vertical-rl;
  font-size: 0.62rem;
  letter-spacing: 0.18em;
  opacity: 0.8;
}
#uiBrand .bhead {
  margin: 0;
  font-weight: 300;
  letter-spacing: -0.03em;
  line-height: 0.95;
  font-size: clamp(22px, 6.2cqh, 54px);
}
#uiBrand .bstack {
  margin-top: auto;
  align-self: flex-end;
  font-size: clamp(14px, 3.2cqh, 28px);
  line-height: 1.16;
}
#uiBrand .bstack em { font-style: normal; font-weight: 300; opacity: 0.78; }
#uiBrand .bstack .dot {
  display: inline-block;
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: var(--ui-accent);
  margin-right: 0.35em;
  vertical-align: 0.05em;
}
#uiBrand .tag {
  font-size: 0.62rem;
  letter-spacing: 0.16em;
  font-weight: 700;
}
#uiBrand .foot { margin-top: auto; }
#uiBrand .bsub {
  font-size: clamp(18px, 4.4cqh, 36px);
  font-weight: 400;
  line-height: 1.05;
}
#uiBrand .rule {
  display: block;
  width: 42px;
  height: 2px;
  background: var(--ui-accent);
  margin: 10px 0;
}
#uiBrand .bcap {
  font-size: 0.58rem;
  letter-spacing: 0.14em;
}

/* poster pair: chrome is brand, art wells are holes into the live pattern */
#uiPosters { gap: 4%; }
#uiPosters .pcard {
  width: min(32%, 200px);
  aspect-ratio: 0.7;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 40px rgba(10,16,32,0.22);
  border-radius: var(--ui-radius);
}
#uiPosters .light { background: var(--ui-surface); color: var(--ui-ink); }
#uiPosters .dark { background: var(--ui-ink); color: var(--ui-surface); }
#uiPosters .ptop {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12% 10% 8%;
}
#uiPosters .ptop h3 {
  font-weight: 400;
  letter-spacing: -0.03em;
  font-size: clamp(14px, 2.6cqh, 22px);
  line-height: 1.05;
}
#uiPosters .purl {
  margin-top: auto;
  font-weight: 700;
  font-size: 0.62rem;
  letter-spacing: 0.04em;
}
#uiPosters .bars { height: 42%; }

/* page section: the artboard is a website — page wash, pattern in a well */
#uiPromo {
  display: block;
  background: transparent;
}
#uiPromo .pchrome {
  position: absolute;
  background: var(--ui-page);
  pointer-events: none;
}
#uiPromo .pchrome-t { left: 0; right: 0; top: 0; height: calc(11% + 2px); }
#uiPromo .pchrome-b { left: 0; right: 0; bottom: 0; height: calc(8% + 2px); }
#uiPromo .pchrome-l { left: 0; width: calc(6% + 2px); top: 11%; bottom: 8%; }
#uiPromo .pchrome-r { right: 0; width: calc(6% + 2px); top: 11%; bottom: 8%; }
#uiPromo .promoCard {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 11%;
  bottom: 8%;
  display: flex;
  background: transparent;
  box-shadow: 0 18px 50px rgba(10,16,32,0.16);
  border-radius: calc(var(--ui-radius) * 1.15);
  overflow: hidden;
}
#uiPromo .pleft {
  position: relative;
  width: 48%;
  background: transparent;
}
#uiPromo .codewin {
  position: absolute;
  left: 10%;
  top: 22%;
  width: 78%;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.1);
  border-radius: calc(var(--ui-radius) * 0.45);
  font-size: 0.62rem;
  line-height: 1.45;
  box-shadow: 0 10px 28px rgba(10,16,32,0.12);
}
#uiPromo .cwbar {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 0.55rem;
  letter-spacing: 0.12em;
  font-weight: 700;
}
#uiPromo .cwbar i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ui-accent);
}
#uiPromo .codewin pre { padding: 8px 9px 10px; color: var(--ink-soft); font-family: ui-monospace, Menlo, monospace; }
#uiPromo .pright {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 7% 6% 7% 7%;
  background: var(--ui-surface);
}
#uiPromo .pright h3 {
  font-weight: 600;
  font-size: clamp(20px, 4.4cqh, 40px);
  line-height: 1.04;
  letter-spacing: -0.035em;
  color: var(--ui-ink);
}
#uiPromo .pright p {
  margin: 0.85em 0 1.4em;
  font-size: clamp(11px, 1.7cqh, 16px);
  line-height: 1.45;
  color: var(--ink-soft);
  max-width: 28em;
}
#appCopyFields textarea {
  width: 100%;
  min-height: 3.2em;
  margin: 0 0 8px;
  padding: 7px 8px;
  font-family: inherit;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  resize: vertical;
}
#appCopyFields label {
  display: block;
  margin: 0 0 3px;
  font-size: 0.58rem;
  font-weight: 650;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--label);
}

#uiPromo .btn {
  align-self: flex-start;
  background: var(--ui-ink);
  color: var(--ui-surface);
  border-radius: 999px;
  padding: 0.5em 1.05em;
  font-size: 0.72rem;
  font-weight: 650;
}

/* reduced motion: keep opacity fades that aid comprehension, drop movement */

@media (prefers-reduced-motion: reduce) {
  .panel { transition: opacity 140ms var(--ease-out); }
  @starting-style {
    .panel { transform: none; }
  }
  .chip:hover,
  .pie-btn:hover .pie,
  .solid-swatch:hover,
  .art-handle:hover {
    transform: none;
    box-shadow: none;
  }
  .canvas[data-motion] .pattern-host,
  .canvas[data-motion] .pattern-host svg,
  .canvas[data-motion] .pattern-host svg > g,
  .canvas[data-motion] .pattern-host .motif-unit,
  .canvas[data-motion] .backdrop,
  .canvas[data-motion] .bg-canvas {
    animation: none !important;
    transform: none !important;
    filter: none !important;
  }
}

/* responsive */

@media (max-width: 900px) {
  body { padding: 12px; overflow: auto; }
  .app-frame {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }
  .stage-col { order: 1; }
  .stage-well { min-height: 48vh; padding: 10px 10px 0; }
  .sidebar { order: 2; border-left: none; border-top: 1px solid var(--line); }
}
