* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Exo 2', sans-serif;
    background: #0a0a0f;
    color: #e0e0e0;
    min-height: 100vh;
    overflow-x: hidden;
}

#starfield {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.star {
    position: absolute;
    background: #fff;
    border-radius: 50%;
    animation: twinkle var(--duration) ease-in-out infinite;
}

@keyframes twinkle {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 1; }
}

header {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: 40px 20px 20px;
    background: linear-gradient(180deg, rgba(0,0,0,0.9) 0%, rgba(10,10,15,0.7) 100%);
    border-bottom: 1px solid #1a1a2e;
}

header h1 {
    font-family: 'Orbitron', sans-serif;
    font-size: 3rem;
    font-weight: 900;
    color: #FFE81F;
    text-shadow: 0 0 30px rgba(255,232,31,0.3);
    letter-spacing: 8px;
    text-transform: uppercase;
}

header h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 400;
    color: #4fc3f7;
    letter-spacing: 4px;
    margin-top: 8px;
    text-transform: uppercase;
}

.search-bar {
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 24px;
    flex-wrap: wrap;
}

.search-bar input,
.search-bar select {
    padding: 10px 20px;
    border: 1px solid #1a1a3e;
    border-radius: 25px;
    background: rgba(15, 15, 30, 0.8);
    color: #e0e0e0;
    font-family: 'Exo 2', sans-serif;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.3s;
}

.search-bar input {
    width: 300px;
}

.search-bar input:focus,
.search-bar select:focus {
    border-color: #FFE81F;
}

.search-bar select option {
    background: #0a0a1f;
}

.stats {
    margin-top: 16px;
    font-size: 0.85rem;
    color: #888;
    letter-spacing: 1px;
}

main {
    position: relative;
    z-index: 1;
    padding: 30px 20px;
    max-width: 1400px;
    margin: 0 auto;
}

.species-section {
    margin-bottom: 40px;
}

.species-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    cursor: pointer;
    user-select: none;
    padding: 12px 16px;
    background: linear-gradient(90deg, rgba(30,30,60,0.6) 0%, rgba(10,10,20,0) 100%);
    border-left: 3px solid #FFE81F;
    border-radius: 4px;
    transition: background 0.3s;
}

.species-header:hover {
    background: linear-gradient(90deg, rgba(40,40,80,0.8) 0%, rgba(10,10,20,0) 100%);
}

.species-header h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.2rem;
    color: #FFE81F;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.species-count {
    background: rgba(255,232,31,0.15);
    color: #FFE81F;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.species-toggle {
    margin-left: auto;
    color: #FFE81F;
    font-size: 1.2rem;
    transition: transform 0.3s;
}

.species-toggle.collapsed {
    transform: rotate(-90deg);
}

.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 16px;
    padding: 0 8px;
    transition: max-height 0.5s ease, opacity 0.3s;
    overflow: hidden;
}

.characters-grid.collapsed {
    max-height: 0 !important;
    opacity: 0;
    padding: 0;
    margin: 0;
}

.character-card {
    background: linear-gradient(145deg, #12122a 0%, #0a0a1a 100%);
    border: 1px solid #1a1a3e;
    border-radius: 10px;
    padding: 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.character-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--side-color, #4fc3f7), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.character-card:hover {
    transform: translateY(-4px);
    border-color: #4fc3f7;
    box-shadow: 0 8px 25px rgba(79,195,247,0.15);
}

.character-card:hover::before {
    opacity: 1;
}

.character-card .avatar {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    margin: 0 auto 12px;
    overflow: hidden;
    border: 2px solid #1a1a3e;
    transition: border-color 0.3s;
    background: #1a1a2e;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-card:hover .avatar {
    border-color: #4fc3f7;
}

.character-card .avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.character-card .avatar .initials {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: #4fc3f7;
}

.character-card .name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #e0e0e0;
    margin-bottom: 4px;
    line-height: 1.2;
}

.character-card .affiliation {
    font-size: 0.7rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.era-badges {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 8px;
    flex-wrap: wrap;
}

.era-badge {
    font-size: 0.55rem;
    padding: 2px 6px;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.era-badge.prequel { background: rgba(255,87,34,0.2); color: #ff7043; }
.era-badge.original { background: rgba(79,195,247,0.2); color: #4fc3f7; }
.era-badge.sequel { background: rgba(156,39,176,0.2); color: #ce93d8; }
.era-badge.other { background: rgba(76,175,80,0.2); color: #81c784; }

/* Side colors */
.character-card[data-side="light"] { --side-color: #4fc3f7; }
.character-card[data-side="dark"] { --side-color: #f44336; }
.character-card[data-side="neutral"] { --side-color: #FFE81F; }
.character-card[data-side="bounty"] { --side-color: #ff9800; }

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    background: rgba(0,0,0,0.85);
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-content {
    background: linear-gradient(145deg, #12122a 0%, #0a0a1a 100%);
    border: 1px solid #1a1a3e;
    border-radius: 16px;
    padding: 32px;
    max-width: 800px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.4s ease;
}

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

.modal-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 2rem;
    color: #888;
    cursor: pointer;
    transition: color 0.3s;
    line-height: 1;
    z-index: 10;
}

.modal-close:hover {
    color: #FFE81F;
}

.modal-header {
    display: flex;
    gap: 24px;
    margin-bottom: 28px;
    align-items: flex-start;
}

.modal-photo {
    flex-shrink: 0;
    width: 150px;
    height: 150px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid #FFE81F;
    background: #1a1a2e;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-photo .initials-large {
    font-family: 'Orbitron', sans-serif;
    font-size: 2.5rem;
    font-weight: 700;
    color: #FFE81F;
}

.modal-info h2 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    color: #FFE81F;
    margin-bottom: 12px;
    letter-spacing: 2px;
}

.modal-info .detail-row {
    display: flex;
    gap: 8px;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.modal-info .detail-label {
    color: #4fc3f7;
    font-weight: 600;
    min-width: 100px;
}

.modal-info .detail-value {
    color: #ccc;
}

.modal-timeline h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    color: #4fc3f7;
    margin-bottom: 20px;
    letter-spacing: 2px;
    text-transform: uppercase;
    border-bottom: 1px solid #1a1a3e;
    padding-bottom: 8px;
}

.timeline {
    position: relative;
    padding-left: 30px;
}

.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(180deg, #FFE81F 0%, #4fc3f7 50%, #f44336 100%);
}

.timeline-event {
    position: relative;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: rgba(20,20,40,0.6);
    border-radius: 8px;
    border-left: 3px solid var(--event-color, #4fc3f7);
    transition: background 0.3s;
}

.timeline-event:hover {
    background: rgba(30,30,60,0.8);
}

.timeline-event::before {
    content: '';
    position: absolute;
    left: -27px;
    top: 16px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--event-color, #4fc3f7);
    border: 2px solid #0a0a1a;
}

.timeline-event .event-date {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.7rem;
    color: #FFE81F;
    letter-spacing: 1px;
    margin-bottom: 4px;
}

.timeline-event .event-title {
    font-weight: 600;
    font-size: 0.9rem;
    color: #e0e0e0;
    margin-bottom: 4px;
}

.timeline-event .event-desc {
    font-size: 0.8rem;
    color: #999;
    line-height: 1.4;
}

.timeline-event.birth { --event-color: #4caf50; }
.timeline-event.death { --event-color: #f44336; }
.timeline-event.battle { --event-color: #ff9800; }
.timeline-event.turning { --event-color: #FFE81F; }
.timeline-event.jedi { --event-color: #4fc3f7; }
.timeline-event.sith { --event-color: #e91e63; }
.timeline-event.political { --event-color: #9c27b0; }

/* Scrollbar */
.modal-content::-webkit-scrollbar {
    width: 6px;
}

.modal-content::-webkit-scrollbar-track {
    background: transparent;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 { font-size: 2rem; letter-spacing: 4px; }
    header h2 { font-size: 0.8rem; }
    .search-bar input { width: 100%; }
    .modal-header { flex-direction: column; align-items: center; text-align: center; }
    .modal-photo { width: 120px; height: 120px; }
    .modal-content { padding: 20px; }
    .characters-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
    .modal-info .detail-row { flex-direction: column; gap: 2px; }
    .modal-info .detail-label { min-width: unset; }
}

@media (max-width: 480px) {
    .characters-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
    .character-card .avatar { width: 70px; height: 70px; }
    .character-card .name { font-size: 0.75rem; }
}
