:root {
  --pj-ink: #322541;
  --pj-muted: #5e526c;
  --pj-lavender: #b69de2;
  --pj-rose: #f29bb7;
  --pj-coral: #f4a591;
  --pj-mint: #78cda7;
  --pj-border: #d9c6e9;
  --pj-shadow: 0 14px 38px rgba(107, 74, 145, 0.12);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--pj-ink);
  background: #f4e9f8;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(ellipse at 8% 10%, #cbb8ed8c, transparent 50%),
    radial-gradient(ellipse at 90% 12%, #f4bfd079, transparent 48%),
    radial-gradient(ellipse at 48% 85%, #afebd385, transparent 58%),
    linear-gradient(155deg, #f6edfa, #fff0f3 50%, #e9f8f1);
  background-attachment: fixed;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle 180px at 85% 35%, #d8c1ef38, transparent 100%),
    radial-gradient(circle 220px at 12% 65%, #f3b5c638, transparent 100%);
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: #63478c; text-decoration: none; }

.pj-top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 12px clamp(16px, 4vw, 65px);
  border-bottom: 1px solid #b69de27a;
  background: #fffaf1dc;
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
  box-shadow: 0 4px 20px #8c69ae13;
}

.pj-brand {
  font-family: 'Orbitron', 'Inter', sans-serif;
  font-weight: 800;
  font-size: 1.3rem;
  color: #704b9d;
}

.pj-brand span { color: #bf5889; }
.pj-top nav { display: flex; flex-wrap: wrap; gap: 8px; }

.pj-top nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 13px;
  border-radius: 999px;
  border: 1px solid #cbb4e0;
  background: #f3e9f8;
  color: #50386a;
  font-size: .84rem;
  font-weight: 700;
  transition: background .2s, border-color .2s;
}

.pj-top nav a:hover { background: #eaddf4; border-color: #aa8acc; }

main {
  position: relative;
  z-index: 1;
  max-width: 1590px;
  margin: auto;
  padding: 25px clamp(12px, 3vw, 44px) 80px;
}

.pj-intro {
  position: relative;
  overflow: hidden;
  margin: 0 0 23px;
  padding: clamp(20px, 3vw, 32px);
  border: 1px solid #ddcae9;
  border-radius: 22px;
  background: linear-gradient(115deg, #fffefdf0, #fceaf4ee 60%, #e8f7efea);
  box-shadow: var(--pj-shadow);
}

.pj-intro::after {
  content: '';
  position: absolute;
  z-index: 0;
  top: -110px;
  right: -45px;
  width: 330px;
  height: 330px;
  border-radius: 50%;
  background: radial-gradient(circle, #c6b0eb77, #f3b5c533 55%, transparent 72%);
  pointer-events: none;
}

.pj-intro > * { position: relative; z-index: 1; }

.pj-eyebrow {
  display: inline-block;
  padding: 8px 14px;
  border: 1px solid #c7ade6;
  border-radius: 999px;
  background: #eee1f9;
  color: #624185;
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .12em;
}

.pj-intro h1 {
  margin: 14px 0 8px;
  color: #352346;
  font-family: 'Orbitron', 'Inter', sans-serif;
  font-size: clamp(2rem, 4.2vw, 3.6rem);
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -.03em;
}

.pj-intro h1 span { color: #b04e80; }

.pj-intro p {
  margin: 0;
  max-width: 850px;
  color: var(--pj-muted);
  line-height: 1.6;
}

.pj-intro .pj-dev-note {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px 14px;
  width: fit-content;
  max-width: 100%;
  margin-top: 20px;
  padding: 11px 15px;
  border: 1px solid #dc9caa;
  border-radius: 14px;
  background: linear-gradient(110deg, #ffe3d7, #fce4ee 62%, #f1e7fc);
  color: #583343;
  font-size: .9rem;
  font-weight: 600;
  box-shadow: 0 6px 20px #c8759b24;
}

/* Creator already provides its own header and navigation around the iframe. */
.pj-embedded .pj-top, .pj-embedded .pj-intro { display: none; }
.pj-embedded main { padding-top: 12px; }
/* Creator expands this iframe to the document's height on touch devices.
   Keeping the frame non-scrollable lets one-finger swipes chain to the host. */
.pj-host-scrolling, .pj-host-scrolling body { height: auto; min-height: 0; overflow: visible; }

.pj-dev-note strong {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  background: #9c496a;
  color: #fff;
  font-size: .8rem;
  font-weight: 800;
  white-space: nowrap;
}

.pj-workspace {
  display: grid;
  grid-template-columns: minmax(410px, 1fr) minmax(400px, 1.1fr);
  align-items: start;
  gap: 20px;
  height: calc(100dvh - 95px);
  min-height: 480px;
}

.pj-controls {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 18px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  padding: 2px 8px 12px 2px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #a47bcc #f3e9f8;
  scrollbar-width: thin;
}

.pj-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: clamp(16px, 2vw, 24px);
  border: 1px solid #d9c6e9;
  border-radius: 20px;
  background: #fffffff0;
  box-shadow: var(--pj-shadow);
}

.pj-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--pj-lavender), var(--pj-rose), var(--pj-mint));
}

.pj-controls details > summary {
  display: flex;
  align-items: center;
  list-style: none;
  gap: 6px;
  padding: 2px 0 13px;
  color: #372548;
  font-size: 1.13rem;
  font-weight: 800;
  cursor: pointer;
}
.pj-controls details > summary::-webkit-details-marker { display: none; }
.pj-controls details > summary::after { content: '⌄'; margin-left: 4px; font-size: 1.35rem; }
.pj-controls details:not([open]) > summary::after { content: '›'; }
.pj-controls details > summary:focus-visible { outline: 3px solid #7c51ae; outline-offset: 3px; }
.pj-expand { margin-left: auto; font-size: .68rem; font-weight: 600; color: var(--pj-muted); }
.pj-subgroup { padding: 12px 14px; margin: 14px 0; border-radius: 13px; background: #f6f0fb; }
.pj-subgroup + .pj-subgroup { background: #eff8f3; }
.pj-subgroup h3 { margin: 0; font-size: .91rem; color: #503672; }
.pj-subgroup .pj-hint { margin: 8px 0 12px; }
.pj-subgroup .pj-hint:last-child { margin-bottom: 0; }

.pj-controls .pj-card:nth-child(2)::before {
  background: linear-gradient(90deg, var(--pj-mint), var(--pj-lavender));
}

.pj-controls .pj-card:nth-child(3)::before {
  background: linear-gradient(90deg, var(--pj-coral), var(--pj-rose), var(--pj-lavender));
}

.pj-card h2 {
  margin: 2px 0 17px;
  color: #372548;
  font-size: 1.13rem;
  font-weight: 800;
}

.pj-step {
  display: inline-grid;
  place-items: center;
  width: 31px;
  height: 31px;
  margin-right: 7px;
  border-radius: 10px;
  background: #eadcf5;
  color: #624282;
  font-size: .82rem;
  font-weight: 800;
}

.pj-controls .pj-card:nth-child(2) .pj-step { background: #d9f4e8; color: #286b53; }
.pj-controls .pj-card:nth-child(3) .pj-step { background: #ffe5d9; color: #915342; }

.pj-upload {
  display: block;
  min-height: 48px;
  padding: 14px;
  border: 2px dashed #b79adc;
  border-radius: 13px;
  background: linear-gradient(120deg, #f2e8fb, #ffeaf1);
  color: #593b77;
  text-align: center;
  font-weight: 800;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}

.pj-upload:hover, .pj-upload.pj-drag-over { background: #dff5e9; border-color: #4caa83; }
.pj-upload:focus-within { outline: 3px solid #7d56af; outline-offset: 2px; }

.pj-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; }

.pj-hint {
  margin: 11px 0;
  color: var(--pj-muted);
  font-size: .81rem;
  line-height: 1.55;
}

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

.pj-canvas-wrap { position: relative; min-width: 0; }
.pj-editor canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #bba8d1;
  border-radius: 11px;
  touch-action: auto;
  background-color: #e9e1ee;
  background-image: linear-gradient(45deg, #d3c9df 25%, transparent 25%), linear-gradient(-45deg, #d3c9df 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d3c9df 75%), linear-gradient(-45deg, transparent 75%, #d3c9df 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
}

.pj-editor canvas.white { background: #fff; }
.pj-editor canvas.pj-editing { touch-action: none; cursor: crosshair; }
.pj-editor canvas.pj-erasing { cursor: none; }

.pj-crop-box {
  position: absolute;
  border: 2px dashed #fff;
  outline: 2px solid #673898;
  background: #aa71df32;
  pointer-events: none;
}
.pj-crop-box[hidden], .pj-erase-cursor[hidden] { display: none; }
.pj-erase-cursor {
  position: absolute;
  border: 2px solid #a33873;
  border-radius: 50%;
  background: #fff9;
  box-shadow: 0 0 0 1px #fff, 0 1px 7px #33254188;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.pj-actions .pj-tool {
  min-height: 42px;
  padding: 8px 12px;
  border: 1px solid #bc9fdc;
  border-radius: 10px;
  background: #eee4f8;
  cursor: pointer;
}
.pj-actions .pj-tool:has(input:checked), .pj-actions button[aria-pressed="true"] {
  border-color: #a33873;
  background: #fbd8eb;
  color: #662345;
  box-shadow: inset 0 0 0 1px #a33873;
}
.pj-actions button:disabled { opacity: .5; cursor: not-allowed; }
.pj-edit-hint { margin: -4px 0 15px; color: #5c426f; font-size: .83rem; line-height: 1.5; }

.pj-editor-labels {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 1px 12px;
  color: #655775;
  font-size: .72rem;
}

.pj-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 9px; margin-bottom: 16px; }

.pj-actions button {
  min-height: 42px;
  padding: 8px 13px;
  border: 1px solid #bc9fdc;
  border-radius: 10px;
  background: #eee4f8;
  color: #523477;
  font-weight: 700;
  transition: background .2s;
}

.pj-actions button:hover { background: #dec9f1; }
.pj-check { display: inline-flex; align-items: center; gap: 5px; color: #513e65; font-size: .83rem; font-weight: 600; }
.pj-check input { accent-color: #8d6cbd; }

.pj-params { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }

.pj-params label { display: block; color: #493554; font-size: .82rem; font-weight: 700; }
.pj-params output { float: right; color: #7850a7; font-weight: 800; font-variant-numeric: tabular-nums; }
.pj-params input[type="range"] { display: block; width: 100%; margin: 0; accent-color: #a375d0; }
.pj-params input:disabled { opacity: .45; }
.pj-param { min-width: 0; }
.pj-slider-field { display: flex; align-items: center; gap: 9px; margin-top: 8px; }
.pj-params .pj-number {
  flex: 0 0 72px;
  width: 72px;
  min-width: 0;
  min-height: 34px;
  padding: 4px 3px 4px 7px;
  border: 1px solid #bba5d3;
  border-radius: 8px;
  background: white;
  color: #493554;
  font-size: .85rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.pj-number::-webkit-inner-spin-button, .pj-number::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pj-params .pj-number { appearance: textfield; }
.pj-stepper { display: flex; flex: 0 0 25px; flex-direction: column; gap: 2px; }
.pj-arrow {
  height: 19px;
  padding: 0;
  border: 1px solid #b89bce;
  border-radius: 5px;
  background: #f1e6f8;
  color: #563276;
  font-size: .6rem;
  line-height: 1;
  cursor: pointer;
}
.pj-arrow:hover:not(:disabled) { background: #dec9f1; }
.pj-arrow:disabled { opacity: .45; cursor: not-allowed; }
.pj-arrow:focus-visible { outline: 3px solid #7c51ae; outline-offset: 1px; }

.pj-params select {
  width: 100%;
  min-height: 40px;
  margin-top: 8px;
  padding: 6px 9px;
  border: 1px solid #bba5d3;
  border-radius: 9px;
  background: #f8f2fc;
  color: var(--pj-ink);
}

.pj-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 15px; }
.pj-choices label { position: relative; cursor: pointer; }
.pj-choices input { position: absolute; opacity: 0; }

.pj-choices span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 49px;
  padding: 6px;
  border: 1px solid #c5addc;
  border-radius: 10px;
  background: #f7f0fb;
  color: #59416e;
  text-align: center;
  font-size: .8rem;
  font-weight: 700;
  transition: background .2s, border-color .2s;
}

.pj-choices label:hover span { background: #ebdcf8; }

.pj-choices input:checked + span {
  border-color: #a068b9;
  background: linear-gradient(125deg, #e1cff5, #ffd6e1);
  box-shadow: inset 0 0 0 1px #aa80c4;
  color: #422659;
}

.pj-choices input:focus-visible + span,
.pj-top a:focus-visible,
.pj-actions button:focus-visible,
.pj-params select:focus-visible,
.pj-params input:focus-visible,
.pj-download:focus-visible, .pj-center-view:focus-visible {
  outline: 3px solid #7c51ae;
  outline-offset: 2px;
}

.pj-textures { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pj-preview { height: 100%; overflow-y: auto; scrollbar-width: thin; }
.pj-mobile-controls-link { display: none; }
.pj-touch-hint { display: none; }

.pj-colors { display: flex; flex-wrap: wrap; gap: 12px 24px; margin: -4px 0 15px; }
.pj-colors label { display: inline-flex; align-items: center; gap: 9px; color: #493554; font-size: .85rem; font-weight: 700; }
.pj-colors input { width: 45px; height: 36px; padding: 2px; border: 1px solid #ae90cc; border-radius: 8px; background: #fff; cursor: pointer; }
.pj-colors input:focus-visible, .pj-actions .pj-tool:focus-within, .pj-actions button:focus-visible {
  outline: 3px solid #7c51ae; outline-offset: 2px;
}
.pj-color-note { margin: -5px 0 12px; }

.pj-preview #pjViewport {
  height: min(60dvh, calc(100dvh - 345px), 650px);
  min-height: 200px;
  overflow: hidden;
  border: 2px solid #cbb8e9;
  border-radius: 15px;
  background: radial-gradient(circle at 50% 38%, #514067, #241d38 75%);
  box-shadow: 0 10px 28px #61468132;
}

.pj-preview canvas { display: block; touch-action: none; }
.pj-center-view {
  min-height: 40px; padding: 8px 16px; border: 1px solid #ab87ca;
  border-radius: 9px; background: #f0e5f8; color: #51346b; font-weight: 700;
}
.pj-center-view:hover { background: #e5d5f4; }

.pj-status {
  min-height: 1.2em;
  margin: 13px 0;
  padding: 10px 12px;
  border: 1px solid #b4dfc9;
  border-radius: 9px;
  background: #eaf9f0;
  color: #256449;
  font-size: .83rem;
  font-weight: 700;
}

.pj-status.error { border-color: #edafbd; background: #fff0f1; color: #913c52; }

.pj-download {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 13px;
  border: 0;
  border-radius: 11px;
  background: linear-gradient(110deg, #f3a3a6, #d8acec, #aedfcc);
  color: #352447;
  font-weight: 900;
  box-shadow: 0 6px 18px #bc8abd4a;
  transition: filter .2s, transform .2s;
}

.pj-download:not(:disabled):hover { filter: saturate(1.2); transform: translateY(-2px); }
.pj-download:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

/* Desktop gets a full-size preview, not another scrollable pane inside Creator. */
@media (min-width: 921px) {
  .pj-workspace { height: auto; min-height: 0; }
  .pj-controls { height: calc(100dvh - 95px); min-height: 480px; }
  .pj-preview { height: auto; overflow: visible; }
  .pj-preview #pjViewport { height: clamp(500px, 75dvh, 760px); }
}

@media (max-width: 920px) {
  .pj-workspace { display: flex; flex-direction: column; height: calc(100dvh - 15px); }
  .pj-preview { order: -1; flex: 0 0 auto; width: 100%; height: auto; overflow: visible; }
  .pj-controls { width: 100%; flex: 1 1 auto; height: auto; }
  .pj-preview #pjViewport { height: clamp(160px, 28dvh, 260px); min-height: 160px; }
  .pj-preview > .pj-hint { display: none; }
}

@media (max-width: 520px) {
  .pj-top { padding: 10px 14px; }
  .pj-top nav { width: 100%; }
  .pj-top nav a { flex: 1; justify-content: center; padding-inline: 8px; font-size: .75rem; }
  main { padding: 15px 12px 50px; }
  .pj-intro { padding: 20px 16px; border-radius: 16px; }
  .pj-intro h1 { font-size: 2rem; }
  .pj-intro .pj-dev-note { font-size: .82rem; }
  .pj-card { padding: 16px 13px; border-radius: 16px; }
  .pj-preview #pjViewport { height: clamp(145px, 22dvh, 200px); min-height: 145px; }
  .pj-preview .pj-colors { margin-bottom: 6px; }
  .pj-preview .pj-status { margin: 7px 0; padding: 6px 9px; }
  .pj-params { gap: 13px; grid-template-columns: 1fr; }
  .pj-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pj-textures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pj-expand { font-size: .62rem; }
}

@media (max-width: 360px) {
  .pj-params { grid-template-columns: 1fr; }
  .pj-editor-labels { font-size: .65rem; }
}

/* In the touch layout the iframe's document is the only vertical scroller.
   A fixed-height control pane leaves only a few lines visible on phones. */
@media (max-width: 920px) and (pointer: coarse) {
  body { background-attachment: scroll; }
  body::before { display: none; }
  .pj-preview canvas { touch-action: pan-y; }
  .pj-workspace { height: auto; min-height: 0; gap: 16px; }
  .pj-controls {
    flex: none;
    height: auto;
    min-height: 0;
    padding: 0 2px 28px;
    overflow: visible;
    overscroll-behavior: auto;
  }
  .pj-preview {
    display: grid;
    grid-template-columns: minmax(90px, .55fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }
  .pj-preview h2, .pj-preview .pj-colors, .pj-preview #pjViewport,
  .pj-preview .pj-status { grid-column: 1 / -1; margin: 0; }
  .pj-preview h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .pj-mobile-controls-link {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 10px;
    border: 1px solid #bca2d5;
    border-radius: 8px;
    background: #f3e9f8;
    font: 700 .73rem 'Inter', system-ui, sans-serif;
    white-space: nowrap;
  }
  .pj-mobile-controls-link:focus-visible { outline: 3px solid #7c51ae; outline-offset: 2px; }
  .pj-preview .pj-color-note { display: none; }
  .pj-preview .pj-colors { gap: 6px 14px; }
  .pj-preview #pjViewport { height: clamp(230px, 42svh, 360px); min-height: 230px; }
  .pj-preview .pj-status { padding: 6px 9px; }
  .pj-touch-hint {
    display: block;
    grid-column: 1 / -1;
    margin: 0;
    color: var(--pj-muted);
    font-size: .76rem;
    line-height: 1.4;
  }
  .pj-preview #pjCenterView { grid-column: 1; }
  .pj-preview #pjDownload { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  .pj-top nav a, .pj-upload, .pj-actions button, .pj-choices span, .pj-download { transition: none; }
}
