:root {
    --bg-dark: #0f0f0f;
    --bg-sidebar: #1a1a1a;
    --card-bg: #252525;
    --accent: #D65A31; /* User/Mic Color (Orange/Red) */
    --ai-accent: #00d2ff; /* AI Voice Color (Cyan) */
    --text: #ffffff;
}

body { margin: 0; font-family: 'Inter', sans-serif; background: var(--bg-dark); color: var(--text); height: 100vh; overflow: hidden; }

.container { display: flex; height: 100%; }

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: #211f1f;
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 30px 20px; 
    border-right: 1px solid #333;
    height: 100vh;
    box-sizing: border-box; /* Ensures padding doesn't widen the bar */
}
.brand h1 { margin: 0; font-size: 1.5rem; letter-spacing: -1px; }
.brand p { color: #666; font-size: 0.8rem; margin-top: 5px; }
.book-list { 
    margin-top: 2rem; /* Spacing from brand */
    flex: 1; /* Allow this to grow if needed, but mostly lets the bottom push down */
    overflow-y: auto; /* Scroll if library gets huge */
}
.label { color: #555; font-size: 0.75rem; font-weight: bold; letter-spacing: 1px; margin-bottom: 1rem; }

.book-btn {
    width: 100%; padding: 12px; margin-bottom: 8px;
    background: transparent; border: 1px solid transparent;
    color: #aaa; text-align: left; cursor: pointer; border-radius: 8px;
    font-size: 0.9rem; transition: all 0.2s;
}
.book-btn:hover { background: #333; color: white; }

/* Stage */
.stage { flex: 1; padding: 3rem; overflow-y: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; margin-top: 2rem; }

.card { 
    background: var(--card-bg); padding: 1.5rem; border-radius: 12px; border: 1px solid #333;
    /* CRITICAL: fast shadow transition for the audio visualizer */
    transition: transform 0.2s, box-shadow 0.05s linear, border-color 0.2s;
}
.card:hover { transform: translateY(-4px); border-color: #555; }
.card h3 { margin: 0 0 10px 0; color: white; }
.card p { color: #bbb; font-size: 0.9rem; line-height: 1.5; margin-bottom: 1.5rem; }
.meta { font-size: 0.75rem; color: #666; margin-bottom: 1rem; text-transform: uppercase; letter-spacing: 0.5px; }

.chat-btn { width: 100%; padding: 10px; background: white; color: black; border: none; border-radius: 6px; font-weight: 600; cursor: pointer; }
.chat-btn:hover { background: #ddd; }

/* Utilities */
.hidden { display: none; }
.spinner { width: 30px; height: 30px; border: 3px solid #333; border-top-color: var(--accent); border-radius: 50%; animation: spin 1s infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- FOCUS MODE (The Expanded Card) --- */
body.chat-active #character-grid {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 60vh; /* Takes up mostly the screen */
}

/* Hide all non-active cards */
body.chat-active .card:not(.active) {
    display: none;
}

/* The Active Card */
.card.active {
    width: 500px;  /* Much wider */
    height: auto;
    min-height: 400px;
    transform: scale(1.05);
    border-color: var(--accent);
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
}

/* The Transcript Area (Hidden by default) */
.transcript {
    display: none;
    margin-top: 1rem;
    padding: 1rem;
    background: #2a2a2a;
    border-radius: 8px;
    height: 200px;
    overflow-y: auto;
    text-align: left;
    font-size: 0.9rem;
    border: 1px solid #444;
}

.card.active .transcript {
    display: block; /* Show only when active */
}

.msg { margin-bottom: 8px; padding: 5px 10px; border-radius: 5px; }
.msg.user { color: #ccc; text-align: right; border-right: 2px solid var(--accent); }
.msg.ai { color: var(--ai-accent); text-align: left; border-left: 2px solid var(--ai-accent); }

/* --- SPEAKING ANIMATION --- */
@keyframes pulse-blue {
    0% { box-shadow: 0 0 0 0 rgba(0, 210, 255, 0.7); border-color: var(--ai-accent); }
    70% { box-shadow: 0 0 0 20px rgba(0, 210, 255, 0); border-color: var(--ai-accent); }
    100% { box-shadow: 0 0 0 0 rgba(0, 210, 255, 0); border-color: var(--accent); }
}

.card.speaking {
    animation: pulse-blue 1.5s infinite;
    /* We use !important to override the JS visualizer shadow if they overlap */
    box-shadow: 0 0 30px var(--ai-accent) !important;
    border-color: var(--ai-accent) !important;
}

/* The "X" Button */
.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    font-size: 2rem;
    color: #888;
    cursor: pointer;
    line-height: 1;
    z-index: 100; /* Ensure it sits on top */
    display: none; /* Hidden by default */
    transition: color 0.2s;
}

/* Only show it when the card is Active (Expanded) */
.card.active .close-btn {
    display: block;
}

.close-btn:hover {
    color: #ff4444; /* Red on hover */
}

.upload-section {
    margin-top: auto; /* This magic line pushes it to the bottom! */
    display: flex;
    flex-direction: column;
    gap: 12px; 
    padding-top: 20px;
    border-top: 1px solid #333; /* Nice separator line */
}

.upload-btn {
    /* Layout */
    display: flex;           
    justify-content: center; /* Horizontally center text */
    align-items: center;     /* Vertically center text */
    width: 100%;             /* Fill the sidebar width */
    height: 48px;            /* Fixed height for consistency */
    
    /* Styling */
    background: rgba(255, 255, 255, 0.03); /* Very subtle fill */
    border: 1px dashed #555;
    border-radius: 8px;
    
    /* Typography */
    color: #aaa;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-sizing: border-box;
}

/* Hover Effect - Makes it feel interactive */
.upload-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: #fff;
    color: #fff;
    transform: translateY(-1px); /* Subtle lift */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.upload-btn:active {
    transform: translateY(0);
}

.label {
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 1.5px;
    color: #666;
    text-transform: uppercase;
    margin: 0; /* Let flex-gap handle the spacing */
    padding-left: 4px; /* Slight alignment with the button border */
}