* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Light Theme (Default) */
:root {
    --bg-body: linear-gradient(135deg, #667eea 0%, #2d3561 100%);
    --bg-container: white;
    --bg-upload: #f8f9fa;
    --bg-upload-hover: #f0f4ff;
    --bg-frame: #fafafa;
    --bg-config: #f8f9fa;
    --bg-preview: #f8f9fa;
    --bg-modal: white;
    --bg-button-secondary: white;
    --bg-input: white;

    --text-primary: #333;
    --text-secondary: #666;
    --text-tertiary: #999;
    --text-button-secondary: #667eea;

    --border-main: #e0e0e0;
    --border-light: #f0f0f0;
    --border-upload: #ddd;
    --border-input: #e0e0e0;

    --accent-primary: #667eea;
    --accent-hover: #5568d3;
    --accent-danger: #ff5252;
    --accent-danger-hover: #d32f2f;

    --shadow-container: 0 20px 40px rgba(0,0,0,0.1);
    --shadow-modal: 0 20px 40px rgba(0,0,0,0.3);
    --shadow-frame: 0 4px 12px rgba(102, 126, 234, 0.2);
    --modal-backdrop: rgba(0,0,0,0.5);
}

/* Dark Theme */
[data-theme="dark"] {
    --bg-body: #1a1a1a;
    --bg-container: #2a2a2a;
    --bg-upload: #1a1a1a;
    --bg-upload-hover: #333;
    --bg-frame: #1a1a1a;
    --bg-config: #1a1a1a;
    --bg-preview: #1a1a1a;
    --bg-modal: #2a2a2a;
    --bg-button-secondary: #3a3a3a;
    --bg-input: #1a1a1a;

    --text-primary: #ffd580;
    --text-secondary: #b8945f;
    --text-tertiary: #999;
    --text-button-secondary: white;

    --border-main: #3a3a3a;
    --border-light: #3a3a3a;
    --border-upload: #3a3a3a;
    --border-input: #3a3a3a;

    --accent-primary: #c9a876;
    --accent-hover: #d4b586;
    --accent-danger: #ff5252;
    --accent-danger-hover: #d32f2f;

    --shadow-container: 0 20px 40px rgba(0,0,0,0.5);
    --shadow-modal: 0 20px 40px rgba(0,0,0,0.5);
    --shadow-frame: 0 4px 12px rgba(201, 168, 118, 0.2);
    --modal-backdrop: rgba(0,0,0,0.8);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-body);
    min-height: 100vh;
    padding: 20px;
}

.app-container {
    background: var(--bg-container);
    border-radius: 20px;
    box-shadow: var(--shadow-container);
    max-width: 1200px;
    margin: 0 auto;
    min-height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-main);
}

/* Header */
.app-header {
    padding: 20px 30px;
    border-bottom: 2px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header h1 {
    color: var(--text-primary);
    font-weight: 700;
    font-size: 28px;
    text-align: center;
    flex: 1;
}

.header-actions {
    display: flex;
    gap: 10px;
}

.btn-icon {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.btn-icon:hover {
    background: var(--bg-upload);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
}

/* File Upload Section */
.file-upload-section {
    max-width: 700px;
    margin: 0 auto 30px;
}

.upload-area {
    border: 3px dashed var(--border-upload);
    border-radius: 15px;
    padding: 60px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    background: var(--bg-upload);
}

.upload-area:hover {
    border-color: var(--accent-primary);
    background: var(--bg-upload-hover);
}

.upload-area.drag-over {
    border-color: var(--accent-primary);
    background: var(--bg-upload-hover);
    transform: scale(1.02);
}

.upload-icon {
    font-size: 64px;
    margin-bottom: 15px;
}

.upload-area h3 {
    color: var(--text-primary);
    margin-bottom: 10px;
    font-weight: 600;
    font-size: 24px;
}

.upload-instruction {
    color: var(--text-secondary);
    font-size: 16px;
    margin-bottom: 8px;
}

.upload-help {
    color: var(--text-tertiary);
    font-size: 14px;
}

/* Frames Section */
.frames-section {
    margin-bottom: 30px;
}

.frames-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.frames-header h2 {
    color: var(--text-primary);
    font-size: 22px;
    font-weight: 600;
}

.frames-actions {
    display: flex;
    gap: 10px;
}

.frames-help {
    margin-bottom: 20px;
    padding: 12px 20px;
    background: var(--bg-upload-hover);
    border-left: 4px solid var(--accent-primary);
    border-radius: 8px;
}

.frames-help p {
    color: var(--text-secondary);
    font-size: 14px;
    margin: 0;
}

.frames-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.frame-item {
    position: relative;
    border: 2px solid var(--border-main);
    border-radius: 12px;
    padding: 10px;
    background: var(--bg-frame);
    cursor: move;
    transition: all 0.2s;
}

.frame-item:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-frame);
    transform: translateY(-2px);
}

.frame-item.dragging {
    opacity: 0.5;
    transform: scale(0.95);
}

.frame-number {
    position: absolute;
    top: 15px;
    left: 15px;
    background: var(--accent-primary);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    z-index: 10;
}

.frame-item img {
    width: 100%;
    height: 140px;
    object-fit: contain;
    border-radius: 8px;
    background: var(--bg-container);
    margin-bottom: 8px;
}

.frame-name {
    font-size: 12px;
    color: var(--text-secondary);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.frame-remove {
    position: absolute;
    top: 15px;
    right: 15px;
    background: var(--accent-danger);
    color: white;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    transition: all 0.2s;
    z-index: 10;
}

.frame-remove:hover {
    background: var(--accent-danger-hover);
    transform: scale(1.1);
}

/* Configuration Section */
.config-section {
    max-width: 700px;
    margin: 0 auto 30px;
    padding: 25px;
    background: var(--bg-config);
    border-radius: 15px;
    border: 2px solid var(--border-main);
}

.config-section h2 {
    color: var(--text-primary);
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 20px;
}

.config-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.config-item {
    display: flex;
    flex-direction: column;
}

.config-item label {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 8px;
    font-size: 14px;
}

.config-item input[type="number"],
.config-item select {
    padding: 12px 15px;
    border: 2px solid var(--border-input);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
    background: var(--bg-input);
    color: var(--text-primary);
}

.config-item input[type="number"]:focus,
.config-item select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.config-item small {
    color: var(--text-tertiary);
    font-size: 12px;
    margin-top: 5px;
}

/* Preview Section */
.preview-section {
    max-width: 700px;
    margin: 0 auto 30px;
}

.preview-section h2 {
    color: var(--text-primary);
    font-size: 22px;
    font-weight: 600;
    margin-bottom: 20px;
}

.preview-container {
    background: var(--bg-preview);
    border: 2px solid var(--border-main);
    border-radius: 15px;
    padding: 30px;
    text-align: center;
    margin-bottom: 20px;
}

.preview-container img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.preview-info {
    background: var(--bg-upload-hover);
    border-left: 4px solid var(--accent-primary);
    padding: 15px 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.preview-info p {
    color: var(--text-primary);
    font-size: 14px;
    margin: 5px 0;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-primary {
    padding: 15px 40px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-frame);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 12px 30px;
    background: var(--bg-button-secondary);
    color: var(--text-button-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: 10px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-secondary:hover {
    background: var(--accent-primary);
    color: white;
    transform: translateY(-2px);
}

.btn-secondary:active {
    transform: translateY(0);
}

/* Footer */
.app-footer {
    padding: 20px;
    text-align: center;
    border-top: 2px solid var(--border-light);
    color: var(--text-secondary);
}

.app-footer a {
    color: var(--accent-primary);
    text-decoration: none;
    transition: color 0.2s;
}

.app-footer a:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: var(--modal-backdrop);
}

.modal-content {
    background-color: var(--bg-modal);
    margin: 5% auto;
    border-radius: 15px;
    max-width: 600px;
    box-shadow: var(--shadow-modal);
    animation: modalSlideIn 0.3s ease;
    border: 1px solid var(--border-main);
}

.modal-small {
    max-width: 450px;
}

@keyframes modalSlideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 25px 30px;
    border-bottom: 2px solid var(--border-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 24px;
}

.close-btn {
    background: none;
    border: none;
    font-size: 32px;
    color: var(--text-tertiary);
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.close-btn:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 30px;
    max-height: 60vh;
    overflow-y: auto;
}

.modal-body p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 15px;
}

#messageModalText {
    white-space: pre-line;
    color: var(--text-primary);
}

.modal-body h3 {
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    margin: 20px 0 10px;
}

.modal-body ul {
    margin-left: 20px;
    margin-bottom: 15px;
}

.modal-body li {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 8px;
}

.modal-body .version {
    color: var(--text-tertiary);
    font-size: 14px;
    margin-top: 20px;
}

.modal-footer {
    padding: 20px 30px;
    border-top: 2px solid var(--border-light);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.modal-buttons {
    padding: 20px 30px;
    border-top: 2px solid var(--border-light);
    text-align: center;
}

.modal-cancel {
    padding: 12px 30px;
    background: var(--bg-button-secondary);
    color: var(--text-button-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: 8px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.modal-cancel:hover {
    background: var(--accent-primary);
    color: white;
}

.option-section {
    margin-bottom: 25px;
}

.option-section-title {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-light);
}

.option-group {
    margin-bottom: 15px;
}

.option-group label {
    color: var(--text-secondary);
    font-size: 15px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

/* Toggle Switch */
.toggle-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    cursor: pointer;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 28px;
    flex-shrink: 0;
}

.toggle-switch input[type="checkbox"] {
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-main);
    transition: 0.3s;
    border-radius: 28px;
    border: 2px solid var(--border-main);
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-tertiary);
    transition: 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background-color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(22px);
    background-color: white;
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3);
}

[data-theme="dark"] .toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 3px rgba(201, 168, 118, 0.3);
}

.toggle-slider:hover {
    opacity: 0.9;
}

.option-group input[type="number"] {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 2px solid var(--border-input);
}

.option-group input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Progress Modal */
.progress-modal .modal-content {
    max-width: 500px;
}

.progress-modal-content {
    text-align: center;
}

.progress-header {
    padding: 25px 30px;
    border-bottom: 2px solid var(--border-light);
}

.progress-header h3 {
    color: var(--text-primary);
    font-weight: 600;
    font-size: 22px;
}

.progress-body {
    padding: 30px;
}

.progress-bar-container {
    width: 100%;
    height: 30px;
    background: var(--border-main);
    border-radius: 15px;
    overflow: hidden;
    margin-bottom: 20px;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary) 0%, var(--accent-hover) 100%);
    width: 0%;
    transition: width 0.3s ease;
}

.progress-message {
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 10px;
}

.progress-details {
    color: var(--text-tertiary);
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .app-container {
        border-radius: 15px;
        min-height: calc(100vh - 20px);
    }

    .app-header h1 {
        font-size: 22px;
    }

    .main-content {
        padding: 20px;
    }

    .frames-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 15px;
    }

    .frame-item img {
        height: 110px;
    }

    .config-grid {
        grid-template-columns: 1fr;
    }

    .action-buttons {
        flex-direction: column;
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
    }

    .modal-content {
        margin: 10% auto;
        max-width: 90%;
    }
}

/* Theme Toggle Buttons */
.theme-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 20px;
}

.theme-btn {
    padding: 12px;
    background: var(--bg-button-secondary);
    color: var(--text-button-secondary);
    border: 2px solid var(--accent-primary);
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.theme-btn:hover {
    background: var(--bg-upload-hover);
    border-color: var(--accent-primary);
}

.theme-btn.active {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}
