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

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

/* --- Camera Mode --- */

#camera-mode {
    width: 100%;
    height: 100%;
    position: relative;
}

#canvas {
    display: block;
    width: 100%;
    height: 100%;
}

#hint {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    font-size: 16px;
    white-space: nowrap;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    animation: fadeInUp 0.5s ease;
    pointer-events: none;
    z-index: 10;
}

#loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: white;
    font-size: 16px;
    z-index: 20;
    pointer-events: none;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* --- Call Mode (Video Call UI) --- */

#call-mode {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #111;
}

#call-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 16px 12px;
    padding-top: max(16px, env(safe-area-inset-top));
}

#call-back-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

#call-back-btn:active {
    background: rgba(255, 255, 255, 0.2);
}

#call-info {
    flex: 1;
    min-width: 0;
}

#call-name {
    color: white;
    font-size: 18px;
    font-weight: 700;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#call-status {
    color: rgba(255, 255, 255, 0.5);
    font-size: 13px;
    margin-top: 2px;
}

#call-status.active {
    color: #4ade80;
}

/* Portrait area */
#call-portrait {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 20px;
    overflow: hidden;
}

#portrait-canvas {
    max-width: 100%;
    max-height: 100%;
    border-radius: 24px;
    object-fit: contain;
    transform-origin: center bottom;
    will-change: transform;
}

/* Mouth overlay on portrait */
#mouth-overlay {
    position: absolute;
    bottom: 30%;
    left: 50%;
    transform: translateX(-50%);
    width: 60px;
    height: 8px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    transition: height 0.05s ease, width 0.05s ease, border-radius 0.05s ease;
    pointer-events: none;
    display: none;
}

#mouth-overlay.talking {
    display: block;
}

/* Speaking glow ring around portrait */
#call-portrait.speaking #portrait-canvas {
    box-shadow: 0 0 0 4px rgba(74, 222, 128, 0.6), 0 0 30px rgba(74, 222, 128, 0.2);
    transition: box-shadow 0.2s ease;
}

/* Transcript bubble */
#call-transcript {
    padding: 0 20px 8px;
    max-height: 80px;
    overflow: hidden;
}

#transcript-text {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    padding: 10px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    text-align: center;
    backdrop-filter: blur(10px);
}

/* Call controls */
#call-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 32px;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
}

#call-mic-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#call-mic-btn:active {
    transform: scale(0.92);
}

#call-mic-btn.active {
    background: #4ade80;
    color: #111;
    animation: pulse-green 1.5s ease-in-out infinite;
}

#call-end-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: #e53935;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

#call-end-btn:active {
    transform: scale(0.92);
    background: #c62828;
}

/* --- Shared --- */

#error {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 24px;
    border-radius: 16px;
    text-align: center;
    backdrop-filter: blur(10px);
    z-index: 30;
}

#error-msg {
    margin-bottom: 16px;
    font-size: 14px;
    color: #ff6b6b;
}

#retry-btn {
    background: white;
    color: black;
    border: none;
    padding: 10px 24px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 600;
}

.hidden {
    display: none !important;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(20px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.5); }
    50% { box-shadow: 0 0 0 16px rgba(74, 222, 128, 0); }
}
