:root {
    --color-primary: #6366f1;
    --color-primary-dark: #4f46e5;
    --color-primary-light: #818cf8;
    --color-danger: #ef4444;
    --color-danger-glow: rgba(239, 68, 68, 0.4);
    --color-success: #22c55e;
    --color-surface: #ffffff;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;
    --color-border: #e2e8f0;
    --color-bg: #f8fafc;
    --color-lang1: #e0e7ff;
    --color-lang1-text: #3730a3;
    --color-lang2: #ede9fe;
    --color-lang2-text: #5b21b6;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 50%;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --transition-fast: 150ms ease;
    --transition-normal: 300ms ease;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html, body {
    height: 100%;
    overflow: hidden;
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-tap-highlight-color: transparent;
}

button { border: none; background: none; cursor: pointer; font-family: inherit; color: inherit; }
select { font-family: inherit; }
.hidden { display: none !important; }

/* ===== App Layout ===== */
#app {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
}

/* ===== Top Bar ===== */
#top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
    gap: 8px;
    z-index: 10;
}

.lang-pair {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.language-select {
    flex: 1;
    min-width: 0;
    padding: 8px 28px 8px 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    background: var(--color-bg);
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' xmlns='http://www.w3.org/2000/svg'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: border-color var(--transition-fast);
}

.language-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

#swap-languages {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-full);
    color: var(--color-primary);
    flex-shrink: 0;
    transition: all var(--transition-fast);
}

#swap-languages:hover {
    background: var(--color-lang1);
}

#swap-languages:active {
    transform: rotate(180deg);
}

.top-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.top-actions button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    transition: all var(--transition-fast);
}

.top-actions button:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--color-text);
}

/* ===== Status Bar ===== */
#status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
    flex-shrink: 0;
    transition: all var(--transition-normal);
}

#status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.status-idle {
    background: #f1f5f9;
    color: var(--color-text-muted);
}

.status-idle #status-dot {
    background: var(--color-text-light);
}

.status-listening {
    background: #fef2f2;
    color: var(--color-danger);
}

.status-listening #status-dot {
    background: var(--color-danger);
    animation: statusPulse 1.5s ease infinite;
}

.status-translating {
    background: #eef2ff;
    color: var(--color-primary);
}

.status-translating #status-dot {
    background: var(--color-primary);
    animation: statusPulse 0.8s ease infinite;
}

/* ===== Chat ===== */
.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.chat-history::-webkit-scrollbar { width: 4px; }
.chat-history::-webkit-scrollbar-track { background: transparent; }
.chat-history::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    gap: 12px;
    color: var(--color-text-light);
    padding: 20px;
    text-align: center;
}

.empty-state svg { opacity: 0.3; }
.empty-state h3 { font-size: 18px; color: var(--color-text-muted); }
.empty-state p { font-size: 13px; line-height: 1.5; }

/* ===== Message Bubbles ===== */
.message-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    animation: slideUp 0.3s ease forwards;
}

.message-bubble {
    max-width: 90%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    position: relative;
    word-wrap: break-word;
}

.message-bubble .lang-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.message-bubble .text {
    font-size: 15px;
    line-height: 1.45;
}

.message-bubble .time {
    font-size: 10px;
    color: var(--color-text-light);
    margin-top: 3px;
    text-align: right;
    display: block;
}

/* Original bubble (what was said) */
.bubble-original {
    background: var(--color-surface);
    box-shadow: var(--shadow-sm);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.bubble-original .lang-tag { color: var(--color-text-light); }

/* Translation bubble */
.bubble-translated {
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.bubble-translated.lang1 {
    background: var(--color-lang1);
    color: var(--color-lang1-text);
}

.bubble-translated.lang1 .lang-tag { color: var(--color-lang1-text); opacity: 0.7; }

.bubble-translated.lang2 {
    background: var(--color-lang2);
    color: var(--color-lang2-text);
}

.bubble-translated.lang2 .lang-tag { color: var(--color-lang2-text); opacity: 0.7; }

.bubble-translated .speaker-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    margin-left: 6px;
    vertical-align: middle;
    opacity: 0.5;
    transition: opacity var(--transition-fast);
}

.bubble-translated .speaker-btn:hover { opacity: 1; }

/* ===== Interim Text ===== */
#interim {
    padding: 0 16px;
    min-height: 0;
    flex-shrink: 0;
}

#interim:empty { display: none; }

#interim p {
    font-size: 14px;
    color: var(--color-text-muted);
    font-style: italic;
    padding: 8px 0;
    animation: fadeInOut 1.5s ease infinite;
}

/* ===== Volume Bar ===== */
#volume-container {
    height: 3px;
    background: var(--color-border);
    flex-shrink: 0;
}

#volume-bar {
    height: 100%;
    width: 0%;
    background: var(--color-primary);
    transition: width 100ms ease;
    border-radius: 2px;
}

.listening #volume-bar {
    background: var(--color-success);
}

/* ===== Bottom Bar ===== */
#bottom-bar {
    display: flex;
    justify-content: center;
    padding: 12px 12px 20px;
    flex-shrink: 0;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.mic-btn {
    width: 68px;
    height: 68px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: all var(--transition-normal);
}

.mic-btn:hover {
    background: var(--color-primary-dark);
    transform: scale(1.05);
}

.mic-btn:active { transform: scale(0.95); }

.mic-btn.listening {
    background: var(--color-danger);
    animation: pulse 1.5s ease infinite;
}

.mic-btn.listening .mic-icon { display: none; }
.mic-btn.listening .stop-icon { display: block !important; }

.mic-btn:disabled {
    background: var(--color-border);
    cursor: not-allowed;
    box-shadow: none;
}

/* ===== Settings ===== */
#settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

#settings-modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 360px;
    overflow: hidden;
    animation: slideDown 0.3s ease;
}

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

.settings-header h2 { font-size: 18px; font-weight: 600; }

.settings-header button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    transition: all var(--transition-fast);
}

.settings-header button:hover { background: rgba(0, 0, 0, 0.05); }

.settings-body { padding: 20px; }

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.toggle-row span { font-size: 14px; }

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle-switch input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--color-border);
    border-radius: 24px;
    transition: background var(--transition-fast);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: var(--radius-full);
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.toggle-switch input:checked + .toggle-slider { background: var(--color-primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.settings-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
}

.settings-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
}

.settings-input {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition-fast);
    box-sizing: border-box;
}

.settings-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.ai-status {
    font-size: 12px;
    font-weight: 600;
    margin-top: 6px;
    margin-bottom: 0;
}

.ai-active { color: var(--color-success); }
.ai-inactive { color: var(--color-text-light); }

.settings-hint {
    font-size: 12px;
    color: var(--color-text-light);
    margin-top: 8px;
    text-align: center;
}

.settings-hint a {
    color: var(--color-primary);
    text-decoration: none;
}

.settings-hint a:hover { text-decoration: underline; }

/* ===== Toast ===== */
#toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    background: var(--color-text);
    color: white;
    font-size: 14px;
    font-weight: 500;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 300;
    animation: toastIn 0.3s ease;
    max-width: calc(100% - 40px);
    text-align: center;
}

#toast.toast-error { background: var(--color-danger); }
#toast.toast-success { background: var(--color-success); }

/* ===== Browser Warning ===== */
#browser-warning {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 16px;
    background: #fef3c7;
    color: #92400e;
    font-size: 13px;
    text-align: center;
    z-index: 50;
    border-top: 1px solid #fbbf24;
}

/* ===== Animations ===== */
@keyframes pulse {
    0% { box-shadow: 0 0 0 0 var(--color-danger-glow); }
    70% { box-shadow: 0 0 0 20px rgba(239, 68, 68, 0); }
    100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(0.8); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

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

/* ===== Login Screen ===== */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px 30px;
    text-align: center;
    width: 100%;
    max-width: 340px;
    animation: slideDown 0.4s ease;
}

.login-card svg { margin-bottom: 16px; }
.login-card h2 { font-size: 22px; margin-bottom: 6px; color: var(--color-text); }
.login-card p { font-size: 14px; color: var(--color-text-muted); margin-bottom: 20px; }

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

.login-card input {
    padding: 12px 16px;
    font-size: 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    text-align: center;
    outline: none;
    transition: border-color var(--transition-fast);
}

.login-card input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.login-card button[type="submit"] {
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.login-card button[type="submit"]:hover {
    background: var(--color-primary-dark);
}

.login-error {
    color: var(--color-danger) !important;
    font-weight: 600;
    margin-top: 8px !important;
    margin-bottom: 0 !important;
}
