.scene-visual[data-scene-type="custom"] {
  --scene-position-x: 50%;
  --scene-position-y: 50%;
  --scene-scale: var(--custom-scene-scale, 1);
  --scene-translate-x: var(--custom-scene-offset-x, 0%);
  --scene-translate-y: var(--custom-scene-offset-y, 0%);
}

/* Keep all custom-photo phases in one identical compositing box. */
.scene-visual[data-scene-type="custom"] .scene-images {
  -webkit-mask: none;
  clip-path: none;
  height: 100%;
  inset: 0;
  mask: none;
  transform: none;
  width: 100%;
}

.scene-visual[data-scene-type="custom"] .scene-image {
  -webkit-mask: none;
  clip-path: none;
  height: 100%;
  inset: 0;
  mask: none;
  object-fit: cover;
  object-position: var(--scene-position-x) var(--scene-position-y);
  transform: translate(var(--scene-translate-x), var(--scene-translate-y)) scale(var(--scene-scale));
  transform-origin: center;
  width: 100%;
}

.scene-visual[data-scene-type="custom"] .stars {
  bottom: auto;
  height: var(--custom-sky-line, 40%);
}

.scene-visual[data-scene-type="custom"][data-sky-effects-enabled="false"] .stars {
  display: none;
}

.scene-options-custom {
  border-top: 1px solid color-mix(in srgb, var(--scene-text), transparent 86%);
  margin-top: 12px;
  padding-top: 12px;
}

.scene-option--custom {
  width: 100%;
}

.custom-scene-panel {
  background: color-mix(in srgb, var(--panel-strong), transparent 4%);
  border: 1px solid var(--panel-border);
  border-radius: 26px 26px 0 0;
  bottom: 0;
  box-shadow: 0 -24px 70px rgba(3, 8, 18, 0.32);
  color: var(--scene-text);
  left: 0;
  max-height: min(92svh, 860px);
  max-height: min(92dvh, 860px);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 18px calc(18px + var(--safe-bottom));
  position: fixed;
  right: 0;
  z-index: 31;
  -webkit-backdrop-filter: blur(30px) saturate(135%);
  backdrop-filter: blur(30px) saturate(135%);
}

.custom-scene-panel:not([hidden]) {
  animation: sheet-in 330ms var(--ease-out) both;
}

.custom-panel-heading {
  background: color-mix(in srgb, var(--panel-strong), transparent 5%);
  margin-bottom: 10px;
  padding-top: 8px;
  position: sticky;
  top: -8px;
  z-index: 4;
}

.custom-privacy-note,
.custom-helper,
.custom-warning,
.custom-scene-status,
.custom-ai-instructions p {
  font-size: 0.68rem;
  line-height: 1.55;
}

.custom-privacy-note {
  opacity: 0.72;
}

.custom-scene-status {
  color: color-mix(in srgb, var(--scene-text), #ffd9a7 18%);
  min-height: 1.6em;
  padding: 5px 0 7px;
}

.custom-scene-status.is-error,
.custom-warning {
  color: #ffe1d8;
}

.custom-mode-choice {
  display: grid;
  gap: 10px;
}

.custom-mode-card {
  align-items: center;
  background: color-mix(in srgb, var(--panel-bg), transparent 9%);
  border: 1px solid color-mix(in srgb, var(--scene-text), transparent 87%);
  border-radius: var(--radius-small);
  display: grid;
  gap: 12px;
  padding: 15px;
}

.custom-mode-card h3,
.custom-shared-settings h3,
.custom-ai-instructions h3 {
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0 0 5px;
}

.custom-mode-card p {
  font-size: 0.68rem;
  line-height: 1.55;
  opacity: 0.72;
}

.custom-mode-card button,
.custom-apply-button {
  background: color-mix(in srgb, var(--scene-text), transparent 8%);
  border-radius: 999px;
  color: color-mix(in srgb, var(--panel-strong), white 20%);
  font-size: 0.74rem;
  font-weight: 600;
  min-height: 44px;
  padding: 0 16px;
}

.custom-scene-form {
  display: grid;
  gap: 13px;
}

.custom-upload-field {
  align-items: center;
  background: color-mix(in srgb, var(--panel-bg), transparent 10%);
  border: 1px dashed color-mix(in srgb, var(--scene-text), transparent 62%);
  border-radius: var(--radius-small);
  cursor: pointer;
  display: flex;
  gap: 10px;
  min-height: 58px;
  padding: 9px 11px;
}

.custom-upload-field input,
.custom-photo-slot input {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
  width: 1px;
}

.custom-upload-field:has(input:focus-visible),
.custom-photo-slot:has(input:focus-visible) {
  outline: 2px solid currentColor;
  outline-offset: 3px;
}

.custom-upload-action,
.custom-secondary-button {
  align-items: center;
  background: color-mix(in srgb, var(--scene-text), transparent 88%);
  border: 1px solid color-mix(in srgb, var(--scene-text), transparent 76%);
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.7rem;
  justify-content: center;
  min-height: 44px;
  padding: 0 13px;
}

.custom-upload-field small {
  font-size: 0.62rem;
  opacity: 0.64;
}

.custom-source-phase {
  align-items: center;
  border: 0;
  display: flex;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0;
}

.custom-source-phase legend {
  float: left;
  font-size: 0.7rem;
  margin-right: 4px;
  padding: 12px 0;
}

.custom-source-phase label {
  align-items: center;
  background: color-mix(in srgb, var(--panel-bg), transparent 14%);
  border-radius: 999px;
  display: flex;
  font-size: 0.7rem;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px;
}

.custom-preview-block {
  margin-top: 10px;
}

.custom-preview-tabs {
  display: flex;
  gap: 5px;
  margin-bottom: 6px;
}

.custom-preview-tabs button {
  background: transparent;
  border-radius: 999px;
  font-size: 0.66rem;
  min-height: 36px;
  min-width: 54px;
  opacity: 0.6;
  padding: 0 10px;
}

.custom-preview-tabs button.is-active {
  background: color-mix(in srgb, var(--scene-text), transparent 86%);
  opacity: 1;
}

.custom-preview-frame {
  aspect-ratio: 16 / 9;
  background:
    linear-gradient(155deg, rgba(150, 177, 195, 0.26), rgba(35, 49, 75, 0.34)),
    color-mix(in srgb, var(--panel-bg), transparent 10%);
  border: 1px solid color-mix(in srgb, var(--scene-text), transparent 84%);
  border-radius: 14px;
  overflow: hidden;
  position: relative;
}

#custom-preview-canvas {
  display: block;
  height: 100%;
  width: 100%;
}

.custom-sky-guide {
  cursor: ns-resize;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.7));
  height: 28px;
  left: 0;
  pointer-events: auto;
  position: absolute;
  right: 0;
  top: 40%;
  touch-action: none;
  transform: translateY(-14px);
}

.custom-sky-guide::before {
  border-top: 1px solid rgba(255, 244, 215, 0.88);
  content: "";
  left: 0;
  position: absolute;
  right: 0;
  top: 50%;
}

.custom-sky-guide::after {
  background: rgba(10, 18, 34, 0.58);
  border-radius: 999px;
  color: white;
  content: attr(data-label);
  font-size: 9px;
  padding: 2px 6px;
  position: absolute;
  right: 7px;
  top: calc(50% + 4px);
}

.custom-helper {
  margin-top: 8px;
  opacity: 0.66;
}

.custom-three-grid {
  display: grid;
  gap: 8px;
}

.custom-photo-slot {
  align-items: center;
  background: color-mix(in srgb, var(--panel-bg), transparent 10%);
  border: 1px solid color-mix(in srgb, var(--scene-text), transparent 86%);
  border-radius: var(--radius-small);
  display: grid;
  gap: 7px;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  min-height: 68px;
  padding: 8px;
}

.custom-photo-slot strong {
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
}

.custom-photo-slot img {
  border-radius: 9px;
  height: 50px;
  object-fit: cover;
  width: 88px;
}

.custom-slot-placeholder {
  font-size: 0.66rem;
  opacity: 0.58;
}

.custom-photo-slot .custom-upload-action {
  min-width: 86px;
}

.custom-slot-actions {
  display: flex;
  gap: 5px;
}

.custom-slot-remove {
  background: transparent;
  border-radius: 999px;
  color: #ffd6ce;
  font-size: 0.64rem;
  min-height: 44px;
  padding: 0 8px;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.custom-warning {
  background: rgba(100, 43, 35, 0.2);
  border: 1px solid rgba(255, 220, 205, 0.2);
  border-radius: 10px;
  margin-top: 8px;
  padding: 8px 10px;
}

.custom-ai-instructions,
.custom-advanced-settings {
  border-bottom: 1px solid color-mix(in srgb, var(--scene-text), transparent 88%);
  border-top: 1px solid color-mix(in srgb, var(--scene-text), transparent 88%);
  margin-top: 11px;
}

.custom-ai-instructions summary,
.custom-advanced-settings summary {
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
  min-height: 44px;
  padding: 12px 2px;
}

.custom-ai-instructions[open],
.custom-advanced-settings[open] {
  padding-bottom: 10px;
}

.custom-ai-instructions textarea {
  background: rgba(5, 12, 28, 0.22);
  border: 1px solid color-mix(in srgb, var(--scene-text), transparent 82%);
  border-radius: 10px;
  color: inherit;
  font: 0.64rem/1.55 var(--font-sans);
  margin: 9px 0;
  max-height: 230px;
  padding: 10px;
  resize: vertical;
  width: 100%;
}

.custom-shared-settings {
  background: color-mix(in srgb, var(--panel-bg), transparent 13%);
  border-radius: var(--radius-small);
  display: grid;
  gap: 5px;
  padding: 12px;
}

.custom-range-row {
  display: grid;
  gap: 3px;
}

.custom-range-row > span {
  display: flex;
  font-size: 0.68rem;
  justify-content: space-between;
}

.custom-range-row b {
  font-weight: 500;
}

.custom-range-row output {
  font-variant-numeric: tabular-nums;
  opacity: 0.72;
}

.custom-range-row input {
  accent-color: color-mix(in srgb, var(--scene-text), #8aa8ff 30%);
  min-height: 36px;
  width: 100%;
}

.custom-range-row small {
  font-size: 0.62rem;
  line-height: 1.45;
  opacity: 0.62;
}

.custom-check-row {
  align-items: center;
  display: flex;
  font-size: 0.7rem;
  gap: 9px;
  min-height: 44px;
}

.custom-check-row input {
  height: 20px;
  width: 20px;
}

.custom-panel-actions {
  align-items: center;
  background: color-mix(in srgb, var(--panel-strong), transparent 4%);
  bottom: calc(-18px - var(--safe-bottom));
  display: grid;
  gap: 7px;
  grid-template-columns: auto auto 1fr auto auto;
  margin: 0 -18px;
  padding: 9px 18px calc(10px + var(--safe-bottom));
  position: sticky;
  z-index: 4;
}

.custom-text-button {
  background: transparent;
  font-size: 0.66rem;
  min-height: 44px;
  padding: 0 5px;
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--scene-text), transparent 62%);
  text-underline-offset: 3px;
}

.custom-remove-button {
  color: #ffd6ce;
}

.custom-apply-button {
  min-width: 82px;
}

.custom-apply-button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

@media (min-width: 700px) {
  .custom-scene-panel {
    border-radius: 26px;
    bottom: 3vh;
    left: 50%;
    max-width: 760px;
    padding-left: 22px;
    padding-right: 22px;
    right: auto;
    transform: translateX(-50%);
    width: min(760px, calc(100vw - 48px));
  }

  .custom-scene-panel:not([hidden]) {
    animation: custom-panel-in 300ms var(--ease-out) both;
  }

  @keyframes custom-panel-in {
    from { opacity: 0; transform: translate(-50%, 22px); }
    to { opacity: 1; transform: translate(-50%, 0); }
  }

  .custom-mode-choice,
  .custom-three-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .custom-three-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .custom-photo-slot {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 170px;
    text-align: center;
  }

  .custom-photo-slot img {
    height: 76px;
    width: 100%;
  }

  .custom-panel-actions {
    margin-left: -22px;
    margin-right: -22px;
    padding-left: 22px;
    padding-right: 22px;
  }
}

@media (max-width: 430px) {
  .custom-panel-actions {
    grid-template-columns: 1fr 1fr;
  }

  .custom-panel-actions > span {
    display: none;
  }

  .custom-text-button {
    justify-self: start;
  }

  .custom-secondary-button,
  .custom-apply-button {
    width: 100%;
  }
}

@media (max-height: 640px) {
  .custom-scene-panel {
    max-height: 96dvh;
  }

  .custom-preview-frame {
    max-height: 180px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .custom-scene-panel:not([hidden]) {
    animation: none;
  }
}
