/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg-dark: #0a0a0f;
    --bg-surface: #12121a;
    --bg-elevated: #1a1a26;
    --text-primary: #f0f0f5;
    --text-muted: rgba(240, 240, 245, 0.5);
    --blue: #2563eb;
    --blue-glow: rgba(37, 99, 235, 0.25);
    --green: #059669;
    --green-glow: rgba(5, 150, 105, 0.25);
    --red: #ef4444;
    --radius: 16px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-dark);
    color: var(--text-primary);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== App Layout ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
    height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
}

/* ===== Header ===== */
header {
    flex-shrink: 0;
    text-align: center;
    padding: calc(12px + var(--safe-top)) 16px 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

header h1 {
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.header-actions {
    position: absolute;
    right: 0;
    display: flex;
    gap: 8px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.92);
}

.icon-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    color: var(--red);
}

.model-selectors {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 8px;
}

.model-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.model-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    width: 24px;
    text-align: right;
}

.model-selector {
    display: flex;
    gap: 6px;
}

.model-btn {
    padding: 4px 12px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 20px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s ease;
}

.model-btn:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
}

.model-btn.claude.active {
    background: var(--blue);
    border-color: var(--blue);
    color: #ffffff;
}

.model-btn.whisper.active {
    background: #7c3aed;
    border-color: #7c3aed;
    color: #ffffff;
}

#status {
    font-size: 0.75rem;
    margin-top: 4px;
    color: var(--text-muted);
    transition: color 0.3s ease;
}

#status.active {
    color: var(--blue);
}

#status.error {
    color: var(--red);
}

/* ===== Chat Area ===== */
main#chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -ms-overflow-style: none;
    scrollbar-width: none;
}

main#chat::-webkit-scrollbar {
    display: none;
}

/* ===== Chat Bubbles ===== */
.bubble {
    max-width: 82%;
    padding: 12px 16px;
    border-radius: var(--radius);
    animation: fadeSlideIn 0.3s ease-out;
    position: relative;
}

.bubble.left {
    align-self: flex-start;
    background: var(--blue);
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 12px var(--blue-glow);
}

.bubble.right {
    align-self: flex-end;
    background: var(--green);
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 12px var(--green-glow);
}

.bubble .original {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 6px;
    line-height: 1.4;
}

.bubble .translated {
    font-size: 1.05rem;
    color: #ffffff;
    line-height: 1.5;
    font-weight: 500;
}

/* ===== Play Button (CSS-only) ===== */
.play-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    cursor: pointer;
    margin-top: 8px;
    transition: background 0.2s ease, transform 0.15s ease;
}

.play-btn:hover {
    background: rgba(255, 255, 255, 0.28);
}

.play-btn:active {
    transform: scale(0.92);
}

.play-icon {
    display: block;
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 6px 0 6px 11px;
    border-color: transparent transparent transparent #ffffff;
    margin-left: 2px;
}

/* ===== Loading Bubble ===== */
.bubble.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    min-width: 80px;
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* ===== Footer Buttons ===== */
footer {
    flex-shrink: 0;
    display: flex;
    gap: 12px;
    padding: 12px 16px calc(12px + var(--safe-bottom));
    background: var(--bg-surface);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.record-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    border: none;
    border-radius: 14px;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.15s ease, box-shadow 0.3s ease, background 0.3s ease;
    position: relative;
    overflow: hidden;
}

.record-btn:active {
    transform: scale(0.96);
}

.record-btn .icon {
    font-size: 1.4rem;
    line-height: 1;
}

.record-btn .label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 4px;
    letter-spacing: 0.02em;
}

/* English button */
.record-btn.en {
    background: var(--blue);
    color: #ffffff;
    box-shadow: 0 4px 16px var(--blue-glow);
}

.record-btn.en:hover {
    background: #3b82f6;
}

/* Malayalam button */
.record-btn.ml {
    background: var(--green);
    color: #ffffff;
    box-shadow: 0 4px 16px var(--green-glow);
}

.record-btn.ml:hover {
    background: #10b981;
}

/* ===== Recording State ===== */
.record-btn.recording {
    background: var(--red) !important;
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4) !important;
    animation: pulse 1.2s ease-in-out infinite;
}

.record-btn.recording .icon::after {
    content: '';
}

/* ===== Animations ===== */
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
    }
    50% {
        transform: scale(1.03);
        box-shadow: 0 4px 28px rgba(239, 68, 68, 0.6);
    }
}

/* ===== Progress Steps ===== */
.bubble.progress-bubble {
    min-width: 200px;
}

.progress-steps {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.progress-step {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.4);
    transition: color 0.3s ease;
}

.progress-step.running {
    color: #ffffff;
}

.progress-step.done {
    color: rgba(255, 255, 255, 0.7);
}

.progress-step .step-icon {
    width: 16px;
    text-align: center;
    flex-shrink: 0;
}

.progress-step.running .step-icon {
    animation: spin 0.7s linear infinite;
}

.progress-step .step-label {
    flex: 1;
}

.progress-step .step-time {
    font-size: 0.7rem;
    opacity: 0.6;
}

/* ===== Empty State ===== */
#chat:empty::after {
    content: 'Tap a button and speak';
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 0.95rem;
    text-align: center;
}

/* ===== Login Screen ===== */
#login {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    height: 100dvh;
    padding: 24px;
    background: var(--bg-dark);
}

.login-box {
    width: 100%;
    max-width: 320px;
    text-align: center;
}

.login-box h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 32px;
}

#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

#login-form input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s ease;
}

#login-form input:focus {
    border-color: var(--blue);
}

#login-form button {
    padding: 14px;
    border: none;
    border-radius: 12px;
    background: var(--blue);
    color: #ffffff;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.2s ease, transform 0.15s ease;
}

#login-form button:active {
    transform: scale(0.97);
}

#login-form button:hover {
    background: #3b82f6;
}

#login-error {
    margin-top: 16px;
    font-size: 0.85rem;
    color: var(--red);
    min-height: 1.2em;
}

/* ===== Media Queries ===== */
@media (max-width: 380px) {
    .record-btn {
        min-height: 56px;
    }
    .record-btn .icon {
        font-size: 1.2rem;
    }
    .record-btn .label {
        font-size: 0.7rem;
    }
    header h1 {
        font-size: 1.1rem;
    }
}

@media (min-width: 601px) {
    #app {
        border-left: 1px solid rgba(255, 255, 255, 0.06);
        border-right: 1px solid rgba(255, 255, 255, 0.06);
    }
}
