* { box-sizing: border-box; }
body {
    background-color: #0f172a;
    color: #e2e8f0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    min-height: 100vh;
    margin: 0;
    padding: 16px;
    -webkit-overflow-scrolling: touch;
}
.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: 12px;
    transition: color 0.15s;
}
.back-link:hover { color: #e2e8f0; }
h1 { font-size: 1.75rem; font-weight: 900; margin: 0 0 4px; text-align: center; }
.label-text { font-size: 10px; color: #94a3b8; margin-bottom: 12px; letter-spacing: 2px; text-align: center; }
.size-selector select {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    font-weight: bold;
    background: #1e293b;
    color: #e2e8f0;
    border: 2px solid #334155;
    border-radius: 8px;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23e2e8f0' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 16px center;
}
.size-selector select:focus { outline: none; background-color: #334155; }
.size-selector { margin-bottom: 16px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; cursor: pointer; }
.checkbox-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: #e2e8f0; cursor: pointer; }
.checkbox-label { font-size: 12px; color: #e2e8f0; font-weight: bold; }
.tab-buttons { display: flex; gap: 8px; margin-bottom: 20px; }
.tab-btn { flex: 1; padding: 14px 20px; font-size: 14px; font-weight: 900; background: transparent; color: #e2e8f0; border: 2px solid #334155; border-radius: 8px; cursor: pointer; text-transform: uppercase; transition: 0.3s; }
.tab-btn.active { background: #e2e8f0; color: #0f172a; }
.tab-btn:active { background: #94a3b8; }
.page { display: none; }
.page.active { display: block; }
.upload-btn {
    background: #1e293b;
    color: #e2e8f0;
    padding: 16px 24px;
    font-weight: 900;
    font-size: 14px;
    cursor: pointer;
    border: 2px solid #334155;
    display: block;
    width: 100%;
    text-align: center;
    border-radius: 8px;
    text-transform: uppercase;
}
.upload-btn:active { background: #334155; }
.upload-btn input[type="file"] {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}
.download-btn { background: #10b981; color: #fff; padding: 16px 32px; font-weight: 900; font-size: 14px; cursor: pointer; border: none; border-radius: 8px; width: 100%; margin-top: 20px; text-transform: uppercase; }
.download-btn:active { background: #059669; }
.download-btn:disabled { background: #334155; cursor: not-allowed; }
#template-area {
    border: 3px solid #334155;
    background-color: #1a2332;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 50px rgba(0,0,0,0.4);
    touch-action: none;
    min-height: 200px;
}
#draggable-image { position: absolute; cursor: move; user-select: none; display: none; max-width: none; }
.handle { position: absolute; background: rgba(255,255,255,0.9); z-index: 5; display: none; border: 2px solid #0f172a; }
.handle-scale { bottom: -10px; right: -10px; width: 32px; height: 32px; border-radius: 50%; cursor: nwse-resize; }
.handle-width { top: 50%; right: -16px; width: 32px; height: 32px; border-radius: 50%; transform: translateY(-50%); cursor: ew-resize; display: none; }
.handle-height { bottom: -16px; left: 50%; width: 32px; height: 32px; border-radius: 50%; transform: translateX(-50%); cursor: ns-resize; display: none; }
#draggable-image-wrapper.active .handle-width, #draggable-image-wrapper.active .handle-height { display: block; }
#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: 2px solid rgba(255,255,255,0.3); }
.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%; }
#gridOptions {
    display: none;
    background: #1e293b;
    border: 2px solid #334155;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
}
#gridOptions.active { display: block; }
.grid-option-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.grid-option-row:last-child { margin-bottom: 0; }
.grid-option-label {
    font-size: 10px;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 1px;
    min-width: 60px;
}
.grid-options input[type="color"],
#gridOptions input[type="color"] {
    width: 36px;
    height: 36px;
    border: 2px solid #334155;
    border-radius: 4px;
    cursor: pointer;
    padding: 2px;
    background: none;
}
.grid-option-value,
#gridOptions .grid-option-value {
    font-size: 12px;
    font-weight: bold;
    color: #e2e8f0;
    min-width: 24px;
    text-align: right;
}
#gridOptions input[type="range"] {
    flex: 1;
    accent-color: #e2e8f0;
    cursor: pointer;
}
.crop-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.crop-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    background: #1e293b;
    color: #e2e8f0;
    font-size: 24px;
    font-weight: 900;
    border: 2px solid #334155;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.crop-header .upload-btn-wrapper { flex: 1; }
#crop-area {
    position: relative;
    overflow: hidden;
    display: none;
    min-height: 150px;
    border: 3px solid #334155;
    background: #1a2332;
}
#crop-area.active { display: block; }
#crop-image { max-width: 100%; display: block; }
.crop-message { margin-top: 12px; padding: 12px; background: #1e293b; color: #e2e8f0; font-size: 14px; font-weight: 900; text-align: center; border-radius: 8px; display: none; line-height: 1.4; border: 2px solid #334155; }
.crop-message.active { display: block; }
.crop-table { width: 100%; border-collapse: collapse; }
.crop-table tr:first-child td { font-size: 16px; padding-bottom: 8px; }
.crop-table td { padding: 4px 0; font-size: 13px; }
.crop-table td:first-child { text-align: left; color: #e2e8f0; }
.crop-table td:last-child { text-align: right; font-weight: bold; }
.proceed-btn { margin-top: 12px; padding: 14px 24px; font-size: 14px; font-weight: 900; background: #10b981; color: #fff; border: none; border-radius: 8px; cursor: pointer; width: 100%; text-transform: uppercase; display: none; }
.proceed-btn:active { background: #059669; }
.info-box { background: #1e293b; border: 2px solid #334155; border-radius: 8px; padding: 16px; margin-bottom: 20px; display: none; }
.info-text { font-size: 12px; line-height: 1.5; color: #94a3b8; margin-bottom: 16px; }
.calc-box { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px; background: #0f172a; border: 2px solid #334155; border-radius: 8px; margin-bottom: 12px; }
.calc-label { font-size: 14px; font-weight: bold; color: #e2e8f0; }
.calc-input { width: 70px; padding: 8px 12px; font-size: 14px; font-weight: bold; background: #1e293b; color: #e2e8f0; border: 2px solid #334155; border-radius: 4px; text-align: center; }
.calc-input:focus { outline: none; background: #334155; }
.result-box { display: flex; gap: 20px; margin-bottom: 12px; }
.result-item { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.result-label { font-size: 12px; color: #94a3b8; }
.result-value { font-size: 16px; font-weight: 900; color: #10b981; }
.calc-buttons { display: flex; gap: 10px; }
.calc-copy { padding: 8px 16px; font-size: 12px; font-weight: 900; background: #3b82f6; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.calc-close { padding: 8px 16px; font-size: 12px; font-weight: 900; background: #334155; color: #e2e8f0; border: none; border-radius: 4px; cursor: pointer; }
.crop-preview-area { display: none; margin-top: 16px; }
.crop-preview-area.active { display: block; }
.grid-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
}
.grid-overlay svg { width: 100%; height: 100%; }
.process-crop-btn { margin-top: 12px; padding: 14px 24px; font-size: 14px; font-weight: 900; background: #10b981; color: #fff; border: none; border-radius: 8px; cursor: pointer; width: 100%; text-transform: uppercase; display: none; }
.process-crop-btn:active { background: #059669; }
.crop-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; margin-top: 12px; }
.crop-result-item { position: relative; overflow: hidden; border: 2px solid #334155; border-radius: 4px; background: #1e293b; }
.crop-result-item img { width: 100%; height: auto; display: block; }
.crop-result-item .download-item-btn {
    position: absolute;
    bottom: 4px;
    right: 4px;
    padding: 4px 8px;
    font-size: 10px;
    font-weight: bold;
    background: #3b82f6;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}
.download-buttons { margin-top: 12px; display: none; }
.download-buttons.active { display: block; }
.download-single-btn { padding: 14px 24px; font-size: 14px; font-weight: 900; background: #3b82f6; color: #fff; border: none; border-radius: 8px; cursor: pointer; width: 100%; text-transform: uppercase; }
.download-single-btn:active { background: #2563eb; }
.loading-bar { display: none; width: 100%; height: 8px; background: #334155; border-radius: 4px; margin-top: 12px; overflow: hidden; }
.loading-bar.active { display: block; }
.loading-bar-fill { height: 100%; background: #10b981; border-radius: 4px; transition: width 0.3s; width: 0%; }
.loading-text { font-size: 12px; color: #94a3b8; margin-top: 8px; display: none; }
.loading-text.active { display: block; }
.format-btn {
    flex: 1;
    padding: 10px;
    font-size: 12px;
    font-weight: bold;
    background: #1e293b;
    color: #64748b;
    border: 2px solid #334155;
    border-radius: 6px;
    cursor: pointer;
}
.format-btn.active { border-color: #e2e8f0; color: #e2e8f0; }
.format-selector { display: flex; gap: 8px; margin-bottom: 12px; }
#generate-area { display: none; margin-top: 16px; }
#generate-area.active { display: block; }
.gen-size-info {
    background: #1e293b;
    border: 2px solid #334155;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    text-align: center;
}
.gen-size-info span { color: #10b981; font-weight: bold; }
.gen-preview { display: none; margin-top: 16px; }
.gen-preview.active { display: block; }
#generated-image { max-width: 100%; border: 2px solid #334155; border-radius: 8px; }
#placeholder-text { color: #64748b; font-weight: 900; }
#downloadGenBtn { display: none; margin-top: 12px; }

.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(255,255,255,0.03) 3px, rgba(255,255,255,0.03) 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', -apple-system, BlinkMacSystemFont, sans-serif;
    position: relative;
    min-height: 80vh;
    width: 100%;
    margin: 0 auto;
}
.desktop-notice h1 {
    font-size: 64px;
    font-weight: 900;
    letter-spacing: 8px;
    text-transform: uppercase;
    margin: 0 0 32px 0;
    color: #fff;
    animation: titleShimmer 3.5s ease-in-out infinite;
    background: linear-gradient(90deg, #fff 0%, #888 30%, #fff 50%, #888 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: 28px;
    color: #888;
    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: 22px;
    color: #666;
    letter-spacing: 3px;
}
.notice-size span {
    color: #fff;
    font-weight: 700;
    font-size: 30px;
}
.size-icon {
    display: inline-block;
    width: 36px;
    height: 36px;
    line-height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.2);
    color: #666;
    font-size: 18px;
    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; }
}
.notice-icon-wrap {
    position: relative;
    width: 200px;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 48px;
}
.desktop-notice-icon {
    font-size: 120px;
    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); }
}

@media (min-width: 768px) {
    body {
        background: #0f172a;
        margin: 0;
        overflow: hidden;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 100vh;
        padding: 40px;
    }
    h1, .tab-buttons, #create-page, #crop-page, .page { display: none !important; }
    .desktop-notice { display: flex !important; }
    .noise-overlay { display: block !important; }
    .noise-glow { display: block !important; }
}
