/*
 * ╔══════════════════════════════════════════════════════════════════╗
 * ║           UNIVERSAL 9:16 CANVAS SYSTEM — 1080 × 1920            ║
 * ╠══════════════════════════════════════════════════════════════════╣
 * ║                                                                  ║
 * ║  .stickerbook-page = 9:16 canvas, centered on dark background   ║
 * ║  .page-canvas = fills .stickerbook-page exactly (STICKERS)      ║
 * ║                                                                  ║
 * ║  The canvas fits entirely on screen — no overflow, no clipping. ║
 * ║  Height fills available space; width = height × (9/16).         ║
 * ║                                                                  ║
 * ║  Snapshot system renders at 1080×1920 (1:1 with stage).        ║
 * ║  Thumbnails are 360×640 (also 9:16, simple downscale).         ║
 * ║                                                                  ║
 * ║  Sticker positions are stored as percentages — canvas size      ║
 * ║  does not affect stored data.                                   ║
 * ║                                                                  ║
 * ║  Last updated: 2026-02-17                                       ║
 * ╚══════════════════════════════════════════════════════════════════╝
 */

    /* ========== GLOBAL TAP HIGHLIGHT REMOVAL ========== */
    *, *::before, *::after {
      -webkit-tap-highlight-color: transparent !important;
    }

    /* ========== PAGE-SPECIFIC STYLES ========== */
    html, body {
      touch-action: manipulation;
      overflow: hidden;
      height: 100%;
      user-select: none;
      -webkit-user-select: none;
      background: #fff;
    }

    /* During drag - prevent ALL selection */
    body.dragging-sticker * {
      user-select: none !important;
      -webkit-user-select: none !important;
      -webkit-touch-callout: none !important;
    }

    .stickerbook-shell {
      width: 100%;
      height: 100vh;
      height: 100dvh;
      display: flex;
      flex-direction: column;
      background: #fff;
      overflow: hidden;
      padding-top: 0;
      user-select: none;
      -webkit-user-select: none;
    }

    /* ========== EDITOR HEADER ========== */
    .editor-header {
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      height: 98px;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 0 16px;
      padding-top: calc(env(safe-area-inset-top, 0px) + 3.5px);
      z-index: 100;
      pointer-events: none;
    }

    .editor-header > * {
      pointer-events: auto;
    }

    .editor-header-btn {
      width: 38px;
      height: 38px;
      border-radius: 50%;
      background: #6D28D9;
      border: none;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
      pointer-events: auto;
      transition: transform 0.15s ease;
    }

    .editor-header-btn:active {
      transform: scale(0.92);
    }

    .editor-header-btn svg {
      width: 20px;
      height: 20px;
      color: #fff;
    }

    /* ========== PAGE CONTAINER ========== */
    /* Centers the 9:16 canvas vertically and horizontally */
    .page-container {
      position: relative;
      flex: 1;
      z-index: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      background: #D8D8D8;
      overflow: hidden;
      padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px));
      padding-top: 2px;
    }

    /* ========== STICKERBOOK PAGE ========== */
    /* 9:16 canvas — fills available height, width derived from aspect ratio */
    .stickerbook-page {
      position: relative;
      aspect-ratio: 9 / 16;
      height: 100%;
      max-height: 100%;
      max-width: 100%;
      background: #fafafa;
      touch-action: none;
      user-select: none;
      -webkit-user-select: none;
      isolation: isolate;
      overflow: hidden;
      z-index: 1;
      pointer-events: auto;
      border-radius: 16px;
      border: 2px solid rgba(109, 40, 217, 0.6);
      box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
      animation: canvas-pulse 2s ease-in-out infinite;
    }

    @keyframes canvas-pulse {
      0%, 100% {
        border-color: rgba(109, 40, 217, 0.6);
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 0 0 0 rgba(109, 40, 217, 0.3);
      }
      50% {
        border-color: rgba(109, 40, 217, 1);
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12), 0 0 0 6px rgba(109, 40, 217, 0);
      }
    }

    .stickerbook-page.canvas-active {
      border: none;
      animation: none;
      box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12);
    }

    /* ========== PAGE CANVAS (Live Zone) ========== */
    /* Sticker container - fills .stickerbook-page exactly */
    .page-canvas {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      overflow: hidden;
      user-select: none;
      -webkit-user-select: none;
      z-index: 1;
      pointer-events: auto;
    }

    /* ========== STICKERS ON PAGE ========== */
    .placed-sticker {
      position: absolute;
      touch-action: none;
      user-select: none;
      transform-origin: center center;
      cursor: pointer;
      /* Force GPU layer to prevent drop-shadow trail artifacts */
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
      will-change: transform, filter;
      /* Hide until image loads to prevent gray box flash */
      opacity: 0;
      transition: opacity 0.15s ease;
    }
    
    .placed-sticker.loaded {
      opacity: 1;
    }

    .placed-sticker img {
      width: 100%;
      height: 100%;
      object-fit: contain;
      pointer-events: none;
      user-select: none;
      display: block;
    }

    /* Selection highlight - CSS drop-shadow traces actual pixels */
    /* --sticker-highlight-color is set dynamically in JS for background contrast */
    .placed-sticker.selected-highlight {
      --highlight: var(--sticker-highlight-color, #6D28D9);
      filter: drop-shadow(0 0 4px var(--highlight)) drop-shadow(0 0 1px var(--highlight));
    }

    .placed-sticker.active {
      cursor: grab;
    }

    .placed-sticker.dragging {
      cursor: grabbing;
      opacity: 0.95;
    }

    /* Sticker returning to drawer - shrink and fade */
    .placed-sticker.to-drawer {
      transition: transform 0.3s ease, opacity 0.3s ease;
      transform: scale(0.5) !important;
      opacity: 0;
    }

    /* Sticker being trashed - fade and slight shrink */
    .placed-sticker.to-trash {
      transition: transform 0.3s ease, opacity 0.3s ease;
      transform: scale(0.8) !important;
      opacity: 0;
    }

    /* ========== STICKER ACTION POPUP ========== */
    .sticker-popup {
      position: fixed;
      z-index: 900;
      display: flex;
      gap: 6px;
      padding: 6px;
      background: white;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
      animation: popupAppear 0.15s ease-out;
    }

    @keyframes popupAppear {
      0% { opacity: 0; transform: scale(0.9); }
      100% { opacity: 1; transform: scale(1); }
    }

    .sticker-popup-btn {
      padding: 10px 16px;
      border: none;
      border-radius: 8px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: transform 0.1s ease, background 0.15s ease;
      font-family: var(--font-primary);
    }

    .sticker-popup-btn:active {
      transform: scale(0.95);
    }

    .sticker-popup-drawer {
      background: #6D28D9;
      color: white;
      border: none;
    }

    .sticker-popup-drawer:active {
      background: #5b21b6;
    }

    /* Confirmation popup for return to drawer - glass-morphism style */
    .sticker-confirm-popup {
      position: fixed;
      z-index: 950;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 16px;
      padding: 24px 32px;
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 24px;
      box-shadow:
        inset 0 0 12px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 8px 32px rgba(0, 0, 0, 0.12);
      animation: popupFadeIn 0.15s ease-out;
    }

    @keyframes popupFadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }

    .sticker-confirm-text {
      font-size: 15px;
      font-weight: 600;
      color: var(--color-text-primary);
      font-family: var(--font-primary);
      text-align: center;
      line-height: 1.4;
    }

    .sticker-confirm-buttons {
      display: flex;
      gap: 12px;
    }

    .sticker-confirm-btn {
      padding: 12px 24px;
      min-width: 80px;
      border: none;
      border-radius: 8px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      font-family: var(--font-primary);
      transition: transform 0.1s ease, background 0.15s ease;
    }

    .sticker-confirm-no {
      background: #e5e7eb;
      color: #374151;
    }

    .sticker-confirm-no:active {
      transform: scale(0.95);
      background: #d1d5db;
    }

    .sticker-confirm-yes {
      background: #6D28D9;
      color: white;
    }

    .sticker-confirm-yes:active {
      transform: scale(0.95);
      background: #5b21b6;
    }

    /* Sticker action menu buttons */
    .sticker-action-buttons {
      display: flex;
      flex-direction: column;
      gap: 8px;
      width: 100%;
    }

    .sticker-action-btn {
      padding: 12px 24px;
      width: 100%;
      border: none;
      border-radius: 8px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      font-family: var(--font-primary);
      transition: transform 0.1s ease, background 0.15s ease;
      background: #6D28D9;
      color: white;
      text-align: center;
    }

    .sticker-action-btn:active {
      transform: scale(0.97);
      background: #5b21b6;
    }

    .sticker-action-drawer {
      background: #e5e7eb;
      color: #374151;
    }

    .sticker-action-drawer:active {
      background: #d1d5db;
    }

    .sticker-action-cancel {
      background: transparent;
      color: #6b7280;
      border: 1px solid rgba(0,0,0,0.1);
    }

    .sticker-action-cancel:active {
      background: rgba(0,0,0,0.05);
    }

    /* ========== FLOATING EDIT BUTTONS (TikTok-style right side) ========== */
    /* Permanently hidden - replaced by editor-bottom-bar in SPA */
    .floating-edit-stack {
      display: none !important;
    }

    .floating-edit-btn {
      width: 48px;
      height: 48px;
      border-radius: 50%;
      background: rgba(255, 255, 255, 0.95);
      border: none;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
      transition: transform 0.15s ease, background 0.15s ease;
      -webkit-tap-highlight-color: transparent;
    }

    .floating-edit-btn:hover {
      background: rgba(255, 255, 255, 1);
    }

    .floating-edit-btn:active {
      transform: scale(0.92);
    }

    .floating-edit-btn svg {
      width: 22px;
      height: 22px;
    }

    .floating-edit-btn--purple {
      color: var(--color-purple);
      border: 2px solid var(--color-purple);
    }

    .floating-edit-btn--turquoise {
      color: var(--color-turquoise);
      border: 2px solid var(--color-turquoise);
    }

    .floating-edit-btn--purple.pulse-hint {
      animation: pulse-hint 2s ease-in-out 3;
    }

    @keyframes pulse-hint {
      0%, 100% {
        box-shadow: 0 0 0 0 rgba(109, 40, 217, 0.4);
      }
      50% {
        box-shadow: 0 0 0 8px rgba(109, 40, 217, 0);
      }
    }

    /* ========== PAGE INDICATOR ========== */
    .page-indicator {
      display: none; /* Hidden - replaced by share button */
    }

    /* Header share button (top right) */
    .header-share-btn {
      background: none;
      border: none;
      color: var(--color-turquoise);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 8px;
      transition: opacity 0.15s ease;
      position: relative;
    }

    .header-share-btn:active {
      opacity: 0.6;
    }

    /* Icon visibility control */
    .header-share-btn .share-icon {
      display: block;
    }

    .header-share-btn .close-icon {
      display: none;
    }

    /* When grid view is open, swap icons */
    body.grid-view-open .header-share-btn .share-icon {
      display: none;
    }

    body.grid-view-open .header-share-btn .close-icon {
      display: block;
    }

    /* ========== GRID VIEW ========== */
    /* Hide page container when grid view is open */
    body.grid-view-open .page-container {
      display: none;
    }

    .grid-view-container {
      position: fixed;
      /* Start below the app header */
      top: calc(60px + env(safe-area-inset-top, 0px));
      left: 0;
      right: 0;
      bottom: 0;
      background: var(--color-canvas);
      z-index: 50; /* Below header (which is 100) */
      display: none;
      flex-direction: column;
      opacity: 0;
      transform: scale(0.95);
      transition: opacity 0.3s ease, transform 0.3s ease;
    }

    .grid-view-container.active {
      display: flex;
      opacity: 1;
      transform: scale(1);
    }

    .grid-view-content {
      flex: 1;
      overflow-y: auto;
      overflow-x: hidden;
      -webkit-overflow-scrolling: touch;
      padding: 20px 16px;
      /* Enable native scrolling - critical for scroll sensitivity */
      touch-action: pan-y;
      overscroll-behavior: contain;
    }

    .grid-view-pages {
      display: grid;
      grid-template-columns: repeat(2, 1fr);
      gap: 16px;
      max-width: 500px;
      margin: 0 auto;
      /* Allow scroll gestures to propagate to parent */
      touch-action: pan-y;
    }

    .grid-page-item {
      /* Aspect ratio will be set dynamically via JS to match canvas */
      border-radius: var(--radius-lg);
      background: white;
      /* Use inset box-shadow instead of border - doesn't affect dimensions */
      box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
      position: relative;
      overflow: hidden;
      cursor: pointer;
      opacity: 0;
      transform: scale(0.9);
      animation: fadeInScale 0.3s ease forwards;
      transition: transform 0.15s ease, box-shadow 0.15s ease;
      /* Allow scroll gestures to pass through */
      touch-action: pan-y;
    }

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

    .grid-page-item:active {
      transform: scale(0.98);
    }

    .grid-page-item.filled {
      box-shadow: inset 0 0 0 2px rgba(109, 40, 217, 0.2);
    }

    .grid-page-item.empty {
      box-shadow: inset 0 0 0 2px rgba(109, 40, 217, 0.15);
    }

    .grid-page-item.locked {
      box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
      opacity: 0.6;
      cursor: default;
    }

    .grid-page-thumbnail {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      pointer-events: none; /* Thumbnails are display-only */
    }

    /* ALL content inside grid thumbnails must be non-interactive */
    .grid-page-thumbnail * {
      pointer-events: none !important;
      touch-action: none !important;
      user-select: none !important;
      -webkit-user-select: none !important;
    }

    .grid-page-plus {
      width: 36px;
      height: 36px;
      border-radius: 50%;
      border: 2px solid;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .grid-page-item.filled .grid-page-plus {
      display: none;
    }

    .grid-page-item.empty .grid-page-plus {
      border-color: var(--color-purple);
      color: var(--color-purple);
    }

    .grid-page-item.locked .grid-page-plus {
      border-color: var(--color-text-muted);
      color: var(--color-text-muted);
    }

    .grid-add-more-btn {
      margin: 16px auto 0;
      padding: 12px 24px;
      border-radius: 20px;
      background: white;
      border: 1.5px solid var(--color-purple);
      color: var(--color-purple);
      font-family: 'Poppins', var(--font-primary);
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      transition: transform 0.15s ease, background 0.15s ease;
      display: block;
    }

    .grid-add-more-btn:active {
      transform: scale(0.98);
    }

    .grid-add-more-btn:hover {
      background: rgba(109, 40, 217, 0.08);
    }

    /* Drag and drop states */
    .grid-page-item.dragging {
      opacity: 0.5; /* Original stays visible but faded */
    }

    .grid-page-item.drag-over {
      box-shadow: inset 0 0 0 3px var(--color-turquoise);
    }

    /* Wiggle animation for rearrange mode */
    body.rearrange-mode .grid-page-item.filled {
      animation: wiggle 0.4s ease-in-out infinite alternate;
    }

    @keyframes wiggle {
      0% {
        transform: rotate(-2deg);
      }
      100% {
        transform: rotate(2deg);
      }
    }

    /* Dragging clone that follows cursor */
    .drag-clone {
      position: fixed;
      pointer-events: none;
      z-index: 9999;
      opacity: 0.9;
      transform-origin: center center;
      box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    }

    /* ========== HEADER STYLES ========== */
    /* Override header background to white for page editor */
    .stickerbook-shell .site-header {
      position: relative;
      z-index: 100;
      background: white !important;
    }

    /* Hide gloss overlay for solid white editor header */
    .stickerbook-shell .site-header::after {
      display: none;
    }

    /* ========== EMPTY STATE ========== */
    /* Container for empty state (centered button + text) */
    .empty-state-container {
      position: absolute;
      inset: 0;
      display: none;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      z-index: 50;
      pointer-events: none;
    }

    .empty-state-container.visible {
      display: flex;
    }

    /* Centered plus button for empty pages */
    .empty-plus-btn {
      width: 72px;
      height: 72px;
      border: 2.5px solid var(--color-purple);
      border-radius: 50%;
      background: var(--color-canvas-subtle, #fafafa);
      color: var(--color-purple);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: background 0.2s ease, transform 0.2s ease;
      animation: pulse 2s ease-in-out infinite;
      pointer-events: none;
    }

    .empty-plus-btn svg {
      width: 32px;
      height: 32px;
    }

    .empty-plus-btn:hover {
      background: rgba(109, 40, 217, 0.08);
      transform: scale(1.08);
      animation: none;
    }

    .empty-plus-btn:active {
      transform: scale(0.95);
    }

    /* Text above the plus button */
    .empty-state-text {
      margin-bottom: 20px;
      font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
      font-size: 18px;
      font-weight: 500;
      color: #000;
      text-align: center;
      pointer-events: none;
      user-select: none;
      line-height: 1.4;
    }

    /* Empty state 2x2 grid - matches inbox filter sheet style */
    .empty-state-grid {
      display: grid;
      grid-template-columns: repeat(2, auto);
      column-gap: 32px;
      row-gap: 24px;
      margin-top: 28px;
      justify-items: center;
    }

    .empty-state-grid-item {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
    }

    .empty-state-circle {
      width: 64px;
      height: 64px;
      border-radius: 50%;
      background: #6D28D9;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .empty-state-circle svg {
      width: 28px;
      height: 28px;
      color: #fff;
    }

    .empty-state-label {
      font-size: 13px;
      font-weight: 600;
      color: var(--color-text-primary, #000);
      text-align: center;
      white-space: nowrap;
    }

    @keyframes pulse {
      0%, 100% {
        box-shadow: 0 0 0 0 rgba(109, 40, 217, 0.4);
      }
      50% {
        box-shadow: 0 0 0 10px rgba(109, 40, 217, 0);
      }
    }

    /* ========== EDITOR SIDE PILL ========== */
    /* Glass pill on right side of canvas — HIDDEN, replaced by editor-footer-toolbar */
    .editor-side-pill {
      display: none !important;
      position: absolute;
      right: 20px;
      bottom: 15%;
      z-index: 20;
      flex-direction: column;
      align-items: center;
      gap: 22px;
      padding: 12px 6px;
      background: rgba(255, 255, 255, 0.12);
      backdrop-filter: blur(12px) saturate(180%);
      -webkit-backdrop-filter: blur(12px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      box-shadow:
        inset 0 0 12px rgba(0, 0, 0, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.15),
        0 2px 8px rgba(0, 0, 0, 0.15);
      border-radius: 28px;
      pointer-events: auto;
    }

    .editor-side-pill.visible {
      display: flex;
    }

    .editor-pill__btn {
      position: relative;
      z-index: 1;
      width: 43px;
      height: 43px;
      min-width: 43px;
      min-height: 43px;
      display: flex;
      align-items: center;
      justify-content: center;
      background: var(--color-purple, #6D28D9);
      border: none;
      border-radius: 50%;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
      transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
    }

    .editor-pill__btn:active {
      transform: scale(0.92);
      opacity: 0.9;
    }

    .editor-pill__btn svg {
      width: 20px;
      height: 20px;
      color: white;
      stroke-width: 2.5;
    }

    .editor-pill__btn.active-control {
      border: 2.5px solid #fff;
    }

    /* ===== BACKGROUND COLOR SHEET ===== */
    .bg-swatch-row {
      display: flex;
      gap: 8px;
      justify-content: center;
      padding: 12px 16px 6px;
    }

    .bg-swatch-pill {
      flex: 1;
      height: 36px;
      border-radius: 999px;
      border: 0.5px solid rgba(0, 0, 0, 0.12);
      box-sizing: border-box;
      max-width: 90px;
      cursor: pointer;
    }

    .bg-swatch-pill.active {
      border: 2px solid #6D28D9;
    }

    .bg-hex-row {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 10px;
      padding: 6px 16px 4px;
    }

    .bg-hex-label {
      font-size: 14px;
      font-weight: 600;
      color: rgba(0, 0, 0, 0.5);
      white-space: nowrap;
    }

    .bg-hex-input {
      width: 100px;
      font-size: 13px;
      font-family: monospace;
      text-align: center;
      box-sizing: border-box;
    }

    .bg-hex-return {
      font-size: 12px;
      color: #6D28D9;
      opacity: 0;
      transition: opacity 0.15s;
      white-space: nowrap;
    }

    /* ===== BACKGROUND STYLE MINI SHEET ===== */
    .bg-style-sheet-scrim {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 9000;
      background: rgba(0, 0, 0, 0.4);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
    }

    .bg-style-sheet-scrim.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .bg-style-sheet {
      position: fixed;
      bottom: -400px;
      left: 0;
      right: 0;
      z-index: 9001;
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 20px 20px 0 0;
      padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
      transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .bg-style-sheet.visible {
      bottom: 0;
    }

    .bg-style-sheet-body {
      padding: 8px 20px 28px;
    }

    .bg-style-sheet-title {
      font-size: 14px;
      font-weight: 500;
      color: #111;
      margin-bottom: 16px;
      text-align: center;
    }

    .bg-style-sheet-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 8px;
    }

    .bg-style-tile {
      border: 0.5px solid rgba(0, 0, 0, 0.12);
      border-radius: 12px;
      padding: 16px 8px;
      text-align: center;
      cursor: pointer;
      font-size: 13px;
      font-weight: 500;
      color: #333;
      background: #fff;
    }

    .bg-style-tile.active {
      border: 2px solid #6D28D9;
      color: #6D28D9;
      font-weight: 600;
    }

    /* ===== BACKGROUND ORIENTATION MINI SHEET ===== */
    .bg-orient-sheet-scrim {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 9000;
      background: rgba(0, 0, 0, 0.4);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
    }

    .bg-orient-sheet-scrim.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .bg-orient-sheet {
      position: fixed;
      bottom: -200px;
      left: 0;
      right: 0;
      z-index: 9001;
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 20px 20px 0 0;
      padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
      transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .bg-orient-sheet.visible {
      bottom: 0;
    }

    .bg-orient-sheet-body {
      padding: 8px 20px 24px;
    }

    .bg-orient-sheet-title {
      font-size: 14px;
      font-weight: 500;
      color: #111;
      margin-bottom: 20px;
      text-align: center;
    }

    .bg-orient-sheet-buttons {
      display: flex;
      gap: 12px;
    }

    .bg-orient-btn-large {
      flex: 1;
      padding: 16px 12px;
      border-radius: 14px;
      border: 0.5px solid rgba(0, 0, 0, 0.12);
      background: #f9f9f9;
      font-size: 13px;
      font-weight: 500;
      color: #333;
      cursor: pointer;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 8px;
    }

    .bg-orient-btn-large:active {
      background: #f3e8ff;
      border-color: #6D28D9;
    }

    /* ===== BACKGROUND SIZE MINI SHEET ===== */
    .bg-size-sheet-scrim {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      z-index: 9000;
      background: rgba(0, 0, 0, 0.4);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.25s ease;
    }

    .bg-size-sheet-scrim.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .bg-size-sheet {
      position: fixed;
      bottom: -200px;
      left: 0;
      right: 0;
      z-index: 9001;
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 20px 20px 0 0;
      padding-bottom: calc(env(safe-area-inset-bottom) + 16px);
      transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .bg-size-sheet.visible {
      bottom: 0;
    }

    .bg-size-sheet-body {
      padding: 8px 20px 24px;
    }

    .bg-size-sheet-row {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16px;
    }

    .bg-size-sheet-label {
      font-size: 14px;
      color: rgba(0, 0, 0, 0.5);
      text-align: center;
    }

    .bg-size-sheet-value {
      font-size: 14px;
      font-weight: 600;
      color: #6D28D9;
    }

    .bg-size-slider-row {
      display: flex;
      align-items: center;
      gap: 10px;
    }

    .bg-size-range-label {
      font-size: 12px;
      color: rgba(0, 0, 0, 0.4);
      white-space: nowrap;
    }

    /* ===== BACKGROUND PILL ROW ===== */
    .bg-choice-row {
      position: fixed;
      bottom: calc(49px + env(safe-area-inset-bottom));
      left: 0;
      right: 0;
      z-index: 8998;
      display: flex;
      justify-content: center;
      gap: 6px;
      padding: 10px 16px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease;
      transform: translateY(-12px);
    }

    .bg-choice-row.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .bg-pill-row {
      position: fixed;
      bottom: calc(49px + env(safe-area-inset-bottom));
      left: 0;
      right: 0;
      z-index: 8998;
      display: flex;
      justify-content: center;
      gap: 6px;
      padding: 10px 16px;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease;
      transform: translateY(-12px);
    }

    .bg-pill-row.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .bg-pill {
      padding: 8px 12px;
      border-radius: 999px;
      border: 1.5px solid #6D28D9;
      background: rgba(255, 255, 255, 0.95);
      color: #6D28D9;
      font-size: 15px;
      font-weight: 500;
      cursor: pointer;
      box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
    }

    .bg-pill.active {
      background: #6D28D9;
      color: #ffffff;
      font-weight: 600;
    }

    /* ===== EDITOR FOOTER TOOLBAR ===== */
    .editor-footer-toolbar {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      z-index: 8999;
      display: flex;
      align-items: center;
      justify-content: center;
      min-height: 49px;
      box-sizing: content-box;
      padding-bottom: env(safe-area-inset-bottom);
      background: #ffffff;
      border-top: 1px solid rgba(0,0,0,0.1);
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }


    .editor-footer-toolbar.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .editor-footer-pill {
      display: flex;
      align-items: flex-start;
      width: 100%;
      justify-content: space-around;
      height: 56px;
      gap: 16px;
      position: relative;
      padding-top: 14px;
      padding-left: 20px;
      padding-right: 20px;
      box-sizing: border-box;
    }


    .editor-footer-btn {
      position: relative;
      z-index: 1;
      width: 49px;
      height: 49px;
      border: none;
      background: transparent;
      color: #6D28D9;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      gap: 4px;
      cursor: pointer;
      font-size: 13px;
      -webkit-tap-highlight-color: transparent;
      transition: transform 0.15s ease;
    }

    .editor-footer-btn:active {
      transform: scale(0.96);
    }

    .editor-footer-btn svg {
      width: 28px;
      height: 28px;
      min-width: 28px;
      min-height: 28px;
      color: #6D28D9;
      flex-shrink: 0;
    }

    .editor-footer-btn-label {
      font-family: 'Poppins', sans-serif;
      font-weight: 400;
      font-size: 12px;
      color: #6D28D9;
      letter-spacing: 0.04em;
    }

    .editor-footer-btn.active-control {
      background: transparent;
    }

    .editor-footer-btn.active-control svg {
      color: #6D28D9;
    }

    /* Explicit styling to prevent bleed from nav pill */
    .editor-footer-pill .editor-footer-btn {
      background: transparent;
      color: #6D28D9;
    }

    .editor-footer-pill .editor-footer-btn svg {
      color: #6D28D9;
    }

    /* ===== EDITOR NAV PILL (5-tab footer) ===== */
    .editor-nav-pill {
      position: fixed;
      bottom: 20px;
      left: 16px;
      right: 16px;
      z-index: 8999;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .editor-nav-pill.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .editor-nav-pill-inner {
      display: flex;
      align-items: center;
      justify-content: space-evenly;
      width: 100%;
      max-width: 400px;
      height: 56px;
      background: rgba(255, 255, 255, 0.85);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.3);
      border-radius: 999px;
      box-shadow: 0 4px 24px rgba(0, 0, 0, 0.15), 0 1px 4px rgba(0, 0, 0, 0.1);
      padding: 0 8px;
    }

    .editor-nav-btn {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      border: none;
      background: transparent;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      -webkit-tap-highlight-color: transparent;
      transition: transform 0.15s ease, background-color 0.15s ease;
      color: #6D28D9;
    }

    .editor-nav-btn:active {
      transform: scale(0.92);
    }

    .editor-nav-btn--create {
      background: #6D28D9;
      box-shadow: 0 2px 8px rgba(109, 40, 217, 0.4);
    }

    .editor-nav-btn--create:active {
      background: #5B21B6;
    }

    .editor-nav-btn--disabled {
      opacity: 0.5;
      cursor: not-allowed;
    }

    .editor-nav-btn--disabled:active {
      transform: none;
    }

    .editor-nav-btn svg {
      width: 22px;
      height: 22px;
    }

    /* ========== DRAG DROP ZONES ========== */
    /* Page dot states for editability */
    .page-dot.locked-edit {
      background: var(--color-border-subtle);
      border: 1px dashed var(--color-border);
      cursor: not-allowed;
    }

    /* ========== SAVE/DISCARD MODAL ========== */
    .modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease;
      z-index: 3500;
      touch-action: manipulation;
    }

    .modal-overlay.visible {
      opacity: 1;
      pointer-events: auto;
    }

    /* When modal is open, disable interactions underneath */
    body.modal-open .stickerbook-page,
    body.modal-open .page-canvas,
    body.modal-open .drawer-panel,
    body.modal-open .drawer-overlay {
      pointer-events: none;
    }

    .modal-card {
      background: var(--color-canvas-elevated);
      border-radius: var(--radius-lg);
      padding: 24px;
      max-width: 300px;
      width: 90%;
      box-shadow: var(--shadow-xl);
    }

    .modal-title {
      font-family: var(--font-display);
      font-size: 16px;
      font-weight: 600;
      color: var(--color-text-primary);
      margin-bottom: 8px;
    }

    .modal-text {
      font-size: 13px;
      color: var(--color-text-muted);
      margin-bottom: 20px;
      line-height: 1.5;
    }

    .modal-buttons {
      display: flex;
      gap: 10px;
    }

    .modal-btn {
      flex: 1;
      padding: 10px 16px;
      border-radius: var(--radius-pill);
      font-size: 12px;
      font-weight: 600;
      cursor: pointer;
      transition: transform 0.12s ease, box-shadow 0.12s ease;
      font-family: var(--font-primary);
    }

    .modal-btn:active {
      transform: scale(0.98);
    }

    .modal-btn-secondary {
      background: var(--color-canvas-subtle);
      border: 1px solid var(--color-border);
      color: var(--color-text-primary);
    }

    .modal-btn-secondary:hover {
      background: var(--color-hover-bg);
    }

    .modal-btn-primary {
      background: var(--gradient-primary);
      border: none;
      color: var(--color-text-inverse);
      box-shadow: var(--shadow-button);
    }

    .modal-btn-primary:hover {
      box-shadow: var(--shadow-button-hover);
    }

    /* ========== SHARE POPOVER ========== */
    .share-popover-overlay {
      position: fixed;
      inset: 0;
      background: transparent;
      opacity: 0;
      pointer-events: none;
      z-index: 3500;
    }

    .share-popover-overlay.visible {
      opacity: 1;
      pointer-events: auto;
    }

    .share-popover {
      position: absolute;
      /* Position below header: safe-area + header content (~48px) + small gap */
      top: calc(max(12px, env(safe-area-inset-top, 0px)) + 52px);
      right: 12px;
      background: var(--color-canvas-elevated);
      border-radius: var(--radius-lg);
      padding: 10px;
      min-width: 280px;
      max-width: calc(100vw - 24px);
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
      transform: scale(0.9) translateY(-10px);
      transform-origin: top right;
      opacity: 0;
      transition: transform 0.15s ease, opacity 0.15s ease;
    }

    .share-popover-overlay.visible .share-popover {
      transform: scale(1) translateY(0);
      opacity: 1;
    }

    /* Arrow pointing up toward button */
    .share-popover::before {
      content: '';
      position: absolute;
      top: -6px;
      right: 16px;
      width: 12px;
      height: 12px;
      background: var(--color-canvas-elevated);
      transform: rotate(45deg);
      box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.05);
    }

    .share-popover__option {
      display: flex;
      align-items: center;
      gap: 12px;
      padding: 12px;
      background: transparent;
      border: none;
      border-radius: var(--radius-md);
      cursor: pointer;
      width: 100%;
      text-align: left;
      transition: background 0.12s ease;
    }

    .share-popover__option:hover,
    .share-popover__option:active {
      background: var(--color-hover-bg);
    }

    .share-popover__option-icon {
      width: 32px;
      height: 32px;
      border-radius: var(--radius-sm);
      background: var(--gradient-primary);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }

    .share-popover__option-icon svg {
      width: 16px;
      height: 16px;
      color: white;
    }

    .share-popover__option-icon--image {
      background: linear-gradient(135deg, #8B5CF6, #7C3AED);
    }

    .share-popover__option-text {
      flex: 1;
    }

    .share-popover__option-title {
      font-size: 13px;
      font-weight: 600;
      color: var(--color-text-primary);
    }

    .share-popover__option-desc {
      font-size: 11px;
      color: var(--color-text-muted);
      margin-top: 1px;
    }

    /* ========== TOAST ========== */
    /* Glass-morphism style to match modal design language */
    .toast {
      position: fixed;
      bottom: 100px;
      left: 50%;
      transform: translateX(-50%) translateY(20px);
      padding: 10px 20px;
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      color: var(--color-text-primary);
      border-radius: var(--radius-pill);
      font-size: 12px;
      font-weight: 600;
      opacity: 0;
      pointer-events: none;
      transition: opacity 0.2s ease, transform 0.2s ease;
      z-index: 800;
      box-shadow:
        inset 0 0 8px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 4px 16px rgba(0, 0, 0, 0.10);
    }

    .toast.visible {
      opacity: 1;
      transform: translateX(-50%) translateY(0);
    }

    /* ========== DRAWER MODAL ========== */
    .drawer-overlay {
      position: fixed;
      inset: 0;
      background: transparent;
      backdrop-filter: none;
      -webkit-backdrop-filter: none;
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 0.3s ease, visibility 0.3s ease;
      z-index: 9000;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
    }

    .drawer-overlay.visible {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    .drawer-modal {
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 24px;
      box-shadow:
        inset 0 0 12px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 8px 32px rgba(0, 0, 0, 0.12);
      width: 100%;
      max-width: 360px;
      height: 60vh;
      max-height: 480px;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      transform: scale(0.9);
      opacity: 0;
      transition: transform 0.3s ease, opacity 0.3s ease;
      position: relative;
      user-select: none;
      -webkit-user-select: none;
    }

    .drawer-overlay.visible .drawer-modal {
      transform: scale(1);
      opacity: 1;
    }

    /* ========== BOTTOM SHEET VARIANT ========== */

    .drawer-overlay.bottom-sheet {
      align-items: flex-end;
      justify-content: center;
      padding: 0;
      background: rgba(0, 0, 0, 0.4);
    }

    .drawer-overlay.bottom-sheet .drawer-modal {
      max-width: none;
      width: 100%;
      height: auto;
      max-height: calc(100vh - env(safe-area-inset-top) - 80px);
      border-radius: 0;
      border-top-left-radius: 20px;
      border-top-right-radius: 20px;
      border-bottom: none;
      transform: translateY(100%);
      opacity: 1;
      transition: transform 0.3s ease;
      padding-bottom: 20px;
    }

    .drawer-overlay.bottom-sheet.visible .drawer-modal {
      transform: translateY(0);
    }

    .drawer-overlay.bottom-sheet .drawer-modal::after {
      border-radius: 0;
      border-top-left-radius: 20px;
      border-top-right-radius: 20px;
    }

    .drawer-sheet-handle {
      width: 100%;
      padding: 12px 0 4px;
      display: flex;
      justify-content: center;
      flex-shrink: 0;
      position: relative;
      z-index: 1;
    }

    .drawer-sheet-handle-bar {
      width: 40px;
      height: 4px;
      border-radius: 2px;
      background: rgba(0, 0, 0, 0.2);
    }

    /* Background picker modal - ensure content clips to border-radius */
    #background-picker-modal {
      overflow: hidden;
    }

    #background-picker-modal .drawer-modal-body {
      max-width: 360px;
      margin: 0 auto;
    }

    /* Gloss sweep overlay for glass effect */
    .drawer-modal::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      border-radius: 24px;
      background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.15) 0%,
        rgba(255, 255, 255, 0.03) 40%,
        transparent 60%
      );
      pointer-events: none;
      z-index: 0;
    }

    .drawer-modal-header {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 16px 16px 12px;
      border-bottom: none;
      background: transparent;
      flex-shrink: 0;
      position: relative;
      z-index: 1;
    }

    .drawer-modal-title {
      font-size: 15px;
      font-weight: 600;
      font-family: var(--font-primary);
      color: #000;
    }

    .drawer-modal-body {
      flex: 1;
      overflow: hidden;
      position: relative;
      z-index: 1;
      background: transparent;
    }

    /* Sticker drawer body content - always visible in its modal */
    #sticker-drawer-body {
      height: 100%;
      overflow-y: auto;
    }

    /* Background picker body content - always visible in its modal */
    #background-picker-body {
      height: 100%;
      overflow-y: auto;
      position: relative;
    }

    .drawer-modal-footer {
      flex-shrink: 0;
      border-top: none;
      background: transparent;
      position: relative;
      z-index: 1;
    }

    /* Stickers footer - always visible in sticker drawer */
    .drawer-stickers-footer {
      display: flex;
      padding: 12px 16px;
      gap: 12px;
    }

    #sticker-drawer-modal {
      max-height: 50vh;
    }

    #sticker-drawer-modal .drawer-modal-title {
      display: none;
    }

    /* ===== MY BACKGROUNDS SHEET ===== */
    #bg-owned-sheet {
      max-height: 60vh;
    }

    .bg-owned-grid {
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 8px;
      padding: 8px;
      padding-bottom: 10px;
    }

    .bg-owned-grid .bg-owned-thumb {
      aspect-ratio: 9 / 16;
      border-radius: 8px;
      overflow: hidden;
      cursor: pointer;
      background: rgba(0, 0, 0, 0.06);
    }

    .bg-owned-grid .bg-owned-thumb img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }

    .bg-owned-empty {
      grid-column: 1 / -1;
      text-align: center;
      color: rgba(0, 0, 0, 0.4);
      font-size: 13px;
      padding: 24px;
    }

    #drawer-stickers-footer {
      display: none;
    }

    .drawer-create-btn {
      flex: 1;
      padding: 12px 20px;
      border: none;
      border-radius: var(--radius-pill);
      background: var(--color-turquoise);
      color: white;
      font-size: 13px;
      font-weight: 600;
      font-family: var(--font-primary);
      cursor: pointer;
      transition: transform 0.15s ease;
      position: relative;
      z-index: 2;
      -webkit-tap-highlight-color: transparent;
    }

    .drawer-create-btn:active {
      transform: scale(0.96);
    }

    .drawer-add-btn {
      flex: 1;
      padding: 12px 20px;
      border: none;
      border-radius: var(--radius-pill);
      background: var(--color-purple);
      color: white;
      font-size: 13px;
      font-weight: 600;
      font-family: var(--font-primary);
      cursor: pointer;
      transition: transform 0.15s ease, opacity 0.15s ease;
      display: none;
      position: relative;
      z-index: 2;
      -webkit-tap-highlight-color: transparent;
    }

    .drawer-add-btn.visible {
      display: block;
    }

    .drawer-add-btn:active {
      transform: scale(0.96);
    }

    /* Backgrounds footer - always visible in background picker */
    .drawer-backgrounds-footer {
      display: flex;
      padding: 12px 16px;
      flex-direction: column;
      gap: 12px;
    }

    .bg-size-row {
      display: none;
      padding: 4px 0;
    }

    .bg-size-row.visible {
      display: block;
    }

    .bg-size-slider {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 6px;
      border-radius: 3px;
      background: var(--color-border);
      outline: none;
      cursor: pointer;
    }

    .bg-size-slider::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--color-purple);
      cursor: pointer;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    }

    .drawer-backgrounds-footer .bg-controls-row {
      display: flex;
      gap: 8px;
    }

    .drawer-backgrounds-footer .bg-control-btn {
      height: 44px;
      border: 1px solid var(--color-border);
      border-radius: var(--radius-md);
      background: white;
      font-size: 13px;
      font-weight: 500;
      font-family: var(--font-primary);
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 6px;
      transition: border-color 0.15s ease, background 0.15s ease;
      position: relative;
      z-index: 2;
      -webkit-tap-highlight-color: transparent;
    }

    .drawer-backgrounds-footer .bg-control-btn:hover {
      border-color: var(--color-border-strong);
    }

    .drawer-backgrounds-footer .bg-style-btn {
      flex: 1;
      padding: 0 12px;
      background: var(--color-turquoise) !important;
      border: 2.5px solid transparent !important;
      border-radius: var(--radius-pill);
      box-shadow: none !important;
      color: white;
      font-weight: 600;
      transition: transform 0.15s ease, border-color 0.15s ease;
    }

    .drawer-backgrounds-footer .bg-style-btn:active {
      transform: scale(0.92);
    }

    .drawer-backgrounds-footer .bg-btn-label {
      color: #fff;
      font-weight: 600;
    }

    .drawer-backgrounds-footer .bg-btn-arrow {
      font-size: 10px;
      color: var(--color-text-muted);
    }

    .drawer-backgrounds-footer .bg-color-btn {
      width: 44px;
      border-radius: var(--radius-md);
      position: relative;
      background: #ffffff;
      border: 2.5px solid transparent !important;
      box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
    }

    .drawer-backgrounds-footer #bg-color2-btn {
      background: #ffffff;
    }

    /* Active-control state: white border for current interaction */
    .drawer-backgrounds-footer .bg-style-btn.active-control,
    .drawer-backgrounds-footer .bg-orient-btn.active-control,
    .drawer-backgrounds-footer .bg-color-btn.active-control {
      border: 2.5px solid #fff !important;
    }

    /* Gradient underline for active color swatch - only in multi-color modes */
    /* Uses :has() to detect when color2 button is visible (not display:none) */
    .bg-controls-row:has(#bg-color2-btn:not([style*="none"])) .bg-color-btn.active-control::after {
      content: '';
      position: absolute;
      bottom: -6px;
      left: 0;
      right: 0;
      height: 3px;
      background: var(--gradient-accent);
      border-radius: 3px;
    }

    .drawer-backgrounds-footer .bg-orient-btn {
      width: 44px;
      font-size: 18px;
      background: var(--color-turquoise) !important;
      border: 2.5px solid transparent !important;
      border-radius: var(--radius-pill);
      box-shadow: none !important;
      color: #fff;
      transition: transform 0.15s ease, border-color 0.15s ease;
    }

    .drawer-backgrounds-footer .bg-orient-btn:active {
      transform: scale(0.92);
    }

    /* Hex input row */
    .bg-hex-row {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 2px 16px 8px;
    }

    .bg-hex-input {
      flex: 1;
      min-width: 0;
      max-width: 140px;
      padding: 10px 12px;
      border: 1.5px solid var(--color-text-secondary);
      border-radius: var(--radius-md);
      font-size: 14px;
      font-weight: 500;
      font-family: var(--font-primary);
      color: #000;
      background: white;
      text-transform: uppercase;
      text-align: center;
      position: relative;
      z-index: 2;
    }

    .bg-hex-input::placeholder {
      color: var(--color-text-secondary);
      text-transform: none;
    }

    .bg-hex-input:focus {
      outline: none;
      border-color: var(--color-purple);
    }

    /* Style overlay - centered over color grid */
    .bg-style-overlay {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 85%;
      background: rgba(255, 255, 255, 0.40);
      backdrop-filter: blur(20px) saturate(180%);
      -webkit-backdrop-filter: blur(20px) saturate(180%);
      border: 1px solid rgba(255, 255, 255, 0.25);
      border-radius: 24px;
      box-shadow:
        inset 0 0 12px rgba(0, 0, 0, 0.04),
        inset 0 1px 0 rgba(255, 255, 255, 0.4),
        0 8px 32px rgba(0, 0, 0, 0.12);
      z-index: 10;
      /* Hidden by default */
      display: none;
    }

    .bg-style-overlay.visible {
      display: block;
    }

    /* Gloss sweep for style overlay */
    .bg-style-overlay::after {
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      border-radius: 24px 24px 0 0;
      background: linear-gradient(
        135deg,
        rgba(255, 255, 255, 0.15) 0%,
        rgba(255, 255, 255, 0.03) 40%,
        transparent 60%
      );
      pointer-events: none;
      z-index: 0;
    }

    .bg-style-overlay-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px 12px;
      font-size: 15px;
      font-weight: 600;
      color: #000;
      position: relative;
      z-index: 1;
    }

    .bg-style-overlay-close {
      width: 28px;
      height: 28px;
      border: none;
      background: rgba(0, 0, 0, 0.08);
      border-radius: 50%;
      color: #000;
      font-size: 16px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
      z-index: 2;
      -webkit-tap-highlight-color: transparent;
    }

    .bg-style-options {
      display: flex;
      flex-direction: column;
      padding: 0 16px 20px;
      gap: 4px;
      position: relative;
      z-index: 1;
    }

    .bg-style-option {
      padding: 10px 16px;
      border: 2.5px solid transparent;
      background: transparent;
      border-radius: 14px;
      font-size: 14px;
      font-weight: 600;
      font-family: var(--font-primary);
      color: #000;
      text-align: center;
      cursor: pointer;
      transition: all 0.15s ease;
      position: relative;
      z-index: 2;
      -webkit-tap-highlight-color: transparent;
    }

    .bg-style-option:hover {
      background: rgba(0, 0, 0, 0.06);
    }

    .bg-style-option.active {
      background: var(--color-turquoise);
      color: #fff;
      border: 2.5px solid #fff;
    }

    /* Create sticker overlay */
    .drawer-create-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 0.3s ease, visibility 0.3s ease;
      z-index: 2600;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 24px;
    }

    .drawer-create-overlay.visible {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    .drawer-create-modal {
      background: white;
      border-radius: var(--radius-xl);
      width: 100%;
      max-width: 340px;
      transform: scale(0.9);
      opacity: 0;
      transition: transform 0.3s ease, opacity 0.3s ease;
    }

    .drawer-create-overlay.visible .drawer-create-modal {
      transform: scale(1);
      opacity: 1;
    }

    .drawer-create-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      border-bottom: 1px solid var(--color-border);
    }

    .drawer-create-title {
      font-size: 16px;
      font-weight: 600;
      color: var(--color-text-primary);
    }

    .drawer-create-close {
      width: 28px;
      height: 28px;
      border: none;
      background: var(--color-canvas-subtle);
      border-radius: 50%;
      color: var(--color-text-muted);
      font-size: 16px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .drawer-create-inner {
      padding: 20px;
      text-align: center;
    }

    .drawer-create-subtitle {
      font-size: 13px;
      color: var(--color-text-muted);
      margin-bottom: 20px;
    }

    /* Legacy chip styles - kept for compatibility */
    .drawer-chip {
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 4px;
      padding: 8px 12px;
      min-width: 0;
      white-space: nowrap;
      background: var(--color-canvas-subtle);
      border: 1px solid var(--color-border);
      border-radius: var(--radius-pill);
      color: var(--color-text-muted);
      font-size: 12px;
      font-weight: 600;
      letter-spacing: 0.03em;
      cursor: pointer;
      transition: all 0.2s ease;
      font-family: var(--font-primary);
      flex-shrink: 0;
    }

    /* Base chips same width for cohesion */
    .drawer-chip-base {
      min-width: 100px;
    }

    .drawer-chip:hover {
      background: var(--color-hover-bg);
      border-color: var(--color-border-strong);
      color: var(--color-text-secondary);
    }

    .drawer-chip.active {
      background: var(--color-purple);
      border-color: var(--color-purple);
      color: white;
    }

    .drawer-chip-arrow {
      display: inline-block;
      width: 0;
      height: 0;
      border-left: 4px solid transparent;
      border-right: 4px solid transparent;
      border-top: 5px solid currentColor;
      opacity: 0.6;
      margin-left: 4px;
      vertical-align: middle;
    }

    /* Color swatch chip - small colored square */
    .drawer-chip-color {
      width: 36px;
      height: 36px;
      min-width: 36px;
      padding: 0;
      border-radius: 8px;
      border: 1px solid var(--color-border);
      background: white;
    }

    .drawer-chip-color.active {
      border: 2px solid var(--color-purple);
    }

    .drawer-chip-color:hover {
      border-color: var(--color-border-strong);
    }

    /* Icon-only chip (orientation) - same size as color chips */
    .drawer-chip-icon-only {
      width: 36px;
      height: 36px;
      min-width: 36px;
      padding: 0;
      border-radius: 8px;
      font-size: 16px;
      background: var(--color-canvas-subtle);
      border: 1px solid var(--color-border);
    }

    .drawer-chip-icon-only:hover {
      border-color: var(--color-border-strong);
      background: var(--color-hover-bg);
    }

    /* Chip dropdown popover */
    .chip-popover {
      position: absolute;
      z-index: 2700;
      background: white;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
      padding: 6px;
      display: flex;
      flex-direction: column;
      gap: 2px;
      min-width: 120px;
      animation: popupAppear 0.15s ease-out;
    }

    .chip-popover-option {
      padding: 10px 14px;
      border: none;
      background: transparent;
      border-radius: 8px;
      font-size: 13px;
      font-weight: 500;
      text-align: left;
      cursor: pointer;
      transition: background 0.15s ease;
      font-family: var(--font-primary);
      color: var(--color-text-primary);
    }

    .chip-popover-option:hover {
      background: var(--color-canvas-subtle);
    }

    .chip-popover-option.selected {
      background: var(--color-purple);
      color: white;
    }

    /* Slider popover */
    .chip-slider-popover {
      padding: 16px 14px;
      min-width: auto;
    }

    .chip-slider {
      -webkit-appearance: none;
      appearance: none;
      width: 100%;
      height: 6px;
      border-radius: 3px;
      background: var(--color-border);
      outline: none;
      cursor: pointer;
    }

    .chip-slider::-webkit-slider-thumb {
      -webkit-appearance: none;
      appearance: none;
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--color-purple);
      cursor: pointer;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
      transition: transform 0.1s ease;
    }

    .chip-slider::-webkit-slider-thumb:active {
      transform: scale(1.15);
    }

    .chip-slider::-moz-range-thumb {
      width: 22px;
      height: 22px;
      border-radius: 50%;
      background: var(--color-purple);
      cursor: pointer;
      border: none;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    }

    .drawer-archived-view {
      display: none;
      flex: 1;
      overflow: hidden;
    }

    .drawer-archived-view.visible {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    /* Color swatches row - simplified */

    .drawer-create-view {
      display: none;
      flex: 1;
      overflow: hidden;
    }

    .drawer-create-view.visible {
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 18px 16px;
      text-align: center;
    }

    .drawer-create-inner {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 12px;
      color: var(--color-text-muted);
      max-width: 280px;
    }

    .drawer-create-note {
      font-size: 11px;
      line-height: 1.3;
      opacity: 0.85;
    }

    .drawer-create-note code {
      font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
      font-size: 10px;
      background: var(--color-canvas-subtle);
      padding: 2px 6px;
      border-radius: 999px;
      border: 1px solid var(--color-border);
    }

    .drawer-create-title{
      font-size: 14px;
      font-weight: 700;
      color: var(--color-text-primary);
      letter-spacing: 0.02em;
    }

    .drawer-create-subtitle{
      font-size: 11px;
      line-height: 1.35;
      color: var(--color-text-muted);
      opacity: 0.92;
      margin-top: -6px;
    }

    .drawer-create-hint {
      font-size: 11px;
      line-height: 1.4;
      color: var(--color-text-muted);
      opacity: 0.7;
      margin-top: 8px;
      max-width: 240px;
    }

    .drawer-create-preview{
      width: 140px;
      height: 140px;
      border-radius: 18px;
      border: 1px solid var(--color-border);
      background: var(--color-canvas-subtle);
      display: none;
      align-items: center;
      justify-content: center;
      overflow: hidden;
      box-shadow: 0 6px 20px rgba(0,0,0,0.08);
    }

    .drawer-create-preview.visible{ display: flex; }

    .drawer-create-preview img{
      width: 100%;
      height: 100%;
      object-fit: contain;
      display: block;
    }

    .drawer-create-processing{
      display: none;
      align-items: center;
      justify-content: center;
      gap: 10px;
      margin-top: 2px;
    }

    .drawer-create-processing.visible{ display: flex; }

    .drawer-create-processing-text{
      font-size: 11px;
      color: var(--color-text-muted);
    }

    .drawer-create-spinner{
      width: 14px;
      height: 14px;
      border-radius: 50%;
      border: 2px solid rgba(20, 184, 166, 0.35);
      border-top-color: rgba(109, 40, 217, 0.85);
      animation: sbSpin 0.9s linear infinite;
    }

    @keyframes sbSpin{
      from{ transform: rotate(0deg); }
      to{ transform: rotate(360deg); }
    }


.drawer-archived-empty {
      text-align: center;
      color: var(--color-text-muted);
    }

    .drawer-grid {
      padding: 12px;
      display: grid;
      grid-template-columns: repeat(4, 1fr);
      grid-auto-rows: min-content;
      gap: 8px;
      align-content: start;
      background: transparent;
    }

    /* Custom scrollbar for drawer */
    .drawer-grid::-webkit-scrollbar {
      width: 4px;
    }

    .drawer-grid::-webkit-scrollbar-track {
      background: var(--color-border-subtle);
      border-radius: 2px;
    }

    .drawer-grid::-webkit-scrollbar-thumb {
      background: var(--color-border-strong);
      border-radius: 2px;
    }

    /* Swipe delete wrapper */
    .drawer-sticker-wrapper {
      position: relative;
      overflow: hidden;
      border-radius: var(--radius-md);
      aspect-ratio: 1 / 1;
      -webkit-tap-highlight-color: transparent;
    }

    .drawer-sticker {
      position: absolute;
      inset: 0;
      background: transparent;
      border-radius: var(--radius-md);
      padding: 4px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: transform 0.15s ease, background 0.15s ease;
      border: none;
      box-shadow: none;
      touch-action: pan-y;
      user-select: none;
      -webkit-user-select: none;
      -webkit-touch-callout: none;
      -webkit-tap-highlight-color: transparent;
    }

    .drawer-sticker.on-page {
      opacity: 0.35;
      filter: grayscale(50%);
      pointer-events: none;
    }

    .drawer-sticker-wrapper.on-page-wrapper {
      order: 999;
    }

    .drawer-sticker-delete {
      position: absolute;
      right: 0;
      top: 0;
      bottom: 0;
      width: 50px;
      background: var(--color-error);
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 18px;
      transform: translateX(100%);
      transition: transform 0.2s ease;
    }

    .drawer-sticker-wrapper.swiped .drawer-sticker-delete {
      transform: translateX(0);
    }

    .drawer-sticker-wrapper.swiped .drawer-sticker {
      transform: translateX(-50px);
    }

    /* Selection mode */
    .drawer-sticker.selectable {
      cursor: pointer;
    }

    /* Multi-select removed - drag-to-place only */

    /* Draggable mode (half-screen) */
    .drawer-sticker.draggable {
      cursor: grab;
    }

    .drawer-sticker.draggable:active {
      cursor: grabbing;
    }

    .drawer-sticker:hover {
      background: var(--color-hover-bg);
      border-color: var(--color-border-strong);
      box-shadow: var(--shadow-sm);
    }

    .drawer-sticker img {
      max-width: 100%;
      max-height: 100%;
      object-fit: contain;
      pointer-events: none;
      user-select: none;
      -webkit-user-select: none;
      -webkit-user-drag: none;
    }

    .drawer-sticker.dragging {
      opacity: 0.5;
      transform: scale(0.95);
    }

    .drawer-empty {
      display: none;
    }

    .drawer-empty.hidden {
      display: none;
    }
    
    .drawer-empty-text {
      font-size: 13px;
      font-weight: 500;
      line-height: 1.6;
    }
    
    /* Drawer Sticker Popup - Add/Delete on long press */
    .drawer-sticker-popup {
      position: fixed;
      z-index: 2600;
      display: flex;
      gap: 6px;
      padding: 6px;
      background: white;
      border-radius: 12px;
      box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
      animation: popupAppear 0.15s ease-out;
    }

    .drawer-popup-btn {
      padding: 10px 16px;
      border-radius: 8px;
      font-size: 13px;
      font-weight: 600;
      cursor: pointer;
      transition: transform 0.1s ease, background 0.15s ease;
      font-family: var(--font-primary);
    }

    .drawer-popup-btn:active {
      transform: scale(0.95);
    }

    .drawer-popup-add {
      background: var(--color-purple);
      color: white;
      border: none;
    }

    .drawer-popup-add:hover {
      background: var(--color-purple-dark, #5b21b6);
    }

    .drawer-popup-delete {
      background: #1a1a1a;
      color: white;
      border: none;
    }

    .drawer-popup-delete:hover {
      background: #333;
    }

    /* Sticker being dragged from drawer */
    .drag-ghost {
      position: absolute;
      pointer-events: none;
      z-index: 3000;
      opacity: 0;
      display: none;
      transform: translate(-50%, -50%) scale(1.1);
      transition: opacity 0.15s ease;
      background: transparent !important;
      border: none !important;
      outline: none !important;
      box-shadow: none !important;
      -webkit-tap-highlight-color: transparent;
    }

    .drag-ghost img {
      width: 120px;
      height: 120px;
      object-fit: contain;
      filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.3));
      background: transparent !important;
      border: none !important;
      outline: none !important;
    }

    /* ========== BACKGROUND PANEL ========== */
    .bg-panel {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      height: 52vh;
      background: var(--color-canvas-elevated);
      border-radius: var(--radius-xl) var(--radius-xl) 0 0;
      box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.15);
      transform: translateY(100%);
      transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
      z-index: 2501;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      border-top: 1px solid var(--color-border);
    }

    .bg-panel.visible {
      transform: translateY(0);
    }

    .bg-panel-header {
      display: flex;
      align-items: center;
      padding: 12px 16px;
      border-bottom: 1px solid var(--color-border);
      flex-shrink: 0;
    }

    .bg-header-spacer {
      width: 28px;
      flex-shrink: 0;
    }

    .bg-panel-title {
      flex: 1;
      text-align: center;
      font-family: 'Poppins', var(--font-display);
      font-size: 14px;
      font-weight: 600;
      color: var(--color-text-primary);
    }

    .bg-header-tabs {
      display: flex;
      gap: 8px;
      flex: 1;
      justify-content: center;
    }

    .bg-header-tab {
      padding: 8px 16px;
      background: var(--color-canvas-subtle);
      border: 1px solid var(--color-border);
      border-radius: var(--radius-pill);
      color: var(--color-text-muted);
      font-size: 12px;
      font-weight: 600;
      letter-spacing: 0.03em;
      cursor: pointer;
      transition: all 0.2s ease;
      font-family: var(--font-primary);
    }

    .bg-header-tab:hover {
      background: var(--color-hover-bg);
      border-color: var(--color-border-strong);
      color: var(--color-text-secondary);
    }

    .bg-header-tab.active {
      background: var(--color-purple);
      border-color: var(--color-purple);
      color: white;
    }

    .bg-header-tab.active:hover {
      background: var(--color-purple-dark, #5b21b6);
    }

    .bg-panel-close {
      background: transparent;
      border: none;
      color: var(--color-text-muted);
      font-size: 20px;
      cursor: pointer;
      padding: 4px 8px;
      transition: color 0.15s ease;
    }

    .bg-panel-close:hover {
      color: var(--color-text-primary);
    }

    /* Pattern tabs */
    .bg-pattern-tabs {
      display: flex;
      gap: 6px;
      padding: 12px 16px;
      flex-shrink: 0;
    }

    .bg-pattern-tab {
      flex: 1;
      padding: 8px 0;
      border: 1px solid var(--color-border);
      border-radius: var(--radius-pill);
      background: var(--color-canvas);
      color: var(--color-text-muted);
      font-size: 10px;
      font-weight: 600;
      letter-spacing: 0.05em;
      text-transform: uppercase;
      text-align: center;
      cursor: pointer;
      transition: all 0.15s ease;
      font-family: var(--font-primary);
    }

    .bg-pattern-tab:hover {
      border-color: var(--color-border-strong);
      color: var(--color-text-secondary);
    }

    .bg-pattern-tab.active {
      background: var(--color-purple);
      border-color: var(--color-purple);
      color: white;
    }

    /* Sub-filter buttons - now inside controls row */
    .bg-subfilter {
      display: none;
      gap: 4px;
      flex-shrink: 0;
    }

    .bg-subfilter.visible {
      display: flex;
    }

    .bg-subfilter-btn {
      padding: 5px 8px;
      border: 1px solid var(--color-border);
      border-radius: var(--radius-pill);
      background: transparent;
      color: var(--color-text-secondary);
      font-size: 11px;
      font-weight: 700;
      letter-spacing: 0.02em;
      text-align: center;
      cursor: pointer;
      transition: all 0.15s ease;
      font-family: var(--font-primary);
    }

    .bg-subfilter-btn:hover {
      border-color: var(--color-border-strong);
      color: var(--color-text-muted);
    }

    .bg-subfilter-btn.active {
      background: var(--color-text-primary);
      border-color: var(--color-text-primary);
      color: var(--color-text-inverse);
    }

    /* Color grid */
    .bg-color-grid {
      padding: 12px;
      margin-bottom: -6px;
    }

    .bg-color-row {
      display: grid;
      grid-template-columns: repeat(7, 1fr);
      gap: 6px;
      margin-bottom: 6px;
    }

    .bg-color-tile {
      aspect-ratio: 1;
      width: 100%;
      min-width: 40px;
      border-radius: var(--radius-sm);
      cursor: pointer;
      transition: transform 0.12s ease;
      box-shadow: var(--shadow-xs);
      border: 2px solid transparent;
    }

    .bg-color-tile:hover {
      transform: scale(1.08);
    }

    .bg-color-tile:active {
      transform: scale(0.98);
    }

    .bg-color-tile.selected {
      border-color: var(--color-accent);
      box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.3), var(--shadow-sm);
    }

    /* Shop link in background panel */
    /* Background panel footer */
    .bg-footer {
      flex-shrink: 0;
      padding: 12px 16px;
      border-top: 1px solid var(--color-border);
      background: var(--color-canvas-elevated);
    }

    /* Shared shop button style for both panels */
    .panel-shop-btn {
      width: 100%;
      display: flex;
      align-items: center;
      justify-content: center;
      gap: 8px;
      padding: 12px 20px;
      background: var(--color-purple);
      border: none;
      border-radius: var(--radius-pill);
      color: white;
      font-size: 12px;
      font-weight: 600;
      letter-spacing: 0.03em;
      cursor: pointer;
      transition: transform 0.15s ease, background 0.15s ease;
      font-family: var(--font-primary);
    }

    .panel-shop-btn:hover {
      transform: translateY(-1px);
      background: var(--color-purple-dark, #5b21b6);
    }

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

    /* My Backgrounds view */
    .bg-my-view {
      display: none;
      flex: 1;
      overflow: hidden;
      flex-direction: column;
    }

    .bg-my-view.visible {
      display: flex;
    }

    .bg-default-view {
      display: flex;
      flex: 1;
      overflow: hidden;
      flex-direction: column;
    }

    .bg-default-view.hidden {
      display: none;
    }

    .bg-my-grid {
      flex: 1;
      overflow-y: auto;
      padding: 12px 16px;
      display: grid;
      grid-template-columns: repeat(3, 1fr);
      gap: 10px;
      align-content: start;
    }

    .bg-my-grid::-webkit-scrollbar {
      width: 4px;
    }

    .bg-my-grid::-webkit-scrollbar-track {
      background: var(--color-border-subtle);
      border-radius: 2px;
    }

    .bg-my-grid::-webkit-scrollbar-thumb {
      background: var(--color-border-strong);
      border-radius: 2px;
    }

    .bg-my-item-wrapper {
      position: relative;
      overflow: hidden;
      border-radius: var(--radius-md);
      aspect-ratio: 1 / 1;
    }

    .bg-my-item {
      position: absolute;
      inset: 0;
      border-radius: var(--radius-md);
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease;
      border: 2px solid transparent;
      box-shadow: var(--shadow-sm);
      background-size: cover;
      background-position: center;
    }

    .bg-my-item:hover {
      transform: scale(1.03);
    }

    .bg-my-item.selected {
      border-color: var(--color-accent);
      box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.3), var(--shadow-sm);
    }

    .bg-my-item-delete {
      position: absolute;
      right: 0;
      top: 0;
      bottom: 0;
      width: 50px;
      background: var(--color-error);
      display: flex;
      align-items: center;
      justify-content: center;
      color: white;
      font-size: 16px;
      transform: translateX(100%);
      transition: transform 0.2s ease;
      border-radius: 0 var(--radius-md) var(--radius-md) 0;
    }

    .bg-my-item-wrapper.swiped .bg-my-item-delete {
      transform: translateX(0);
    }

    .bg-my-item-wrapper.swiped .bg-my-item {
      transform: translateX(-50px);
    }

    .bg-my-empty {
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      padding: 40px 20px;
      text-align: center;
      color: var(--color-text-muted);
    }

    .bg-my-empty-icon {
      font-size: 32px;
      margin-bottom: 12px;
      opacity: 0.5;
    }

    .bg-my-empty-text {
      font-size: 12px;
      line-height: 1.5;
    }

    /* ========== STICKER INTERACTION MODES ========== */
    /* Disable sticker interactions in preview mode (default) */
    .placed-sticker {
      pointer-events: none;
    }

    /* Enable sticker interactions in edit mode */
    body.edit-mode .placed-sticker {
      pointer-events: auto;
    }

    /* ============ STICKER CREATION MODAL ============ */
    .sticker-modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(8px);
      -webkit-backdrop-filter: blur(8px);
      z-index: 10000;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .sticker-modal-overlay.visible {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    .sticker-modal {
      background: rgba(255, 255, 255, 0.95);
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
      border-radius: 24px;
      padding: 32px;
      width: 90%;
      max-width: 340px;
      text-align: center;
      transform: scale(0.9);
      opacity: 0;
      transition: transform 0.3s ease, opacity 0.3s ease;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }

    .sticker-modal-overlay.visible .sticker-modal {
      transform: scale(1);
      opacity: 1;
    }

    .sticker-modal__preview {
      width: 200px;
      height: 200px;
      margin: 0 auto 24px;
      display: flex;
      align-items: center;
      justify-content: center;
      position: relative;
    }

    /* Placeholder with animated rotating border */
    .sticker-modal__placeholder {
      width: 160px;
      height: 160px;
      background: #f5f5f5;
      border-radius: 24px;
      position: relative;
    }

    /* Rotating gradient border */
    .sticker-modal__placeholder::before {
      content: '';
      position: absolute;
      inset: -3px;
      border-radius: 27px;
      background: linear-gradient(90deg, #8B5CF6, #EC4899, #8B5CF6, #EC4899);
      background-size: 300% 100%;
      animation: borderSlide 1.5s linear infinite;
      z-index: -1;
    }

    /* Inner fill to create border effect */
    .sticker-modal__placeholder::after {
      content: '';
      position: absolute;
      inset: 3px;
      background: #f5f5f5;
      border-radius: 21px;
    }

    @keyframes borderSlide {
      0% { background-position: 0% 50%; }
      100% { background-position: 100% 50%; }
    }

    /* Pulsing inner icon/shape */
    .sticker-modal__placeholder-icon {
      position: absolute;
      inset: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 1;
    }

    .sticker-modal__placeholder-icon::before {
      content: '';
      width: 60px;
      height: 60px;
      border: 3px dashed rgba(139, 92, 246, 0.3);
      border-radius: 16px;
      animation: pulse 1.5s ease-in-out infinite;
    }

    @keyframes pulse {
      0%, 100% { transform: scale(0.9); opacity: 0.5; }
      50% { transform: scale(1.1); opacity: 1; }
    }

    /* Actual sticker preview (hidden during processing) */
    .sticker-modal__result {
      max-width: 200px;
      max-height: 200px;
      object-fit: contain;
      opacity: 0;
      transform: scale(0.8);
      transition: opacity 0.4s ease, transform 0.4s ease;
      position: absolute;
    }

    .sticker-modal--success .sticker-modal__placeholder {
      opacity: 0;
      transform: scale(0.8);
      transition: opacity 0.3s ease, transform 0.3s ease;
    }

    .sticker-modal--success .sticker-modal__result {
      opacity: 1;
      transform: scale(1);
    }

    .sticker-modal__text {
      font-family: var(--font-sans);
      font-size: 18px;
      font-weight: 600;
      color: #333;
      margin-bottom: 8px;
    }

    .sticker-modal__subtext {
      font-family: var(--font-sans);
      font-size: 14px;
      color: #666;
      margin-bottom: 24px;
      min-height: 20px;
    }

    .sticker-modal__buttons {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .sticker-modal__btn {
      width: 100%;
      padding: 14px 24px;
      border: none;
      border-radius: 14px;
      font-family: var(--font-sans);
      font-size: 15px;
      font-weight: 600;
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease;
    }

    .sticker-modal__btn--primary {
      background: var(--gradient-primary);
      color: white;
    }

    .sticker-modal__btn--primary:hover {
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(138, 43, 226, 0.3);
    }

    .sticker-modal__btn--primary:active {
      transform: translateY(1px);
    }

    .sticker-modal__btn--secondary {
      background: rgba(0, 0, 0, 0.05);
      color: #333;
    }

    .sticker-modal__btn--secondary:hover {
      background: rgba(0, 0, 0, 0.08);
    }

    .sticker-modal__btn--tertiary {
      background: transparent;
      color: #999;
      font-weight: 500;
      padding: 10px 24px;
    }

    .sticker-modal__btn--tertiary:hover {
      color: #ef4444;
      background: rgba(239, 68, 68, 0.08);
    }

    /* Error state */
    .sticker-modal--error .sticker-modal__placeholder {
      background: #ffebee;
    }

    .sticker-modal--error .sticker-modal__placeholder::before {
      background: rgba(244, 67, 54, 0.4);
      animation: none;
    }

    .sticker-modal--error .sticker-modal__placeholder::after {
      background: #ffebee;
    }

    .sticker-modal--error .sticker-modal__placeholder-icon::before {
      border-color: rgba(244, 67, 54, 0.3);
      animation: none;
    }

    .sticker-modal--error .sticker-modal__text {
      color: #c62828;
    }

    /* ============ TUTORIAL MODAL ============ */
    .tutorial-modal-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0, 0, 0, 0.6);
      backdrop-filter: blur(8px);
      -webkit-backdrop-filter: blur(8px);
      z-index: 10000;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0;
      visibility: hidden;
      pointer-events: none;
      transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .tutorial-modal-overlay.visible {
      opacity: 1;
      visibility: visible;
      pointer-events: auto;
    }

    .tutorial-modal {
      background: rgba(255, 255, 255, 0.98);
      backdrop-filter: blur(20px);
      -webkit-backdrop-filter: blur(20px);
      border-radius: 24px;
      padding: 24px;
      width: 90%;
      max-width: 340px;
      transform: scale(0.9);
      opacity: 0;
      transition: transform 0.3s ease, opacity 0.3s ease;
      box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    }

    .tutorial-modal-overlay.visible .tutorial-modal {
      transform: scale(1);
      opacity: 1;
    }

    .tutorial-modal__header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16px;
    }

    .tutorial-modal__title {
      font-family: var(--font-sans);
      font-size: 20px;
      font-weight: 700;
      color: #333;
    }

    .tutorial-modal__close {
      background: none;
      border: none;
      font-size: 28px;
      color: #999;
      cursor: pointer;
      padding: 0;
      line-height: 1;
    }

    .tutorial-modal__close:hover {
      color: #666;
    }

    .tutorial-modal__content {
      margin-bottom: 20px;
    }

    .tutorial-modal__intro {
      font-family: var(--font-sans);
      font-size: 14px;
      color: #555;
      margin: 0 0 16px 0;
    }

    .tutorial-modal__steps {
      display: flex;
      flex-direction: column;
      gap: 12px;
      margin-bottom: 20px;
    }

    .tutorial-modal__step {
      display: flex;
      align-items: center;
      gap: 12px;
    }

    .tutorial-modal__step-num {
      width: 26px;
      height: 26px;
      background: var(--gradient-primary);
      color: white;
      border-radius: 50%;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      font-weight: 600;
      flex-shrink: 0;
    }

    .tutorial-modal__step-text {
      font-family: var(--font-sans);
      font-size: 15px;
      color: #333;
    }

    .tutorial-modal__or {
      font-family: var(--font-sans);
      font-size: 14px;
      color: #555;
      margin: 0;
    }

    .tutorial-modal__clipboard {
      margin-top: 16px;
      padding: 16px;
      background: rgba(109, 40, 217, 0.08);
      border-radius: 16px;
      text-align: center;
    }

    .tutorial-modal__clipboard-preview {
      width: 80px;
      height: 80px;
      margin: 0 auto 12px;
      border-radius: 12px;
      background: white;
      display: flex;
      align-items: center;
      justify-content: center;
      overflow: hidden;
    }

    .tutorial-modal__clipboard-preview img {
      max-width: 100%;
      max-height: 100%;
      object-fit: contain;
    }

    .tutorial-modal__clipboard-text {
      font-family: var(--font-sans);
      font-size: 13px;
      font-weight: 600;
      color: var(--color-purple);
      margin-bottom: 12px;
    }

    .tutorial-modal__actions {
      display: flex;
      flex-direction: column;
      gap: 10px;
    }

    .tutorial-modal__btn {
      width: 100%;
      padding: 14px 24px;
      border: none;
      border-radius: 14px;
      font-family: var(--font-sans);
      font-size: 15px;
      font-weight: 600;
      cursor: pointer;
      transition: transform 0.15s ease, box-shadow 0.15s ease;
    }

    .tutorial-modal__btn--primary {
      background: var(--gradient-primary);
      color: white;
    }

    .tutorial-modal__btn--primary:hover {
      transform: translateY(-1px);
      box-shadow: 0 4px 12px rgba(138, 43, 226, 0.3);
    }

    .tutorial-modal__btn--clipboard {
      background: var(--color-turquoise);
      color: white;
      padding: 12px 20px;
    }

    .tutorial-modal__footnote {
      margin-top: 16px;
      font-family: var(--font-sans);
      font-size: 11px;
      color: #999;
      text-align: center;
    }

    /* ========== EDITOR BOTTOM BAR ========== */
    /* Transparent bar — buttons float on black background */
    .editor-bottom-bar {
      position: fixed;
      bottom: calc(6px + env(safe-area-inset-bottom, 0px));
      left: 16px;
      right: 16px;
      height: 56px;
      padding-bottom: 0;
      background: transparent;
      border: none;
      box-shadow: none;
      border-radius: 0;
      display: none; /* Hidden by default */
      justify-content: space-between;
      padding: 0 24px;
      align-items: center;
      z-index: 9000;
    }

    /* Show editor bar in edit mode when active (not in empty state) */
    body.edit-mode .editor-bottom-bar.active {
      display: flex;
    }

    .editor-btn-squircle {
      width: 44px;
      height: 44px;
      border-radius: 50%;
      background: #6D28D9 !important;
      border: 2.5px solid transparent !important;
      box-shadow: none !important;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: transform 0.15s ease, border-color 0.15s ease;
      padding: 0;
      -webkit-tap-highlight-color: transparent;
    }

    .editor-btn-squircle.active-control {
      border: 2.5px solid #fff !important;
    }

    .editor-btn-squircle:active {
      transform: scale(0.92);
    }

    .editor-btn-squircle svg {
      pointer-events: none;
    }

    /* ========== MODAL SPRING ANIMATION ========== */
    @keyframes modalSpringIn {
      0% { transform: scale(0.85); opacity: 0; }
      60% { transform: scale(1.02); opacity: 1; }
      100% { transform: scale(1); opacity: 1; }
    }

    /* Apply spring animation only when .animate-in is added */
    .drawer-modal.animate-in {
      animation: modalSpringIn 300ms ease-out forwards;
    }

    /* Close animation: simple fade out */
    .drawer-overlay.closing .drawer-modal {
      transition: opacity 150ms ease-out;
      opacity: 0;
    }

    /* ========== GLASS EFFECT FOR FOOTER BUTTONS ========== */
    .drawer-backgrounds-footer .bg-control-btn:not(.bg-style-btn):not(.bg-orient-btn) {
      background: rgba(255, 255, 255, 0.35);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
      border: 1px solid rgba(255, 255, 255, 0.25);
      color: var(--color-text-primary, #1a1a1a);
    }

    .drawer-backgrounds-footer .bg-color-btn {
      background: rgba(255, 255, 255, 0.35);
      backdrop-filter: blur(12px);
      -webkit-backdrop-filter: blur(12px);
    }

    /* bg-style-btn and bg-orient-btn use turquoise squircle styling - no glass override */

    /* ========== SAVE MODAL ========== */
    .save-modal {
      max-height: auto;
      height: auto;
    }

    .save-modal-body {
      padding: 16px;
      display: flex;
      flex-direction: column;
      gap: 10px;
      overflow: visible;
    }

    .save-modal-btn {
      width: 100%;
      padding: 14px 20px;
      border: none;
      border-radius: var(--radius-pill, 24px);
      font-size: 15px;
      font-weight: 600;
      font-family: var(--font-primary, system-ui, sans-serif);
      cursor: pointer;
      transition: transform 0.15s ease, opacity 0.15s ease;
      -webkit-tap-highlight-color: transparent;
    }

    .save-modal-btn:active {
      transform: scale(0.96);
    }

    .save-modal-btn--primary {
      background: var(--color-turquoise, #14b8a6);
      color: white;
    }

    .save-modal-btn--secondary {
      background: rgba(0, 0, 0, 0.06);
      color: var(--color-text-primary, #1a1a1a);
      border: 1px solid rgba(0, 0, 0, 0.1);
    }

    .save-modal-btn--danger {
      background: transparent;
      color: #ef4444;
    }

    .save-modal-btn--danger:hover {
      background: rgba(239, 68, 68, 0.08);
    }

    /* ========== DARK MODE ========== */
    @media (prefers-color-scheme: dark) {
      /* Only color buttons get dark mode glass treatment - style/orient keep turquoise */
      /* NOTE: Do NOT set border here - it's controlled by active-control class */
      .drawer-backgrounds-footer .bg-color-btn {
        background: rgba(255, 255, 255, 0.12);
      }
      .bg-hex-input {
        background: #1c1c1e;
        color: #ffffff;
        border-color: #3a3a3c;
      }
    }
