        * {
            box-sizing: border-box;
        }
        :root{
            --controls-w: 280px;
            --controls-w-md: 240px;
            --sheet-max-h: min(70dvh, 520px);
        }
        html, body {
            height: 100%;
            margin: 0;
            overflow: hidden;
        }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f8f9fa;
        }
        .dropzone {
            display: block;
            border: 2px dashed #cbd5e1;
            border-radius: 10px;
            padding: 14px;
            text-align: center;
            margin-bottom: 10px;
            cursor: pointer;
            background: #fff;
            transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
            outline: none;
        }
        #rdDrop {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            gap: 4px;
            text-align: left;
        }
        .dropzone-instruction {
            flex: 0 0 auto;
            font-size: 12px;
            color: #475569;
            width: 100%;
        }
        .dropzone-filename {
            flex: 1 1 auto;
            text-align: left;
            font-size: 12px;
            color: #1f2937;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            display: none;
            width: 100%;
        }
        .has-file .dropzone-filename {
            display: block;
        }
        #assetsDrop {
            display: flex;
            flex-direction: column;
            align-items: flex-start;
            gap: 4px;
            text-align: left;
            font-size: 12px;
            color: #475569;
        }
        .dropzone:focus-visible {
            border-color: #0d6efd;
            box-shadow: 0 0 0 3px rgba(13,110,253,0.35);
        }
        .dropzone.is-dragover {
            border-color: #0d6efd;
            background: #e7f1ff;
        }
        .preview-images {
            display: flex;
            flex-wrap: wrap;
            gap: 8px;
            margin-top: 4px;
        }
        .preview-img {
            width: 30px;
            height: 30px;
            object-fit: contain;
            border: 1px solid #dee2e6;
            border-radius: 4px;
            background: white;
        }
        .editor-section {
            display: grid;
            grid-template-columns: 1fr;
            gap: 10px;
            height: 100%;
            padding: 8px;
            box-sizing: border-box;
        }
        .canvas-container {
            border: 1px solid #dee2e6;
            border-radius: 8px;
            position: relative;
            overflow: hidden;
            background: #f8f9fa;
            box-shadow: 0 2px 6px rgba(0,0,0,0.08);
        }
        .canvas-scroll {
            height: 100%;
            overflow: auto;
            -webkit-overflow-scrolling: touch;
            overscroll-behavior: contain;
            touch-action: pan-y;
            /* Center the scaled content horizontally */
            display: flex;
            justify-content: center;
            align-items: flex-start;
            position: relative;
        }
        .pages-container {
            display: flex;
            flex-direction: column;
            gap: 15px;
            padding: 15px;
            align-items: center;
            transform-origin: center top;
            transition: transform 0.2s ease;
        }
        .empty-state {
            text-align: center;
            color: #6c757d;
            font-size: 14px;
            padding: 40px 20px;
            max-width: 360px;
        }
        .empty-state p {
            margin: 8px 0 0;
        }
        .page-wrapper {
            position: relative;
            border: 2px solid #dee2e6;
            border-radius: 8px;
            padding: 10px;
            background: white;
            box-shadow: 0 3px 8px rgba(0,0,0,0.08);
            transition: all 0.2s ease;
            cursor: pointer;
            outline: none;
        }
        .page-wrapper:hover {
            box-shadow: 0 4px 12px rgba(0,0,0,0.12);
            transform: translateY(-1px);
        }
        .page-wrapper.active {
            border-color: #007bff;
            box-shadow: 0 0 0 3px rgba(0,123,255,0.25);
        }
        .page-wrapper:focus-visible {
            border-color: #0d6efd;
            box-shadow: 0 0 0 3px rgba(13,110,253,0.35);
        }
        .page-wrapper canvas {
            max-width: 100%;
            height: auto;
            display: block;
            border-radius: 4px;
            touch-action: pan-y;
        }
        .page-label {
            position: absolute;
            top: -8px;
            left: 12px;
            background: linear-gradient(135deg, #007bff, #0056b3);
            color: white;
            padding: 4px 12px;
            border-radius: 12px;
            font-size: 11px;
            font-weight: 600;
            box-shadow: 0 2px 6px rgba(0,123,255,0.3);
        }
        .controls {
            background: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 2px 6px rgba(0,0,0,0.08);
            height: fit-content;
        }
        .controls h4 {
            margin: 0 0 10px 0;
            color: #343a40;
            font-size: 14px;
            font-weight: 600;
            border-bottom: 1px solid #e9ecef;
            padding-bottom: 6px;
        }
        .controls-group {
            margin-bottom: 15px;
        }
        .btn {
            background: linear-gradient(135deg, #007bff, #0056b3);
            color: white;
            border: none;
            padding: 8px 12px;
            border-radius: 6px;
            cursor: pointer;
            margin: 2px 0;
            width: 100%;
            font-weight: 500;
            transition: all 0.2s;
            box-shadow: 0 2px 4px rgba(0,123,255,0.3);
            font-size: 13px;
        }
        .btn:hover:not(:disabled) {
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(0,123,255,0.4);
        }
        .btn:active {
            transform: translateY(0);
        }
        .btn:disabled {
            background: #6c757d;
            cursor: not-allowed;
            box-shadow: none;
        }
        .btn-success {
            background: linear-gradient(135deg, #28a745, #1e7e34);
            box-shadow: 0 2px 4px rgba(40,167,69,0.3);
        }
        .btn-success:hover {
            box-shadow: 0 4px 8px rgba(40,167,69,0.4);
        }
        .btn-danger {
            background: linear-gradient(135deg, #dc3545, #c82333);
            box-shadow: 0 2px 4px rgba(220,53,69,0.3);
        }
        .load-btn {
            background: linear-gradient(135deg, #17a2b8, #138496);
            color: white;
            border: none;
            padding: 8px 16px;
            border-radius: 6px;
            cursor: pointer;
            font-weight: 600;
            box-shadow: 0 2px 6px rgba(23,162,184,0.3);
            transition: all 0.2s;
            font-size: 13px;
            white-space: nowrap;
        }
        .load-btn:hover {
            transform: translateY(-1px);
            box-shadow: 0 4px 8px rgba(23,162,184,0.4);
        }
        #progress {
            display: none;
            margin: 10px 0;
            text-align: center;
        }
        .progress-bar {
            width: 100%;
            height: 6px;
            background-color: #e9ecef;
            border-radius: 3px;
            overflow: hidden;
            margin: 8px 0;
        }
        .progress-fill {
            height: 100%;
            background: linear-gradient(90deg, #007bff, #0056b3);
            border-radius: 3px;
            transition: width 0.3s ease;
            width: 0%;
        }
        .error-message {
            background: linear-gradient(135deg, #f8d7da, #f5c6cb);
            color: #721c24;
            padding: 10px;
            border-radius: 6px;
            margin: 8px 0;
            display: none;
            border-left: 3px solid #dc3545;
            font-size: 13px;
            animation: shake 0.5s ease-in-out;
        }
        .hotkeys-info {
            background: #e3f2fd;
            padding: 8px;
            border-radius: 6px;
            font-size: 11px;
            color: #1565c0;
            border-left: 3px solid #2196f3;
            line-height: 1.3;
        }
        .zoom-controls {
            position: absolute;
            top: 10px;
            right: 10px;
            display: flex;
            gap: 5px;
            background: rgba(255,255,255,0.9);
            padding: 5px;
            border-radius: 6px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        .zoom-btn {
            width: 44px;
            height: 44px;
            border: none;
            background: #007bff;
            color: white;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .zoom-btn.active {
            background: #28a745;
        }
        .zoom-level {
            display: flex;
            align-items: center;
            font-size: 11px;
            color: #495057;
            padding: 0 5px;
        }
        .btn-warning {
            background: linear-gradient(135deg, #ffc107, #e0a800);
            box-shadow: 0 2px 4px rgba(255,193,7,0.3);
            color: #212529;
        }
        .btn.grid-toggle[aria-pressed="true"] {
            background: linear-gradient(135deg, #17a2b8, #138496);
            box-shadow: 0 2px 4px rgba(23,162,184,0.35);
        }
        .btn.snap-toggle[aria-pressed="true"] {
            background: linear-gradient(135deg, #28a745, #1e7e34);
            box-shadow: 0 2px 4px rgba(40,167,69,0.35);
        }
        .button-row {
            display: flex;
            gap: 8px;
            margin: 2px 0;
        }
        .button-row .btn {
            flex: 1;
            width: auto;
        }
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 12px 20px;
            background: #28a745;
            color: white;
            border-radius: 6px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.2);
            transform: translateX(calc(100% + 40px));
            transition: transform 0.3s ease;
            z-index: 1000;
            max-width: 400px;
            word-wrap: break-word;
        }
        .notification.show {
            transform: translateX(0);
        }
        .notification.error {
            background: #dc3545;
        }
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            25% { transform: translateX(-5px); }
            75% { transform: translateX(5px); }
        }
        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }
        .element-copying {
            animation: pulse 0.3s ease-in-out;
        }
    
.preview-images img { max-height: 48px; height: auto; width: auto; object-fit: contain; border: 1px solid #dee2e6; border-radius: 4px; background: white; }


.asset-thumb {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  background: #fff;
  flex: 1 1 calc(33.333% - 8px);
  max-width: calc(33.333% - 8px);
  min-width: 120px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.asset-thumb img {
  display: block;
  max-height: 48px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  background: white;
  flex-shrink: 0;
}
.asset-thumb .del-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid #888;
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.asset-thumb .del-btn:hover {
  background: #f8d7da;
}


        summary::-webkit-details-marker {
            display: none;
        }
        summary::marker {
            content: '';
        }
        .controls details{
            margin-bottom: 12px;
        }
        .controls summary{
            font-weight: 600;
            color: #343a40;
            font-size: 14px;
            display: block;
            margin-bottom: 8px;
            padding-bottom: 6px;
            border-bottom: 1px solid #e9ecef;
        }
        .overlay[hidden] {
            display: none;
        }
        .overlay {
            display: none;
        }
        .fab {
            display: none;
        }
        .canvas-scroll{
            height: 100%;
        }
        @media (min-width:1024px){
          .editor-section{ grid-template-columns: 1fr var(--controls-w); }
          .controls{ position: sticky; top: 0; max-height: 100%; overflow:auto; }
        }
        @media (min-width:768px) and (max-width:1023.98px){
          .editor-section{ grid-template-columns: 1fr var(--controls-w-md); }
          .controls .btn{ inline-size: 100%; }
          .controls-group{ margin-bottom: 12px; }
          .hotkeys-info{ display:none; }
        }
        @media (max-width:767.98px){
          .editor-section{ grid-template-columns: 1fr; }
          .controls{
            position: fixed; left: 0; right: 0; bottom: 0; z-index: 1001;
            max-height: var(--sheet-max-h); height: auto; overflow:auto;
            border-top-left-radius: 12px; border-top-right-radius: 12px;
            box-shadow: 0 -8px 24px rgba(0,0,0,.18);
            transform: translateY(100%); transition: transform .28s ease;
            will-change: transform; padding-bottom: max(12px, env(safe-area-inset-bottom));
            background: #fff;
          }
          .controls.open{ transform: translateY(0); }
          .overlay{
            position: fixed; inset: 0; background: rgba(0,0,0,.32); z-index: 1000; display:block;
          }
          .fab{
            position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom));
            inline-size: 52px; block-size: 52px; border-radius: 50%;
            border: none; box-shadow: 0 6px 18px rgba(0,0,0,.2); font-size: 22px;
            background: linear-gradient(135deg,#007bff,#0056b3); color:#fff; z-index:1002;
            display: inline-flex; align-items: center; justify-content: center;
          }
          .hotkeys-info{ display:none; }
          .controls .btn{ font-size: 14px; padding: 10px; }
          .controls .controls-group{ margin-bottom: 12px; }
          .controls details:nth-of-type(2) .btn,
          .controls details:nth-of-type(3) .btn{
            width:auto; display:inline-block; inline-size: calc(50% - 6px); margin-right: 8px;
          }
        }
        /* Канвас-область — на всю высоту родителя */
        @media (max-width:767.98px){
          .pages-container{ padding: 12px; gap: 12px; }
          .page-wrapper{ padding: 6px; }
        }
        @media (max-width:767.98px){
          .zoom-controls{ top: auto; bottom: 12px; right: 12px; }
          .asset-thumb .del-btn{ width:28px; height:28px; font-size:14px; }
        }
        @media (max-width:767.98px){
          .controls details{ border:1px solid #e9ecef; border-radius:10px; padding:8px 10px; margin-bottom:8px; }
          .controls summary{ cursor:pointer; font-weight:600; border-bottom:none; margin-bottom:8px; padding:0; }
        }
        @media (min-width:768px){
          .controls details{ border:none; padding:0; }
          .controls summary{ list-style:none; cursor: default; }
          .controls details[open] > .controls-group{ margin-top:8px; }
        }

        @media (prefers-reduced-motion: reduce) {
          *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
            scroll-behavior: auto !important;
          }
        }

        @media (forced-colors: active) {
          body {
            background: Canvas;
            color: CanvasText;
          }
          .page-wrapper,
          .controls,
          .dropzone {
            border-color: CanvasText;
          }
          .btn {
            border: 1px solid CanvasText;
            box-shadow: none;
          }
        }

        /* Hint overlay */
        .hint-overlay {
            position: fixed;
            inset: 0;
            background: rgba(0, 0, 0, 0.5);
            z-index: 9998;
            display: none;
            animation: hintOverlayFadeIn 0.3s ease-out;
        }

        .hint-overlay.active {
            display: block;
        }

        .hint-overlay.fade-out {
            animation: hintOverlayFadeOut 0.3s ease-in forwards;
        }

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

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

        /* Hint tooltips */
        .hint-tooltip {
            position: fixed;
            background: #fff;
            border: 2px solid #007bff;
            border-radius: 12px;
            padding: 16px 20px;
            box-shadow: 0 4px 20px rgba(0, 123, 255, 0.3);
            z-index: 9999;
            max-width: 320px;
            font-size: 15px;
            line-height: 1.5;
            color: #212529;
            animation: hintFadeIn 0.4s ease-out;
            pointer-events: auto;
        }

        .hint-tooltip::before {
            content: '';
            position: absolute;
            width: 0;
            height: 0;
            border-style: solid;
        }

        .hint-tooltip.arrow-right::before {
            right: 100%;
            top: 50%;
            transform: translateY(-50%);
            border-width: 10px 10px 10px 0;
            border-color: transparent #007bff transparent transparent;
        }

        .hint-tooltip.arrow-right::after {
            content: '';
            position: absolute;
            right: 100%;
            top: 50%;
            transform: translateY(-50%);
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 8px 8px 8px 0;
            border-color: transparent #fff transparent transparent;
            margin-right: -1px;
        }

        .hint-tooltip.arrow-left::before {
            left: 100%;
            top: 50%;
            transform: translateY(-50%);
            border-width: 10px 0 10px 10px;
            border-color: transparent transparent transparent #007bff;
        }

        .hint-tooltip.arrow-left::after {
            content: '';
            position: absolute;
            left: 100%;
            top: 50%;
            transform: translateY(-50%);
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 8px 0 8px 8px;
            border-color: transparent transparent transparent #fff;
            margin-left: -1px;
        }

        .hint-tooltip.arrow-up::before {
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            border-width: 10px 10px 0 10px;
            border-color: #007bff transparent transparent transparent;
        }

        .hint-tooltip.arrow-up::after {
            content: '';
            position: absolute;
            top: 100%;
            left: 50%;
            transform: translateX(-50%);
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 8px 8px 0 8px;
            border-color: #fff transparent transparent transparent;
            margin-top: -1px;
        }

        .hint-tooltip.arrow-down::before {
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            border-width: 0 10px 10px 10px;
            border-color: transparent transparent #007bff transparent;
        }

        .hint-tooltip.arrow-down::after {
            content: '';
            position: absolute;
            bottom: 100%;
            left: 50%;
            transform: translateX(-50%);
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 0 8px 8px 8px;
            border-color: transparent transparent #fff transparent;
            margin-bottom: -1px;
        }

        /* Стрелка вправо (динамическая позиция) */
        .hint-tooltip.arrow-right-dynamic::before {
            left: 100%;
            top: var(--arrow-top, 50%);
            transform: translateY(-50%);
            border-width: 10px 0 10px 20px;
            border-color: transparent transparent transparent #007bff;
        }

        .hint-tooltip.arrow-right-dynamic::after {
            content: '';
            position: absolute;
            left: 100%;
            top: var(--arrow-top, 50%);
            transform: translateY(-50%);
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 8px 0 8px 16px;
            border-color: transparent transparent transparent #fff;
            margin-left: -2px;
        }

        /* Стрелка вниз (динамическая позиция по горизонтали) */
        .hint-tooltip.arrow-down-dynamic::before {
            top: 100%;
            left: var(--arrow-left, 20px);
            border-width: 20px 10px 0 10px;
            border-color: #007bff transparent transparent transparent;
        }

        .hint-tooltip.arrow-down-dynamic::after {
            content: '';
            position: absolute;
            top: 100%;
            left: var(--arrow-left, 20px);
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 16px 8px 0 8px;
            border-color: #fff transparent transparent transparent;
            margin-top: -2px;
        }

        /* Стрелка вниз в левом нижнем углу (динамическая горизонтальная позиция) */
        .hint-tooltip.arrow-down-left::before {
            top: 100%;
            left: 20px;
            border-width: 20px 10px 0 10px;
            border-color: #007bff transparent transparent transparent;
        }

        .hint-tooltip.arrow-down-left::after {
            content: '';
            position: absolute;
            top: 100%;
            left: 20px;
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 16px 8px 0 8px;
            border-color: #fff transparent transparent transparent;
            margin-top: -2px;
        }

        /* Стрелка вниз в правом нижнем углу (динамическая горизонтальная позиция) */
        .hint-tooltip.arrow-down-right::before {
            top: 100%;
            right: 20px;
            border-width: 20px 10px 0 10px;
            border-color: #007bff transparent transparent transparent;
        }

        .hint-tooltip.arrow-down-right::after {
            content: '';
            position: absolute;
            top: 100%;
            right: 20px;
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 16px 8px 0 8px;
            border-color: #fff transparent transparent transparent;
            margin-top: -2px;
        }

        .hint-close {
            position: absolute;
            top: 8px;
            right: 8px;
            background: none;
            border: none;
            font-size: 18px;
            line-height: 1;
            cursor: pointer;
            color: #6c757d;
            padding: 0;
            width: 20px;
            height: 20px;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .hint-close:hover {
            color: #212529;
        }

        @keyframes hintFadeIn {
            from {
                opacity: 0;
                transform: translateY(-10px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        .hint-tooltip.hint-fade-out {
            animation: hintFadeOut 0.3s ease-in forwards;
        }

        @keyframes hintFadeOut {
            to {
                opacity: 0;
                transform: translateY(-10px);
            }
        }

        @media (max-width:767.98px){
            .hint-tooltip {
                max-width: 280px;
                font-size: 14px;
                padding: 14px 18px;
            }
        }


/* Spinner animation */
@keyframes spin { to { transform: rotate(360deg); } }
