* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #0284c7;
    --primary-hover: #0ea5e9;
    --secondary: #7dd3fc;

    --bg-dark: #0a0e14;
    --bg-darker: #05070b;
    --bg-panel: #111827;

    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --border: #1e293b;

    --accent: #f59e0b;
}

[data-theme="light"] {
    --primary: #0284c7;
    --primary-hover: #0369a1;
    --secondary: #38bdf8;

    --bg-dark: #f8fafc;
    --bg-darker: #ffffff;
    --bg-panel: #f1f5f9;

    --text-primary: #0f172a;
    --text-secondary: #475569;
    --border: #e2e8f0;

    --accent: #f59e0b;
}

[data-theme="dark"] .TSD-3d-indicator {
    filter: brightness(2)
}

html {
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: url('./../images/bg-gradient.png') no-repeat center center fixed;
    background-size: cover;
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
    transition: background 0.3s ease, color 0.3s ease;
}

.app-container {
    display: grid;
    grid-template-columns: 1fr 412px;
    grid-template-rows: auto 1fr;
    height: 100vh;
}

/* Header */
.header {
    grid-column: 1 / -1;
    background: transparent;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    display: flex;
    align-items: center;
}

.logo img {
    display: block;
    height: 1.75rem;
    width: 1.75rem;
    margin-right: 0.25rem;
}

.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.header-actions .btn {
    padding: 0.5rem;
    height: 2.5rem;
}

/* Main Viewer */
.viewer-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Camera Controls Overlay */
.camera-controls {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-panel);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 0.75rem 1.5rem;
    display: flex;
    gap: 0.5rem;
}

.camera-btn {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 0.5rem 1rem;
    border-radius: 1.5rem;
    cursor: pointer;
    transition: border 0.2s, color 0.2s;
    font-size: 0.875rem;
}

.camera-btn:hover {
    border-color: var(--primary);
}

/* Side Panel */
.side-panel {
    background: transparent;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition-property: transform;
    transition-timing-function: cubic-bezier(.17, .67, 0, 1);
    transition-delay: 100ms;
    transition-duration: 200ms;
    padding: 0 2rem 2rem 0;
}

.side-panel.is-open {
    transform: translateX(0);
    transition-delay: 1750ms;
    transition-duration: 1000ms;
}

.side-panel-content {
    height: 100%;
    background: rgba(198, 213, 226, 0.2);
    border-radius: 1.5rem;
    backdrop-filter: blur(16px);
    border: 1px solid rgba(18, 49, 77, 0.1);
    overflow: scroll;
}

.panel-section {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.panel-section:last-child {
    border-bottom: none;
}

.panel-section-inner {
    padding: 1rem 1.5rem 1.5rem;
}

.section-title {
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
}

/* Accordion */
.accordion-section {
    border-bottom: 1px solid var(--border);
}

.accordion-header {
    width: 100%;
    background: transparent;
    border: none;
    padding: 1rem 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    transition: all 0.2s;
}

.accordion-header:hover {
    color: var(--text-primary);
}

.accordion-header.active {
    color: var(--text-primary);
}

.accordion-header svg {
    transition: transform 0.2s;
}

.accordion-header.active svg {
    transform: rotate(180deg);
}

.accordion-content {
    overflow: hidden;
    transition: all 0.3s ease-out;
}

.accordion-content[style*="display: none"] {
    max-height: 0;
}

.accordion-content[style*="display: block"] {
    max-height: 2000px;
}

/* Panel Colors */
.panel-grid {
    display: grid;
    gap: 0.75rem;
}

.panel-item {
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.panel-item:hover {
    border-color: var(--primary);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-name {
    font-size: 0.875rem;
    font-weight: 500;
}

/* Color Swatches */
.color-swatches {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.5rem;
    padding-top: 0.75rem;
}

.color-swatch {
    aspect-ratio: 1;
    border: 3px solid transparent;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    padding: 0;
    min-width: 0;
    background-clip: padding-box;
}

.color-swatch:hover {
    transform: scale(1.15);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.color-swatch.is-active {
    border-color: var(--text-primary) !important;
}

.color-swatch.is-active::after {
    content: '✓';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: white;
    font-size: 0.75rem;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.color-swatch.is-transparent {
    background-image:
        linear-gradient(45deg, #ddd 25%, transparent 25%),
        linear-gradient(-45deg, #ddd 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #ddd 75%),
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 8px 8px;
    background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
    background-color: #f5f5f5;
    position: relative;
}

.color-swatch.is-transparent::before {
    content: '∅';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #666;
    font-size: 1rem;
    font-weight: bold;
}

.color-swatch.is-transparent.is-active::before {
    display: none;
}

.color-swatch.is-transparent.is-active::after {
    color: #333;
    text-shadow: 0 0 3px white;
}

.graphic-only {
    display: none;
}

[data-graphic="true"] .graphic-only {
    display: block;
}

/* Custom Color Picker */
.color-swatch.is-custom {
    background: linear-gradient(135deg,
            #ff0000 0%, #ff00ff 17%, #0000ff 33%,
            #00ffff 50%, #00ff00 67%, #ffff00 83%, #ff0000 100%);
    position: relative;
    overflow: visible;
}

.color-picker-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    cursor: pointer;
    border: none;
}

.color-swatch.is-custom:hover {
    transform: scale(1.15);
}

.color-swatch.is-custom.is-active {
    border-color: var(--text-primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal.is-open {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1;
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: transparent;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Gallery Modal */
.modal-content--gallery {
    max-width: 860px;
}

.gallery-loading {
    text-align: center;
    padding: 3rem;
}

.gallery-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

.gallery-item {
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    overflow: hidden;
}

.gallery-img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    display: block;
}

.gallery-item-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
}

.gallery-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.gallery-download {
    font-size: 0.75rem;
    padding: 0.25rem 0.75rem;
    text-decoration: none;
    width: auto;
}

/* Upload Section */
.upload-area {
    background: var(--bg-dark);
    border: 2px dashed var(--border);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    display: block;
}

.upload-area:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.upload-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.upload-text {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.upload-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.upload-input {
    display: none;
}

/* Logo field list */
.logo-field-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.logo-field-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.logo-field-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-field-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.logo-field-preview {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.logo-preview-img {
    width: 3rem;
    height: 3rem;
    object-fit: contain;
    border-radius: 0.25rem;
    background: var(--bg-panel);
    flex-shrink: 0;
}

.logo-preview-actions {
    display: flex;
    flex: 1;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    min-width: 0;
}

.logo-preview-name {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.btn-remove {
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
    padding: 0.25rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    width: auto;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.btn-remove:hover {
    background: #ef4444;
    color: white;
}

.logo-field-item .upload-area {
    padding: 1.25rem;
}

/* Export Buttons */
.btn {
    width: 100%;
    padding: 0.875rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg-dark);
    color: var(--text-primary);
    border: 1px solid var(--border);
    width: auto;
}

.btn-secondary:hover {
    border-color: var(--primary);
}

.export-grid {
    display: grid;
    gap: 0.75rem;
}

/* Scrollbar */
.side-panel::-webkit-scrollbar {
    width: 8px;
}

.side-panel::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

.side-panel::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.side-panel::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Responsive */
@media (max-width: 1024px) {
    .app-container {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
    }

    .side-panel {
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 50vh;
        transform: translateY(100%);
        transition: transform 1000ms cubic-bezier(.17, .67, 0, 1) 1250ms;
    }

    .side-panel.is-open {
        transform: translateY(0);
    }

    .camera-controls {
        bottom: 1rem;
    }
}

@media (max-width: 640px) {
    .header {
        padding: 1rem;
    }

    .logo {
        font-size: 1.25rem;
    }

    .viewer-container {
        padding: 0;
    }

    .panel-section {
        padding: 1rem;
    }

    .TSD-3d-indicator {
        display: none !important;
    }

    .camera-controls {
        display: none;
    }
}