/* CSS Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #8b5cf6;
    --accent-color: #f59e0b;
    --background-color: #f8fafc;
    --card-background: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--background-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Header Styles */
.header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: white;
    padding: 2rem 1rem;
    text-align: center;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

.logo {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
}

.header h1 {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.tagline {
    font-size: 1rem;
    opacity: 0.9;
    max-width: 500px;
    margin: 0 auto;
}

/* Main Content */
.main-content {
    flex: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    width: 100%;
}

/* Tool Sections */
.tool-section {
    background: var(--card-background);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: var(--transition);
}

.tool-section:hover {
    box-shadow: var(--shadow-lg);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--primary-light);
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.section-content {
    padding: 1.25rem;
}

/* Buttons */
.randomize-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.randomize-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.randomize-btn:active {
    transform: translateY(0);
}

.btn-icon {
    font-size: 1.1rem;
}

/* Form Elements */
.template-selector,
.element-options,
.twist-options,
.character-options,
.scene-options {
    margin-bottom: 1rem;
}

.template-selector {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.element-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--background-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
}

.checkbox-label:hover {
    background: var(--primary-light);
}

.checkbox-label input[type="checkbox"] {
    accent-color: var(--primary-color);
    width: 16px;
    height: 16px;
}

.twist-options,
.character-options,
.scene-options {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: center;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    background: white;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}

select:hover {
    border-color: var(--primary-color);
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
}

/* Output Cards */
.output-card {
    background: var(--background-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1.25rem;
    min-height: 120px;
}

.placeholder-text {
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

.output-card h3 {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--primary-light);
}

.output-card h4 {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin: 1rem 0 0.5rem;
}

.output-card p {
    margin-bottom: 0.5rem;
}

.output-card ul {
    margin-left: 1.5rem;
    margin-bottom: 0.75rem;
}

.output-card li {
    margin-bottom: 0.375rem;
}

.output-card .highlight {
    background: linear-gradient(120deg, var(--primary-light) 0%, transparent 100%);
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-weight: 500;
}

.output-card .stage {
    background: var(--card-background);
    border-left: 3px solid var(--primary-color);
    padding: 0.75rem 1rem;
    margin: 0.75rem 0;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.output-card .stage-title {
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 0.25rem;
}

/* Twist History */
.twist-history {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border-color);
}

.twist-history h4 {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

#twist-history-list {
    list-style: none;
    margin: 0;
    max-height: 150px;
    overflow-y: auto;
}

#twist-history-list li {
    font-size: 0.85rem;
    padding: 0.375rem 0.5rem;
    background: var(--background-color);
    border-radius: var(--radius-sm);
    margin-bottom: 0.375rem;
    color: var(--text-secondary);
}

#twist-history-list:empty::after {
    content: "No twists generated yet";
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.85rem;
}

/* Export Section */
.export-section {
    background: linear-gradient(135deg, var(--primary-light) 0%, #fdf4ff 100%);
}

.export-section .section-header {
    background: transparent;
    border-bottom: none;
    justify-content: center;
}

.export-buttons {
    display: flex;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding: 0 1rem 1.5rem;
}

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    border: 2px solid var(--primary-color);
    background: white;
    color: var(--primary-color);
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.export-btn:hover {
    background: var(--primary-color);
    color: white;
}

.export-btn:last-child {
    border-color: #ef4444;
    color: #ef4444;
}

.export-btn:last-child:hover {
    background: #ef4444;
    color: white;
}

/* Footer */
.footer {
    background: var(--text-primary);
    color: var(--text-muted);
    text-align: center;
    padding: 1.5rem 1rem;
    margin-top: auto;
}

.footer a {
    color: var(--primary-light);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.footer a:hover {
    color: white;
    text-decoration: underline;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.output-card.animated {
    animation: fadeIn 0.3s ease-out;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

.randomize-btn.generating {
    animation: pulse 0.6s ease-in-out;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text-primary);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translate(-50%, 20px);
    }
    to {
        opacity: 1;
        transform: translate(-50%, 0);
    }
}

/* Responsive Design */
@media (max-width: 768px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .tagline {
        font-size: 0.9rem;
    }

    .section-header {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
    }

    .section-header h2 {
        font-size: 1.1rem;
    }

    .template-selector {
        flex-direction: column;
        align-items: stretch;
    }

    .twist-options,
    .character-options,
    .scene-options {
        flex-direction: column;
        align-items: stretch;
    }

    .option-group {
        justify-content: space-between;
    }

    .option-group select {
        flex: 1;
    }

    .export-buttons {
        flex-direction: column;
    }

    .export-btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    html {
        font-size: 14px;
    }

    .main-content {
        padding: 1rem 0.75rem;
    }

    .section-content {
        padding: 1rem;
    }

    .element-options {
        flex-direction: column;
    }

    .checkbox-label {
        width: 100%;
    }

    .output-card {
        padding: 1rem;
        min-height: 100px;
    }
}

/* Print Styles */
@media print {
    .header {
        background: none;
        color: black;
    }

    .randomize-btn,
    .export-section {
        display: none;
    }

    .tool-section {
        box-shadow: none;
        border: 1px solid #ccc;
        break-inside: avoid;
    }
}
