:root {
    /* Color Palette - Subtle Blue Theme */
    --primary-color: #3B82F6; /* Blue 500 */
    --primary-dark: #2563EB; /* Blue 600 */
    --primary-light: #93C5FD; /* Blue 300 */
    --background: #EFF6FF; /* Blue 50 */
    --surface: #FFFFFF;
    --text-main: #1E293B; /* Slate 800 */
    --text-muted: #64748B; /* Slate 500 */
    --border: #E2E8F0; /* Slate 200 */
    --danger: #EF4444;
    --success: #10B981;
    
    /* AIS Colors (Refined) */
    --ais-1: #D1FAE5; /* Emerald 100 */
    --ais-2: #FEF3C7; /* Amber 100 */
    --ais-3: #FFEDD5; /* Orange 100 */
    --ais-4: #FEE2E2; /* Red 100 */
    --ais-5: #FECACA; /* Red 200 */
    --ais-6: #1F2937; /* Gray 800 */

    /* Spacing & Sizes */
    --radius-lg: 16px;
    --radius-md: 8px;
    --radius-sm: 4px;
    --shadow-sm: 0 1px 2px 0 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);
    
    /* Animation */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.3s ease;
}

/* Reset & Base */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background-color: var(--background);
    color: var(--text-main);
    margin: 0;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
    /* Subtle blue gradient overlay */
    background-image: linear-gradient(to bottom right, #EFF6FF, #DBEAFE); 
    background-attachment: fixed;
}

button {
    font-family: inherit;
    cursor: pointer;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* Layout */
.app-container {
    width: 100%;
    max-width: 1200px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

/* Header Actions */
.header-actions {
    display: flex;
    gap: 12px;
}

.app-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: -0.03em;
    color: var(--primary-dark);
}

.subtitle {
    color: var(--text-muted);
    font-size: 0.875rem;
    margin: 4px 0 0 0;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: box-shadow var(--transition-normal);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

/* Main Content Grid */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Default to side-by-side */
    gap: 24px;
    align-items: start;
    /* Padding for the content wrapper for cleaner export */
    padding: 20px;
    background: transparent; 
}

/* Diagram Section */
.diagram-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 32px;
    position: relative;
    background: rgba(255, 255, 255, 0.8); /* Semi-transparent */
    backdrop-filter: blur(8px);
}

.diagram-header {
    width: 100%;
    text-align: center;
    margin-bottom: 24px;
}

.diagram-header h2 {
    font-size: 1.1rem;
    margin: 0;
    color: var(--text-main);
    font-weight: 600;
}

.hint-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.body-diagram-container {
    width: 100%;
    max-width: 320px;
    height: auto;
    position: relative;
    padding-top: 20px;
    margin: 0 auto; /* Center the diagram */
}

/* SVG Styles */
#body-svg {
    width: 100%;
    height: auto;
    display: block;
    filter: drop-shadow(0 8px 16px rgba(59, 130, 246, 0.15)); /* Blue-ish shadow */
}

#body-parts path {
    stroke: var(--text-main); 
    stroke-width: 1.5;
    fill: #F1F5F9; /* Slate 100 */
    transition: all var(--transition-fast);
    cursor: pointer;
}

@media (hover: hover) {
    #body-parts path:hover {
        fill: #BFDBFE; /* Blue 200 */
        transform: scale(1.01); 
        transform-origin: center;
        filter: url(#glow);
    }
}

/* AIS Color Classes */
#body-parts .ais-1 { fill: #6EE7B7; stroke: #059669; }
#body-parts .ais-2 { fill: #FCD34D; stroke: #D97706; }
#body-parts .ais-3 { fill: #FDBA74; stroke: #EA580C; }
#body-parts .ais-4 { fill: #FCA5A5; stroke: #DC2626; }
#body-parts .ais-5 { fill: #F87171; stroke: #991B1B; }
#body-parts .ais-6 { fill: #374151; stroke: #000; }

/* Results Section Updates */
.results-section {
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    background: #FFFFFF; /* Solid white for clarity */
    min-height: 500px; /* Ensure minimum height so footer pushes down */
}

.results-footer {
    margin-top: auto; /* Push to bottom */
    padding-top: 24px;
    border-top: 1px solid var(--border);
    width: 100%;
}

.score-container {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.score-container h2 {
    font-size: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.score-circle {
    width: 140px; /* Slightly larger */
    height: 140px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FFFFFF, #EFF6FF);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        inset 0 2px 4px rgba(255,255,255,1),
        0 12px 24px rgba(59, 130, 246, 0.15);
    border: 4px solid #DBEAFE;
    position: relative;
}

#iss-score {
    font-size: 3.5rem;
    font-weight: 800;
    color: var(--primary-dark);
    line-height: 1;
}

/* Summary List */
.summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.summary-header h3 {
    font-size: 1rem;
    margin: 0;
    font-weight: 600;
    color: var(--text-main);
}

.badge {
    background: #DBEAFE;
    color: var(--primary-dark);
    font-size: 0.75rem;
    padding: 4px 10px;
    border-radius: 12px;
    font-weight: 700;
}

.injury-list-container {
    max-height: 400px;
    overflow-y: auto;
}

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.9rem;
    background: #F8FAFC;
    border-radius: var(--radius-md);
    border: 1px dashed var(--border);
}

.injury-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin-bottom: 10px;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 16px; 
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.injury-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.04);
    border-color: var(--primary-light);
}

.injury-ais-indicator {
    width: 36px;
    height: 36px;
    border-radius: 50%; 
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-main);
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.5); /* Subtle inner border */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Background colors for indicators - slightly more vivid for badges */
.injury-ais-indicator.ais-1 { background-color: #6EE7B7; color: #064E3B; }
.injury-ais-indicator.ais-2 { background-color: #FCD34D; color: #78350F; }
.injury-ais-indicator.ais-3 { background-color: #FDBA74; color: #7C2D12; }
.injury-ais-indicator.ais-4 { background-color: #FCA5A5; color: #7F1D1D; }
.injury-ais-indicator.ais-5 { background-color: #F87171; color: #450A0A; }
.injury-ais-indicator.ais-6 { background-color: #1F2937; color: white; }

.injury-details {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex-grow: 1; 
}

/* Injury Item Improvements */
.injury-description {
    font-size: 0.95rem;
    font-weight: 700; /* Bolder */
    color: #0F172A; /* Darker slate */
    line-height: 1.3;
}

.injury-region {
    font-size: 0.75rem;
    color: #475569; /* Darker muted text */
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.04em;
}

#reset-button {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: #F1F5F9;
    color: #64748B;
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: var(--radius-md);
    font-weight: 600;
    transition: all 0.2s;
}

#reset-button:hover {
    background: #FEE2E2;
    color: var(--danger);
    border-color: #FCA5A5;
}

#reset-button svg {
    opacity: 0.7;
}

.btn-delete {
    background: #F1F5F9;
    border: none;
    color: var(--text-muted); 
    padding: 8px;
    border-radius: var(--radius-md); /* Softer corners */
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    margin-left: auto; 
    transition: all 0.2s;
}

.btn-delete:hover {
    color: var(--danger);
    background-color: #FEF2F2;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: rgba(30, 41, 59, 0.5); /* Slate overlay */
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: var(--surface);
    margin: 5% auto; 
    padding: 32px;
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    box-shadow: var(--shadow-lg);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 20px;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
}

.close-button {
    background: #F1F5F9;
    border: none;
    color: var(--text-muted);
    padding: 8px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.close-button:hover {
    background: #E2E8F0;
    color: var(--text-main);
}

/* Form Elements */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

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

.select-wrapper {
    position: relative;
}

select {
    width: 100%;
    padding: 14px 40px 14px 16px; 
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    appearance: none;
    background-color: #F8FAFC;
    color: var(--text-main);
    transition: all 0.2s;
    cursor: pointer;
    font-weight: 500;
}

select:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: #FFFFFF;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1);
}

.chevron-down {
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
    box-sizing: border-box;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Updated Select for Searchable List */
select[size] {
    padding: 8px;
    background-image: none; /* Remove chevron for list view */
    height: 150px; /* Fixed height for scrolling */
}

select[size] option {
    padding: 8px;
    border-bottom: 1px solid #f1f5f9;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.form-actions button {
    flex: 1;
    padding: 14px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 6px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 6px 8px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
    background-color: #F1F5F9;
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: #E2E8F0;
}

/* Reset/Export Button (Header) */
.btn-icon-text {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #FFFFFF;
    border: 1px solid var(--border);
    padding: 10px 18px;
    border-radius: 99px;
    color: var(--text-main);
    font-weight: 600;
    font-size: 0.9rem;
    transition: all 0.2s;
    box-shadow: var(--shadow-sm);
}

.btn-icon-text:hover {
    background: #F8FAFC;
    border-color: #CBD5E1;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-icon-text svg {
    color: var(--primary-color);
}

/* Export Mode Overrides - FIXED READABILITY & PADDING */
.export-mode * {
    transition: none !important;
}

.export-mode .main-content {
    background-color: #EFF6FF !important; 
    padding: 30px !important;
}

.export-mode .card {
    background-color: #FFFFFF !important; /* Pure white background */
    border: 1px solid #94A3B8 !important; /* Visible slate border */
    box-shadow: none !important;
}

/* Force PURE BLACK for primary text to ensure readability */
.export-mode h1, .export-mode h2, .export-mode h3, 
.export-mode .injury-description, .export-mode #iss-score {
    color: #000000 !important;
    font-weight: 700 !important; /* Bump weight for clarity */
}

/* Darker color for secondary text */
.export-mode .injury-region {
    color: #333333 !important; 
    font-weight: 600 !important;
}

.export-mode .injury-ais-indicator {
    border: 1px solid #000000 !important;
    font-weight: bold !important;
    color: #000000 !important;
}

/* Fix padding above head - specific for export */
.export-mode .body-diagram-container {
    padding-top: 60px !important; /* Increased padding */
    margin-top: 20px !important;
    display: block !important;
}

/* Responsive */
@media (max-width: 600px) {
    .main-content {
        grid-template-columns: 1fr; /* Stack vertically */
        padding: 10px; /* Reduce container padding */
    }

    .diagram-section, .results-section {
        padding: 20px; /* Reduce card padding */
        min-height: auto; /* Let content dictate height on mobile */
    }

    .modal-content {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        margin: 0;
        max-width: none;
        border-radius: 20px 20px 0 0; /* Sheet style */
        padding: 24px;
        box-sizing: border-box;
        animation: slideUpMobile 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    }

    @keyframes slideUpMobile {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
}

/* DEBUG EXPORT VIEW - FORCE STYLES ON LIVE DOM */
.debug-export-view {
    background-color: #EFF6FF !important;
}

.debug-export-view * {
    font-family: Arial, Helvetica, sans-serif !important;
    text-shadow: none !important;
    filter: none !important;
    backdrop-filter: none !important;
    -webkit-font-smoothing: antialiased !important;
    transition: none !important;
}

.debug-export-view .main-content {
    width: 1100px !important;
    margin: 0 auto !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 30px !important;
    padding: 40px !important;
}

.debug-export-view h1, 
.debug-export-view h2, 
.debug-export-view h3, 
.debug-export-view .injury-description, 
.debug-export-view #iss-score, 
.debug-export-view .badge, 
.debug-export-view .injury-region, 
.debug-export-view .injury-ais-indicator,
.debug-export-view span,
.debug-export-view li,
.debug-export-view div,
.debug-export-view p {
    color: #000000 !important;
    opacity: 1 !important;
    fill: #000000 !important;
}

.debug-export-view .injury-description,
.debug-export-view #iss-score {
    font-weight: 900 !important;
}

.debug-export-view .card, 
.debug-export-view .injury-item {
    background-color: #FFFFFF !important;
    background: #FFFFFF !important;
    border: 2px solid #000000 !important;
    box-shadow: none !important;
}

.debug-export-view .diagram-section {
    padding-top: 100px !important;
    background: #FFFFFF !important;
}

.debug-export-view #body-svg {
    overflow: visible !important;
}