/* CSS Variables */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --secondary-color: #8b5cf6;
    --accent-color: #f59e0b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --background-color: #0f172a;
    --surface-color: #1e293b;
    --surface-hover: #334155;
    --border-color: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

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

html {
    scroll-behavior: smooth;
}

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

/* App Container */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.app-header {
    text-align: center;
    padding: 30px 20px;
    margin-bottom: 30px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.app-header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.app-header .tagline {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Section Styles */
.section {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    padding: 25px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.section h2 {
    font-size: 1.4rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section h2::before {
    content: '';
    width: 4px;
    height: 24px;
    background: linear-gradient(to bottom, var(--primary-color), var(--secondary-color));
    border-radius: 2px;
}

/* Style Selection */
.style-options {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.style-btn {
    padding: 12px 24px;
    border: 2px solid var(--border-color);
    background: var(--surface-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: var(--transition);
}

.style-btn:hover {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

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

/* Character Preview */
.preview-section {
    text-align: center;
}

.character-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.avatar-container {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: linear-gradient(135deg, #374151, #1f2937);
    padding: 10px;
    box-shadow: var(--shadow-lg), inset 0 2px 4px rgba(255, 255, 255, 0.1);
}

.avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
    background: #ffe4c4;
}

.avatar-base {
    position: absolute;
    inset: 0;
    background: inherit;
    border-radius: 50%;
}

.avatar-hair {
    position: absolute;
    top: 0;
    left: 10%;
    right: 10%;
    height: 45%;
    background: #4a3728;
    border-radius: 50% 50% 0 0;
    transition: var(--transition);
}

.avatar-hair.short {
    height: 35%;
    border-radius: 40% 40% 20% 20%;
}

.avatar-hair.long {
    height: 60%;
    left: 5%;
    right: 5%;
    border-radius: 45% 45% 30% 30%;
}

.avatar-hair.curly {
    height: 50%;
    border-radius: 60% 60% 40% 40%;
    background: repeating-radial-gradient(circle at 50% 100%, transparent 0, transparent 3px, currentColor 3px, currentColor 6px);
}

.avatar-hair.bald {
    display: none;
}

.avatar-hair.ponytail {
    height: 40%;
    border-radius: 50% 50% 10% 10%;
}

.avatar-hair.ponytail::after {
    content: '';
    position: absolute;
    top: 80%;
    right: -10%;
    width: 30%;
    height: 80%;
    background: inherit;
    border-radius: 30%;
    transform: rotate(20deg);
}

.avatar-hair.braided {
    height: 45%;
    border-radius: 50% 50% 20% 20%;
}

.avatar-hair.braided::after {
    content: '';
    position: absolute;
    top: 90%;
    left: 35%;
    width: 30%;
    height: 60%;
    background: inherit;
    border-radius: 20%;
}

.avatar-eyes {
    position: absolute;
    top: 45%;
    left: 25%;
    right: 25%;
    height: 12%;
    display: flex;
    justify-content: space-between;
}

.avatar-eyes::before,
.avatar-eyes::after {
    content: '';
    width: 35%;
    height: 100%;
    background: white;
    border-radius: 50%;
    position: relative;
}

.avatar-eyes::before {
    box-shadow: inset 10px 0 0 var(--eye-color, #4a3728);
}

.avatar-eyes::after {
    box-shadow: inset 10px 0 0 var(--eye-color, #4a3728);
}

.avatar-mouth {
    position: absolute;
    top: 65%;
    left: 35%;
    right: 35%;
    height: 8%;
    background: #c9787c;
    border-radius: 0 0 50% 50%;
}

.avatar-accessory {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.avatar-accessory.glasses::before {
    content: '';
    position: absolute;
    top: 42%;
    left: 15%;
    right: 15%;
    height: 18%;
    border: 3px solid #333;
    border-radius: 30%;
    background: rgba(100, 149, 237, 0.2);
}

.avatar-accessory.hat::before {
    content: '';
    position: absolute;
    top: -5%;
    left: 5%;
    right: 5%;
    height: 30%;
    background: #4a3728;
    border-radius: 50% 50% 10% 10%;
}

.avatar-accessory.headband::before {
    content: '';
    position: absolute;
    top: 25%;
    left: 0;
    right: 0;
    height: 8%;
    background: var(--primary-color);
}

.avatar-accessory.earrings::before,
.avatar-accessory.earrings::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 8px;
    height: 8px;
    background: gold;
    border-radius: 50%;
}

.avatar-accessory.earrings::before {
    left: 5%;
}

.avatar-accessory.earrings::after {
    right: 5%;
}

.avatar-accessory.scar::before {
    content: '';
    position: absolute;
    top: 40%;
    left: 55%;
    width: 25%;
    height: 4px;
    background: linear-gradient(90deg, transparent, #d9a9a9, transparent);
    transform: rotate(-15deg);
}

.character-name-display {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Form Styles */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.input-with-btn {
    display: flex;
    gap: 8px;
}

.input-with-btn input,
.input-with-btn select {
    flex: 1;
}

input, select, textarea {
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--background-color);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

input::placeholder, textarea::placeholder {
    color: var(--text-muted);
}

select {
    cursor: pointer;
}

/* Randomize Button */
.randomize-btn {
    padding: 10px 14px;
    border: 2px solid var(--border-color);
    background: var(--surface-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1.1rem;
    transition: var(--transition);
}

.randomize-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: rotate(180deg);
}

/* Visual Customization */
.visual-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 25px;
    margin-bottom: 20px;
}

.visual-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.visual-group label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.option-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.option-btn {
    padding: 8px 16px;
    border: 2px solid var(--border-color);
    background: var(--background-color);
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
}

.option-btn:hover {
    border-color: var(--primary-color);
}

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

.color-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.color-btn {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-radius: 50%;
    cursor: pointer;
    transition: var(--transition);
}

.color-btn:hover {
    transform: scale(1.15);
}

.color-btn.active {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.4);
}

.randomize-visual-btn {
    margin-top: 15px;
}

/* Traits Section */
.traits-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 25px;
    margin-bottom: 20px;
}

.trait-category h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.trait-count {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 400;
}

.trait-options {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.trait-btn {
    padding: 8px 14px;
    border: 2px solid var(--border-color);
    background: var(--background-color);
    color: var(--text-primary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: var(--transition);
}

.trait-btn:hover {
    border-color: var(--primary-color);
    background: var(--surface-hover);
}

.trait-btn.selected {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.trait-btn.selected.flaw {
    background: var(--danger-color);
    border-color: var(--danger-color);
}

/* Story Section */
.story-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.prompt-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.prompt-group label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.story-output {
    margin-top: 20px;
}

.story-output textarea {
    width: 100%;
    min-height: 200px;
    resize: vertical;
    font-family: inherit;
    line-height: 1.7;
}

/* Export Section */
.export-preview {
    background: var(--background-color);
    border: 2px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 25px;
    margin-bottom: 20px;
    min-height: 300px;
}

.sheet-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 250px;
    color: var(--text-muted);
    font-style: italic;
}

.character-sheet {
    font-family: 'Georgia', serif;
}

.character-sheet .sheet-header {
    text-align: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
}

.character-sheet .sheet-name {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary-color);
    margin-bottom: 5px;
}

.character-sheet .sheet-title {
    color: var(--text-secondary);
    font-style: italic;
}

.character-sheet .sheet-section {
    margin-bottom: 20px;
}

.character-sheet .sheet-section-title {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--secondary-color);
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.character-sheet .sheet-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.character-sheet .sheet-item {
    display: flex;
    gap: 8px;
}

.character-sheet .sheet-label {
    color: var(--text-muted);
    min-width: 80px;
}

.character-sheet .sheet-value {
    color: var(--text-primary);
    font-weight: 500;
}

.character-sheet .sheet-traits {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.character-sheet .sheet-trait {
    padding: 4px 12px;
    background: var(--surface-color);
    border-radius: 15px;
    font-size: 0.9rem;
}

.character-sheet .sheet-story {
    line-height: 1.8;
    color: var(--text-secondary);
    font-style: italic;
}

.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.export-btn {
    padding: 12px 24px;
    border: 2px solid var(--primary-color);
    background: transparent;
    color: var(--primary-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
}

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

/* Action Buttons */
.actions-section {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    justify-content: center;
}

.action-btn {
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: var(--transition);
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    box-shadow: var(--shadow-md);
}

.action-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.action-btn.secondary {
    background: var(--surface-color);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.action-btn.secondary:hover {
    border-color: var(--danger-color);
    color: var(--danger-color);
}

.action-btn:not(.primary):not(.secondary) {
    background: var(--surface-hover);
    color: var(--text-primary);
}

.action-btn:not(.primary):not(.secondary):hover {
    background: var(--primary-color);
    color: white;
}

/* Footer */
.app-footer {
    text-align: center;
    padding: 25px 20px;
    margin-top: 30px;
    border-top: 1px solid var(--border-color);
    color: var(--text-secondary);
}

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

.app-footer a:hover {
    color: var(--secondary-color);
    text-decoration: underline;
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 16px 24px;
    background: var(--surface-color);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--success-color);
    transform: translateX(120%);
    transition: transform 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateX(0);
}

.toast.error {
    border-left-color: var(--danger-color);
}

/* Responsive Design */
@media (max-width: 768px) {
    .app-container {
        padding: 15px;
    }

    .app-header {
        padding: 20px 15px;
    }

    .app-header h1 {
        font-size: 1.8rem;
    }

    .app-header .tagline {
        font-size: 0.95rem;
    }

    .section {
        padding: 20px 15px;
    }

    .section h2 {
        font-size: 1.2rem;
    }

    .style-options {
        justify-content: center;
    }

    .style-btn {
        padding: 10px 18px;
        font-size: 0.9rem;
    }

    .avatar-container {
        width: 160px;
        height: 160px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .visual-grid {
        grid-template-columns: 1fr;
    }

    .traits-container {
        grid-template-columns: 1fr;
    }

    .story-prompts {
        grid-template-columns: 1fr;
    }

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

    .export-btn {
        width: 100%;
    }

    .actions-section {
        flex-direction: column;
    }

    .action-btn {
        width: 100%;
    }

    .character-sheet .sheet-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .app-header h1 {
        font-size: 1.5rem;
    }

    .option-buttons {
        justify-content: center;
    }

    .color-options {
        justify-content: center;
    }

    .toast {
        left: 20px;
        right: 20px;
        bottom: 15px;
    }
}

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

.section {
    animation: fadeIn 0.4s ease forwards;
}

.section:nth-child(1) { animation-delay: 0.05s; }
.section:nth-child(2) { animation-delay: 0.1s; }
.section:nth-child(3) { animation-delay: 0.15s; }
.section:nth-child(4) { animation-delay: 0.2s; }
.section:nth-child(5) { animation-delay: 0.25s; }
.section:nth-child(6) { animation-delay: 0.3s; }
.section:nth-child(7) { animation-delay: 0.35s; }
.section:nth-child(8) { animation-delay: 0.4s; }

/* Print Styles */
@media print {
    .app-header,
    .style-section,
    .visual-section,
    .traits-section .action-btn,
    .story-section .story-prompts,
    .story-section .action-btn,
    .export-buttons,
    .actions-section,
    .app-footer {
        display: none;
    }

    .export-preview {
        border: none;
        padding: 0;
    }

    body {
        background: white;
        color: black;
    }

    .section {
        background: white;
        border: none;
        box-shadow: none;
    }
}
