    
        :root {
            --bg-color: #050505;
            --accent-cyan: #00ffcc;
            --accent-pink: #ff00ff;
            --accent-yellow: #f1c40f;
            --glass-bg: rgba(255, 255, 255, 0.04);
            --tool-bg: rgba(20, 20, 20, 0.94);
            --border-thin: 1px solid rgba(255, 255, 255, 0.18);
            --paper: #ffffff;
            --ink: #1a1a1a;
        }

        * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

        html, body {
            margin: 0;
            background-color: var(--bg-color);
            background-image:
                linear-gradient(rgba(0, 255, 204, 0.03) 1px, transparent 1px),
                linear-gradient(90deg, rgba(0, 255, 204, 0.03) 1px, transparent 1px);
            background-size: 40px 40px;
            color: #fff;
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            overflow: hidden;
            overscroll-behavior: none;
            user-select: none;
            -webkit-user-select: none;
        }

        body {
            display: flex;
            flex-direction: column;
            height: 100vh;
            height: 100dvh;
            padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
        }

        header.top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 0.4rem;
            padding: 0.35rem 0.7rem;
            border-bottom: var(--border-thin);
            flex-shrink: 0;
            min-height: 44px;
        }

        header.top h1 {
            font-size: clamp(1rem, 4vw, 1.4rem);
            margin: 0;
            font-weight: 900;
            background: linear-gradient(to bottom, #fff 60%, var(--accent-cyan));
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
            filter: drop-shadow(2px 2px 0 var(--accent-pink));
            letter-spacing: 1px;
            white-space: nowrap;
            text-align: center;
            flex: 1;
        }

        .back, .rotate-btn {
            color: var(--accent-cyan);
            text-decoration: none;
            font-family: monospace;
            font-size: 0.85rem;
            padding: 0.4rem 0.65rem;
            border: 1px solid var(--accent-cyan);
            border-radius: 8px;
            white-space: nowrap;
            min-height: 40px;
            min-width: 40px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            touch-action: manipulation;
            background: transparent;
            cursor: pointer;
            line-height: 1;
        }
        .rotate-btn .ico {
            font-size: 1.4rem;
            display: inline-block;
            transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        }
        .rotate-btn.spin .ico { transform: rotate(360deg); }
        .back:active, .rotate-btn:active {
            background: var(--accent-cyan);
            color: #000;
            box-shadow: 0 0 12px var(--accent-cyan);
        }

        .stage {
            position: relative;
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 0.5rem;
            min-height: 0;
            overflow: hidden;
        }

        .paper-frame {
            width: 100%;
            height: 100%;
            box-sizing: border-box;
            padding: 10px;
            border-radius: 14px;
            position: relative;
            display: flex;
            align-items: center;
            justify-content: center;
            transition: background 0.25s, box-shadow 0.25s;
        }

        .paper {
            position: relative;
            background: var(--paper);
            border-radius: 6px;
            box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
            overflow: hidden;
            aspect-ratio: 4 / 3;
            max-width: 100%;
            max-height: 100%;
            width: auto;
            height: auto;
        }
        .paper.landscape { aspect-ratio: 4 / 3; }
        .paper.portrait { aspect-ratio: 3 / 4; }

        #template-svg, #canvas {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            display: block;
        }
        #canvas { touch-action: none; cursor: crosshair; }
        #template-svg { pointer-events: none; }

        #canvas.flipping {
            animation: flipPage 0.6s forwards;
            pointer-events: none !important;
        }
        @keyframes flipPage {
            0%     { transform: translateY(0) rotate(0deg); animation-timing-function: cubic-bezier(0.55, 0.085, 0.68, 0.53); }
            50%    { transform: translateY(-115%) rotate(-3deg); animation-timing-function: linear; }
            50.5%  { transform: translateY(115%) rotate(0deg); animation-timing-function: cubic-bezier(0.2, 0.8, 0.2, 1); }
            100%   { transform: translateY(0) rotate(0deg); }
        }
        .paper.pulse::after {
            content: '';
            position: absolute;
            inset: 0;
            border-radius: 6px;
            box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.6);
            animation: pulseRing 0.45s ease-out forwards;
            pointer-events: none;
        }
        @keyframes pulseRing {
            0%   { box-shadow: 0 0 0 0 rgba(241, 196, 15, 0.7); }
            100% { box-shadow: 0 0 0 14px rgba(241, 196, 15, 0); }
        }

        /* === Toolbar === */
        .toolbar {
            display: flex;
            flex-direction: column;
            background: var(--tool-bg);
            backdrop-filter: blur(14px);
            -webkit-backdrop-filter: blur(14px);
            border-top: var(--border-thin);
            flex-shrink: 0;
            padding-bottom: env(safe-area-inset-bottom);
        }

        .panel-area {
            position: relative;
            min-height: 70px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        }
        .panel {
            display: none;
            padding: 8px 6px;
            flex-direction: column;
            gap: 6px;
        }
        .panel.active { display: flex; }

        .row {
            display: flex;
            gap: 6px;
            align-items: center;
            justify-content: center;
            flex-wrap: wrap;
        }

        .palette {
            display: flex;
            gap: 8px;
            overflow-x: auto;
            overflow-y: hidden;
            padding: 4px 4px 6px;
            scroll-snap-type: x proximity;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: thin;
            scrollbar-color: rgba(0, 255, 204, 0.4) transparent;
        }
        .palette::-webkit-scrollbar { height: 4px; }
        .palette::-webkit-scrollbar-track { background: transparent; }
        .palette::-webkit-scrollbar-thumb { background: rgba(0, 255, 204, 0.35); border-radius: 2px; }

        .swatch {
            width: 44px;
            height: 44px;
            min-width: 44px;
            border-radius: 50%;
            border: 3px solid rgba(255, 255, 255, 0.25);
            background: var(--c);
            cursor: pointer;
            padding: 0;
            transition: transform 0.1s, box-shadow 0.15s, border-color 0.15s;
            touch-action: manipulation;
            scroll-snap-align: center;
            box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
        }
        .swatch.active {
            border-color: var(--accent-cyan);
            transform: scale(1.12);
            box-shadow: 0 0 14px var(--accent-cyan), 0 2px 6px rgba(0, 0, 0, 0.4);
        }
        .swatch:active { transform: scale(0.92); }
        .swatch.active:active { transform: scale(1.05); }

        .sizes {
            display: flex;
            gap: 6px;
            padding: 0 4px;
            border-right: 1px solid rgba(255, 255, 255, 0.1);
            margin-right: 4px;
        }

        .size-btn {
            width: 48px;
            height: 48px;
            min-width: 48px;
            border-radius: 12px;
            border: 2px solid rgba(255, 255, 255, 0.25);
            background: rgba(255, 255, 255, 0.05);
            color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            padding: 0;
            touch-action: manipulation;
            transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
            font-weight: 700;
            font-size: 0.9rem;
            font-family: 'Inter', sans-serif;
        }
        .size-btn .dot { background: #fff; border-radius: 50%; display: block; }
        .size-btn[data-size="4"] .dot { width: 8px; height: 8px; }
        .size-btn[data-size="14"] .dot { width: 18px; height: 18px; }
        .size-btn[data-size="30"] .dot { width: 28px; height: 28px; }
        .size-btn.active {
            border-color: var(--accent-cyan);
            background: rgba(0, 255, 204, 0.14);
            box-shadow: 0 0 10px rgba(0, 255, 204, 0.55);
        }
        .size-btn:active { transform: scale(0.92); }

        .tool-btn {
            min-height: 48px;
            min-width: 48px;
            padding: 4px 10px;
            background: rgba(255, 255, 255, 0.05);
            border: 2px solid rgba(255, 255, 255, 0.25);
            color: #fff;
            border-radius: 12px;
            font-family: 'Inter', sans-serif;
            font-size: 0.85rem;
            font-weight: 700;
            cursor: pointer;
            touch-action: manipulation;
            display: inline-flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 2px;
            line-height: 1.1;
            transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s, color 0.15s;
        }
        .tool-btn .ico { font-size: 1.4rem; line-height: 1; display: block; }
        .tool-btn .lbl { font-size: 0.65rem; letter-spacing: 0.5px; text-transform: uppercase; }
        .tool-btn:active { transform: scale(0.94); }
        .tool-btn.active {
            border-color: var(--accent-cyan);
            color: var(--accent-cyan);
            background: rgba(0, 255, 204, 0.12);
            box-shadow: 0 0 12px rgba(0, 255, 204, 0.55);
        }
        .tool-btn.primary {
            border-color: var(--accent-pink);
            color: var(--accent-pink);
            background: rgba(255, 0, 255, 0.08);
        }
        .tool-btn.primary:active {
            background: var(--accent-pink);
            color: #000;
            box-shadow: 0 0 16px var(--accent-pink);
        }
        .tool-btn.newpage {
            border-color: rgba(241, 196, 15, 0.75);
            color: #ffe066;
            background: rgba(241, 196, 15, 0.1);
        }
        .tool-btn.newpage:active {
            background: var(--accent-yellow);
            color: #000;
            box-shadow: 0 0 16px var(--accent-yellow);
        }

        /* === Thumbnail strips === */
        .thumbs {
            display: flex;
            gap: 8px;
            overflow-x: auto;
            overflow-y: hidden;
            padding: 4px 4px 6px;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: thin;
            scrollbar-color: rgba(0, 255, 204, 0.4) transparent;
            min-height: 60px;
        }
        .thumbs::-webkit-scrollbar { height: 4px; }
        .thumbs::-webkit-scrollbar-thumb { background: rgba(0, 255, 204, 0.35); border-radius: 2px; }

        .page-thumb {
            width: 60px;
            height: 50px;
            min-width: 60px;
            background: #fff;
            border: 2px solid rgba(255, 255, 255, 0.25);
            border-radius: 8px;
            cursor: pointer;
            padding: 4px;
            transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
            touch-action: manipulation;
            display: flex;
            align-items: center;
            justify-content: center;
            position: relative;
            flex-shrink: 0;
        }
        .page-thumb svg { width: 100%; height: 100%; }
        .page-thumb.active {
            border-color: var(--accent-cyan);
            box-shadow: 0 0 12px var(--accent-cyan);
            transform: scale(1.05);
        }
        .page-thumb:active { transform: scale(0.95); }
        .page-thumb.empty {
            background: repeating-linear-gradient(45deg, #f5f5f5, #f5f5f5 6px, #fff 6px, #fff 12px);
            color: #888;
            font-size: 0.7rem;
            font-weight: 700;
        }

        .frame-thumb {
            width: 60px;
            height: 50px;
            min-width: 60px;
            border: 2px solid rgba(255, 255, 255, 0.25);
            border-radius: 8px;
            cursor: pointer;
            padding: 4px;
            transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
            touch-action: manipulation;
            position: relative;
            flex-shrink: 0;
            overflow: hidden;
            background: rgba(255, 255, 255, 0.04);
        }
        .frame-thumb-inner {
            width: 100%;
            height: 100%;
            border-radius: 4px;
            padding: 5px;
            box-sizing: border-box;
            position: relative;
        }
        .frame-thumb-paper {
            background: #fff;
            width: 100%;
            height: 100%;
            border-radius: 2px;
        }
        .frame-thumb.active {
            border-color: var(--accent-cyan);
            box-shadow: 0 0 12px var(--accent-cyan);
            transform: scale(1.05);
        }
        .frame-thumb:active { transform: scale(0.95); }

        /* === Tabs row (bottom) === */
        .tabs-row {
            display: flex;
            gap: 4px;
            padding: 6px;
            overflow-x: auto;
            overflow-y: hidden;
            -webkit-overflow-scrolling: touch;
            scrollbar-width: none;
            justify-content: center;
        }
        .tabs-row::-webkit-scrollbar { display: none; }

        .tab-btn {
            min-height: 50px;
            min-width: 56px;
            padding: 4px 10px;
            background: rgba(255, 255, 255, 0.04);
            border: 2px solid rgba(255, 255, 255, 0.2);
            color: rgba(255, 255, 255, 0.85);
            border-radius: 12px;
            font-family: 'Inter', sans-serif;
            cursor: pointer;
            touch-action: manipulation;
            display: inline-flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            gap: 2px;
            line-height: 1.1;
            transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s, color 0.15s, background 0.15s;
            flex-shrink: 0;
        }
        .tab-btn .ico { font-size: 1.25rem; line-height: 1; display: block; }
        .tab-btn .lbl {
            font-size: 0.62rem;
            letter-spacing: 0.5px;
            text-transform: uppercase;
            font-weight: 700;
        }
        .tab-btn:active { transform: scale(0.94); }
        .tab-btn.active {
            border-color: var(--accent-cyan);
            color: var(--accent-cyan);
            background: rgba(0, 255, 204, 0.14);
            box-shadow: 0 0 10px rgba(0, 255, 204, 0.5);
        }

        /* === 10 Frames + None === */
        /* All frames keep the same padding so the inner paper size is constant. */
        .paper-frame.frame-none {
            background: transparent;
        }
        .paper-frame.frame-rainbow {
            background: linear-gradient(135deg, #ff4d4d, #ff9933, #ffd633, #66cc66, #3399ff, #9966cc, #ff66b3);
            box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4) inset, 0 8px 24px rgba(0, 0, 0, 0.45);
        }
        .paper-frame.frame-dots {
            background:
                radial-gradient(circle, white 5px, transparent 6px) 0 0/22px 22px,
                #ff4fa3;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
        }
        .paper-frame.frame-stars {
            background:
                radial-gradient(circle, #ffd700 3px, transparent 4px) 0 0/24px 24px,
                radial-gradient(circle, #ffd700 2px, transparent 3px) 12px 12px/24px 24px,
                #0a1a4a;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
        }
        .paper-frame.frame-construction {
            background: #f4d03f;
            outline: 5px dashed #6b4f00;
            outline-offset: -8px;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
        }
        .paper-frame.frame-gold {
            background: linear-gradient(135deg, #b8860b 0%, #ffd700 25%, #fff7c0 50%, #ffd700 75%, #b8860b 100%);
            box-shadow: inset 0 0 0 3px #8b6914, 0 8px 24px rgba(0, 0, 0, 0.6);
        }
        .paper-frame.frame-scallops {
            background:
                radial-gradient(circle at 50% 0%, #ff66b3 9px, transparent 10px) 0 0/20px 10px,
                radial-gradient(circle at 50% 100%, #ff66b3 9px, transparent 10px) 0 100%/20px 10px,
                radial-gradient(circle at 0% 50%, #ff66b3 9px, transparent 10px) 0 0/10px 20px,
                radial-gradient(circle at 100% 50%, #ff66b3 9px, transparent 10px) 100% 0/10px 20px,
                #ffd6e8;
            background-repeat: repeat-x, repeat-x, repeat-y, repeat-y, no-repeat;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
        }
        .paper-frame.frame-clouds {
            background:
                radial-gradient(ellipse 38px 20px at 12% 0%, white 70%, transparent 71%),
                radial-gradient(ellipse 38px 20px at 50% 0%, white 70%, transparent 71%),
                radial-gradient(ellipse 38px 20px at 88% 0%, white 70%, transparent 71%),
                radial-gradient(ellipse 38px 20px at 12% 100%, white 70%, transparent 71%),
                radial-gradient(ellipse 38px 20px at 50% 100%, white 70%, transparent 71%),
                radial-gradient(ellipse 38px 20px at 88% 100%, white 70%, transparent 71%),
                radial-gradient(ellipse 20px 38px at 0% 50%, white 70%, transparent 71%),
                radial-gradient(ellipse 20px 38px at 100% 50%, white 70%, transparent 71%),
                #87ceeb;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
        }
        .paper-frame.frame-confetti {
            background:
                radial-gradient(circle at 8% 12%, #e74c3c 4px, transparent 5px),
                radial-gradient(circle at 28% 8%, #2ecc71 4px, transparent 5px),
                radial-gradient(circle at 50% 14%, #3498db 4px, transparent 5px),
                radial-gradient(circle at 72% 6%, #f1c40f 4px, transparent 5px),
                radial-gradient(circle at 92% 18%, #ff66cc 4px, transparent 5px),
                radial-gradient(circle at 6% 88%, #f39c12 4px, transparent 5px),
                radial-gradient(circle at 32% 92%, #9b59b6 4px, transparent 5px),
                radial-gradient(circle at 64% 86%, #00ffcc 4px, transparent 5px),
                radial-gradient(circle at 88% 94%, #e74c3c 4px, transparent 5px),
                radial-gradient(circle at 4% 50%, #f1c40f 3px, transparent 4px),
                radial-gradient(circle at 96% 50%, #2ecc71 3px, transparent 4px),
                #1a1a2e;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
        }
        .paper-frame.frame-layers {
            background: #ff6b6b;
            box-shadow:
                inset 0 0 0 3px #ffe66d,
                inset 0 0 0 6px #4ecdc4,
                inset 0 0 0 9px #ffe66d,
                0 8px 24px rgba(0, 0, 0, 0.45);
        }
        .paper-frame.frame-spotlight {
            background: radial-gradient(ellipse at center, #fff8b0 0%, #ffe066 50%, #f1c40f 100%);
            box-shadow: 0 8px 24px rgba(241, 196, 15, 0.6);
        }

        .frame-thumb-inner.frame-none { background: transparent; padding: 0; border: 1px dashed rgba(255, 255, 255, 0.4); }
        .frame-thumb-inner.frame-rainbow { background: linear-gradient(135deg, #ff4d4d, #ff9933, #ffd633, #66cc66, #3399ff, #9966cc, #ff66b3); }
        .frame-thumb-inner.frame-dots { background: radial-gradient(circle, white 2px, transparent 3px) 0 0/9px 9px, #ff4fa3; }
        .frame-thumb-inner.frame-stars { background: radial-gradient(circle, #ffd700 1.5px, transparent 2px) 0 0/9px 9px, #0a1a4a; }
        .frame-thumb-inner.frame-construction { background: #f4d03f; outline: 2px dashed #6b4f00; outline-offset: -4px; }
        .frame-thumb-inner.frame-gold { background: linear-gradient(135deg, #b8860b, #ffd700, #fff7c0, #ffd700, #b8860b); }
        .frame-thumb-inner.frame-scallops { background: #ff66b3; }
        .frame-thumb-inner.frame-clouds { background: #87ceeb; }
        .frame-thumb-inner.frame-confetti {
            background:
                radial-gradient(circle at 20% 20%, #e74c3c 1.5px, transparent 2px),
                radial-gradient(circle at 60% 30%, #2ecc71 1.5px, transparent 2px),
                radial-gradient(circle at 80% 70%, #3498db 1.5px, transparent 2px),
                radial-gradient(circle at 30% 80%, #f1c40f 1.5px, transparent 2px),
                radial-gradient(circle at 70% 50%, #ff66cc 1.5px, transparent 2px),
                #1a1a2e;
        }
        .frame-thumb-inner.frame-layers {
            background: #ff6b6b;
            box-shadow: inset 0 0 0 1.5px #ffe66d, inset 0 0 0 3px #4ecdc4;
        }
        .frame-thumb-inner.frame-spotlight { background: radial-gradient(ellipse at center, #fff8b0, #ffe066, #f1c40f); }

        @media (max-width: 420px) {
            header.top { padding: 0.25rem 0.55rem; min-height: 40px; }
            header.top h1 { font-size: 0.95rem; }
            .back, .rotate-btn { font-size: 0.75rem; padding: 0.35rem 0.5rem; min-height: 36px; min-width: 36px; }
            .swatch { width: 40px; height: 40px; min-width: 40px; }
            .size-btn { width: 44px; height: 44px; min-width: 44px; }
            .tool-btn { min-height: 44px; min-width: 44px; padding: 3px 7px; }
            .tool-btn .ico { font-size: 1.2rem; }
            .tool-btn .lbl { font-size: 0.58rem; }
            .tab-btn { min-height: 46px; min-width: 50px; padding: 3px 6px; }
            .tab-btn .ico { font-size: 1.1rem; }
            .tab-btn .lbl { font-size: 0.55rem; }
            .stage { padding: 0.3rem; }
            .panel { padding: 6px 4px; }
            .panel-area { min-height: 64px; }
            .page-thumb, .frame-thumb { width: 54px; height: 46px; min-width: 54px; }
            .paper-frame { padding: 8px; }
            .paper-frame.frame-construction { outline-offset: -6px; }
        }

        @media (orientation: landscape) and (max-height: 500px) {
            header.top h1 { font-size: 0.9rem; }
            .stage { padding: 0.3rem; }
            .panel { padding: 4px 4px; }
            .panel-area { min-height: 56px; }
            .swatch { width: 36px; height: 36px; min-width: 36px; }
            .size-btn { width: 40px; height: 40px; min-width: 40px; }
            .tool-btn { min-height: 40px; min-width: 40px; padding: 2px 6px; }
            .tool-btn .ico { font-size: 1.1rem; }
            .tab-btn { min-height: 40px; }
            .page-thumb, .frame-thumb { width: 48px; height: 40px; min-width: 48px; }
            .paper-frame { padding: 6px; }
            .paper-frame.frame-construction { outline-offset: -4px; }
        }
