/* Google Font */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Mono:wght@400;500;700&family=Roboto+Mono:wght@500&display=swap');

:root {
    --primary-bg: #000000;
    --secondary-bg: #1a1a1a;
    --text-color: #e0e0e0;
    --text-secondary: #888888;
    --accent-color: #f2e7fe; /* Defaulting to white accent for dark mode */
    --mic-default: var(--accent-color);
    --mic-listening: #ff4081;
    --mic-speaking: var(--accent-color);
    --stop-bg: #cf6679;
}

body.bright-theme {
    --primary-bg: #f5f5f5;
    --secondary-bg: #ffffff;
    --text-color: #212121;
    --text-secondary: #757575;
    --accent-color: #3f51b5;
    --mic-listening: #f50057;
    --stop-bg: #f44336;
}

html, body {
    height: 100%;
    margin: 0;
    overflow: hidden;
    background-color: var(--primary-bg);
    transition: background-color 0.3s ease;
}

body {
    font-family: 'Inter', sans-serif;
    display: flex;
}

/* --- Main Layout --- */
.container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: var(--primary-bg);
    transition: background-color 0.3s ease;
    position: relative;
    flex-grow: 1;
}

/* --- App Title (New Glassmorphism) --- */
.title-container {
    position: absolute;
    top: 15%;
    padding: 1.5rem 2.5rem;
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
    text-align: center;
    
    /* Fallback for Dark Mode (default) */
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 
        inset 0 1px 0 0 rgba(255, 255, 255, 0.2),
        inset 0 -1px 0 0 rgba(255, 255, 255, 0.1);
}

/* Fallback for Light Mode */
body.bright-theme .title-container {
    background: rgba(255, 255, 255, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow:
        0 8px 32px 0 rgba(31, 38, 135, 0.2),
        0 2px 16px 0 rgba(31, 38, 135, 0.1),
        inset 0 1px 0 0 rgba(255, 255, 255, 0.4),
        inset 0 -1px 0 0 rgba(255, 255, 255, 0.2);
}

/* Enhanced styles for browsers that support backdrop-filter */
@supports (backdrop-filter: blur(12px)) or (-webkit-backdrop-filter: blur(12px)) {
    /* Dark Mode (default) */
    .title-container {
        background: hsl(0 0% 0% / 0.2);
        -webkit-backdrop-filter: blur(12px) saturate(1.2);
        backdrop-filter: blur(12px) saturate(1.2);
        box-shadow:
            /* Inner highlights for dark mode */
            inset 0 0 2px 1px hsla(0, 0%, 100%, 0.35),
            inset 0 0 10px 4px hsla(0, 0%, 100%, 0.15),
            /* Outer shadows */
            0px 4px 16px rgba(0, 0, 0, 0.1),
            0px 8px 24px rgba(0, 0, 0, 0.1),
            0px 16px 56px rgba(0, 0, 0, 0.1);
    }
    
    /* Light Mode */
    body.bright-theme .title-container {
        background: hsl(0 0% 100% / 0.2);
        -webkit-backdrop-filter: blur(12px) saturate(1.8);
        backdrop-filter: blur(12px) saturate(1.8);
        box-shadow:
            /* Inner shadows for light mode */
            inset 0 0 2px 1px hsla(0, 0%, 0%, 0.15),
            inset 0 0 10px 4px hsla(0, 0%, 0%, 0.1),
            /* Outer shadows */
            0px 4px 16px rgba(17, 17, 26, 0.05),
            0px 8px 24px rgba(17, 17, 26, 0.05),
            0px 16px 56px rgba(17, 17, 26, 0.05);
    }
}

#app-title {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 500;
    font-size: 2rem;
    margin: 0;
    letter-spacing: 3px;
    color: var(--text-color);
}

#app-subtitle {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.9rem;
    margin: 8px 0 0 0;
    opacity: 0.7;
    color: var(--text-color);
}

/* --- Microphone Button & Controls --- */
.mic-controls-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 120px;
    height: 120px;
}

#mic-btn {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    position: absolute;
    background-color: var(--mic-default);
    box-shadow: 0 0 20px var(--mic-default);
    overflow: hidden;
}

#mic-btn:hover:not([disabled]):not(.listening):not(.speaking) {
    transform: scale(1.05);
    box-shadow: 0 0 35px var(--mic-default);
}

#mic-btn:disabled {
    cursor: not-allowed;
    background-color: var(--text-secondary);
    box-shadow: none;
}

#mic-icon-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    position: absolute;
    left: 0;
    top: 0;
    border-radius: 60px;
    transition: width 0.3s ease, border-radius 0.3s ease, background-color 0.3s ease;
}

#mic-icon-container svg {
    width: 50px;
    height: 50px;
    fill: var(--primary-bg);
    transition: fill 0.3s ease, transform 0.2s ease, opacity 0.3s ease;
}

#hex-display {
    position: absolute;
    font-family: 'Roboto Mono', monospace;
    font-size: 50px;
    font-weight: 500;
    color: var(--primary-bg);
    opacity: 0;
    transition: opacity 0.1s ease-in-out;
    -webkit-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

#mic-btn.listening {
    background-color: var(--mic-listening);
    box-shadow: 0 0 40px var(--mic-listening);
    animation: pulse-listen 1.5s infinite ease-in-out;
}

#mic-btn.speaking {
    background-color: var(--mic-speaking);
    box-shadow: 0 0 40px var(--mic-speaking);
}

#mic-btn.speaking #mic-icon-container svg { opacity: 0; }
#mic-btn.speaking #hex-display { opacity: 1; }

#mic-btn.paused {
    animation-play-state: paused;
    background-color: transparent;
    box-shadow: none;
}

#mic-btn.paused #mic-icon-container {
    width: 50%;
    background-color: var(--text-secondary);
    border-radius: 60px 0 0 60px;
}

#mic-btn.paused #mic-icon-container svg { opacity: 1; }
#mic-btn.paused #hex-display { opacity: 0; }

#stop-btn {
    width: 50%;
    height: 100%;
    border: none;
    background-color: var(--stop-bg);
    color: white;
    position: absolute;
    right: 0;
    top: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.3s, transform 0.3s;
    visibility: hidden;
    border-radius: 0 60px 60px 0;
}

#stop-btn.visible {
    opacity: 1;
    transform: translateX(0);
    visibility: visible;
}

#stop-btn svg {
    width: 24px;
    height: 24px;
    fill: white;
}

@keyframes pulse-listen { 0% { transform: scale(1); } 50% { transform: scale(1.1); } 100% { transform: scale(1); } }

#transcription-area {
    position: absolute;
    bottom: 5%;
    width: 80%;
    max-width: 600px;
    text-align: center;
    color: var(--text-secondary);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 1rem;
    height: 6em;
    line-height: 1.5;
    opacity: 0;
    transition: opacity 0.5s ease;
    overflow-y: auto; /* Allow vertical scrolling */
    -ms-overflow-style: none;  /* Hide scrollbar for IE and Edge */
    scrollbar-width: none;  /* Hide scrollbar for Firefox */
}

/* Hide scrollbar for Chrome, Safari and Opera */
#transcription-area::-webkit-scrollbar {
    display: none;
}

#transcription-area.visible { opacity: 1; }
#transcription-area p {
    margin: 0;
    min-height: 1.5em;
    white-space: pre-wrap;
    word-break: break-all;
}
#transcription-area .user-text { font-style: italic; }
#transcription-area .bot-text { font-weight: bold; }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7); display: flex;
    justify-content: center; align-items: center; z-index: 2000;
    backdrop-filter: blur(5px); opacity: 0; visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
}
.modal-overlay.visible { opacity: 1; visibility: visible; }
.modal-content {
    background: var(--secondary-bg); padding: 2rem; border-radius: 12px;
    width: 90%; max-width: 400px; text-align: center;
    box-shadow: 0 5px 25px rgba(0,0,0,0.2); transform: scale(0.9);
    transition: transform 0.3s;
}
.modal-overlay.visible .modal-content { transform: scale(1); }
.modal-content h2 { margin-top: 0; color: var(--accent-color); }
.modal-content p { color: var(--text-secondary); margin-bottom: 1.5rem; }
.modal-input {
    width: calc(100% - 22px); padding: 10px; border: 1px solid var(--text-secondary);
    background-color: var(--primary-bg); color: var(--text-color);
    border-radius: 8px; margin-bottom: 1rem; font-size: 1rem;
}
.modal-btn {
    width: 100%; padding: 12px; border: none; border-radius: 8px;
    background-color: var(--accent-color); color: var(--primary-bg);
    font-size: 1rem; font-weight: bold; cursor: pointer; transition: background-color 0.2s;
}
.modal-btn:hover { opacity: 0.9; }

#menu-toggle-btn {
    position: fixed; top: 1.5rem; left: 1.5rem; z-index: 1001;
    background: var(--secondary-bg); border: 1px solid var(--text-secondary);
    color: var(--text-color); cursor: pointer; border-radius: 8px;
    width: 44px; height: 44px; display: flex; flex-direction: column;
    justify-content: center; align-items: center; gap: 5px; transition: all 0.3s;
}
#menu-toggle-btn:hover { background: var(--accent-color); color: var(--primary-bg); }
#menu-toggle-btn .bar {
    width: 22px; height: 2px; background-color: currentColor;
    border-radius: 2px; transition: all 0.3s;
}
#menu-toggle-btn.open .bar:nth-child(1) { transform: translateY(7px) rotate(45deg); }
#menu-toggle-btn.open .bar:nth-child(2) { opacity: 0; }
#menu-toggle-btn.open .bar:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.sidebar {
    position: fixed; left: 0; top: 0; height: 100%; width: 300px;
    background-color: var(--secondary-bg); z-index: 1000;
    transform: translateX(-100%); transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    padding: 2rem; padding-top: 6rem; box-shadow: 4px 0 15px rgba(0,0,0,0.2);
    color: var(--text-color); display: flex; flex-direction: column; overflow-y: auto;
}
.sidebar.open { transform: translateX(0); }
.sidebar h2 {
    color: var(--accent-color); border-bottom: 2px solid;
    padding-bottom: 0.5rem; margin-top: 0;
}
.sidebar h3 {
    color: var(--text-secondary); font-size: 0.9rem; text-transform: uppercase;
    letter-spacing: 1px; margin-top: 2rem; margin-bottom: 1rem;
}
.options-group { margin-top: 1rem; }
.options-group label {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; font-size: 1rem; margin-bottom: 1rem;
}
.sidebar-input {
    width: calc(100% - 22px); padding: 10px; border: 1px solid var(--text-secondary);
    background-color: var(--primary-bg); color: var(--text-color);
    border-radius: 8px; margin-bottom: 1rem; font-size: 1rem;
}
.sidebar-btn {
    width: 100%; padding: 10px; border: none; border-radius: 8px;
    background-color: var(--accent-color); color: var(--primary-bg);
    font-size: 0.9rem; font-weight: bold; cursor: pointer; transition: background-color 0.2s;
}
.sidebar-btn:hover { opacity: 0.9; }
#api-key-status {
    font-size: 0.8rem; text-align: center; padding: 8px; border-radius: 4px;
    margin-top: 10px; opacity: 0; transition: opacity 0.3s;
}
#api-key-status.visible { opacity: 1; }
.color-swatches { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch {
    width: 30px; height: 30px; border-radius: 50%;
    cursor: pointer; border: 2px solid transparent; transition: border-color 0.2s;
}
.swatch.selected { border-color: var(--text-color); }

.switch { position: relative; display: inline-block; width: 50px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc; transition: .4s; border-radius: 24px;
}
.slider:before {
    position: absolute; content: ""; height: 18px; width: 18px; left: 3px;
    bottom: 3px; background-color: white; transition: .4s; border-radius: 50%;
}
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(26px); }