:root {
            --black: #000000;
            --white: #ffffff;
            --gray-300: #b0b0b0;
            --gray-400: #808080;
            --gray-500: #555555;
            --gray-700: #1a1a1a;
            --shadow: 0 4px 20px rgba(0,0,0,0.4);
            --border: 2px solid #334155;
            --radius: 4px;
        }
* { box-sizing: border-box; }
body {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
            background: #0f172a;
            color: #e2e8f0;
            min-height: 100vh;
            margin: 0;
            padding: 40px 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }
.back-link {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            font-size: 11px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            color: #64748b;
            text-decoration: none;
            margin-bottom: 16px;
            transition: color 0.15s;
        }
.back-link:hover {
            color: #e2e8f0;
        }
.app {
            max-width: 600px;
            width: 100%;
        }
.label-text {
            font-size: 11px;
            font-weight: 700;
            letter-spacing: 3px;
            text-transform: uppercase;
            color: #94a3b8;
            margin-bottom: 12px;
            display: block;
        }
.mode-selector {
            margin-bottom: 20px;
        }
.mode-selector select {
            width: 100%;
            padding: 14px 20px;
            font-size: 13px;
            font-weight: 600;
            background: #1e293b;
            color: #e2e8f0;
            border: var(--border);
            border-radius: var(--radius);
            cursor: pointer;
            appearance: none;
            -webkit-appearance: none;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='M7 10L2.5 4.5h9z' fill='%23e2e8f0'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-position: right 16px center;
            font-family: inherit;
            transition: box-shadow 0.2s;
        }
.mode-selector select:focus {
            outline: none;
            box-shadow: 0 0 0 3px rgba(255,255,255,0.1);
        }
.mode-preview-container {
            margin-bottom: 24px;
        }
.mode-preview {
            background: var(--gray-700);
            padding: 20px;
            height: 140px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: var(--border);
            border-radius: var(--radius);
        }
.mode-preview-grid {
            display: grid;
            width: 100%;
            height: 100%;
            gap: 3px;
        }
.mode-preview-grid .cell {
            background: var(--gray-500);
            position: relative;
            overflow: hidden;
            border-radius: 1px;
        }
.mode-preview-grid .cell-tall { background: var(--gray-400); }
.mode-preview-grid .cell::after {
            content: '';
            position: absolute;
            top: 0;
            left: -100%;
            width: 200%;
            height: 100%;
            background: linear-gradient(90deg, transparent 0%, rgba(255,255,255,0.5) 40%, rgba(255,255,255,0.7) 50%, rgba(255,255,255,0.5) 60%, transparent 100%);
            animation: diagonalShine 2s ease-in-out infinite;
            transform: skewX(-20deg);
        }
.mode-preview-grid.morphing .cell {
            animation: cellMorph 0.7s ease-in-out;
        }
.mode-preview-grid.morphing .cell::after {
            opacity: 0;
            animation: none;
        }
@keyframes diagonalShine {
            0% { left: -100%; }
            100% { left: 200%; }
        }
@keyframes cellMorph {
            0% { transform: scale(0.8); opacity: 0.3; }
            100% { transform: scale(1); opacity: 1; }
        }
#template-area::before {
            content: '';
            position: absolute;
            inset: 0;
            background: repeating-linear-gradient(
                0deg,
                transparent,
                transparent 2px,
                rgba(0,0,0,0.015) 2px,
                rgba(0,0,0,0.015) 4px
            );
            pointer-events: none;
            z-index: 3;
        }
.generate-btn:not(:disabled) {
            position: relative;
            overflow: hidden;
        }
.generate-btn:not(:disabled)::after {
            content: '';
            position: absolute;
            inset: 0;
            background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
            transform: translateX(-100%);
            transition: none;
        }
.generate-btn:not(:disabled):hover::after {
            transform: translateX(100%);
            transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
        }
@keyframes dotPulse {
            0%, 20% { opacity: 0.2; }
            40% { opacity: 1; }
            60% { opacity: 0.4; }
            80%, 100% { opacity: 0.2; }
        }
.results-section.active .result-item {
            animation: resultFadeIn 0.4s ease-out forwards;
        }
.results-section.active .result-item:nth-child(1) { animation-delay: 0s; }
.results-section.active .result-item:nth-child(2) { animation-delay: 0.08s; }
.results-section.active .result-item:nth-child(3) { animation-delay: 0.16s; }
.results-section.active .result-item:nth-child(4) { animation-delay: 0.24s; }
@keyframes resultFadeIn {
            to { opacity: 1; transform: translateY(0); }
        }
.grid-2x2 { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.grid-horizontal { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr; }
.grid-vertical { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.grid-mixed-left { display: flex; gap: 3px; }
.grid-mixed-left .cell-tall { flex: 1; background: var(--gray-400); }
.grid-mixed-left .cell-group { flex: 1; display: grid; gap: 3px; grid-template-rows: 1fr 1fr; }
.checkbox-row {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 20px;
            cursor: pointer;
            padding: 4px 0;
        }
.checkbox-row input[type="checkbox"] {
            width: 20px;
            height: 20px;
            accent-color: #e2e8f0;
            cursor: pointer;
            border: var(--border);
            border-radius: 2px;
        }
.checkbox-label {
            font-size: 11px;
            font-weight: 600;
            color: #94a3b8;
            text-transform: uppercase;
            letter-spacing: 1.5px;
        }
.grid-options {
            display: none;
            margin: -12px 0 20px 0;
            padding: 16px;
            background: #1e293b;
            border: var(--border);
            border-radius: var(--radius);
        }
.grid-options.active { display: block; }
.grid-option-row {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 10px;
        }
.grid-option-row:last-child { margin-bottom: 0; }
.grid-option-label {
            font-size: 10px;
            font-weight: 600;
            color: #94a3b8;
            text-transform: uppercase;
            letter-spacing: 1px;
            min-width: 70px;
        }
.grid-option-value {
            font-size: 11px;
            font-weight: 600;
            color: #94a3b8;
            min-width: 36px;
            text-align: right;
        }
.grid-options input[type="color"] {
            width: 34px;
            height: 34px;
            border: var(--border);
            border-radius: var(--radius);
            cursor: pointer;
            padding: 2px;
            background: none;
        }
.grid-options input[type="range"] {
            flex: 1;
            accent-color: #e2e8f0;
            cursor: pointer;
            height: 6px;
        }
.upload-btn {
            background: #1e293b;
            color: #e2e8f0;
            padding: 14px 24px;
            font-weight: 600;
            font-size: 13px;
            cursor: pointer;
            border: var(--border);
            border-radius: var(--radius);
            display: block;
            width: 100%;
            text-align: center;
            text-transform: uppercase;
            letter-spacing: 2px;
            margin-bottom: 20px;
            transition: all 0.15s;
            font-family: inherit;
            position: relative;
        }
.upload-btn:hover {
            background: #334155;
        }
.upload-btn input[type="file"] {
            position: absolute;
            width: 0;
            height: 0;
            opacity: 0;
            overflow: hidden;
            border: none;
            pointer-events: none;
        }
#template-area {
            border: var(--border);
            border-radius: var(--radius);
            background: #1a2332;
            position: relative;
            overflow: hidden;
            display: flex;
            align-items: center;
            justify-content: center;
            touch-action: none;
            min-height: 200px;
            margin-bottom: 20px;
            box-shadow: var(--shadow);
        }
#draggable-image { position: absolute; cursor: move; user-select: none; display: none; max-width: none; }
.handle {
            position: absolute;
            background: var(--black);
            z-index: 5;
            display: none;
            border: 2px solid var(--white);
            border-radius: 2px;
        }
.handle-scale { bottom: -10px; right: -10px; width: 24px; height: 24px; cursor: nwse-resize; }
.handle-width { top: 50%; right: -12px; width: 22px; height: 22px; transform: translateY(-50%); cursor: ew-resize; display: none; }
.handle-height { bottom: -12px; left: 50%; width: 22px; height: 22px; transform: translateX(-50%); cursor: ns-resize; display: none; }
#draggable-image-wrapper { position: absolute; display: none; }
#draggable-image-wrapper.active { display: block; }
#draggable-image-wrapper.active .handle { display: block; }
#draggable-image-wrapper.active #draggable-image { outline: 3px solid #e2e8f0; outline-offset: -1px; }
.grid-lines { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; display: none; z-index: 2; }
.grid-lines.active { display: block; }
.grid-lines svg { width: 100%; height: 100%; }
.btn-group {
            display: flex;
            gap: 12px;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }
.generate-btn {
            background: var(--black);
            color: var(--white);
            padding: 14px 32px;
            font-weight: 600;
            font-size: 13px;
            cursor: pointer;
            border: none;
            border-radius: var(--radius);
            text-transform: uppercase;
            letter-spacing: 2px;
            transition: all 0.15s;
            font-family: inherit;
            flex: 1;
            min-width: 120px;
        }
.generate-btn:hover {
            background: var(--gray-700);
        }
.generate-btn:disabled {
            background: var(--gray-300);
            color: var(--white);
            cursor: not-allowed;
        }
.export-options {
            display: flex;
            gap: 16px;
            align-items: center;
            margin-bottom: 20px;
            flex-wrap: wrap;
        }
.export-row {
            display: flex;
            align-items: center;
            gap: 8px;
        }
.export-label {
            font-size: 10px;
            font-weight: 600;
            color: #94a3b8;
            text-transform: uppercase;
            letter-spacing: 1px;
        }
.export-options select {
            padding: 6px 10px;
            font-size: 12px;
            font-weight: 600;
            border: var(--border);
            border-radius: var(--radius);
            background: #1e293b;
            color: #e2e8f0;
            font-family: inherit;
            cursor: pointer;
        }
.export-options select:focus { outline: none; }
.export-options input[type="range"] {
            width: 80px;
            accent-color: #e2e8f0;
            cursor: pointer;
        }
.export-value {
            font-size: 11px;
            font-weight: 600;
            color: #94a3b8;
            min-width: 30px;
        }
.loading-bar {
            display: none;
            width: 100%;
            height: 4px;
            background: #334155;
            margin-bottom: 8px;
            overflow: hidden;
            border-radius: 2px;
        }
.loading-bar.active { display: block; }
.loading-bar-fill {
            height: 100%;
            background: var(--black);
            transition: width 0.3s ease;
            width: 0%;
            border-radius: 2px;
        }
.loading-text {
            font-size: 12px;
            color: #94a3b8;
            margin-bottom: 16px;
            display: none;
            font-weight: 500;
        }
.loading-text.active { display: block; }
.loading-text .dots {
            display: inline-block;
            animation: dotPulse 1.4s ease-in-out infinite;
            letter-spacing: 0.5px;
        }
.results-section { display: none; margin-top: 28px; }
.results-section.active { display: block; }
.results-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 16px;
            padding-bottom: 12px;
            border-bottom: 1px solid #334155;
        }
.results-header-title {
            font-size: 13px;
            font-weight: 700;
            text-transform: uppercase;
            letter-spacing: 2px;
            color: #94a3b8;
        }
.download-all-btn {
            background: none;
            color: #e2e8f0;
            padding: 8px 16px;
            font-weight: 600;
            font-size: 11px;
            cursor: pointer;
            border: var(--border);
            border-radius: var(--radius);
            text-transform: uppercase;
            letter-spacing: 1.5px;
            font-family: inherit;
            transition: all 0.15s;
        }
.download-all-btn:hover {
            background: #334155;
        }
.results-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
            gap: 12px;
        }
.result-item {
            opacity: 0;
            transform: translateY(12px);
            border: var(--border);
            border-radius: var(--radius);
            background: #1e293b;
            overflow: hidden;
            transition: box-shadow 0.2s;
        }
.result-item:hover {
            box-shadow: var(--shadow);
        }
.result-item img {
            width: 100%;
            height: auto;
            display: block;
        }
.result-item-info {
            background: #0f172a;
            padding: 8px 10px;
            font-size: 10px;
            font-weight: 600;
            color: #94a3b8;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-top: 1px solid #334155;
        }
.result-item-download {
            background: var(--black);
            color: var(--white);
            border: none;
            padding: 5px 10px;
            font-size: 9px;
            font-weight: 600;
            cursor: pointer;
            border-radius: 2px;
            font-family: inherit;
            letter-spacing: 0.5px;
            transition: background 0.15s;
        }
.result-item-download:hover {
            background: var(--gray-700);
        }
@media (min-width: 768px) {
            body {
            background: #0f172a;
                margin: 0;
                overflow: hidden;
                display: flex;
                align-items: center;
                justify-content: center;
                min-height: 100vh;
                padding: 40px;
            }
            .app { display: none !important; }
            .desktop-notice { display: flex !important; }
            .noise-overlay { display: block !important; }
        }
.noise-overlay {
            display: none;
            position: fixed;
            inset: 0;
            z-index: -1;
            pointer-events: none;
            opacity: 0.5;
            background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
            background-repeat: repeat;
            background-size: 256px 256px;
            animation: noiseShift 0.8s steps(4) infinite;
        }
@keyframes noiseShift {
            0% { background-position: 0 0; }
            25% { background-position: 128px 64px; }
            50% { background-position: 64px 192px; }
            75% { background-position: 192px 128px; }
        }
.noise-overlay::after {
            content: '';
            position: fixed;
            inset: 0;
            background: repeating-linear-gradient(
                0deg,
                transparent,
                transparent 3px,
                rgba(0,0,0,0.06) 3px,
                rgba(0,0,0,0.06) 4px
            );
            animation: scanlines 6s linear infinite;
        }
@keyframes scanlines {
            0% { transform: translateY(0); }
            100% { transform: translateY(4px); }
        }
.noise-glow {
            position: fixed;
            inset: 0;
            z-index: -1;
            pointer-events: none;
            background: radial-gradient(ellipse at center, rgba(255,255,255,0.03) 0%, transparent 70%);
            animation: glowPulse2 4s ease-in-out infinite;
        }
@keyframes glowPulse2 {
            0%, 100% { opacity: 0.5; }
            50% { opacity: 1; }
        }
.desktop-notice {
            display: none;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            text-align: center;
            max-width: 900px;
            font-family: 'Inter', sans-serif;
            position: relative;
        }
.notice-icon-wrap {
            position: relative;
            width: 300px;
            height: 300px;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-bottom: 56px;
        }
.desktop-notice-icon {
            font-size: 200px;
            line-height: 1;
            animation: iconDance 2.8s ease-in-out infinite;
            z-index: 2;
        }
@keyframes iconDance {
            0%, 100% { transform: rotate(0deg) translateY(0); filter: none; }
            15% { transform: rotate(-20deg) translateY(-12px) scale(1.1); filter: drop-shadow(0 8px 20px rgba(255,255,255,0.2)); }
            30% { transform: rotate(20deg) translateY(-8px) scale(1.1); filter: drop-shadow(0 8px 20px rgba(255,255,255,0.2)); }
            45% { transform: rotate(-10deg) translateY(-4px) scale(1.05); }
            60% { transform: rotate(10deg) translateY(-6px) scale(1.08); }
            75% { transform: rotate(-5deg) translateY(-2px) scale(1.02); }
            90% { transform: rotate(5deg) translateY(-3px) scale(1.04); }
        }
.desktop-notice h1 {
            font-size: 72px;
            font-weight: 800;
            letter-spacing: 10px;
            text-transform: uppercase;
            margin: 0 0 36px 0;
            color: #fff;
            animation: titleShimmer 3.5s ease-in-out infinite;
            background: linear-gradient(90deg, #fff 0%, #ccc 30%, #fff 50%, #ccc 70%, #fff 100%);
            background-size: 300% 100%;
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
@keyframes titleShimmer {
            0%, 100% { background-position: 0% 50%; }
            50% { background-position: 100% 50%; }
        }
.desktop-notice p {
            font-size: 34px;
            color: #999;
            line-height: 1.6;
            margin: 0 0 10px 0;
            font-weight: 400;
        }
.desktop-notice .highlight {
            color: #fff;
            font-weight: 700;
            letter-spacing: 4px;
            animation: wordPulse 2s ease-in-out infinite;
        }
@keyframes wordPulse {
            0%, 100% { opacity: 0.6; }
            50% { opacity: 1; text-shadow: 0 0 40px rgba(255,255,255,0.3); }
        }
.notice-size {
            margin-top: 48px;
            padding-top: 36px;
            border-top: 2px solid rgba(255,255,255,0.08);
            font-size: 28px;
            color: #666;
            letter-spacing: 3px;
        }
.notice-size span {
            color: #fff;
            font-weight: 700;
            font-size: 36px;
            display: inline-block;
            animation: sizeGlow 2s ease-in-out infinite;
        }
@keyframes sizeGlow {
            0%, 100% { text-shadow: 0 0 5px rgba(255,255,255,0.1); }
            50% { text-shadow: 0 0 35px rgba(255,255,255,0.3); }
        }
.size-icon {
            display: inline-block;
            width: 40px;
            height: 40px;
            line-height: 40px;
            border-radius: 50%;
            border: 2px solid rgba(255,255,255,0.2);
            color: #666;
            font-size: 22px;
            font-weight: 700;
            text-align: center;
            margin-left: 10px;
            animation: iconQ 2.5s ease-in-out infinite;
            vertical-align: middle;
        }
@keyframes iconQ {
            0%, 100% { transform: scale(1); border-color: rgba(255,255,255,0.15); color: #555; }
            50% { transform: scale(1.15); border-color: rgba(255,255,255,0.4); color: #999; }
        }