/* css/studio.css — the Studio section builder. */

.studio {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 20px 80px;
}

.builder {
  display: grid;
  grid-template-columns: 200px 1fr 232px;
  gap: 18px;
  align-items: start;
}

/* ── Inspector ───────────────────────────────────────────────────────────── */
.inspector {
  position: sticky;
  top: 12px;
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
  z-index: 100;
}

.inspector .tpl-wrap {
  z-index: auto;
}

.insp-sec {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.insp-sec[hidden] {
  display: none;
}

.insp-title {
  margin: 0 0 10px;
  font: 800 13px/1 'Inter', system-ui, sans-serif;
  color: #0f172a;
}

.insp-lbl {
  display: flex;
  justify-content: space-between;
  font: 700 11.5px/1 'Inter', system-ui, sans-serif;
  color: #64748b;
}

.insp-lbl b {
  color: #5b3ff0;
  font-weight: 800;
}

.insp-name {
  font: 700 13.5px/1.2 'Inter', system-ui, sans-serif;
  color: #5b3ff0;
  margin-bottom: 12px;
}

.insp-field {
  display: block;
  margin-bottom: 14px;
}

.insp-field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  margin-top: 8px;
  background: linear-gradient(90deg, #ddd6fe, #5b3ff0);
  outline: none;
  cursor: pointer;
}

.insp-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #5b3ff0;
  box-shadow: 0 2px 6px rgba(91, 63, 240, .4);
}

.insp-field input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid #5b3ff0;
  box-shadow: 0 2px 6px rgba(91, 63, 240, .4);
}

.insp-select {
  width: 100%;
  margin-top: 6px;
  border: 1.5px solid #e2e8f0;
  border-radius: 9px;
  padding: 8px 10px;
  background: #fff;
  cursor: pointer;
  font: 700 12.5px/1 'Inter', system-ui, sans-serif;
  color: #0f172a;
}

.insp-select:focus-visible {
  outline: 2px solid #5b3ff0;
  outline-offset: 1px;
}

.insp-textarea {
  width: 100%;
  min-height: 76px;
  margin-top: 6px;
  resize: vertical;
  border: 1.5px solid #e2e8f0;
  border-radius: 9px;
  padding: 9px 10px;
  background: #fff;
  font: 600 12.5px/1.45 'Inter', system-ui, sans-serif;
  color: #0f172a;
}

.insp-textarea:focus-visible {
  outline: 2px solid #5b3ff0;
  outline-offset: 1px;
}

.insp-color {
  width: 100%;
  height: 36px;
  margin-top: 6px;
  padding: 3px;
  border: 1.5px solid #e2e8f0;
  border-radius: 9px;
  background: #fff;
  cursor: pointer;
}

.insp-field[hidden] {
  display: none;
}

.insp-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.insp-sw {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  cursor: pointer;
  border: 1.5px solid #e2e8f0;
  padding: 0;
  background-image: radial-gradient(circle, #cbd5e1 1px, transparent 1px);
  background-size: 7px 7px;
  background-color: #fbfbfd;
  transition: border-color .14s ease, transform .1s ease;
}

.insp-sw:hover {
  transform: scale(1.08);
}

.insp-sw.is-active {
  border-color: #5b3ff0;
  box-shadow: 0 0 0 2px rgba(91, 63, 240, .25);
}

.insp-sw--round {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background-image: none;
}

.insp-tip {
  font: 500 11.5px/1.5 'Inter', system-ui, sans-serif;
  color: #94a3b8;
  margin: 0 0 12px;
}

.insp-remove {
  width: 100%;
}

.insp-remove:hover {
  border-color: #fca5a5;
  color: #dc2626;
  background: #fef2f2;
}

.insp-hint {
  font: 500 12px/1.5 'Inter', system-ui, sans-serif;
  color: #94a3b8;
  margin: 0;
}

.insp-selected-on .insp-hint {
  display: none;
}

/* ── Palette ─────────────────────────────────────────────────────────────── */
.palette {
  position: sticky;
  top: 12px;
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
  max-height: calc(100vh - 200px);
  /* leaves room for header + spacing */
  overflow-y: auto;
  /* scroll the whole sidebar if needed */
}

.palette__title {
  margin: 0;
  font: 800 14px/1 'Inter', system-ui, sans-serif;
  color: #0f172a;
}

.palette__hint {
  margin: 6px 0 14px;
  font: 500 12px/1.4 'Inter', system-ui, sans-serif;
  color: #94a3b8;
}

.palette__items {
  display: flex;
  flex-direction: column;
  gap: 7px;
  max-height: 70vh;
  overflow: auto;
}

.palette__text {
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid #f1f5f9;
}

.pal-item {
  text-align: left;
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: #334155;
  border-radius: 10px;
  padding: 10px 12px;
  cursor: grab;
  font: 700 13px/1 'Inter', system-ui, sans-serif;
  transition: border-color .14s ease, background .14s ease, transform .1s ease;
}

.pal-item:hover {
  border-color: #c4b5fd;
  background: #faf9ff;
  color: #5b3ff0;
}

.pal-item:active {
  cursor: grabbing;
  transform: scale(.98);
}

.pal-item--text {
  border-style: dashed;
  color: #0f172a;
}

/* ── Palette: head + grouped sections ─────────────────────────────────────── */
.palette__head {
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.palette__title {
  margin: 0;
  font: 800 15px/1 'Inter', system-ui, sans-serif;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.palette__hint {
  margin: 6px 0 0;
  font: 500 12px/1.4 'Inter', system-ui, sans-serif;
  color: #94a3b8;
}

.palette-group {
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.palette-group:last-child {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: 0;
}

.palette-group__title {
  margin: 0 0 9px;
  font: 800 11px/1 'Inter', system-ui, sans-serif;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.palette-templates__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
  padding-right: 4px;
}

/* Cards must take the grid track width, never their (full-size) scene content. */
.palette-templates__grid .tpl-card {
  min-width: 0;
}

.palette-templates__grid .tpl-preview {
  width: 100%;
}

/* ── Template cards (shared base) ── */
.tpl-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  border: 1.5px solid #e2e8f0;
  background: #fff;
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  text-align: center;
  transition: border-color .14s ease, box-shadow .14s ease, transform .2s ease, z-index 0s .2s;
  position: relative;
  z-index: 1;
}

.tpl-card:hover {
  border-color: #c4b5fd;
  box-shadow: 0 4px 12px rgba(91, 63, 240, .12);
  transform: translateY(-2px);
}

/* Mini canvas preview */
.tpl-preview {
  width: 100%;
  height: 80px;
  /* slightly taller by default */
  overflow: hidden;
  border-radius: 6px;
  background:
    radial-gradient(circle, #e2e8f0 1px, transparent 1px) 0 0 / 8px 8px;
  background-color: #fbfbfd;
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.04);
  position: relative;
  transition: height .25s ease, overflow 0s .25s;
  /* delay overflow visible */
}

.tpl-card:hover .tpl-preview {
  height: 140px;
  /* grow on hover */
  overflow: visible;
  /* allow scaled content to spill out */
  z-index: 21;
}

.tpl-preview-inner {
  position: absolute;
  top: 4px;
  left: 4px;
  transform: scale(0.28);
  /* slightly larger base scale */
  transform-origin: top left;
  width: 357%;
  /* 1/0.28 ≈ 357% */
  display: flex;
  flex-direction: column;
  gap: 5px;
  pointer-events: none;
  transition: transform .25s ease;
}

.tpl-card:hover .tpl-preview-inner {
  transform: scale(0.48);
  /* zoom in more */
  /* width adjusts automatically */
}

.tpl-card__name {
  font: 700 11px/1.2 'Inter', system-ui, sans-serif;
  color: #0f172a;
  transition: color .14s ease;
}

.tpl-card:hover .tpl-card__name {
  color: #5b3ff0;
}

/* Sidebar-specific: keep the grid calm, let the card hover freely */
.tpl-card {
  width: auto;
  border-radius: 10px;
}

.tpl-preview {
  height: 64px;
}

/* Template hover popup */
.tpl-popup {
  position: fixed;
  z-index: 1000;
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 14px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .25);
  padding: 14px;
  pointer-events: none;
  /* don't interfere with hover */
  width: 360px;
  max-height: 80vh;
  overflow-y: auto;
  transition: opacity .15s ease;
  opacity: 0;
}

.tpl-popup[hidden] {
  display: none;
  opacity: 0;
}

.tpl-popup:not([hidden]) {
  opacity: 1;
}

.tpl-popup__inner {
  /* The inner container will hold the actual preview HTML */
  background:
    radial-gradient(circle, #e2e8f0 1px, transparent 1px) 0 0 / 12px 12px;
  background-color: #fbfbfd;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tpl-popup__inner>* {
  /* No scaling needed – components render at native size */
  pointer-events: none;
}

/* ── Canvas ──────────────────────────────────────────────────────────────── */
.canvas-wrap {
  min-width: 0;
}

.canvas-bar {
  position: relative;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  background: rgba(255, 255, 255, .85);
  -webkit-backdrop-filter: blur(12px) saturate(1.3);
  backdrop-filter: blur(12px) saturate(1.3);
  border: 1px solid #ece9fb;
  border-radius: 16px;
  box-shadow: 0 12px 34px rgba(15, 23, 42, .07);
}

.canvas-bar__count {
  font: 700 13px/1 'Inter', system-ui, sans-serif;
  color: #475569;
}

.tokens-saved {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font: 600 12.5px/1 'Inter', system-ui, sans-serif;
  color: #5b21b6;
  background: linear-gradient(120deg, #ede9fe, #fae8ff);
  border: 1px solid #e9d5ff;
  white-space: nowrap;
  transition: transform .18s cubic-bezier(.22, 1.4, .5, 1);
}

.tokens-saved b {
  font-weight: 800;
  color: #6d28d9;
  font-variant-numeric: tabular-nums;
}

.tokens-saved__spark {
  color: #a855f7;
}

.tokens-saved.is-bump {
  animation: tokens-bump .5s cubic-bezier(.22, 1.4, .5, 1);
}

@keyframes tokens-bump {

  0%,
  100% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.12);
  }
}

@media (max-width: 900px) {
  .tokens-saved {
    display: none;
  }
}

.canvas-bar__actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sc-btn--icon {
  padding: 8px 11px;
  font-size: 15px;
  line-height: 1;
}

.cv-stage {
  position: relative;
  height: 620px;
  overflow: hidden;
  background: radial-gradient(circle, #e2e8f0 1px, transparent 1px) 0 0 / 22px 22px;
  background-color: #fbfbfd;
  border: 1.5px dashed #e2e8f0;
  border-radius: 18px;
  transition: border-color .15s ease, background-color .15s ease;
  z-index: 0;
}

.cv-stage.is-drop {
  border-color: #5b3ff0;
  background-color: #f5f3ff;
}

.cv-stage.organizing .cv-item {
  transition: left .3s cubic-bezier(.4, 0, .2, 1), top .3s cubic-bezier(.4, 0, .2, 1);
}

.cv-stage.interact-on {
  border-color: #2563eb;
  border-style: solid;
  background-color: #f5f7ff;
}

.cv-empty {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  max-width: 320px;
  text-align: center;
  color: #94a3b8;
  font: 500 14px/1.6 'Inter', system-ui, sans-serif;
}

.cv-empty__lead {
  font: 800 15px/1 'Inter', system-ui, sans-serif;
  color: #0f172a;
  margin-bottom: 14px;
}

.cv-empty__or {
  margin-top: 16px;
  font-size: 12.5px;
  color: #94a3b8;
}

.cv-empty__mark {
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #ede9fe;
  color: #5b3ff0;
  font: 800 26px/1 'Inter', system-ui, sans-serif;
}

.tpl-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

/* Legacy chip (used for variant menu) */
.tpl-chip {
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: #334155;
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  font: 700 12.5px/1 'Inter', system-ui, sans-serif;
  transition: border-color .14s ease, background .14s ease, color .14s ease, transform .1s ease;
}

.tpl-chip:hover {
  border-color: #c4b5fd;
  background: #faf9ff;
  color: #5b3ff0;
  transform: translateY(-1px);
}

/* Variant dropdown */
.tpl-wrap {
  position: relative;
  display: inline-block;
}

.tpl-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 168px;
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
  background: #fff;
  border: 1px solid #eef0f4;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, .16);
}

.tpl-menu[hidden] {
  display: none;
}

.tpl-menu .tpl-chip {
  text-align: left;
  border-color: transparent;
}

.tpl-menu .tpl-chip:hover {
  transform: none;
}

/* Canvas items */
.cv-item {
  position: absolute;
  width: max-content;
  cursor: grab;
  touch-action: none;
  border-radius: 6px;
  outline: 2px solid transparent;
  outline-offset: 4px;
  transition: outline-color .14s ease, opacity .14s ease;
}

.cv-item:hover {
  outline-color: #c4b5fd;
}

.cv-item.is-selected {
  outline-color: #5b3ff0;
}

.cv-item--dragging {
  opacity: .65;
  cursor: grabbing;
}

.cv-item__preview {
  display: block;
  overflow: visible;
}

.cv-text {
  display: block;
  /* Size to the text's own content (so the wrapper width can never re-flow it),
     capped so long paragraphs still wrap. */
  width: max-content;
  max-width: 560px;
  margin: 0;
  line-height: 1.12;
  letter-spacing: 0;
  white-space: pre-wrap;
}

.cv-img {
  display: block;
  object-fit: cover;
}

.cv-item--text .cv-item__preview {
  min-width: 80px;
}

.cv-item.is-selected [data-tx] {
  cursor: text;
}

.cv-editing {
  outline: 2px solid #5b3ff0 !important;
  outline-offset: 2px;
  border-radius: 3px;
  background: rgba(91, 63, 240, .06);
}

.insp-zrow {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.insp-zrow .sc-btn {
  flex: 1;
}

.cv-group-box {
  position: absolute;
  pointer-events: none;
  border: 1.5px dashed #5b3ff0;
  border-radius: 10px;
  background: rgba(91, 63, 240, .04);
  z-index: 40;
}

/* A lagging box during the arrange animation reads as broken — hide it, redraw on settle. */
.cv-stage.organizing .cv-group-box {
  display: none;
}

/* Rubber-band marquee for drag-to-highlight selection. */
.cv-marquee {
  position: absolute;
  pointer-events: none;
  border: 1.5px solid #5b3ff0;
  background: rgba(91, 63, 240, .08);
  border-radius: 4px;
  z-index: 45;
}

.insp-align {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 6px;
}

.insp-align .sc-btn--icon {
  padding: 6px 0;
  font-size: 15px;
  line-height: 1;
}

/* Guides */
.cv-guide {
  position: absolute;
  pointer-events: none;
  z-index: 50;
  color: #ef4444;
  font: 800 10px/1 'Inter', system-ui, sans-serif;
}

.cv-guide--v {
  width: 0;
  border-left: 1.5px solid #ef4444;
}

.cv-guide--h {
  height: 0;
  border-top: 1.5px solid #ef4444;
}

.cv-guide--measure {
  border-color: #ef4444;
}

.cv-guide--w {
  height: 0;
  border-top: 1.5px solid #ef4444;
}

.cv-guide--hgt {
  width: 0;
  border-left: 1.5px solid #ef4444;
}

.cv-guide--distance {
  border-color: #dc2626;
}

.cv-guide__label {
  position: absolute;
  left: 50%;
  top: -18px;
  transform: translateX(-50%);
  padding: 4px 6px;
  border-radius: 6px;
  background: #ef4444;
  color: #fff;
  font: 800 10px/1 'Inter', system-ui, sans-serif;
  white-space: nowrap;
}

.cv-guide--v>.cv-guide__label,
.cv-guide--hgt>.cv-guide__label {
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
}

.cv-guide--hgt .cv-guide__label {
  left: -12px;
  top: 50%;
  transform: rotate(-90deg) translateX(-50%);
  transform-origin: left center;
  white-space: nowrap;
}

/* Resize & close */
.cv-item__resize {
  position: absolute;
  right: -7px;
  bottom: -7px;
  width: 14px;
  height: 14px;
  background: #5b3ff0;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .3);
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity .14s ease;
  z-index: 3;
  touch-action: none;
}

.cv-item:hover .cv-item__resize,
.cv-item.is-selected .cv-item__resize {
  opacity: 1;
}

.cv-item__x {
  position: absolute;
  top: -9px;
  right: -9px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: #0f172a;
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transform: scale(.8);
  transition: opacity .14s ease, transform .14s ease, background .14s ease;
  z-index: 2;
}

.cv-item:hover .cv-item__x {
  opacity: 1;
  transform: scale(1);
}

.cv-item__x:hover {
  background: #dc2626;
}

/* Shared buttons + toast */
.sc-btn {
  border: 1.5px solid #e2e8f0;
  background: #fff;
  color: #334155;
  border-radius: 10px;
  padding: 9px 15px;
  cursor: pointer;
  font: 700 12.5px/1 'Inter', system-ui, sans-serif;
  transition: background .14s ease, border-color .14s ease, transform .14s ease;
}

.sc-btn:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
  transform: translateY(-1px);
}

.sc-btn--primary {
  background: #5b3ff0;
  border-color: #5b3ff0;
  color: #fff;
}

.sc-btn--primary:hover {
  background: #4c33d4;
  border-color: #4c33d4;
}

/* Split button: primary "Copy section" + a caret revealing secondary copy modes. */
.split-copy {
  display: inline-flex;
  align-items: stretch;
}

.sc-btn--split {
  border-radius: 10px 0 0 10px;
  border-right-color: rgba(255, 255, 255, .35);
}

.sc-btn--split-caret {
  border-radius: 0 10px 10px 0;
  padding: 9px 10px;
  border-left: none;
  font-size: 11px;
}

.tpl-chip__hint {
  display: block;
  font: 500 10.5px/1.3 'Inter', system-ui, sans-serif;
  color: #94a3b8;
  margin-top: 2px;
}

.tpl-menu .tpl-chip:hover .tpl-chip__hint {
  color: #8b7ae8;
}

.studio-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 20px);
  background: #0f172a;
  color: #fff;
  padding: 12px 18px;
  border-radius: 12px;
  font: 700 13px/1 'Inter', system-ui, sans-serif;
  box-shadow: 0 14px 40px rgba(15, 23, 42, .35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60;
}

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

@media (max-width: 860px) {
  .builder {
    grid-template-columns: 1fr;
  }

  .palette,
  .inspector {
    position: static;
  }

  .palette__items {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: none;
  }

  .pal-item {
    flex: 0 0 auto;
  }
}