/* --- HIGH-END TECH AESTHETIC --- */
:root {
    --bg-color: #030303;
    --accent-cyan: #00f2ff;
    --accent-purple: #bd00ff;
    --accent-error: #ff0055;
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-dim: rgba(255, 255, 255, 0.3);
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.1);
    --panel-bg: rgba(10, 10, 10, 0.6);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
    user-select: none;
}

/* --- UI LAYER --- */
#ui-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    z-index: 10;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    padding: 30px;
}



/* --- HEADER --- */
.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.header-actions {
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.mode-selector {
    display: flex;
    gap: 4px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 3px;
    backdrop-filter: blur(5px);
    pointer-events: auto;
}

.mode-btn {
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-family: 'Inter', sans-serif;
    font-size: 0.7rem;
    padding: 5px 10px;
    border-radius: 9px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.mode-btn:hover {
    color: var(--text-primary);
}

.mode-btn.active {
    background: rgba(0, 242, 255, 0.12);
    color: var(--accent-cyan);
    font-weight: 500;
}

.settings-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.8);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(5px);
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    font-size: 1rem;
}

.settings-btn:hover {
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
    box-shadow: 0 0 16px rgba(0, 242, 255, 0.2);
    transform: rotate(90deg);
}

/* --- SETTINGS PANEL --- */
.settings-panel {
    position: fixed;
    top: 80px;
    right: 30px;
    width: 320px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
    z-index: 100;
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    visibility: hidden;
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.settings-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--glass-border);
    font-family: 'Courier Prime', monospace;
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--text-secondary);
}

.settings-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 4px;
    transition: color 0.2s;
}

.settings-close:hover {
    color: var(--accent-cyan);
}

.settings-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.setting-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-primary);
}

.setting-label span:last-child {
    font-family: 'Courier Prime', monospace;
    color: var(--accent-cyan);
    font-size: 0.75rem;
}

.setting-hint {
    font-size: 0.65rem;
    color: var(--text-dim);
    line-height: 1.4;
}

.settings-body input[type="range"] {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    outline: none;
}

.settings-body input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-cyan);
    box-shadow: 0 0 10px rgba(0, 242, 255, 0.5);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.settings-body input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 14px rgba(0, 242, 255, 0.8);
}

.settings-reset {
    margin-top: 8px;
    padding: 10px 16px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-reset:hover {
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    background: rgba(0, 242, 255, 0.05);
}

.brand {
    font-family: 'Dancing Script', cursive;
    font-size: 2.2rem;
    font-weight: 700;
    color: #ffffff;
    letter-spacing: 0;
    text-shadow: 0 0 20px rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
}

/* Remove dot and previous gradient styles */
.brand::before { display: none; }
.brand-gradient { display: none; }

.version {
    font-size: 0.6rem;
    color: var(--accent-cyan);
    font-weight: 400;
    margin-left: 10px;
    background: rgba(0, 242, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
}

.status-panel {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
}

.status-item {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 5px;
}

.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background-color: #333;
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

.status-dot.healthy {
    background-color: #00ff88;
    box-shadow: 0 0 8px #00ff88;
}

.status-dot.busy {
    background-color: var(--accent-cyan);
    box-shadow: 0 0 8px var(--accent-cyan);
    animation: blink 0.5s infinite alternate;
}

.status-text {
    font-family: 'Courier Prime', monospace;
    font-size: 0.65rem;
    letter-spacing: 1px;
    color: var(--text-secondary);
}

.track-info {
    font-family: 'Courier Prime', monospace;
    font-size: 0.75rem;
    color: var(--accent-cyan);
    letter-spacing: 1px;
    text-transform: uppercase;
    text-shadow: 0 0 5px rgba(0, 242, 255, 0.3);
}

/* --- SESSION LOG (Left Sidebar) --- */
.session-log {
    position: absolute;
    top: 30px;
    left: 30px;
    bottom: 140px;
    width: 360px;
    display: flex;
    flex-direction: column;
    z-index: 30;
}

.session-log-header {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: 'Courier Prime', monospace;
    font-size: 0.7rem;
    letter-spacing: 2px;
    color: var(--text-secondary);
    padding: 12px 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
    backdrop-filter: blur(10px);
    cursor: pointer;
    user-select: none;
}

.log-chevron {
    margin-left: auto;
    transition: transform 0.3s;
    font-size: 0.65rem;
    opacity: 0.5;
}

.session-log.collapsed .log-chevron {
    transform: rotate(-90deg);
}

.session-log.collapsed .session-log-list {
    display: none;
}

.session-log.collapsed .session-log-header {
    border-radius: 12px;
    border-bottom: 1px solid var(--glass-border);
}

.session-log-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 0 0 12px 12px;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.session-log-list::-webkit-scrollbar { width: 4px; }
.session-log-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.log-bubble {
    max-width: 90%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.85rem;
    line-height: 1.5;
    font-weight: 300;
    animation: logEnter 0.4s cubic-bezier(0.16, 1, 0.3, 1) both;
    word-break: break-word;
}

.log-bubble.user {
    align-self: flex-end;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-bottom-right-radius: 4px;
    color: var(--text-primary);
}

.log-bubble.assistant {
    align-self: flex-start;
    background: rgba(0, 242, 255, 0.06);
    border: 1px solid rgba(0, 242, 255, 0.15);
    border-bottom-left-radius: 4px;
    color: var(--accent-cyan);
}

.log-role {
    font-family: 'Courier Prime', monospace;
    font-size: 0.55rem;
    letter-spacing: 1px;
    opacity: 0.5;
    margin-bottom: 4px;
    text-transform: uppercase;
}

@keyframes logEnter {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- TECH-CLOUD DIALOGUE (Top-Right of Sphere) --- */
.active-message-zone {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 420px;
    /* Offset significantly to the top-right to ensure center is clear */
    transform: translate(220px, -300px);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    z-index: 25;
}

.active-bubble {
    padding: 22px 28px;
    /* Organic 'Cloud' Shape: soft and techy */
    border-radius: 40px 40px 40px 15px; 
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 
        0 8px 32px rgba(0, 0, 0, 0.3),
        inset 0 0 20px rgba(255, 255, 255, 0.02);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    animation: cloudEnter 0.8s cubic-bezier(0.16, 1, 0.3, 1) both;
    position: relative;
}

/* The 'Cloud' connection point / tail */
.active-bubble::after {
    content: '';
    position: absolute;
    bottom: -10px;
    left: 20px;
    width: 20px;
    height: 20px;
    background: inherit;
    backdrop-filter: inherit;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transform: rotate(45deg);
    z-index: -1;
}

.active-bubble.assistant {
    border-color: rgba(0, 242, 255, 0.2);
    background: radial-gradient(circle at top left, rgba(0, 242, 255, 0.05), rgba(255, 255, 255, 0.02));
    box-shadow: 0 10px 40px rgba(0, 242, 255, 0.08);
}

.active-bubble .content {
    font-size: 1rem;
    line-height: 1.5;
    text-align: left;
    color: var(--text-primary);
    font-weight: 300;
    letter-spacing: 0.3px;
}

@keyframes cloudEnter {
    from { opacity: 0; transform: scale(0.8) translateY(20px); filter: blur(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); filter: blur(0); }
}

@keyframes cloudExit {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.9) translateY(-10px); filter: blur(5px); }
}

/* Clean up previous styles */
.active-bubble.user { border-left: none; }
@keyframes ghostEnter { from { opacity: 0; } to { opacity: 1; } }
@keyframes ghostExit { from { opacity: 1; } to { opacity: 0; } }

/* Remove old animations */
@keyframes bubbleEnter { from { opacity: 0; } to { opacity: 1; } }
@keyframes bubbleExit { from { opacity: 1; } to { opacity: 0; } }

@keyframes bubbleExit {
    from { opacity: 1; transform: translateY(0) scale(1); }
    to { opacity: 0; transform: translateY(-10px) scale(0.98); }
}


/* --- BOTTOM BAR (Footer) --- */
.footer {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: end;
    gap: 20px;
}

/* Left: Text Input */


.input-group {
    display: flex;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    padding: 5px;
    backdrop-filter: blur(5px);
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-group:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 15px rgba(0, 242, 255, 0.1);
}

#text-input {
    background: transparent;
    border: none;
    color: white;
    padding: 10px 15px;
    width: 100%;
    font-family: 'Inter', sans-serif;
    outline: none;
    font-size: 0.9rem;
}

#send-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    color: var(--accent-cyan);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

#send-btn:hover {
    background: var(--accent-cyan);
    color: #000;
}

/* Center: Record Button */
.footer-center {
    display: flex;
    justify-content: center;
}

.main-ctrl-btn {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    backdrop-filter: blur(5px);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    outline: none;
}

.main-ctrl-btn:hover, .main-ctrl-btn.active {
    border-color: var(--accent-cyan);
    background: rgba(0, 242, 255, 0.05);
    box-shadow: 0 0 20px rgba(0, 242, 255, 0.2);
    width: 90px;
    height: 90px;
}

.main-ctrl-btn.active .mic-icon {
    color: var(--accent-cyan);
    text-shadow: 0 0 10px var(--accent-cyan);
}

.main-ctrl-btn.recording {
    border-color: var(--accent-error);
    background: rgba(255, 0, 85, 0.1);
    box-shadow: 0 0 30px rgba(255, 0, 85, 0.3);
    animation: pulse 1.5s infinite;
}

.mic-icon {
    font-size: 1.5rem;
    color: rgba(255, 255, 255, 0.8);
    transition: color 0.3s;
}

.main-ctrl-btn.recording .mic-icon {
    color: var(--accent-error);
}

.btn-label {
    position: absolute;
    bottom: -25px;
    font-size: 0.6rem;
    letter-spacing: 2px;
    color: var(--text-dim);
    white-space: nowrap;
}

/* Right: Frequency Monitor */
.footer-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    justify-content: flex-end;
}

.monitor-label {
    font-family: 'Courier Prime', monospace;
    font-size: 0.6rem;
    color: var(--text-dim);
    margin-bottom: 5px;
    letter-spacing: 1px;
}

#mini-monitor {
    border-bottom: 1px solid var(--accent-cyan);
    border-left: 1px solid var(--glass-border);
    background: linear-gradient(to top, rgba(0, 242, 255, 0.05), transparent);
}

/* 3D Canvas */
#canvas-container {
    position: absolute;
    top: 0; left: 0;
    z-index: 1;
}

/* Animations */
@keyframes blink {
    from { opacity: 0.5; }
    to { opacity: 1; }
}

@keyframes pulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 0, 85, 0.4); }
    70% { transform: scale(1.05); box-shadow: 0 0 0 15px rgba(255, 0, 85, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255, 0, 85, 0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   ACCESS GATE — Passcode overlay
   ============================================================ */
.access-gate {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(3, 3, 3, 0.92);
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    justify-content: center;
}

.access-gate-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 32px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    backdrop-filter: blur(20px);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
}

.access-gate-card .brand {
    font-family: 'Dancing Script', cursive;
    font-size: 2rem;
    color: #fff;
}

#access-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    padding: 10px 16px;
    color: #fff;
    font-size: 1rem;
    outline: none;
    text-align: center;
    width: 220px;
    transition: border-color 0.2s;
}

#access-input:focus {
    border-color: var(--accent-cyan);
}

#access-submit {
    background: var(--accent-cyan);
    color: #000;
    border: none;
    border-radius: 10px;
    padding: 10px 32px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: box-shadow 0.2s;
}

#access-submit:hover {
    box-shadow: 0 0 16px rgba(0, 242, 255, 0.3);
}

/* Remove mobile tap highlight and focus ring */
* {
    -webkit-tap-highlight-color: transparent;
}
button:focus,
input:focus {
    outline: none;
}

/* ============================================================
   RESPONSIVE — Mobile
   ============================================================ */
@media (max-width: 768px) {
    body {
        overflow-x: hidden;
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    #canvas-container {
        position: fixed;
        top: 0; left: 0;
        width: 100%; height: 100%;
    }

    #ui-layer {
        position: relative;
        height: auto;
        min-height: 100dvh;
        padding: 12px;
        gap: 14px;
        justify-content: flex-start;
    }

    /* --- Header --- */
    .header {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: space-between;
    }
    .brand {
        font-size: 1.3rem;
    }
    .header-actions {
        gap: 8px;
    }
    .settings-btn {
        width: 30px; height: 30px;
    }
    .status-text { font-size: 0.55rem; }
    .track-info { font-size: 0.6rem; }

    /* --- Mode selector -> floating bar --- */
    .mode-selector {
        order: 3;
        width: 100%;
        justify-content: center;
        margin-top: 4px;
    }
    .mode-btn {
        font-size: 0.65rem;
        padding: 6px 12px;
    }

    /* --- Active bubble --- */
    .active-message-zone {
        position: relative;
        top: auto; left: auto;
        transform: none;
        width: 100%;
        max-width: 100%;
        margin: 40px auto 12px;
        padding: 0 8px;
    }
    .active-bubble {
        padding: 16px 18px;
        border-radius: 20px 20px 20px 8px;
        max-width: 100%;
    }
    .active-bubble .content { font-size: 0.9rem; }

    /* --- Session log -> bottom drawer --- */
    .session-log {
        position: fixed;
        top: auto; left: 0; right: 0; bottom: 0;
        width: 100%;
        max-height: 50vh;
        border-radius: 16px 16px 0 0;
        z-index: 35;
    }
    .session-log-header {
        font-size: 0.6rem;
        padding: 10px 14px;
        border-radius: 16px 16px 0 0;
    }
    .session-log-list {
        gap: 10px;
        padding: 10px 14px;
        max-height: calc(50vh - 44px);
        overflow-y: auto;
    }
    .log-bubble {
        font-size: 0.78rem;
        padding: 10px 12px;
        max-width: 95%;
    }
    .log-role { font-size: 0.5rem; }

    /* --- Settings panel --- */
    .settings-panel {
        top: 50%; left: 50%;
        right: auto; bottom: auto;
        width: 90vw; max-width: 380px;
        transform: translate(-50%, -50%) translateY(-10px) scale(0.98);
    }
    .settings-panel.open {
        transform: translate(-50%, -50%) translateY(0) scale(1);
    }

    /* --- Footer --- */
    .footer {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 8px;
        margin-top: auto;
        padding-bottom: 70px;
    }
    .main-ctrl-btn {
        width: 62px;
        height: 62px;
    }
    .main-ctrl-btn:hover, .main-ctrl-btn.active {
        width: 68px;
        height: 68px;
    }
    .mic-icon { font-size: 1.2rem; }
    .footer-left { width: 100%; order: 2; }
    .footer-left .input-group { width: 100%; }
    .footer-center { order: 1; }
    .footer-right {
        order: 3;
        width: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
    }
    #mini-monitor {
        width: 150px;
        height: 40px;
        border-radius: 8px;
        border: 1px solid var(--glass-border);
        background: rgba(0, 242, 255, 0.04);
    }

    .btn-label {
        font-size: 0.5rem;
        bottom: -20px;
    }

    /* --- Portrait lock overlay --- */
    .portrait-lock {
        display: none;
    }
}

/* ============================================================
   LANDSCAPE LOCK — force portrait on phones
   ============================================================ */
@media (max-width: 768px) and (orientation: landscape) {
    #ui-layer {
        display: none !important;
    }
    #canvas-container {
        filter: blur(20px) brightness(0.3);
    }
    .portrait-lock {
        display: flex !important;
        position: fixed;
        inset: 0;
        z-index: 999;
        background: rgba(3, 3, 3, 0.85);
        backdrop-filter: blur(10px);
        align-items: center;
        justify-content: center;
        flex-direction: column;
        gap: 16px;
        color: #fff;
        font-size: 1.1rem;
        text-align: center;
        pointer-events: auto;
    }
}

/* Extra small phones */
@media (max-width: 400px) {
    .brand { font-size: 1.1rem; }
    .settings-btn { width: 26px; height: 26px; font-size: 0.85rem; }
    .active-bubble .content { font-size: 0.8rem; }
    .log-bubble { font-size: 0.7rem; }
    .session-log { max-height: 40vh; }
    .session-log-list { max-height: calc(40vh - 44px); }
    .mode-btn { font-size: 0.6rem; padding: 5px 8px; }
    .active-message-zone { margin-top: 60px; }
    #mini-monitor { width: 160px; height: 44px; }
}