{% extends "base.html" %}

{% block title %}Choose Your Origin - Code of Conquest{% endblock %}

{% block content %}
<div class="creation-container">
    <!-- Progress Indicator -->
    <div class="creation-progress">
        <div class="progress-step active">
            <div class="step-number">1</div>
            <div class="step-label">Origin</div>
        </div>
        <div class="progress-line"></div>
        <div class="progress-step">
            <div class="step-number">2</div>
            <div class="step-label">Class</div>
        </div>
        <div class="progress-line"></div>
        <div class="progress-step">
            <div class="step-number">3</div>
            <div class="step-label">Customize</div>
        </div>
        <div class="progress-line"></div>
        <div class="progress-step">
            <div class="step-number">4</div>
            <div class="step-label">Confirm</div>
        </div>
    </div>

    <!-- Page Header -->
    <h1 class="page-title">Choose Your Origin</h1>
    <p class="page-subtitle">Every hero has a beginning. Where does your story start?</p>

    <div class="decorative-line"></div>

    <!-- Origin Selection Form -->
    <form method="POST" action="{{ url_for('character_views.create_origin') }}" id="origin-form">
        <div class="origin-grid">
            {% for origin in origins %}
            <div class="origin-card" data-origin-id="{{ origin.id }}">
                <input
                    type="radio"
                    name="origin_id"
                    value="{{ origin.id }}"
                    id="origin-{{ origin.id }}"
                    class="origin-radio"
                    required
                >
                <label for="origin-{{ origin.id }}" class="origin-label">
                    <div class="origin-header">
                        <h3 class="origin-title">{{ origin.name }}</h3>
                    </div>

                    <div class="origin-description">
                        <p class="description-preview">
                            {{ origin.description[:180] }}{% if origin.description|length > 180 %}...{% endif %}
                        </p>
                        {% if origin.description|length > 180 %}
                        <div class="description-full" style="display: none;">
                            <p>{{ origin.description }}</p>
                        </div>
                        <button type="button" class="expand-btn" onclick="toggleDescription(this)">
                            <span class="expand-text">Read More</span>
                            <span class="expand-icon">▼</span>
                        </button>
                        {% endif %}
                    </div>

                    <div class="origin-details">
                        <div class="detail-item">
                            <span class="detail-label">Starting Location:</span>
                            <span class="detail-value">{{ origin.starting_location.name }}</span>
                        </div>

                        {% if origin.starting_bonus %}
                        <div class="detail-item">
                            <span class="detail-label">Starting Bonus:</span>
                            <div class="bonus-display">
                                <strong>{{ origin.starting_bonus.trait }}</strong>
                                <p class="bonus-description">{{ origin.starting_bonus.description }}</p>
                            </div>
                        </div>
                        {% endif %}
                    </div>
                </label>
            </div>
            {% endfor %}
        </div>

        <!-- Navigation Buttons -->
        <div class="creation-nav">
            <a href="{{ url_for('character_views.list_characters') }}" class="btn btn-secondary">
                Cancel
            </a>
            <button type="submit" class="btn btn-primary">
                Next: Choose Class →
            </button>
        </div>
    </form>
</div>

<style>
/* ===== CHARACTER CREATION CONTAINER ===== */
.creation-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 2rem;
}

/* ===== PROGRESS INDICATOR ===== */
.creation-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 3rem;
    gap: 1rem;
}

.progress-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.step-number {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-input);
    border: 2px solid var(--border-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-weight: 600;
    color: var(--text-muted);
    transition: all 0.3s ease;
}

.step-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    transition: all 0.3s ease;
}

.progress-step.active .step-number {
    background: var(--accent-gold);
    border-color: var(--accent-gold);
    color: var(--bg-primary);
    box-shadow: var(--shadow-glow);
}

.progress-step.active .step-label {
    color: var(--accent-gold);
    font-weight: 600;
}

.progress-step.completed .step-number {
    background: var(--accent-green);
    border-color: var(--accent-green);
    color: var(--bg-primary);
}

.progress-step.completed .step-label {
    color: var(--accent-green);
}

.progress-line {
    width: 60px;
    height: 2px;
    background: var(--border-primary);
}

/* ===== ORIGIN GRID ===== */
.origin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

/* ===== ORIGIN CARDS ===== */
.origin-card {
    position: relative;
}

.origin-radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.origin-label {
    display: block;
    padding: 2rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-primary);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    height: 100%;
}

.origin-label:hover {
    border-color: var(--accent-gold);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.origin-radio:checked + .origin-label {
    border-color: var(--accent-gold);
    box-shadow: var(--shadow-glow);
    background: linear-gradient(135deg, var(--bg-secondary) 0%, rgba(243, 156, 18, 0.1) 100%);
}

.origin-header {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-primary);
}

.origin-title {
    font-family: var(--font-heading);
    font-size: var(--text-xl);
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.origin-description {
    margin-bottom: 1rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.description-preview {
    margin: 0;
}

.description-full {
    margin-top: 0.5rem;
}

.description-full p {
    margin: 0;
}

.expand-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
    padding: 0.5rem 0;
    background: none;
    border: none;
    color: var(--accent-gold);
    font-size: var(--text-sm);
    cursor: pointer;
    transition: all 0.3s ease;
}

.expand-btn:hover {
    color: var(--accent-gold-hover);
}

.expand-icon {
    font-size: var(--text-xs);
    transition: transform 0.3s ease;
}

.expand-btn.expanded .expand-icon {
    transform: rotate(180deg);
}

.origin-details {
    margin-bottom: 1.5rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
}

.detail-label {
    font-family: var(--font-heading);
    font-size: var(--text-sm);
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
}

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

.bonus-display {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-input);
    border-radius: 4px;
}

.bonus-display strong {
    color: var(--accent-gold);
    display: block;
    margin-bottom: 0.25rem;
}

.bonus-description {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    margin: 0.25rem 0;
}

/* ===== CREATION NAVIGATION ===== */
.creation-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
}

.creation-nav .btn {
    min-width: 200px;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .creation-container {
        padding: 1rem;
    }

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

    .creation-progress {
        gap: 0.5rem;
    }

    .progress-line {
        width: 30px;
    }

    .step-label {
        display: none;
    }

    .creation-nav {
        flex-direction: column;
    }

    .creation-nav .btn {
        width: 100%;
    }
}
</style>

<script>
function toggleDescription(button) {
    const card = button.closest('.origin-card');
    const preview = card.querySelector('.description-preview');
    const full = card.querySelector('.description-full');
    const expandText = button.querySelector('.expand-text');

    if (full.style.display === 'none') {
        // Expand
        preview.style.display = 'none';
        full.style.display = 'block';
        expandText.textContent = 'Read Less';
        button.classList.add('expanded');
    } else {
        // Collapse
        preview.style.display = 'block';
        full.style.display = 'none';
        expandText.textContent = 'Read More';
        button.classList.remove('expanded');
    }
}
</script>
{% endblock %}
