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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    gap: 0;
}

/* Video Panel — left 2/3 */
#video-panel {
    flex: 2 1 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    background: #0f0f23;
    min-width: 0;
}

#video-container {
    position: relative;
    flex: 1;
    width: 100%;
    background: #000;
    border-radius: 12px;
    overflow: hidden;
}

#avatar-video {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* Video loading overlay — black + spinner, fades out when avatar appears */
#video-loading-overlay {
    position: absolute;
    inset: 0;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 5;
    opacity: 1;
    transition: opacity 0.25s ease;
    border-radius: 12px;
}

#video-loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

#video-loading-overlay.hidden {
    display: none !important;
}

/* Progress card — shown during avatar setup */
.progress-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 32px 36px;
    background: #16213e;
    border: 1px solid #2a2a4a;
    border-radius: 16px;
    min-width: 280px;
}

.progress-ring-container {
    position: relative;
    width: 80px;
    height: 80px;
}

.progress-ring-fill {
    transition: stroke-dashoffset 0.4s ease;
}

.progress-ring-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #e0e0e0;
}

.progress-steps {
    list-style: none;
    display: flex;
    flex-direction: column;
    width: 100%;
    padding: 0;
    margin: 0;
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    border-bottom: 1px solid #2a2a4a;
    opacity: 0.3;
    transition: opacity 0.3s;
}

.progress-step:last-child {
    border-bottom: none;
}

.progress-step.active,
.progress-step.completed {
    opacity: 1;
}

.step-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #3a3a5a;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s;
}

.progress-step.active .step-dot {
    background: #4fc3f7;
    animation: pulse-dot 1.5s ease-in-out infinite;
}

.progress-step.completed .step-dot {
    background: #66bb6a;
}

.progress-step.completed .step-dot::after {
    content: '✓';
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

.step-label {
    font-size: 13px;
    color: #5a6a7a;
    transition: color 0.3s;
}

.progress-step.active .step-label {
    color: #e0e0e0;
    font-weight: 600;
}

.progress-step.completed .step-label {
    color: #90a4ae;
}

@keyframes pulse-dot {
    0%, 100% { box-shadow: 0 0 0 0 rgba(79, 195, 247, 0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(79, 195, 247, 0); }
}

.progress-footer {
    font-size: 12px;
    color: #5a6a7a;
    margin: 0;
}

#status-indicator {
    position: absolute;
    top: 12px;
    left: 12px;
    background: rgba(0, 0, 0, 0.7);
    color: #4fc3f7;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
}

#status-indicator.hidden {
    display: none;
}

#status-indicator.listening {
    color: #66bb6a;
}

#status-indicator.thinking {
    color: #ffa726;
}

#status-indicator.speaking {
    color: #ab47bc;
}

#status-indicator.error {
    color: #ef5350;
}

/* Sidebar — right 1/3 */
#sidebar {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 0;
    overflow: hidden;
    border-left: 1px solid #2a2a4a;
    min-width: 280px;
    max-width: 480px;
}

#sidebar h3 {
    font-size: 14px;
    font-weight: 600;
    color: #90caf9;
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================
   Phase: Setup
   ============================================================ */

#setup-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    flex: 1;
    padding-right: 4px;
}

.context-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.context-label {
    font-size: 11px;
    font-weight: 600;
    color: #90caf9;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.char-hint {
    font-weight: 400;
    color: #5a6a7a;
    text-transform: none;
    letter-spacing: 0;
}

#personality-box,
#knowledge-box,
#start-script-box,
#coach-text-box {
    width: 100%;
    padding: 10px 12px;
    background: #2a2a4a;
    color: #e0e0e0;
    border: 2px solid #3a3a5a;
    border-radius: 8px;
    font-family: 'Cascadia Code', 'Fira Code', monospace;
    font-size: 11px;
    line-height: 1.5;
    resize: vertical;
    outline: none;
}

#personality-box {
    height: 120px;
}

#knowledge-box {
    height: 100px;
}

#start-script-box {
    height: 50px;
}

#coach-text-box {
    height: 70px;
}

#personality-box:focus,
#knowledge-box:focus,
#start-script-box:focus,
#coach-text-box:focus {
    border-color: #4fc3f7;
}

#character-select {
    width: 100%;
    padding: 8px 12px;
    background: #2a2a4a;
    color: #e0e0e0;
    border: 2px solid #3a3a5a;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    cursor: pointer;
}

#character-select:focus {
    border-color: #4fc3f7;
}

#start-btn {
    width: 100%;
    padding: 14px;
    background: #2e7d32;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.3px;
    transition: background 0.2s;
    margin-top: 4px;
}

#start-btn:hover {
    background: #388e3c;
}

#start-btn:disabled {
    background: #333;
    cursor: not-allowed;
}

.secondary-btn {
    background: transparent;
    border: 1px solid #4a4a6a;
    color: #90a4ae;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 6px;
    width: 100%;
    transition: background 0.15s, color 0.15s;
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #e0e0e0;
}

/* ============================================================
   Phase: Conversing
   ============================================================ */

#conv-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    gap: 10px;
}

#session-timer {
    flex: 0 0 auto;
    font-size: 14px;
    font-weight: 600;
    color: #78909c;
    text-align: center;
    padding: 8px;
}

#session-timer.timer-warning {
    color: #ffa726;
}

#chat-history {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

.chat-msg {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.5;
    max-width: 90%;
}

.chat-msg.user {
    background: #1565c0;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-msg.assistant {
    background: #2a2a4a;
    color: #e0e0e0;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-msg .role {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
    opacity: 0.7;
}

#end-btn {
    flex: 0 0 auto;
    width: 100%;
    padding: 8px;
    background: transparent;
    color: #ef5350;
    border: 1px solid #ef535044;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

#end-btn:hover {
    background: #2a1515;
    border-color: #ef5350;
}

/* ============================================================
   Phase: Done
   ============================================================ */

#done-section {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    gap: 12px;
}

#transcript-result {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-right: 4px;
}

#new-conv-btn {
    width: 100%;
    padding: 12px;
    background: #2e7d32;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    transition: background 0.2s;
}

#new-conv-btn:hover {
    background: #388e3c;
}

/* ============================================================
   Scrollbar
   ============================================================ */

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #3a3a5a;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #4a4a6a;
}

/* ============================================================
   Production mode (hidecontrols)
   ============================================================ */

body.hidecontrols #sidebar    { display: none !important; }
body.hidecontrols #video-panel { flex: 1 1 100%; }

/* Centered start button overlay */
#prod-start-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.35);
    z-index: 10;
}

#prod-start-btn {
    padding: 18px 40px;
    background: #2e7d32;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
    transition: background 0.2s, transform 0.1s;
}

#prod-start-btn:hover  { background: #388e3c; transform: scale(1.03); }
#prod-start-btn:active { transform: scale(0.98); }

/* Mic status indicator — bottom center of video */
#prod-mic-indicator {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
    pointer-events: none;
    line-height: 0;
}

/* Close button — top-right X on video, always on top */
#prod-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 9999;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
    font-size: 28px;
    line-height: 44px;
    text-align: center;
    cursor: pointer;
    user-select: none;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

#prod-close-btn:hover {
    background: rgba(255, 255, 255, 0.45);
}

/* End-of-conversation fade to black */
#fade-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 1.5s ease;
    z-index: 999;
}

#fade-overlay.fading {
    opacity: 1;
    pointer-events: all;
}

/* Coach text panel — bottom-right overlay on video */
#coach-panel {
    position: absolute;
    bottom: 20px;
    right: 20px;
    max-width: 420px;
    padding: 12px 30px 12px 16px;
    background: rgba(20, 20, 40, 0.72);
    backdrop-filter: blur(4px);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: #fff;
    font-size: 13px;
    line-height: 1.55;
    z-index: 10;
    pointer-events: none;
    overflow: hidden;
}

#coach-panel p { margin: 0 0 4px; }
#coach-panel p:last-child { margin-bottom: 0; }
#coach-panel h1,
#coach-panel h2,
#coach-panel h3 {
    font-size: 13px;
    font-weight: 700;
    color: #90caf9;
    margin: 0 0 4px;
}
#coach-panel ul,
#coach-panel ol { padding-left: 16px; margin: 0 0 4px; }
#coach-panel li { margin: 0; }
#coach-panel strong { color: #fff; }

/* Coach panel toggle button */
#coach-toggle-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    pointer-events: all;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    opacity: 0.6;
    transition: opacity 0.15s;
}
#coach-toggle-btn:hover { opacity: 1; }

/* Minimized state */
#coach-panel.minimized {
    padding: 0;
    background: none;
    border: none;
    backdrop-filter: none;
}
#coach-panel.minimized #coach-panel-content { display: none; }
#coach-panel.minimized #coach-toggle-btn {
    position: static;
    width: 32px;
    height: 32px;
    font-size: 18px;
    border-radius: 8px;
    background: rgba(20, 20, 40, 0.72);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    opacity: 0.7;
}
#coach-panel.minimized #coach-toggle-btn:hover { opacity: 1; }

/* Hide-sidebar checkbox in debug sidebar */
.hide-sidebar-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #90a4ae;
    cursor: pointer;
    user-select: none;
    margin-top: 2px;
}

.hide-sidebar-toggle input { cursor: pointer; }

/* ============================================================
   Hidden utility
   ============================================================ */

.hidden {
    display: none !important;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 900px) {
    #app {
        flex-direction: column;
        overflow-y: auto;
    }

    body {
        overflow: auto;
    }

    #video-panel {
        flex: none;
        height: 50vh;
    }

    #sidebar {
        flex: none;
        border-left: none;
        border-top: 1px solid #2a2a4a;
        height: 600px;
        max-width: none;
    }
}
