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

:root {
    --bg-primary: #121212;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #242424;
    --text-primary: #e0e0e0;
    --text-secondary: #9e9e9e;
    --text-muted: #616161;
    --border-color: #2a2a2a;
    --accent: #424242;
    --accent-hover: #4a4a4a;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height */
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Safe area for iOS */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

.container {
    display: flex;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Left Column - Microphone */
.left-column {
    flex: 0 0 360px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    position: relative;
    overflow: visible;
    padding: 40px 20px;
}

.left-column::before {
    content: '';
    position: absolute;
    width: 300px;
    height: 300px;
    background: radial-gradient(circle, rgba(66, 66, 66, 0.15) 0%, transparent 70%);
    border-radius: 50%;
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
}

.left-column:has(.mic-button.recording)::before {
    opacity: 1;
    animation: ambient-pulse 3s ease-in-out infinite;
}

@keyframes ambient-pulse {
    0%, 100% { transform: scale(1); opacity: 0.15; }
    50% { transform: scale(1.2); opacity: 0.25; }
}

.mic-container {
    text-align: center;
    z-index: 1;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 20px;
}

/* Avatar Container - full width, seamless with background */
.avatar-container {
    width: 100%;
    height: 350px;
    overflow: visible;
    position: relative;
    background: transparent;
    transition: all 0.3s ease;
    /* Remove any box appearance */
    border: none;
    box-shadow: none;
    outline: none;
    margin: 0;
    padding: 0;
}

.avatar-container canvas {
    width: 100% !important;
    height: 100% !important;
    /* Seamless canvas */
    background: transparent !important;
    border: none !important;
    outline: none !important;
    /* Smooth edge gradient mask */
    -webkit-mask-image: radial-gradient(ellipse 70% 80% at center, black 50%, transparent 100%);
    mask-image: radial-gradient(ellipse 70% 80% at center, black 50%, transparent 100%);
}

/* Avatar loading animation */
.avatar-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 50px;
    height: 50px;
    margin: -25px 0 0 -25px;
    border: 3px solid var(--border-color);
    border-top-color: var(--text-secondary);
    border-radius: 50%;
    animation: avatar-spinner 0.8s linear infinite;
    z-index: 1;
    transition: opacity 0.3s ease;
}

.avatar-container.loaded::before {
    opacity: 0;
    pointer-events: none;
}

@keyframes avatar-spinner {
    to { transform: rotate(360deg); }
}

/* Spectrum Wrapper - clickable area */
.spectrum-wrapper {
    position: relative;
    width: 320px;
    height: 320px;
    cursor: pointer;
    transition: transform 0.3s ease;
    overflow: visible;
}

.spectrum-wrapper:hover {
    transform: scale(1.02);
}

.spectrum-wrapper:active {
    transform: scale(0.98);
}

.spectrum-wrapper.recording {
    cursor: pointer;
}

.spectrum-wrapper.recording:hover {
    transform: scale(1.01);
}

/* Three.js Spectrum Container */
.spectrum-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    height: 320px;
    pointer-events: none;
    overflow: visible;
}

.spectrum-container canvas {
    display: block;
    overflow: visible;
}

/* Mic overlay in center */
.mic-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(30, 30, 30, 0.8);
    border: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.mic-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(255,255,255,0.05) 0%, transparent 50%);
}

.spectrum-wrapper:hover .mic-overlay {
    border-color: var(--accent);
    background: rgba(50, 50, 50, 0.9);
    transform: translate(-50%, -50%) scale(1.05);
}

.mic-overlay.recording {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow: 0 0 40px rgba(255, 255, 255, 0.2);
}

.mic-icon-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
}

.mic-icon {
    width: 32px;
    height: 32px;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.mic-overlay.recording .mic-icon {
    color: var(--text-primary);
    animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0.7; }
}

.mic-status {
    margin-top: 20px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: color 0.3s ease;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 30px;
    text-align: center;
}

.sidebar-footer p {
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.02em;
}

.sidebar-footer a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
}

.sidebar-footer a:hover {
    color: var(--text-primary);
}

/* Right Column - Translation */
.right-column {
    flex: 1;
    padding: 32px 40px;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border-color);
}

.header h1 {
    font-size: 20px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text-primary);
}

.language-selector {
    display: flex;
    align-items: center;
    gap: 12px;
}

.language-selector label {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
}

.language-selector select {
    padding: 10px 16px;
    padding-right: 36px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239e9e9e' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.language-selector select:hover,
.language-selector select:focus {
    border-color: var(--accent);
    background-color: var(--bg-tertiary);
}

.language-selector select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px;
}

.translation-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.text-box {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 20px 24px;
    border: 1px solid var(--border-color);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.text-box:hover {
    border-color: var(--accent);
}

.text-box.original-text {
    min-height: 120px;
}

.text-box.translated-text {
    flex: 1;
    min-height: 160px;
}

.text-box .label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 12px;
    font-weight: 600;
}

.text-box .label-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s ease;
}

.original-text .label-indicator {
    background: var(--text-secondary);
}

.translated-text .label-indicator {
    background: var(--text-primary);
}

/* TTS Toggle Button */
.tts-toggle {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 6px 8px;
    cursor: pointer;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.tts-toggle:hover {
    background: var(--bg-tertiary);
    border-color: var(--accent);
    color: var(--text-primary);
}

.tts-toggle.disabled {
    opacity: 0.4;
    color: var(--text-muted);
}

.tts-toggle.disabled:hover {
    background: transparent;
    border-color: var(--border-color);
    color: var(--text-muted);
}

.speaker-icon {
    width: 16px;
    height: 16px;
}

/* Speaking animation */
.tts-toggle.speaking {
    color: var(--text-primary);
    animation: pulse-speaker 1s ease-in-out infinite;
}

@keyframes pulse-speaker {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.text-box .content {
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-primary);
    min-height: 24px;
    position: relative;
}

.text-box .content.empty {
    color: var(--text-muted);
}

/* Segment styling for translated text */
.text-box .content .segment {
    display: inline;
    transition: all 0.3s ease;
    border-radius: 3px;
    padding: 2px 0;
}

/* Speaking segment - yellow highlight with pulse animation */
.text-box .content .segment.speaking {
    background: linear-gradient(135deg, rgba(255, 213, 79, 0.3) 0%, rgba(255, 193, 7, 0.25) 100%);
    color: #fff;
    padding: 2px 4px;
    margin: 0 -4px;
    animation: speaking-pulse 1.5s ease-in-out infinite;
    box-shadow: 0 0 10px rgba(255, 193, 7, 0.3);
}

@keyframes speaking-pulse {
    0%, 100% {
        background: linear-gradient(135deg, rgba(255, 213, 79, 0.3) 0%, rgba(255, 193, 7, 0.25) 100%);
        box-shadow: 0 0 10px rgba(255, 193, 7, 0.3);
    }
    50% {
        background: linear-gradient(135deg, rgba(255, 213, 79, 0.5) 0%, rgba(255, 193, 7, 0.4) 100%);
        box-shadow: 0 0 20px rgba(255, 193, 7, 0.5);
    }
}

/* Done segment - subtle fade after speaking */
.text-box .content .segment.done {
    color: var(--text-secondary);
    opacity: 0.85;
}

/* Translating placeholder */
.text-box .content .translating {
    color: var(--text-muted);
    animation: translating-dots 1s ease-in-out infinite;
}

@keyframes translating-dots {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* Partial translation preview - shown while user is still speaking */
.text-box .content .segment.partial-preview {
    color: var(--text-secondary);
    opacity: 0.7;
    font-style: italic;
    border-left: 2px solid var(--accent);
    padding-left: 8px;
    margin-left: 4px;
}

/* Typing cursor animation */
.text-box .content.typing::after {
    content: '';
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--text-primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: cursor-blink 0.8s ease-in-out infinite;
}

@keyframes cursor-blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Loading animation for translation */
.text-box.loading .content::after {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-left: 8px;
    vertical-align: middle;
    border: 2px solid var(--border-color);
    border-top-color: var(--text-secondary);
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
}

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

/* Shimmer loading effect - single clean animation */
.text-box.shimmer .content {
    color: var(--text-muted);
}

.text-box.shimmer::after {
    content: '';
    position: absolute;
    bottom: 20px;
    left: 24px;
    right: 24px;
    height: 3px;
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        var(--text-muted) 50%,
        var(--bg-tertiary) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.2s ease-in-out infinite;
    border-radius: 2px;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.detected-lang {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.detected-lang .label {
    margin-bottom: 0;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
}

.detected-lang #detectedContent {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 13px;
}

.error-message {
    margin-top: 16px;
    padding: 14px 20px;
    background: rgba(244, 67, 54, 0.1);
    border: 1px solid rgba(244, 67, 54, 0.2);
    border-radius: 10px;
    color: #ef5350;
    font-size: 13px;
    display: none;
    animation: fade-in 0.3s ease;
}

.error-message.show {
    display: block;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Status indicator */
.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 20px;
    margin-top: 20px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    transition: background 0.3s ease;
}

.status-dot.connected {
    background: #4caf50;
}

.status-dot.recording {
    background: var(--text-primary);
    animation: status-pulse 1.5s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.status-text {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

/* Responsive - Tablet */
@media (max-width: 900px) {
    .container {
        flex-direction: column;
        min-height: 100vh;
    }

    .left-column {
        flex: 0 0 auto;
        min-height: auto;
        padding: 15px 15px 10px;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }

    .mic-container {
        flex-direction: column;
        gap: 10px;
    }

    .avatar-container {
        width: 100%;
        height: 200px;
    }

    .avatar-container canvas {
        -webkit-mask-image: radial-gradient(ellipse 80% 90% at center, black 60%, transparent 100%);
        mask-image: radial-gradient(ellipse 80% 90% at center, black 60%, transparent 100%);
    }

    .spectrum-wrapper {
        width: 160px;
        height: 160px;
    }

    .spectrum-container {
        width: 160px;
        height: 160px;
    }

    .mic-overlay {
        width: 50px;
        height: 50px;
    }

    .mic-icon {
        width: 22px;
        height: 22px;
    }

    .mic-status {
        margin-top: 8px;
        font-size: 11px;
    }

    .sidebar-footer {
        padding-top: 10px;
    }

    .sidebar-footer p {
        font-size: 10px;
    }

    .right-column {
        flex: 1;
        padding: 20px 16px;
    }

    .header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
        margin-bottom: 16px;
        padding-bottom: 16px;
    }

    .header h1 {
        font-size: 18px;
    }

    .language-selector {
        width: 100%;
        justify-content: center;
    }

    .language-selector select {
        flex: 1;
        max-width: 200px;
    }

    .translation-area {
        gap: 12px;
    }

    .text-box {
        padding: 16px 18px;
    }

    .text-box .content {
        font-size: 15px;
        line-height: 1.6;
    }

    .detected-lang {
        padding: 12px 16px;
    }
}

/* Responsive - Mobile */
@media (max-width: 480px) {
    .container {
        min-height: 100dvh; /* Dynamic viewport height for mobile */
    }

    .left-column {
        min-height: auto;
        padding: 12px 12px 8px;
    }

    .left-column::before {
        display: none;
    }

    .mic-container {
        flex-direction: column;
        gap: 8px;
        align-items: center;
    }

    .avatar-container {
        width: 100%;
        height: 180px;
    }

    .avatar-container canvas {
        -webkit-mask-image: radial-gradient(ellipse 85% 90% at center, black 55%, transparent 100%);
        mask-image: radial-gradient(ellipse 85% 90% at center, black 55%, transparent 100%);
    }

    .spectrum-wrapper {
        width: 120px;
        height: 120px;
    }

    .spectrum-container {
        width: 120px;
        height: 120px;
    }

    .mic-overlay {
        width: 44px;
        height: 44px;
    }

    .mic-icon {
        width: 20px;
        height: 20px;
    }

    .mic-status {
        margin-top: 6px;
        font-size: 10px;
    }

    .sidebar-footer {
        padding-top: 8px;
    }

    .sidebar-footer p {
        font-size: 9px;
    }

    .right-column {
        padding: 16px 14px;
    }

    .header {
        margin-bottom: 14px;
        padding-bottom: 12px;
        gap: 10px;
    }

    .header h1 {
        font-size: 16px;
    }

    .language-selector {
        flex-direction: row;
        gap: 10px;
        align-items: center;
    }

    .language-selector label {
        font-size: 12px;
    }

    .language-selector select {
        flex: 1;
        max-width: none;
        padding: 10px 14px;
        font-size: 14px;
    }

    .translation-area {
        gap: 10px;
    }

    .text-box {
        padding: 12px 14px;
        border-radius: 10px;
    }

    .text-box.original-text {
        min-height: 70px;
    }

    .text-box.translated-text {
        min-height: 100px;
    }

    .text-box .label {
        font-size: 10px;
        margin-bottom: 8px;
        gap: 6px;
    }

    .text-box .label-indicator {
        width: 6px;
        height: 6px;
    }

    .tts-toggle {
        padding: 5px 7px;
    }

    .speaker-icon {
        width: 14px;
        height: 14px;
    }

    .text-box .content {
        font-size: 14px;
        line-height: 1.5;
    }

    .detected-lang {
        padding: 10px 12px;
        gap: 10px;
        border-radius: 8px;
    }

    .detected-lang .label {
        font-size: 10px;
    }

    .detected-lang #detectedContent {
        font-size: 12px;
    }

    .status-bar {
        padding-top: 12px;
        margin-top: 12px;
        gap: 6px;
    }

    .status-dot {
        width: 6px;
        height: 6px;
    }

    .status-text {
        font-size: 11px;
    }

    .error-message {
        padding: 12px 14px;
        font-size: 12px;
        border-radius: 8px;
    }

    /* Segment text adjustments for mobile */
    .text-box .content .segment.speaking {
        padding: 1px 3px;
        margin: 0 -3px;
    }
}

/* Extra small devices */
@media (max-width: 360px) {
    .left-column {
        min-height: auto;
        padding: 10px 10px 6px;
    }

    .avatar-container {
        height: 150px;
    }

    .spectrum-wrapper {
        width: 100px;
        height: 100px;
    }

    .spectrum-container {
        width: 100px;
        height: 100px;
    }

    .mic-overlay {
        width: 40px;
        height: 40px;
    }

    .mic-icon {
        width: 18px;
        height: 18px;
    }

    .right-column {
        padding: 14px 10px;
    }

    .header h1 {
        font-size: 14px;
    }

    .text-box .content {
        font-size: 13px;
    }
}

/* Landscape mode on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .container {
        flex-direction: row;
    }

    .left-column {
        flex: 0 0 220px;
        min-height: auto;
        padding: 10px;
        border-right: 1px solid var(--border-color);
        border-bottom: none;
    }

    .mic-container {
        flex-direction: column;
        gap: 6px;
    }

    .avatar-container {
        height: 140px;
    }

    .spectrum-wrapper {
        width: 100px;
        height: 100px;
    }

    .spectrum-container {
        width: 100px;
        height: 100px;
    }

    .mic-overlay {
        width: 36px;
        height: 36px;
    }

    .mic-icon {
        width: 16px;
        height: 16px;
    }

    .mic-status {
        font-size: 9px;
        margin-top: 4px;
    }

    .sidebar-footer {
        display: none;
    }

    .right-column {
        overflow-y: auto;
        max-height: 100vh;
        padding: 12px;
    }

    .header {
        margin-bottom: 10px;
        padding-bottom: 10px;
    }

    .text-box.original-text {
        min-height: 50px;
    }

    .text-box.translated-text {
        min-height: 70px;
    }

    .text-box {
        padding: 10px 12px;
    }
}

/* Smooth transitions for all interactive elements */
* {
    transition-property: background-color, border-color, color, opacity, transform;
    transition-duration: 0.2s;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Performance optimization */
.mic-button,
.text-box,
.status-dot {
    will-change: transform;
}
