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

body {
    font-family: 'Lato', sans-serif;
    background: #0d1a0d;
    color: #d4c9a8;
    min-height: 100vh;
    overflow-x: hidden;
}

#forestBg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(34, 85, 34, 0.15) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 30%, rgba(85, 107, 47, 0.1) 0%, transparent 50%),
        radial-gradient(ellipse at 50% 80%, rgba(20, 60, 20, 0.12) 0%, transparent 55%);
}

.firefly {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #c8a832;
    border-radius: 50%;
    box-shadow: 0 0 6px 2px rgba(200, 168, 50, 0.4);
    animation: float var(--duration) ease-in-out infinite;
    opacity: 0;
}

@keyframes float {
    0%   { opacity: 0; transform: translate(0, 0); }
    25%  { opacity: 0.8; }
    50%  { opacity: 1; transform: translate(var(--dx), var(--dy)); }
    75%  { opacity: 0.6; }
    100% { opacity: 0; transform: translate(0, 0); }
}

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

header h1 {
    font-family: 'Cinzel', serif;
    font-size: 2.8rem;
    font-weight: 900;
    color: #c8a832;
    text-shadow: 0 0 30px rgba(200,168,50,0.3);
    letter-spacing: 4px;
    text-transform: uppercase;
}

header h2 {
    font-family: 'Cinzel', serif;
    font-size: 1rem;
    font-weight: 400;
    color: #6aaa6a;
    letter-spacing: 3px;
    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 #2a3a1a;
    border-radius: 25px;
    background: rgba(15, 25, 15, 0.8);
    color: #d4c9a8;
    font-family: 'Lato', 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: #c8a832;
}

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

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

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

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

.clan-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,50,30,0.6) 0%, rgba(13,26,13,0) 100%);
    border-left: 3px solid var(--clan-color, #c8a832);
    border-radius: 4px;
    transition: background 0.3s;
}

.clan-header:hover {
    background: linear-gradient(90deg, rgba(40,70,40,0.8) 0%, rgba(13,26,13,0) 100%);
}

.clan-header h3 {
    font-family: 'Cinzel', serif;
    font-size: 1.2rem;
    color: var(--clan-color, #c8a832);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.clan-count {
    background: rgba(200,168,50,0.15);
    color: var(--clan-color, #c8a832);
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}

.clan-toggle {
    margin-left: auto;
    color: var(--clan-color, #c8a832);
    font-size: 1.2rem;
    transition: transform 0.3s;
}

.clan-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, #162216 0%, #0d1a0d 100%);
    border: 1px solid #2a3a1a;
    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(--clan-color, #6aaa6a), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.character-card:hover {
    transform: translateY(-4px);
    border-color: var(--clan-color, #6aaa6a);
    box-shadow: 0 8px 25px rgba(106,170,106,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 #2a3a1a;
    transition: border-color 0.3s;
    background: #1a2a1a;
    display: flex;
    align-items: center;
    justify-content: center;
}

.character-card:hover .avatar {
    border-color: var(--clan-color, #6aaa6a);
}

.character-card .avatar svg {
    width: 100%;
    height: 100%;
}

.character-card .avatar .initials {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--clan-color, #6aaa6a);
}

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

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

.character-card .first-book {
    font-size: 0.65rem;
    color: #5a6a4a;
    margin-top: 6px;
    font-style: italic;
    line-height: 1.3;
}

.cycle-badge {
    display: inline-block;
    font-size: 0.55rem;
    padding: 2px 6px;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-top: 6px;
}

.cycle-badge.cycle1 { background: rgba(200,168,50,0.2); color: #c8a832; }
.cycle-badge.cycle2 { background: rgba(106,170,106,0.2); color: #6aaa6a; }
.cycle-badge.cycle3 { background: rgba(79,135,195,0.2); color: #4f87c3; }
.cycle-badge.cycle4 { background: rgba(156,106,170,0.2); color: #9c6aaa; }
.cycle-badge.cycle5 { background: rgba(200,120,50,0.2); color: #c87832; }
.cycle-badge.cycle6 { background: rgba(170,106,106,0.2); color: #aa6a6a; }
.cycle-badge.cycle7 { background: rgba(106,170,170,0.2); color: #6aaaaa; }
.cycle-badge.horseserie { background: rgba(160,160,160,0.2); color: #aaa; }

/* 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, #162216 0%, #0d1a0d 100%);
    border: 1px solid #2a3a1a;
    border-radius: 16px;
    padding: 32px;
    max-width: 700px;
    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: #6a7a5a;
    cursor: pointer;
    transition: color 0.3s;
    line-height: 1;
    z-index: 10;
}

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

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

.modal-photo {
    flex-shrink: 0;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    overflow: hidden;
    border: 3px solid var(--modal-clan-color, #c8a832);
    background: #1a2a1a;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-photo svg {
    width: 100%;
    height: 100%;
}

.modal-photo .initials-large {
    font-family: 'Cinzel', serif;
    font-size: 2rem;
    font-weight: 700;
    color: var(--modal-clan-color, #c8a832);
}

.modal-info h2 {
    font-family: 'Cinzel', serif;
    font-size: 1.4rem;
    color: #c8a832;
    margin-bottom: 4px;
    letter-spacing: 2px;
}

.modal-info .english-name {
    font-size: 0.85rem;
    color: #6a7a5a;
    font-style: italic;
    margin-bottom: 12px;
}

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

.modal-info .detail-label {
    color: #6aaa6a;
    font-weight: 600;
    min-width: 120px;
}

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

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

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

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

/* Header links */
.header-link {
    color: inherit;
    text-decoration: none;
}

.header-link:hover {
    text-shadow: 0 0 40px rgba(200,168,50,0.5);
}

.back-link {
    padding: 10px 20px;
    border: 1px solid #2a3a1a;
    border-radius: 25px;
    background: rgba(15, 25, 15, 0.8);
    color: #6aaa6a;
    font-family: 'Lato', sans-serif;
    font-size: 0.95rem;
    text-decoration: none;
    transition: border-color 0.3s, color 0.3s;
}

.back-link:hover {
    border-color: #c8a832;
    color: #c8a832;
}

.modal-tree-link {
    display: inline-block;
    margin-top: 16px;
    padding: 8px 18px;
    border: 1px solid #2a3a1a;
    border-radius: 20px;
    background: rgba(106,170,106,0.1);
    color: #6aaa6a;
    font-family: 'Lato', sans-serif;
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.3s;
    letter-spacing: 1px;
}

.modal-tree-link:hover {
    border-color: #c8a832;
    color: #c8a832;
    background: rgba(200,168,50,0.1);
}

/* ============================================================ */
/* FAMILY TREE                                                  */
/* ============================================================ */

.tree-container {
    position: relative;
    z-index: 1;
    padding: 30px 20px;
    max-width: 1200px;
    margin: 0 auto;
    min-height: 60vh;
}

.tree-placeholder {
    text-align: center;
    color: #6a7a5a;
    padding: 80px 20px;
    font-size: 1.1rem;
    font-style: italic;
}

.tree-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
}

.tree-layer {
    position: relative;
    z-index: 1;
    margin-bottom: 20px;
}

.tree-layer-label {
    text-align: center;
    font-family: 'Cinzel', serif;
    font-size: 0.75rem;
    color: #5a6a4a;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.tree-row {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    background: linear-gradient(145deg, #162216 0%, #0d1a0d 100%);
    border: 2px solid #2a3a1a;
    border-radius: 12px;
    min-width: 110px;
    max-width: 140px;
    transition: all 0.3s ease;
    position: relative;
}

.tree-node-self {
    border-color: #c8a832;
    box-shadow: 0 0 20px rgba(200,168,50,0.2);
    background: linear-gradient(145deg, #1a2a10 0%, #0d1a0d 100%);
}

.tree-node-self::after {
    content: '';
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    bottom: -1px;
    border-radius: 12px;
    border: 1px solid rgba(200,168,50,0.3);
    pointer-events: none;
}

.tree-clickable {
    cursor: pointer;
}

.tree-clickable:hover {
    transform: translateY(-3px);
    border-color: var(--node-color, #6aaa6a);
    box-shadow: 0 6px 20px rgba(106,170,106,0.15);
}

.tree-avatar {
    width: 65px;
    height: 65px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid var(--node-color, #3a4a2a);
    margin-bottom: 8px;
    background: #1a2a1a;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tree-avatar svg {
    width: 100%;
    height: 100%;
}

.tree-avatar-unknown {
    border-color: #3a3a3a;
}

.tree-unknown-icon {
    font-family: 'Cinzel', serif;
    font-size: 1.5rem;
    color: #5a5a5a;
}

.tree-name {
    font-size: 0.78rem;
    font-weight: 600;
    color: #d4c9a8;
    text-align: center;
    line-height: 1.2;
    margin-bottom: 2px;
}

.tree-role {
    font-size: 0.6rem;
    color: #6a7a5a;
    text-align: center;
    line-height: 1.2;
}

.tree-relation {
    font-size: 0.55rem;
    color: #4a5a3a;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}

.tree-node-self .tree-name {
    color: #c8a832;
}

.tree-node[data-relation="partner"] .tree-relation {
    color: #c8a832;
}

.tree-node[data-relation="sibling"] .tree-relation {
    color: #6aaa6a;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 { font-size: 1.8rem; letter-spacing: 2px; }
    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: 100px; height: 100px; }
    .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; }
}
