/* Style for Warrior Cats Interactive Family Tree */

/* Design Tokens & Variables */
:root {
    --bg-dark: #0f131a;
    --bg-workspace: #0b0d13;
    --bg-card-primary: rgba(26, 32, 44, 0.8);
    --bg-card-relative: rgba(18, 22, 30, 0.85);
    
    --color-text-primary: #f1f3f9;
    --color-text-secondary: #a0aec0;
    --color-text-muted: #718096;
    
    /* Relation colors */
    --color-parent: #e53e3e;      /* Red */
    --color-mentor: #805ad5;      /* Purple */
    --color-sibling: #dd6b20;     /* Orange/Gold */
    --color-mate: #ffffff;        /* White/Silver on Dark */
    --color-child: #3182ce;       /* Blue */
    --color-apprentice: #38a169;  /* Green */
    
    --font-heading: 'Cinzel', Georgia, serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
    
    --border-glow-primary: 0 0 15px rgba(221, 107, 32, 0.35);
    --border-glow-hover: 0 0 12px rgba(255, 255, 255, 0.15);
    
    --transition-smooth: all 0.25s cubic-bezier(0.2, 0.8, 0.2, 1);
}

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

html {
    height: 100%;
}

body {
    background-color: var(--bg-dark);
    color: var(--color-text-primary);
    font-family: var(--font-body);
    height: 100vh;
    height: 100dvh; /* accounts for mobile browser chrome so the workspace never grows past the real viewport */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* page itself never scrolls - only the tree workspace pans/zooms */
    background-image:
        radial-gradient(circle at 20% 30%, rgba(30, 40, 50, 0.1) 0%, transparent 40%),
        radial-gradient(circle at 80% 70%, rgba(40, 30, 50, 0.1) 0%, transparent 40%);
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Header Styling */
.app-header {
    background: linear-gradient(to bottom, rgba(11, 13, 19, 0.95), rgba(11, 13, 19, 0.85));
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding: 20px 10px;
    backdrop-filter: blur(10px);
    z-index: 100;
}

.header-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

/* Mobile-only collapse toggle - fixed to the viewport (not the header) so it stays put
   and tappable regardless of whether the header is currently expanded or collapsed. */
.header-toggle-btn {
    display: none;
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 300;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgba(15, 20, 30, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: var(--color-text-primary);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transition: var(--transition-smooth);
}

.header-toggle-btn:hover {
    background: rgba(221, 107, 32, 0.6);
}

.header-toggle-btn .toggle-icon {
    font-size: 1.1rem;
    line-height: 1;
    transition: transform 0.35s ease;
}

body.tree-expanded .header-toggle-btn .toggle-icon {
    transform: rotate(180deg);
}

.main-title {
    font-family: 'Cinzel Decorative', var(--font-heading);
    font-weight: 700;
    font-size: 2.2rem;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #fbd38d 0%, #dd6b20 50%, #9c4221 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 2px 10px rgba(221, 107, 32, 0.2);
    margin-bottom: 2px;
}

.subtitle {
    font-family: var(--font-heading);
    font-weight: 500;
    font-size: 0.95rem;
    letter-spacing: 5px;
    color: var(--color-text-secondary);
    text-transform: uppercase;
    margin-bottom: 20px;
}

/* Search Bar styling */
.search-section {
    display: flex;
    gap: 12px;
    width: 100%;
    max-width: 650px;
    justify-content: center;
    flex-wrap: wrap;
}

.search-box-wrapper {
    position: relative;
    flex: 1;
    min-width: 280px;
}

#cat-search-input {
    width: 100%;
    padding: 12px 45px 12px 18px;
    font-size: 1rem;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 30px;
    color: var(--color-text-primary);
    outline: none;
    transition: var(--transition-smooth);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6);
}

#cat-search-input:focus {
    border-color: #dd6b20;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.6), 0 0 10px rgba(221, 107, 32, 0.3);
}

#clear-search-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    display: none;
}

#clear-search-btn:hover {
    color: var(--color-text-primary);
}

/* Suggestive dropdown menu */
.suggestions-list {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: rgba(15, 20, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    max-height: 350px;
    overflow-y: auto;
    z-index: 200;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8), 0 0 15px rgba(0,0,0,0.5);
    backdrop-filter: blur(15px);
    list-style: none;
}

.suggestions-list.hidden {
    display: none;
}

.suggestion-item {
    display: flex;
    align-items: center;
    padding: 10px 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    cursor: pointer;
    transition: var(--transition-smooth);
}

.suggestion-item:last-child {
    border-bottom: none;
}

.suggestion-item:hover, .suggestion-item.active {
    background: rgba(221, 107, 32, 0.15);
    padding-left: 20px;
}

.suggestion-thumb {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: var(--bg-dark);
}

/* Wrapper for placeholder SVG in search — keeps it the same size as a real thumbnail */
.suggestion-thumb-svg {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}
.suggestion-thumb-svg .cat-silhouette {
    width: 80%;
    height: 80%;
}

/* Hide broken image icons when a real image URL fails to load */
.suggestion-thumb.img-error {
    opacity: 0.3;
}

.suggestion-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    flex: 1;
}

.suggestion-name {
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--color-text-primary);
}

.suggestion-clan {
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    margin-top: 1px;
}

/* Button UI */
.header-buttons {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 10px 18px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: 30px;
    border: none;
    cursor: pointer;
    transition: var(--transition-smooth);
    outline: none;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-primary);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.25);
    transform: translateY(-2px);
}

/* Main Workspace Canvas styles */
.app-workspace {
    flex: 1;
    position: relative;
    background-color: var(--bg-workspace);
    overflow: hidden;
}

/* Zoom Control Overlay */
.canvas-controls {
    position: absolute;
    left: 20px;
    bottom: 20px;
    display: flex;
    align-items: center;
    background: rgba(15, 20, 30, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 30px;
    padding: 6px;
    z-index: 90;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
}

.control-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--color-text-primary);
    font-size: 1.1rem;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-smooth);
}

.control-btn:hover {
    background: rgba(221, 107, 32, 0.6);
    transform: scale(1.1);
}

#zoom-level-indicator {
    padding: 0 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    min-width: 55px;
    text-align: center;
}

/* Tree Container: fixed to the workspace box (viewport minus header/footer).
   overflow is hidden, not auto - panning/zooming is handled entirely via JS
   transforms below, so native scrolling never competes with it. */
.tree-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
    cursor: grab;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tree-container:active {
    cursor: grabbing;
}

/* Tree Board gets scaled and translated via JS */
.tree-board {
    position: relative;
    padding: 100px; /* space to pan off screen */
    transform-origin: center center;
    transition: transform 0.05s linear;
}

/* Overlay connections SVG */
.connections-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}

/* Layout Grid structure */
.tree-grid {
    display: flex;
    flex-direction: column;
    gap: 80px; /* vertical gap between rows (parents/mentors -> primary -> children) */
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 20;
}

.grid-row {
    display: flex;
    width: 100%;
    gap: 40px; /* horizontal gap between groups/cards */
    justify-content: center;
    align-items: stretch;
}

.top-row {
    margin-bottom: 20px;
    gap: 80px; /* Extra horizontal space between parents group and mentors group */
}

.grandparents-row {
    margin-bottom: 20px;
    gap: 80px; /* Extra horizontal space between paternal and maternal groups */
}

.bottom-row {
    margin-top: 20px;
    gap: 80px; /* Extra horizontal space between children group and apprentices group */
}

.node-group {
    display: flex;
    gap: 25px;
    align-items: center;
    justify-content: center;
}

/* Custom alignment for siblings, mate and primary card in middle row */
.siblings-group {
    justify-content: flex-end;
    flex: 1;
    min-width: 200px;
}

/* Ensure sibling cards are the same width as all other relative cards */
.siblings-group .cat-card.card-relative {
    width: 170px;
    flex-shrink: 0;
}

.primary-group {
    justify-content: center;
}

.mate-group {
    justify-content: flex-start;
    flex: 1;
    min-width: 200px;
}

/* Card Styling */
.cat-card {
    border-radius: 14px;
    background: var(--bg-card-relative);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6);
    transition: var(--transition-smooth);
    position: relative;
    overflow: hidden;
}

/* Card Size Variations */
.cat-card.card-primary {
    width: 290px;
    background: var(--bg-card-primary);
    border: 2px solid #dd6b20;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.75), 0 0 20px rgba(221, 107, 32, 0.2);
    z-index: 25;
    padding: 20px;
}

.cat-card.card-relative {
    width: 170px;
    padding: 12px;
    cursor: pointer;
}

/* Card image container */
.card-img-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 8px;
    margin-bottom: 12px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    background: #06080c;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    transition: var(--transition-smooth);
}

.cat-card.card-primary .card-img-wrapper {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: 10px;
    border-color: #dd6b20;
    box-shadow: 0 0 15px rgba(221, 107, 32, 0.3);
}

.card-img {
    width: 100%;
    height: 100%;
    /* contain, not cover - the 4:3 wrapper is landscape but many wiki portraits are
       taller/portrait-oriented, so cover cropped their tops and bottoms off */
    object-fit: contain;
}

/* SVG placeholder silhouette styles */
.cat-silhouette {
    width: 70%;
    height: 70%;
    fill: var(--color-text-muted);
    opacity: 0.6;
    transition: var(--transition-smooth);
}

/* Text and Titles inside cards */
.card-relation {
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    color: var(--color-text-muted);
    margin-bottom: 4px;
    padding: 2px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
}

.card-name {
    font-family: var(--font-heading);
    font-weight: bold;
    font-size: 1.1rem;
    line-height: 1.25;
    color: var(--color-text-primary);
    margin-bottom: 6px;
    word-break: break-word;
}

.cat-card.card-primary .card-name {
    font-size: 1.5rem;
    margin-bottom: 10px;
    background: linear-gradient(to right, #ffffff, #e2e8f0);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Info Badges for Clan and Status */
.card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    justify-content: center;
    margin-bottom: 8px;
}

.badge {
    font-size: 0.68rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Custom Clan Colors */
.badge-thunderclan { background: #b7791f; color: #fff; }
.badge-riverclan { background: #2b6cb0; color: #fff; }
.badge-windclan { background: #319795; color: #fff; }
.badge-shadowclan { background: #553c9a; color: #fff; }
.badge-skyclan { background: #2c7a7b; color: #fff; }
.badge-starclan { background: #667eea; color: #fff; box-shadow: 0 0 8px rgba(102, 126, 234, 0.6); }
.badge-darkforest { background: #9b2c2c; color: #fff; box-shadow: 0 0 8px rgba(155, 44, 44, 0.6); }
.badge-kittypet { background: #d53f8c; color: #fff; }
.badge-loner, .badge-rogue { background: #4a5568; color: #fff; }
.badge-unknown { background: rgba(255,255,255,0.1); color: var(--color-text-secondary); }

/* Details list for the primary cat */
.card-details {
    width: 100%;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: left;
    font-size: 0.8rem;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    line-height: 1.4;
}

.detail-label {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.detail-value {
    color: var(--color-text-primary);
    text-align: right;
    max-width: 60%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-value.clickable-rel {
    color: #fbd38d;
    cursor: pointer;
    font-weight: 500;
}

.detail-value.clickable-rel:hover {
    text-decoration: underline;
    color: #dd6b20;
}

/* Hover effects for relative cards based on their relationship type */
.cat-card.card-relative:hover {
    transform: translateY(-8px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.8);
}

.cat-card.card-relative:hover .card-img-wrapper {
    transform: scale(1.05);
}

/* Specific relative hover classes */
.cat-card.rel-mother:hover, .cat-card.rel-father:hover,
.cat-card.rel-grandmother:hover, .cat-card.rel-grandfather:hover {
    border-color: var(--color-parent);
    box-shadow: 0 10px 25px rgba(0,0,0,0.8), 0 0 12px rgba(229, 62, 98, 0.35);
}
.cat-card.rel-mentor:hover {
    border-color: var(--color-mentor);
    box-shadow: 0 10px 25px rgba(0,0,0,0.8), 0 0 12px rgba(128, 90, 213, 0.4);
}
.cat-card.rel-brother:hover, .cat-card.rel-sister:hover {
    border-color: var(--color-sibling);
    box-shadow: 0 10px 25px rgba(0,0,0,0.8), 0 0 12px rgba(221, 107, 32, 0.35);
}
.cat-card.rel-mate:hover {
    border-color: var(--color-mate);
    box-shadow: 0 10px 25px rgba(0,0,0,0.8), 0 0 12px rgba(255, 255, 255, 0.35);
}
.cat-card.rel-son:hover, .cat-card.rel-daughter:hover {
    border-color: var(--color-child);
    box-shadow: 0 10px 25px rgba(0,0,0,0.8), 0 0 12px rgba(49, 130, 206, 0.35);
}
.cat-card.rel-apprentice:hover {
    border-color: var(--color-apprentice);
    box-shadow: 0 10px 25px rgba(0,0,0,0.8), 0 0 12px rgba(56, 161, 105, 0.35);
}

/* Bottom status bar styling */
.app-footer {
    background: #0b0d13;
    border-top: 1px solid rgba(255,255,255,0.05);
    padding: 12px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--color-text-secondary);
    z-index: 100;
}

.footer-credit {
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.footer-credit a {
    color: var(--color-mentor);
    text-decoration: none;
}

.footer-credit a:hover {
    text-decoration: underline;
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.tree-grid {
    animation: fadeIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Media Queries for Mobile/Tablet adaptation */
@media (max-width: 900px) {
    .main-title {
        font-size: 1.8rem;
    }
    .subtitle {
        font-size: 0.8rem;
        letter-spacing: 3px;
    }
    .search-section {
        flex-direction: column;
        align-items: stretch;
    }
    
    /* Tiers (grandparents / parents+mentors / siblings+primary+mate / children+apprentices)
       stay laid out exactly as on desktop - each stays a single horizontal row rather than
       stacking into a column. Narrow screens rely on the same drag-to-pan/pinch-to-zoom
       canvas as desktop to view the full width, instead of a different mobile-only layout. */
    .tree-grid {
        gap: 60px;
    }

    /* Header/footer collapse toggle. Uses the grid-template-rows 1fr -> 0fr trick so the
       title/buttons/footer smoothly shrink away (a real "slide", not an instant hide/opacity
       fade) while the search bar - deliberately left outside .header-collapsible - stays put,
       ending up at the top of the (now much shorter) header once its siblings collapse. */
    .header-toggle-btn {
        display: flex;
    }

    .header-collapsible {
        display: grid;
        grid-template-rows: 1fr;
        transition: grid-template-rows 0.35s ease;
    }

    .header-collapsible-inner {
        overflow: hidden;
        min-height: 0;
    }

    body.tree-expanded .header-collapsible {
        grid-template-rows: 0fr;
    }

    /* The footer has nothing that needs to stay visible, so its own padding/border
       collapse away too rather than leaving an empty bar behind. */
    .app-footer {
        transition: padding 0.35s ease, border-top-width 0.35s ease;
    }

    body.tree-expanded .app-footer {
        padding-top: 0;
        padding-bottom: 0;
        border-top-width: 0;
    }
}
