@font-face {
  font-family: "Theclouds";
  src: url("Theclouds.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "LittleDreams";
  src: url("Littledreams-Regular.otf") format("opentype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

html.lt3-thumb-dragging,
body.lt3-thumb-dragging {
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  overscroll-behavior: none;
}

:root {
  --bg: #e9e5da;
  --panel: #f3efe4;
  --text: #3f2b16;
  --muted: #6f5c46;
  --line: #d2c5af;
  --accent: #5a3b14;
  --accent-hover: #462d0f;
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 2rem;
  line-height: 1.56;
  background: var(--bg);
  color: var(--text);
}

h1,
h2,
.app-header h1,
.panel h2,
#selectImagesBtn {
  font-family: "Theclouds", "LittleDreams", sans-serif;
  font-weight: 400;
  color: var(--panel);
  -webkit-text-fill-color: var(--panel);
  -webkit-text-stroke-color: var(--accent);
  paint-order: stroke fill;
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  font-smooth: always;
  text-shadow:
    0.8px 0 0 var(--accent),
    -0.8px 0 0 var(--accent),
    0 0.8px 0 var(--accent),
    0 -0.8px 0 var(--accent),
    0.8px 0.8px 0 var(--accent),
    -0.8px 0.8px 0 var(--accent),
    0.8px -0.8px 0 var(--accent),
    -0.8px -0.8px 0 var(--accent);
  letter-spacing: 0.01em;
}

h1,
h2,
.app-header h1,
.panel h2 {
  -webkit-text-stroke-width: 5.2px;
}

.app {
  width: min(1160px, 94vw);
  margin: 2rem auto;
  padding-bottom: 2rem;
  opacity: 1;
  transition: opacity 700ms ease;
}

.app.is-hidden-for-intro {
  visibility: hidden;
  opacity: 0;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: grid;
  justify-items: center;
  align-content: center;
  padding: 2rem;
  cursor: default;
}

.intro-stage {
  position: relative;
  width: min(92vw, 1100px);
  height: min(84vh, 820px);
  /* Baseline transform so introStagePulse doesn’t promote a new layer / snap when is-holding starts */
  transform: translate3d(0, 0, 0);
  /* Flex column avoids overlapping title/grid/prompt (Chrome stacks correctly; Firefox needed this). */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(0.75rem, 2.5vh, 1.75rem);
  padding: clamp(0.75rem, 3vh, 2rem) clamp(0.75rem, 3vw, 1.5rem);
  box-sizing: border-box;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.intro-title {
  position: relative;
  left: auto;
  top: auto;
  transform: none;
  margin: 0;
  width: min(70vw, 520px);
  max-width: 100%;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  text-align: center;
  font-family: "Theclouds", "LittleDreams", sans-serif;
  color: var(--panel);
  -webkit-text-fill-color: var(--panel);
  -webkit-text-stroke-color: var(--accent);
  -webkit-text-stroke-width: 5.2px;
  text-shadow:
    0.8px 0 0 var(--accent),
    -0.8px 0 0 var(--accent),
    0 0.8px 0 var(--accent),
    0 -0.8px 0 var(--accent),
    0.8px 0.8px 0 var(--accent),
    -0.8px 0.8px 0 var(--accent),
    0.8px -0.8px 0 var(--accent),
    -0.8px -0.8px 0 var(--accent);
  font-size: clamp(2.4rem, 6vw, 5rem);
  opacity: 1;
  visibility: hidden;
}

.intro-title.is-prepared {
  visibility: visible;
}

.intro-grid {
  position: relative;
  left: auto;
  top: auto;
  transform: translateZ(0);
  width: 520px;
  height: 520px;
  margin: 0 auto;
  flex-shrink: 0;
  border-radius: 0;
  overflow: hidden;
  border: none;
  /* If any seam still shows, match page bg instead of a contrasting line */
  background: var(--bg);
  transition:
    width 1600ms cubic-bezier(0.16, 1, 0.3, 1),
    height 1600ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: width, height;
}

/* First paint: snap to computed size (no 520px→viewport shrink animation). Removed in JS before layout morphs. */
.intro-grid.is-intro-snap-layout,
.intro-grid.is-intro-snap-layout .intro-cell {
  transition: none !important;
}

.intro-cell {
  position: absolute;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  /* Desktop-style intro: fade to 100% + subtle scale (no layout “zoom”) */
  transform: scale(0.9) translateZ(0);
  transition:
    left 1600ms cubic-bezier(0.16, 1, 0.3, 1),
    top 1600ms cubic-bezier(0.16, 1, 0.3, 1),
    width 1600ms cubic-bezier(0.16, 1, 0.3, 1),
    height 1600ms cubic-bezier(0.16, 1, 0.3, 1);
  will-change: left, top, width, height;
  backface-visibility: hidden;
}

.intro-grid.is-row-layout .intro-cell {
  object-fit: contain;
}

.intro-cell-placeholder {
  background: #ddd2be;
}

.intro-letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(10px) scale(0.96);
}

.intro-overlay.start .intro-letter {
  animation: introLetterIn 380ms ease forwards;
  animation-delay: calc(80ms + (var(--li) * 55ms));
}

.intro-overlay.start .intro-cell {
  animation: introCellIn 260ms ease forwards;
  animation-delay: calc(80ms + (var(--intro-seq, 0) * 120ms));
}

.intro-overlay.fade-out {
  animation: introFadeOut 700ms ease forwards;
}

.intro-prompt {
  position: relative;
  left: auto;
  bottom: auto;
  transform: none;
  margin: 0;
  flex-shrink: 0;
  text-align: center;
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: clamp(1.5rem, 2.7vw, 2.1rem);
  color: var(--accent);
  opacity: 1;
  pointer-events: none;
  visibility: hidden;
}

.intro-prompt.is-prepared {
  visibility: visible;
}

.intro-prompt-letter {
  display: inline-block;
  opacity: 0;
  transform: translateY(8px);
}

.intro-overlay.start .intro-prompt-letter {
  animation: introPromptLetterIn 300ms ease forwards;
  animation-delay: calc(80ms + (var(--pi) * 38ms));
}

.intro-overlay.is-holding .intro-stage {
  animation: introStagePulse 1800ms ease-in-out infinite alternate;
}

@keyframes introLetterIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes introCellIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateZ(0);
  }
  to {
    opacity: 1;
    transform: scale(1) translateZ(0);
  }
}

@keyframes introFadeOut {
  to {
    opacity: 0;
    visibility: hidden;
  }
}

@keyframes introPromptIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes introPromptLetterIn {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes introPulse {
  from {
    transform: translate(-50%, -50%) translateZ(0);
  }
  to {
    transform: translate(-50%, calc(-50% - 2.5px)) translateZ(0);
  }
}

@keyframes introStagePulse {
  from {
    transform: translate3d(0, 0, 0);
  }
  to {
    transform: translate3d(0, -7px, 0);
  }
}

.app-header {
  position: relative;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.app-header-text {
  flex: 0 1 auto;
}

.app-header-logo {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  justify-content: center;
  align-items: center;
  pointer-events: none;
}

.header-logo-img {
  display: block;
  max-height: 6rem;
  width: auto;
  pointer-events: auto;
}

.header-refresh {
  cursor: pointer;
}

.header-icon-links {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.header-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--accent);
  color: var(--accent);
  transition: transform 120ms ease, border-color 120ms ease, background-color 120ms ease;
  box-shadow: 0 2px 6px rgba(56, 38, 18, 0.15);
}

.header-icon-btn:hover {
  border-color: var(--accent-hover);
  transform: translateY(-2px);
}

.header-icon-btn:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(90, 59, 20, 0.35);
}

.header-icon {
  width: 1.25rem;
  height: 1.25rem;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(2.2rem, 3vw, 3.1rem);
}

.app-header p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 2.2rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

.upload-panel {
  padding: 1.25rem;
}

.drop-zone {
  border: 2px dashed #b9aa8f;
  border-radius: 16px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 0.75rem;
  text-align: center;
  background: #efe9dd;
  transition: border-color 120ms ease, background-color 120ms ease;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: #e7dece;
}

.drop-zone p {
  margin: 0;
  font-size: 2.35rem;
  line-height: 1.08;
  font-weight: 400;
  color: var(--muted);
}

.drop-zone p strong {
  font-weight: 400;
}

.drop-zone p:first-child {
  margin-top: 1.35rem;
}

.drop-zone small {
  color: var(--muted);
  margin-top: 0;
  font-size: 2rem;
}

.wallet-import {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  text-align: center;
  align-items: center;
}

.wallet-import-heading {
  margin: 0;
  max-width: 38ch;
  font-size: 2.25rem;
  line-height: 1.08;
  font-weight: 400;
  color: var(--muted);
}

.wallet-import-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 640px;
}

.wallet-import-input {
  flex: 1 1 240px;
  min-width: 0;
  font-size: 1.65rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #f7f2e8;
  color: var(--text);
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  letter-spacing: 0.02em;
}

.wallet-import-input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.wallet-import-input:focus,
.wallet-import-input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(90, 59, 20, 0.28);
}

#loadWalletLt3Btn {
  flex: 0 0 auto;
  white-space: nowrap;
}

.wallet-import-status {
  min-height: 1.35em;
  margin: 0;
  font-size: 2.25rem;
  line-height: 1.08;
  max-width: 52ch;
  transform-origin: center left;
  will-change: opacity, transform;
}

.wallet-import-status--busy {
  animation: walletStatusPulse 1.6s ease-in-out infinite;
}

@keyframes walletStatusPulse {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.985);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

.wallet-import-status--error {
  color: #7a1f1f;
}

.btn {
  border: 1px solid var(--line);
  background: #f7f2e8;
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
  font-size: 1.75rem;
  transition: transform 120ms ease, background-color 120ms ease, border-color 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: #ad9b80;
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f8f2e7;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

#selectImagesBtn,
#clearAllBtn,
#createVideoQuickBtn,
#addBorderBtn,
#loadWalletLt3Btn {
  font-family: "Theclouds", "LittleDreams", sans-serif;
  font-size: 1.45rem;
  background: var(--accent);
  border-color: var(--accent);
  color: #f8f2e7;
  -webkit-text-fill-color: #f8f2e7;
  -webkit-text-stroke-width: 0;
  text-shadow: none;
  font-weight: 600;
  box-shadow: 0 2px 8px rgba(56, 38, 18, 0.22);
  padding: 0.5rem 1rem;
  white-space: nowrap;
}

#selectImagesBtn:hover,
#clearAllBtn:hover,
#createVideoQuickBtn:hover,
#addBorderBtn:hover,
#loadWalletLt3Btn:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.video-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  min-width: 232px;
}

/* Carousel: looks like #addBorderBtn but is not interactive (no lift / hover change). */
.carousel-background-label {
  display: inline-block;
  box-sizing: border-box;
  margin: 0;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: 10px;
  font-family: "Theclouds", "LittleDreams", sans-serif;
  font-size: 1.45rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  color: #f8f2e7;
  background: var(--accent);
  -webkit-text-fill-color: #f8f2e7;
  -webkit-text-stroke-width: 0;
  text-shadow: none;
  box-shadow: 0 2px 8px rgba(56, 38, 18, 0.22);
  cursor: default;
  user-select: none;
  pointer-events: none;
  transform: none;
  transition: none;
}

.carousel-background-label:hover,
.carousel-background-label:active,
.carousel-background-label:focus,
.carousel-background-label:focus-visible {
  transform: none;
  background: var(--accent);
  border-color: var(--accent);
  color: #f8f2e7;
  -webkit-text-fill-color: #f8f2e7;
  box-shadow: 0 2px 8px rgba(56, 38, 18, 0.22);
  outline: none;
}

.carousel-background-label.hidden {
  display: none;
}

.video-mode-toggle {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--accent);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(56, 38, 18, 0.12);
}

#videoModeToggle .video-mode-btn {
  font-size: 0.88rem;
  padding: 0.48rem 0.5rem;
}

.video-mode-toggle.hidden {
  display: none;
}

.video-mode-btn {
  border: none;
  background: #fffdf8;
  color: var(--accent);
  font-family: "Theclouds", "LittleDreams", sans-serif;
  font-size: 1.18rem;
  line-height: 1;
  padding: 0.5rem 0.92rem;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.video-mode-btn + .video-mode-btn {
  border-left: 1px solid rgba(90, 59, 20, 0.18);
}

.video-mode-btn.is-active {
  background: var(--accent);
  color: #f8f2e7;
}

.video-mode-btn:not(.is-active):hover {
  background: #f5efe3;
}

.btn-subtle {
  font-size: 1.6rem;
  padding: 0.45rem 0.7rem;
}

.workspace.hidden {
  display: none;
}

.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
  flex-wrap: wrap;
}

.row-between h2 {
  margin: 0;
}

h2 {
  margin: 0 0 0.65rem;
  font-size: 1.72rem;
}

.muted {
  color: var(--muted);
  margin: 0 0 0.75rem;
  font-size: 1.75rem;
}

/* Slightly under .drop-zone p (2.35rem) so long lines match visually; beats .muted */
.wallet-import .wallet-import-status {
  font-size: 2.25rem;
  line-height: 1.08;
}

.video-music-status {
  margin-top: 0.2rem;
  margin-bottom: 0.5rem;
  font-size: 1.75rem;
}

.thumb-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 0.65rem;
  -moz-user-select: none;
  user-select: none;
}

/* While reordering, gap hints must track the finger (no 150ms transform ease). */
.thumb-strip.thumb-strip--drag-active .thumb-item {
  transition: none;
}

.thumb-item {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #e7dfcf;
  aspect-ratio: 1 / 1;
  cursor: grab;
  transition: transform 0.15s ease;
  -webkit-user-select: none;
  -moz-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  /* Pan/zoom allowed; avoids double-tap zoom eating the gesture vs pointer reorder. */
  touch-action: manipulation;
}

.thumb-drag-ghost {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  will-change: transform;
  backface-visibility: hidden;
  isolation: isolate;
}

.thumb-item.dragging {
  opacity: 0.45;
  transition: none;
}

.thumb-item.drop-gap-left {
  transform: translateX(-10px);
}

.thumb-item.drop-gap-right {
  transform: translateX(10px);
}

.thumb-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  /* Hits go to .thumb-item so pointer reorder works on the whole tile (not only the grip icon). */
  pointer-events: none;
  -webkit-user-drag: none;
  -moz-user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.thumb-actions {
  position: absolute;
  top: 0.35rem;
  right: 0.35rem;
  z-index: 2;
  display: flex;
  gap: 0.25rem;
  pointer-events: auto;
}

.thumb-actions--left {
  left: 0.35rem;
  right: auto;
  z-index: 2;
  /* Grip is visual-only; let touches pass through to the thumb for dragging. */
  pointer-events: none;
}

.icon-btn {
  border: none;
  border-radius: 7px;
  width: 24px;
  height: 24px;
  font-size: 0.8rem;
  cursor: pointer;
  background: rgba(70, 45, 15, 0.85);
  color: #f8f2e7;
}

.icon-btn--bento {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: default;
}

.icon-btn--bento svg {
  display: block;
}

.layout-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
  align-items: stretch;
}

.layout-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f3e9;
  padding: 0.45rem;
  cursor: pointer;
  text-align: left;
  transition: transform 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
  min-width: 0;
  box-sizing: border-box;
}

/* Only real hover (desktop mouse); touch-scroll on iOS was triggering :hover lift on every card. */
@media (hover: hover) and (pointer: fine) {
  .layout-card:hover {
    transform: translateY(-2px);
    border-color: #b59f7f;
    box-shadow: 0 6px 20px rgba(56, 38, 18, 0.12);
  }
}

.layout-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(90, 59, 20, 0.2);
}

/* Wallet import: dim Layout, Preview, Export (not Images) while thumbnails stream in — no redraw thrash. */
#workspaceSection.wallet-import-loading > .panel:not(.panel--images) {
  position: relative;
  pointer-events: none;
  cursor: wait;
  animation: walletImportWorkspacePulse 1.65s ease-in-out infinite;
}

@keyframes walletImportWorkspacePulse {
  0%,
  100% {
    opacity: 0.74;
    filter: brightness(0.93) saturate(0.92);
  }

  50% {
    opacity: 1;
    filter: brightness(1) saturate(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  #workspaceSection.wallet-import-loading > .panel:not(.panel--images) {
    animation: none;
    opacity: 0.84;
    filter: brightness(0.94) saturate(0.94);
  }
}

.layout-card-canvas {
  width: 100%;
  height: auto;
  /* iOS Safari: without aspect-ratio, flex + width:100% can collapse canvas display */
  aspect-ratio: 320 / 220;
  border-radius: 8px;
  display: block;
  flex: 0 0 auto;
  background: var(--panel);
}

.layout-card-footer {
  margin-top: auto;
  padding-top: 0.4rem;
  font-size: 2.15rem;
  color: var(--muted);
  min-width: 0;
  width: 100%;
  max-width: 100%;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  /* Reserve ~2 lines so long wrapped names don’t shift the canvas vs single-line labels */
  min-height: 5.35rem;
}

.layout-name {
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 2.2rem;
  line-height: 1.15;
  color: var(--muted);
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-wrap: break-word;
  word-break: break-word;
}

.layout-card.is-carousel-layout .layout-name {
  font-size: 2.2rem;
  line-height: 1.15;
}

.main-preview {
  width: auto;
  max-width: min(100%, 900px);
  max-height: 68vh;
  height: auto;
  display: block;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--panel);
}

/* Mobile WebKit: keep preview canvas from sizing to 0 or overflowing bitmap limits oddly */
#mainPreviewCanvas.main-preview {
  max-width: 100%;
  width: auto;
  height: auto;
}

.panel.preview-panel h2 {
  margin-bottom: 0;
}

/* Desktop: keep “Selected Preview” on one line (no gap between spans in markup). */
.selected-preview-heading .selected-preview-word:first-child::after {
  content: " ";
  white-space: pre;
}

#previewBorderActions.hidden {
  display: none;
}

#addBorderBtn.hidden {
  display: none;
}

/* ID must not set display on the non-hidden state — it beats .video-mode-toggle.hidden. */
#previewBorderToggle.hidden {
  display: none !important;
}

/* Shrink-wrap like #videoModeToggle; avoid width:100% (it stretched the header and preview). */
#previewBorderToggle .video-mode-btn {
  font-size: 0.88rem;
  padding: 0.48rem 0.5rem;
}

.preview-wrapper {
  position: relative;
  display: inline-block;
  overflow: hidden;
}

.main-preview.hidden {
  display: none;
}


.preview-loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(243, 239, 228, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 0;
  transition: opacity 0.25s ease;
}

.preview-loading-overlay.hidden {
  display: none;
}

.preview-loading-gif {
  position: relative;
  z-index: 1;
  width: 80px;
  height: auto;
  display: block;
  animation: previewLoadingPulse 1.6s ease-in-out infinite;
}

@keyframes previewLoadingPulse {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.06); }
}

.main-preview.is-single {
  max-width: min(100%, 640px);
  max-height: 62vh;
}

.controls .control-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.8rem;
  margin-bottom: 0.9rem;
}

.controls h2 {
  font-family: "Theclouds", "LittleDreams", sans-serif;
}

.controls label span {
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.95rem;
  color: var(--muted);
}

.controls select {
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
  font-size: 1.8rem;
  line-height: 1.2;
  padding: 0.55rem 0.75rem;
  min-height: 50px;
  color: var(--muted);
}

.controls select option {
  color: var(--muted);
}

.controls .btn {
  font-family: "LittleDreams", Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 1.65rem;
}

.controls #downloadBtn {
  font-family: "Theclouds", "LittleDreams", sans-serif;
}

.video-panel .btn {
  margin-top: 0.25rem;
}

.video-status {
  min-height: 1.6em;
  margin-top: 0.45rem;
}

label span {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 1.7rem;
  color: var(--muted);
}

select {
  width: 100%;
  border: 1px solid var(--line);
  background: #f7f2e8;
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  font-size: 1.15rem;
}

@media (max-width: 720px) {
  /* Slightly larger type on small screens (LittleDreams UI + controls use rem). */
  html {
    font-size: 108%;
  }

  body {
    overflow-x: clip;
  }

  .app {
    width: 95vw;
    margin-top: 1rem;
  }

  .intro-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    overflow-x: clip;
    padding: max(1rem, env(safe-area-inset-top, 0px)) max(1rem, env(safe-area-inset-right, 0px))
      max(1rem, env(safe-area-inset-bottom, 0px)) max(1rem, env(safe-area-inset-left, 0px));
  }

  .intro-stage {
    width: 100%;
    max-width: min(92vw, 1100px);
    height: min(76vh, 720px);
    margin: 0 auto;
    flex-shrink: 0;
  }

  .intro-title {
    width: min(88vw, 520px);
    max-width: calc(100% - 0.25rem);
    padding: 0 0.35rem;
    box-sizing: border-box;
  }

  /*
   * Thinner outline on small screens. Base `.intro-title` alone is (0,1,0) and can tie/lose ordering;
   * `h1.intro-title` under the overlay wins and visibly slims the intro wordmark.
   */
  /* ~midway between desktop 5.2px / 0.8 shadow and the too-thin 1.1px pass */
  .intro-overlay h1.intro-title {
    -webkit-text-stroke-width: 2.85px;
    text-shadow:
      0.36px 0 0 var(--accent),
      -0.36px 0 0 var(--accent),
      0 0.36px 0 var(--accent),
      0 -0.36px 0 var(--accent),
      0.36px 0.36px 0 var(--accent),
      -0.36px 0.36px 0 var(--accent),
      0.36px -0.36px 0 var(--accent),
      -0.36px -0.36px 0 var(--accent);
  }

  .app h1,
  .app h2 {
    -webkit-text-stroke-width: 2.65px;
    text-shadow:
      0.34px 0 0 var(--accent),
      -0.34px 0 0 var(--accent),
      0 0.34px 0 var(--accent),
      0 -0.34px 0 var(--accent),
      0.34px 0.34px 0 var(--accent),
      -0.34px 0.34px 0 var(--accent),
      0.34px -0.34px 0 var(--accent),
      -0.34px -0.34px 0 var(--accent);
  }

  .intro-prompt {
    width: min(90vw, 400px);
    max-width: calc(100% - 1rem);
    padding: 0 0.5rem;
    box-sizing: border-box;
    font-size: clamp(1.75rem, 4.8vw, 2.2rem);
  }

  .thumb-strip {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.32rem;
  }

  .thumb-item .icon-btn {
    width: 20px;
    height: 20px;
    font-size: 0.62rem;
    border-radius: 5px;
  }

  .thumb-actions {
    top: 0.2rem;
    right: 0.2rem;
    gap: 0.15rem;
  }

  .thumb-actions--left {
    left: 0.2rem;
  }

  .thumb-item .icon-btn--bento svg {
    width: 11px;
    height: 11px;
  }

  .drop-zone {
    min-height: 185px;
  }

  /*
   * Narrow viewports can’t fit two 170px min tracks, so auto-fill collapses to one column and
   * each card stretches full width — huge previews and blurry upscaled canvases (Safari/iOS).
   * Two equal columns keeps cards compact and matches wider-phone behavior.
   */
  .layout-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.55rem;
  }

  /* Layout Options row: keep title + Convert on one row; stacked 2-line button (narrower) */
  .row-between:has(#createVideoQuickBtn) {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 0.45rem;
  }

  .row-between:has(#createVideoQuickBtn) h2 {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.15;
  }

  .video-actions:has(#createVideoQuickBtn) {
    min-width: 0;
    flex-shrink: 0;
  }

  #createVideoQuickBtn {
    white-space: pre-line;
    text-align: center;
    line-height: 1.12;
    padding: 0.48rem 0.55rem 0.52rem;
  }

  /* Selected Preview row: title + border actions on one line; Add/Remove Border stacked */
  .row-between:has(#previewBorderActions) {
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 0.45rem;
  }

  .row-between:has(#previewBorderActions) h2 {
    flex: 1 1 auto;
    min-width: 0;
    line-height: 1.15;
  }

  .panel.preview-panel .selected-preview-heading {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    line-height: 1.1;
  }

  .panel.preview-panel .selected-preview-heading .selected-preview-word:first-child::after {
    content: none;
  }

  #previewBorderActions.video-actions {
    min-width: 0;
    flex-shrink: 0;
  }

  #addBorderBtn {
    white-space: pre-line;
    text-align: center;
    line-height: 1.12;
    padding: 0.48rem 0.55rem 0.52rem;
  }

  /* Header: logo centered on top row; title + subtitle left, socials top-right on second row */
  .app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    gap: 0.35rem 0.65rem;
    align-items: start;
    justify-items: stretch;
    flex-wrap: nowrap;
  }

  .app-header-text {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    padding-right: 0.25rem;
  }

  .app-header-logo {
    grid-column: 1 / -1;
    grid-row: 1;
    position: relative;
    left: auto;
    top: auto;
    transform: none;
    justify-self: center;
    margin: 0 0 0.2rem;
    pointer-events: auto;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  .header-logo-img {
    max-height: clamp(4.85rem, 18vw, 6.75rem);
  }

  .header-icon-links {
    grid-column: 2;
    grid-row: 2;
    flex-shrink: 0;
    align-self: start;
  }

  .app-header h1 {
    font-size: clamp(1.55rem, 5vw, 2.35rem);
    line-height: 1.08;
  }

  .app-header p {
    font-size: clamp(1.5rem, 4.2vw, 2.05rem);
    line-height: 1.22;
    margin-top: 0.25rem;
  }

  .wallet-import-heading {
    max-width: none;
  }

  .wallet-import-row {
    flex-direction: column;
    align-items: stretch;
    max-width: none;
  }

  /* Column flex + flex-grow was stretching the input to fill leftover height */
  .wallet-import-input {
    flex: 0 0 auto;
    width: 100%;
    min-height: 3.1rem;
    max-height: 3.55rem;
    padding: 0.5rem 0.7rem;
    font-size: max(16px, 1.28rem);
    line-height: 1.3;
  }

  #loadWalletLt3Btn {
    width: 100%;
  }
}

/* Download confetti effect */
.download-confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}

.download-confetti-piece {
  position: absolute;
  width: 24px;
  height: auto;
  max-height: 28px;
  object-fit: contain;
  animation: downloadConfettiFall 2.2s ease-out forwards;
  will-change: transform, opacity;
}

@keyframes downloadConfettiFall {
  0% {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  18% {
    transform: translate(var(--cf-bx, 0), var(--cf-by, 0)) rotate(var(--cf-rot-start, 0deg));
    opacity: 1;
  }
  100% {
    transform: translate(calc(var(--cf-bx, 0) + var(--cf-dx, 0)), calc(var(--cf-by, 0) + var(--cf-fy, 400px))) rotate(var(--cf-rot-end, 0deg));
    opacity: 0;
  }
}
