:root {
    --bg: #060610;
    --surface: #0e0e1c;
    --surface-hover: #16162a;
    --surface-glass: rgba(14, 14, 28, 0.85);
    --border: #1a1a30;
    --border-subtle: rgba(124, 58, 237, 0.12);
    --text: #e8e8f4;
    --text-muted: #5e5e7e;
    --text-dim: #3e3e5a;
    --accent: #7c3aed;
    --accent-light: #a78bfa;
    --accent-glow: rgba(124, 58, 237, 0.25);
    --accent-glow-strong: rgba(124, 58, 237, 0.5);
    --highlight-bg: rgba(124, 58, 237, 0.18);
    --highlight-border: rgba(124, 58, 237, 0.6);
    --success: #34d399;
    --warning: #fbbf24;
    --radius: 14px;
    --radius-sm: 8px;
    --sidebar-w: 300px;
    --topbar-h: 52px;
    --player-h: 72px;
}

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

body {
    font-family: 'Georgia', 'Palatino Linotype', 'Book Antiqua', Palatino, serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
}

/* ─── Canvas de estrelas (subtler) ─── */
#starsCanvas {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
    opacity: 0.35;
}

/* ─── App layout ─── */
.app {
    position: relative;
    z-index: 1;
    display: flex;
    height: 100vh;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease, opacity 0.3s ease;
}
.sidebar.collapsed {
    width: 0;
    min-width: 0;
    opacity: 0;
    pointer-events: none;
    border-right: none;
}
.sidebar.collapsed.open {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    opacity: 1;
    pointer-events: auto;
    border-right: 1px solid var(--border);
}
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sidebar-header h2 {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    transition: color 0.2s, background 0.2s;
}
.icon-btn:hover { color: var(--text); background: var(--surface-hover); }
.icon-btn svg { fill: currentColor; }

.sidebar-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 16px;
    font-size: 0.85rem;
    line-height: 1.7;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Message item ─── */
.msg-item {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
    border: 1px solid transparent;
}
.msg-item:hover { background: var(--surface-hover); }
.msg-item.active { background: var(--highlight-bg); border-color: var(--highlight-border); }
.msg-item .msg-role {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--accent-light);
    margin-bottom: 2px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.msg-item .msg-preview {
    font-size: 0.82rem;
    color: var(--text);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: -apple-system, BlinkMacFont, 'Segoe UI', Roboto, sans-serif;
}
.msg-item .msg-meta {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.msg-status {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.msg-status.ready { background: var(--success); }
.msg-status.generating { background: var(--warning); animation: pulse 1.5s infinite; }
.msg-status.error { background: #ef4444; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ─── Main area ─── */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}
.topbar {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface-glass);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    box-shadow: 0 0 12px var(--accent-glow);
}
.logo h1 {
    font-size: 1rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    letter-spacing: 0.02em;
}
.status { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.status-dot {
    width: 7px; height: 7px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 8px rgba(52, 211, 153, 0.4);
}
.status-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Speaking indicator ─── */
.speaking-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 24px;
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.08), transparent 60%);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    animation: fadeInDown 0.4s ease;
}
.speaking-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 12px var(--accent-glow-strong);
    animation: speakingPulse 1.2s ease-in-out infinite;
}
@keyframes speakingPulse {
    0%, 100% { transform: scale(1); opacity: 1; box-shadow: 0 0 12px var(--accent-glow-strong); }
    50% { transform: scale(1.3); opacity: 0.7; box-shadow: 0 0 20px var(--accent-glow-strong); }
}
.speaking-label {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--accent-light);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.speaking-waves {
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
}
.speaking-waves .wave {
    width: 3px;
    height: 4px;
    background: var(--accent-light);
    border-radius: 2px;
    animation: waveAnim 1s ease-in-out infinite;
}
.speaking-waves .wave:nth-child(1) { animation-delay: 0s; }
.speaking-waves .wave:nth-child(2) { animation-delay: 0.1s; }
.speaking-waves .wave:nth-child(3) { animation-delay: 0.2s; }
.speaking-waves .wave:nth-child(4) { animation-delay: 0.3s; }
.speaking-waves .wave:nth-child(5) { animation-delay: 0.4s; }
@keyframes waveAnim {
    0%, 100% { height: 4px; opacity: 0.4; }
    50% { height: 16px; opacity: 1; }
}
@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── Message viewer — hero ─── */
.message-viewer {
    flex: 1;
    overflow-y: auto;
    padding: 40px 32px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.message-viewer::-webkit-scrollbar { width: 4px; }
.message-viewer::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.current-message {
    max-width: 720px;
    width: 100%;
    text-align: center;
}
.current-message p {
    font-size: 1.35rem;
    line-height: 2;
    color: var(--text);
    white-space: pre-wrap;
    letter-spacing: 0.01em;
}
.placeholder {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.placeholder-icon {
    margin-bottom: 20px;
    color: var(--accent);
    opacity: 0.4;
    display: flex;
    align-items: center;
    justify-content: center;
}
.placeholder p {
    font-size: 1rem;
    line-height: 1.6;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.placeholder .sub {
    font-size: 0.85rem;
    margin-top: 10px;
    color: var(--text-dim);
}

/* ─── Text display ─── */
.text-display-area {
    padding: 0 32px 16px;
    flex-shrink: 0;
    max-height: 240px;
    overflow-y: auto;
}
.text-display-area::-webkit-scrollbar { width: 4px; }
.text-display-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.text-display {
    font-size: 1.15rem;
    line-height: 2;
    color: var(--text);
    max-width: 720px;
    margin: 0 auto;
    text-align: center;
}
.text-display .word {
    display: inline-block;
    padding: 2px 5px;
    margin: 1px 2px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s, border 0.15s, box-shadow 0.15s;
    border: 1px solid transparent;
    cursor: default;
}
.text-display .word.active {
    background: var(--highlight-bg);
    color: var(--accent-light);
    border-color: var(--highlight-border);
    font-weight: 600;
    box-shadow: 0 0 16px var(--accent-glow);
}

/* ─── Player ─── */
.player-section {
    padding: 0 24px 16px;
    flex-shrink: 0;
}
.player-card {
    background: var(--surface-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3), 0 0 40px var(--accent-glow);
}
.player-controls {
    display: flex;
    align-items: center;
    gap: 14px;
}
.play-btn {
    width: 48px; height: 48px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent), #5b21b6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 0 24px var(--accent-glow);
}
.play-btn:hover { transform: scale(1.08); box-shadow: 0 0 32px var(--accent-glow-strong); }
.play-btn svg { fill: currentColor; }
.progress-area {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}
.progress-area span {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    min-width: 36px;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
.progress-bar {
    flex: 1;
    height: 6px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 3px;
    width: 0%;
    transition: width 0.1s linear;
    box-shadow: 0 0 8px var(--accent-glow);
}

.hidden { display: none !important; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0; top: 0; bottom: 0;
        z-index: 100;
        width: var(--sidebar-w);
        min-width: var(--sidebar-w);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
        opacity: 1;
        pointer-events: auto;
    }
    .sidebar.collapsed {
        transform: translateX(-100%);
        opacity: 1;
        pointer-events: auto;
    }
    .sidebar.collapsed.open,
    .sidebar.open {
        transform: translateX(0);
    }
    .topbar { padding: 0 16px; }
    .message-viewer { padding: 24px 16px 16px; }
    .current-message p { font-size: 1.1rem; line-height: 1.8; }
    .text-display-area { padding: 0 16px 12px; max-height: 180px; }
    .text-display { font-size: 1rem; }
    .player-section { padding: 0 12px 12px; }
    .speaking-indicator { padding: 8px 16px; }
}

@media (max-width: 480px) {
    .logo h1 { font-size: 0.9rem; }
    .player-controls { gap: 10px; }
    .play-btn { width: 42px; height: 42px; }
    .current-message p { font-size: 1rem; }
    .text-display { font-size: 0.95rem; }
}