/* Klebstar 2.2.12 responsive corrections loaded after every designer style. */
@media (max-width: 900px) {
  #klebstar-designer-app .workspace:has(> .quick-controls) .quick-controls .control-step:first-child {
    grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1fr) !important;
    grid-template-rows: auto !important;
    column-gap: 6px;
    row-gap: 0;
    align-items: center;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .quick-controls .control-step:first-child > .step-heading {
    grid-column: 1 !important;
    grid-row: 1 !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .quick-controls .control-step:first-child .quick-format-toggle {
    grid-column: 2 !important;
    grid-row: 1 !important;
    width: 100% !important;
    min-width: 0;
  }

  #klebstar-designer-app .klebstar-motif-mode-toggle {
    grid-column: 3 !important;
    grid-row: 1 !important;
    grid-template-columns: auto 24px 44px;
    justify-content: start;
    width: 100%;
    min-width: 0;
    min-height: 40px;
    margin: 0;
    padding: 0 0 0 5px;
    gap: 4px;
  }

  #klebstar-designer-app .klebstar-motif-mode-label {
    min-width: 0;
    font-size: 14px;
  }

  #klebstar-designer-app .klebstar-motif-mode-icon {
    flex-basis: 24px;
    width: 24px;
    height: 24px;
  }

  #klebstar-designer-app .klebstar-motif-mode-track {
    width: 44px;
    height: 28px;
  }

  #klebstar-designer-app .klebstar-motif-mode-track::after {
    top: 4px;
    left: 4px;
    width: 20px;
    height: 20px;
  }

  #klebstar-designer-app .klebstar-motif-mode-toggle input:checked + .klebstar-motif-mode-track::after {
    transform: translateX(16px);
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs {
    position: relative;
    z-index: 20;
    isolation: auto;
    grid-auto-rows: auto;
    row-gap: 0;
    overflow: visible;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs > button {
    grid-row: var(--theme-card-row-mobile);
    grid-column: var(--theme-card-column-mobile);
    margin-bottom: 6px;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs > .motif-theme-popover {
    position: relative !important;
    inset: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    left: auto !important;
    z-index: 30 !important;
    grid-row: var(--theme-popover-row-mobile);
    grid-column: 1 / -1;
    order: initial;
    align-self: start;
    width: 100% !important;
    max-width: none;
    max-height: none;
    margin: 3px 0 11px !important;
    padding: 10px !important;
    overflow: visible;
    color: #241f2e;
    background: #fff !important;
    border: 2px solid #6d50d8;
    border-radius: 15px;
    box-shadow: 0 8px 22px #6d50d824;
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    color-scheme: light;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover::before {
    top: -13px;
    left: var(--theme-arrow-left-mobile);
    border-right: 12px solid transparent;
    border-bottom: 13px solid #6d50d8;
    border-left: 12px solid transparent;
    display: block;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover::after {
    top: -9px;
    left: var(--theme-arrow-left-mobile);
    border-right: 9px solid transparent;
    border-bottom: 10px solid #fff;
    border-left: 9px solid transparent;
    display: block;
  }

  #klebstar-designer-app .motif-popover-close {
    display: none !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 8px;
    max-height: 280px !important;
    padding: 1px 4px 6px 1px;
    display: grid !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice {
    position: relative;
    width: 100%;
    min-width: 0;
    min-height: 64px;
    aspect-ratio: 1;
    opacity: 1 !important;
    visibility: visible !important;
    background: #fff;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice > span:not(.motif-touch-pick) {
    width: 100%;
    height: 100%;
    opacity: 1 !important;
    visibility: visible !important;
    display: grid !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs,
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs > button,
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover,
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-choice,
  #klebstar-designer-app .workspace:has(> .quick-controls) .dynamic-template-sheet,
  #klebstar-designer-app .workspace:has(> .quick-controls) .dynamic-template-svg {
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs img,
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover img,
  #klebstar-designer-app .workspace:has(> .quick-controls) .dynamic-template-svg image {
    pointer-events: none !important;
    -webkit-user-drag: none !important;
    -webkit-touch-callout: none !important;
    -webkit-user-select: none !important;
    user-select: none !important;
  }
}

/* Desktop stability correction. Preserve the compact stylesheet's original
   preview grid and paper dimensions; only the free-design tool column becomes
   an independent sticky scroller. */
@media (min-width: 901px) {
  #klebstar-designer-app .workspace:has(> .quick-controls),
  #klebstar-designer-app .workspace:has(> .studio-controls) {
    height: auto !important;
    overflow: visible !important;
  }

  #klebstar-designer-app .workspace:has(> .studio-controls) > .studio-controls {
    position: sticky !important;
    top: 12px !important;
    align-self: start !important;
    height: auto !important;
    max-height: min(900px, calc(100dvh - 24px)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
  }
}

/* 2.2.2: on phones a theme card only opens its child motifs. Card names are
   intentionally omitted; the artwork and plus/minus state carry the UI. */
@media (max-width: 900px) {
  #klebstar-designer-app .motif-category-tabs .motif-touch-pick {
    display: none !important;
    pointer-events: none !important;
  }

  #klebstar-designer-app .motif-category-tabs > button > span:not(.motif-theme-toggle):not(.motif-touch-pick),
  #klebstar-designer-app .motif-theme-popover .motif-choice > b,
  #klebstar-designer-app .motif-theme-popover .motif-choice > small {
    display: none !important;
  }

  #klebstar-designer-app .motif-theme-popover .motif-choice.motif-mix > b {
    right: 4px !important;
    bottom: 4px !important;
    left: auto !important;
    display: grid !important;
    width: 20px !important;
    height: 20px !important;
    place-items: center !important;
    border-radius: 50% !important;
    color: #fff !important;
    background: #6d50d8 !important;
    font-size: 0 !important;
    line-height: 1 !important;
  }

  #klebstar-designer-app .motif-theme-popover .motif-choice.motif-mix > b::after {
    content: "↻";
    font: 900 14px/1 Arial, sans-serif;
  }
}

/* Keep the dynamically mounted motif picker in the document flow even when
   older optimized CSS is still present in a LiteSpeed-generated bundle. */
@media (max-width: 900px) {
  #klebstar-designer-app .workspace:has(> .quick-controls),
  #klebstar-designer-app .workspace:has(> .quick-controls) > .quick-controls,
  #klebstar-designer-app .workspace:has(> .quick-controls) .quick-controls .control-step:nth-child(4),
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-library {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    contain: none !important;
    clip-path: none !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs {
    display: grid !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs > button {
    grid-row: var(--theme-card-row-mobile, auto) !important;
    grid-column: var(--theme-card-column-mobile, auto) !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs > .motif-theme-popover {
    grid-row: var(--theme-popover-row-mobile, auto) !important;
    grid-column: 1 / -1 !important;
    min-height: 92px !important;
    display: grid !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    isolation: isolate;
    scroll-margin-top: 88px;
  }

  #klebstar-designer-app .motif-theme-popover[data-mobile-ready="true"] .motif-choice-grid,
  #klebstar-designer-app .motif-theme-popover[data-mobile-ready="true"] .motif-choice,
  #klebstar-designer-app .motif-theme-popover[data-mobile-ready="true"] .motif-choice > span:not(.motif-touch-pick),
  #klebstar-designer-app .motif-theme-popover[data-mobile-ready="true"] img {
    opacity: 1 !important;
    visibility: visible !important;
  }

  #klebstar-designer-app img.klebstar-no-lazy,
  #klebstar-designer-app .motif-theme-popover img[data-no-lazy="1"] {
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }
}

@media (max-width: 370px) {
  #klebstar-designer-app .workspace:has(> .quick-controls) .quick-controls .control-step:first-child {
    grid-template-columns: 50px minmax(0, 1fr) minmax(0, 1fr) !important;
    column-gap: 4px;
  }

  #klebstar-designer-app .klebstar-motif-mode-toggle {
    grid-template-columns: auto 20px 42px;
    padding-left: 3px;
    gap: 3px;
  }

  #klebstar-designer-app .klebstar-motif-mode-label {
    font-size: 13px;
  }

  #klebstar-designer-app .klebstar-motif-mode-icon {
    width: 20px;
    height: 20px;
  }
}

/* 2.1.16: iOS Safari must not resolve the nested 100%-height image grid to
   an empty area. The card owns the square; its image gets an explicit inset. */
@media (max-width: 900px) {
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-category-tabs > .motif-theme-popover {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice-grid {
    grid-auto-rows: auto !important;
    height: auto !important;
    max-height: none !important;
    padding-bottom: 4px !important;
    overflow: visible !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice {
    position: relative !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: auto !important;
    aspect-ratio: 1 / 1 !important;
    grid-template: none !important;
    display: block !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice:not(.motif-mix) > span:first-child {
    position: absolute !important;
    inset: 5px !important;
    width: auto !important;
    height: auto !important;
    min-width: 0 !important;
    min-height: 0 !important;
    display: block !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice:not(.motif-mix) > span:first-child > img {
    position: absolute !important;
    inset: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: contain !important;
    display: block !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images {
    position: absolute !important;
    inset: 5px !important;
    width: auto !important;
    height: auto !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    grid-template-rows: repeat(2, minmax(0, 1fr)) !important;
    gap: 1px !important;
    display: grid !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images > img {
    position: static !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    object-fit: contain !important;
    display: block !important;
  }
}

/* 2.2.0: the first card applies the complete theme. Four independently
   positioned images avoid Safari's nested-grid collapse. */
@media (max-width: 900px) {
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images {
    position: absolute !important;
    top: 4px !important;
    right: 4px !important;
    bottom: 18px !important;
    left: 4px !important;
    width: auto !important;
    height: auto !important;
    padding: 0 !important;
    grid-template: none !important;
    display: block !important;
    overflow: hidden !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images > img {
    position: absolute !important;
    width: 50% !important;
    height: 50% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    object-fit: contain !important;
    display: block !important;
    opacity: 1 !important;
    visibility: visible !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images > img:nth-child(1) {
    top: 0 !important;
    left: 0 !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images > img:nth-child(2) {
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images > img:nth-child(3) {
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-mix > .motif-mix-images > img:nth-child(4) {
    top: auto !important;
    right: 0 !important;
    bottom: 0 !important;
    left: auto !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice.motif-mix > b {
    position: absolute !important;
    right: 4px !important;
    bottom: 4px !important;
    left: auto !important;
    z-index: 3 !important;
    width: 20px !important;
    height: 20px !important;
    color: #fff !important;
    background: #6d50d8 !important;
    border-radius: 50% !important;
    font: 0/1 Arial, sans-serif !important;
    text-align: center !important;
    white-space: nowrap !important;
    display: grid !important;
    place-items: center !important;
    overflow: hidden !important;
  }

  /* Safari paints ordinary card images reliably, but can omit the four-image
     layer of Motiv-Mix even after every file has loaded. Use one of the same
     180px preview files as a direct button background instead. */
  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice.motif-mix[data-mobile-mix-ready="true"] {
    background-color: #fff !important;
    background-image: var(--klebstar-mobile-mix-preview) !important;
    background-repeat: no-repeat !important;
    background-position: center 4px !important;
    background-size: auto calc(100% - 22px) !important;
  }

  #klebstar-designer-app .workspace:has(> .quick-controls) .motif-theme-popover .motif-choice.motif-mix[data-mobile-mix-ready="true"] > .motif-mix-images {
    display: none !important;
  }
}
