:root {
    --primary: #FF6B35;
    --secondary: #004E89;
    --accent: #F77F00;
    --bg: #FAFAFA;
    --surface: #FFFFFF;
    --text: #1A1A1A;
    --text-secondary: #666666;
    --border: #E0E0E0;
    --shadow: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
    --bg: #1A1A1A;
    --surface: #2A2A2A;
    --text: #FAFAFA;
    --text-secondary: #A0A0A0;
    --border: #404040;
    --shadow: rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #1A1A1A;
        --surface: #2A2A2A;
        --text: #FAFAFA;
        --text-secondary: #A0A0A0;
        --border: #404040;
        --shadow: rgba(0, 0, 0, 0.4);
    }
}

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

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    touch-action: pan-y;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.app {
    max-width: 100vw;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

header {
    background: var(--surface);
    padding: 1.25rem 1.5rem;
    border-bottom: 2px solid var(--primary);
    box-shadow: 0 2px 12px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.header-left {
    flex: 1;
    min-width: 0;
}

.header-save-btn {
    background: var(--primary);
    border: none;
    color: white;
    cursor: pointer;
    padding: 0.75rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 1.125rem;
    width: 48px;
    height: 48px;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    flex-shrink: 0;
}

.header-save-btn:hover:not(:disabled) {
    background: var(--accent);
    box-shadow: 0 4px 12px rgba(247, 127, 0, 0.4);
    transform: translateY(-2px);
}

.header-save-btn:active:not(:disabled) {
    transform: translateY(0) scale(0.95);
}

.header-save-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

h1 {
    font-family: 'Archivo', sans-serif;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--primary);
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

h1 i {
    font-size: 1.25rem;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    font-weight: 400;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: var(--bg);
    border-radius: 20px;
    padding: 0.25rem;
    border: 1px solid var(--border);
}

.theme-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 1rem;
    width: 36px;
    height: 36px;
}

.theme-btn:hover {
    background: var(--border);
}

.theme-btn.active {
    background: var(--primary);
    color: white;
}

.canvas-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    min-height: 400px;
    background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
    position: relative;
    overflow: hidden;
    transition: background 0.3s ease;
}

[data-theme="dark"] .canvas-container {
    background: linear-gradient(135deg, #252525 0%, #1a1a1a 100%);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .canvas-container {
        background: linear-gradient(135deg, #252525 0%, #1a1a1a 100%);
    }
}

.canvas-container::before {
    content: '';
    position: absolute;
    width: 300%;
    height: 300%;
    background: radial-gradient(circle, rgba(255, 107, 53, 0.03) 0%, transparent 70%);
    animation: float 20s ease-in-out infinite;
}

@keyframes float {
    0%, 100% {
        transform: translate(-50%, -50%) rotate(0deg);
    }
    50% {
        transform: translate(-40%, -60%) rotate(180deg);
    }
}

#canvas {
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12),
    0 2px 8px rgba(0, 0, 0, 0.08);
    touch-action: none;
    cursor: grab;
    max-width: 100%;
    max-height: 60vh;
    position: relative;
    z-index: 1;
}

[data-theme="dark"] #canvas {
    background: #2A2A2A;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) #canvas {
        background: #2A2A2A;
    }
}

#canvas:active {
    cursor: grabbing;
}

.controls {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 1.5rem;
    box-shadow: 0 -4px 12px var(--shadow);
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.control-section {
    margin-bottom: 1.5rem;
}

.control-section:last-child {
    margin-bottom: 0;
}

.control-label {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.control-label::before {
    content: '';
    width: 3px;
    height: 14px;
    background: var(--primary);
    border-radius: 2px;
}

.file-input-wrapper {
    position: relative;
    overflow: hidden;
}

input[type="file"] {
    position: absolute;
    left: -9999px;
}

.file-button, .template-btn, .action-btn {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--primary);
    background: var(--surface);
    color: var(--primary);
    font-family: 'Archivo', sans-serif;
    font-weight: 600;
    font-size: 1rem;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    touch-action: manipulation;
}

.file-button:active, .template-btn:active, .action-btn:active {
    transform: scale(0.98);
}

.file-button:hover, .template-btn:hover {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.template-btn {
    aspect-ratio: 1;
    padding: 0.5rem;
    flex-direction: column;
    font-size: 0.875rem;
    position: relative;
    overflow: hidden;
}

.template-btn.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.3);
}

.template-btn .icon {
    width: 100%;
    flex: 1;
    background: var(--bg);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    transition: all 0.2s;
    overflow: hidden;
    position: relative;
}

.template-btn .icon i {
    font-size: 1.25rem;
}

.template-btn .icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.template-btn.active .icon {
    background: rgba(255, 255, 255, 0.2);
}

[data-theme="dark"] .template-btn .icon {
    background: #1A1A1A;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .template-btn .icon {
        background: #1A1A1A;
    }
}

.template-btn .template-name {
    font-size: 0.75rem;
    text-align: center;
    line-height: 1.2;
    margin-top: 0.25rem;
}

.slider-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.slider-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: 8px;
    font-size: 1rem;
    flex-shrink: 0;
    transition: background-color 0.3s ease;
}

[data-theme="dark"] .slider-icon {
    background: #1A1A1A;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .slider-icon {
        background: #1A1A1A;
    }
}

input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 3px;
    background: var(--border);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
    transition: all 0.2s;
}

input[type="range"]::-webkit-slider-thumb:active {
    transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--primary);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(255, 107, 53, 0.3);
}

.slider-value {
    min-width: 48px;
    text-align: right;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.tab-buttons {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    background: var(--bg);
    padding: 0.375rem;
    border-radius: 12px;
    transition: background-color 0.3s ease;
}

[data-theme="dark"] .tab-buttons {
    background: #1A1A1A;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tab-buttons {
        background: #1A1A1A;
    }
}

.tab-btn {
    flex: 1;
    padding: 0.75rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-family: 'Archivo', sans-serif;
    font-weight: 600;
    font-size: 0.875rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--surface);
    color: var(--primary);
    box-shadow: 0 2px 4px var(--shadow);
}

[data-theme="dark"] .tab-btn.active {
    background: #2A2A2A;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tab-btn.active {
        background: #2A2A2A;
    }
}

.action-btn {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-size: 1.125rem;
    padding: 1.25rem;
    margin-top: 1rem;
}

.action-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    box-shadow: 0 6px 20px rgba(247, 127, 0, 0.4);
}

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

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-secondary);
    pointer-events: none;
    z-index: 0;
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.3;
}

.empty-state-text {
    font-size: 1rem;
    font-weight: 500;
}

@media (min-width: 768px) {
    .app {
        max-width: 600px;
        margin: 0 auto;
        box-shadow: 0 0 40px var(--shadow);
    }

    .canvas-container {
        min-height: 500px;
    }

    #canvas {
        max-height: 500px;
    }
}

@media (max-width: 480px) {
    h1 {
        font-size: 1.25rem;
    }

    .subtitle {
        font-size: 0.75rem;
    }

    .header-save-btn {
        width: 44px;
        height: 44px;
        font-size: 1rem;
    }

    .theme-toggle {
        gap: 0.125rem;
        padding: 0.125rem;
    }

    .theme-btn {
        width: 32px;
        height: 32px;
        font-size: 0.875rem;
        padding: 0.375rem;
    }
}