/* ============================
   CSS 变量 & 重置
   ============================ */
:root {
    --primary: #4F46E5;
    --primary-light: #818CF8;
    --primary-dark: #3730A3;
    --accent: #06B6D4;
    --success: #10B981;
    --danger: #EF4444;
    --warning: #F59E0B;
    --bg: #F8FAFC;
    --surface: #FFFFFF;
    --surface-2: #F1F5F9;
    --text: #0F172A;
    --text-2: #64748B;
    --text-3: #94A3B8;
    --border: #E2E8F0;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.04);
    --shadow-lg: 0 4px 24px rgba(0,0,0,0.10), 0 1px 4px rgba(0,0,0,0.06);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-full: 9999px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* ============================
   顶部导航
   ============================ */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.header-brand { display: flex; align-items: center; gap: 12px; }

.brand-icon {
    width: 40px; height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: white; font-size: 18px;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.brand-text h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.brand-text p { font-size: 12px; color: var(--text-2); margin-top: 1px; }

.icon-btn {
    width: 38px; height: 38px;
    border: none; background: var(--surface-2);
    border-radius: var(--radius-sm);
    cursor: pointer; font-size: 15px;
    color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.icon-btn:hover { background: var(--border); color: var(--text); }

/* ============================
   主内容区
   ============================ */
.main {
    max-width: 720px;
    margin: 0 auto;
    padding: 16px 16px 100px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ============================
   语言选择栏
   ============================ */
.lang-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
}

.lang-select-group { flex: 1; min-width: 0; }
.lang-select-group label {
    font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.5px;
    color: var(--text-3);
    display: block; margin-bottom: 8px;
}

.lang-pills { display: flex; flex-wrap: nowrap; overflow-x: auto; gap: 4px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.lang-pills::-webkit-scrollbar { display: none; }
.lang-pills .pill { white-space: nowrap; flex-shrink: 0; }

.pill {
    padding: 5px 11px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-full);
    background: transparent;
    font-size: 13px; font-weight: 500;
    color: var(--text-2);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.pill:hover { border-color: var(--primary-light); color: var(--primary); }
.pill.active {
    background: var(--primary); border-color: var(--primary);
    color: white; box-shadow: 0 2px 8px rgba(79,70,229,0.25);
}

.lang-select-hidden { display: none; }

.swap-btn {
    flex-shrink: 0;
    width: 36px; height: 36px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px;
    color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
}
.swap-btn:hover { border-color: var(--primary); color: var(--primary); transform: rotate(180deg); }

/* 双向对话开关 */
.bidirectional-toggle {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    background: var(--surface);
    border: 1.5px solid var(--border);
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
}
.bidirectional-toggle:hover { border-color: var(--primary-light); }
.bidirectional-toggle.active {
    background: #EEF2FF;
    border-color: var(--primary);
}
.bidirectional-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-2);
    transition: color 0.2s;
}
.bidirectional-toggle.active .bidirectional-label { color: var(--primary); }

.toggle-switch { position: relative; display: inline-block; width: 32px; height: 18px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: var(--border);
    border-radius: 9px;
    transition: 0.25s;
}
.toggle-slider::before {
    content: ''; position: absolute;
    height: 12px; width: 12px;
    left: 3px; bottom: 3px;
    background: white; border-radius: 50%;
    transition: 0.25s;
}
input:checked + .toggle-slider { background: var(--primary); }
input:checked + .toggle-slider::before { transform: translateX(14px); }

/* 双向模式下 lang-bar 紧凑布局 */
.lang-bar.bi-mode { gap: 6px; }
.lang-bar.bi-mode .lang-select-group { min-width: 0; }
.bidirectional-toggle.bi-active { background: #EEF2FF; border-color: var(--primary); }
.bidirectional-toggle.bi-active .bidirectional-label { color: var(--primary); }

/* ============================
   录音区
   ============================ */
.record-section { display: flex; justify-content: center; padding: 8px 0; }
.record-area { display: flex; flex-direction: column; align-items: center; gap: 12px; }

.record-ring {
    position: relative;
    width: 120px; height: 120px;
    display: flex; align-items: center; justify-content: center;
}

.ring-inner { position: relative; z-index: 2; }

.mic-btn {
    width: 80px; height: 80px;
    border-radius: 50%; border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; font-size: 28px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(79,70,229,0.4), 0 0 0 0 rgba(79,70,229,0.2);
    transition: all 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.mic-btn:hover { transform: scale(1.05); box-shadow: 0 6px 24px rgba(79,70,229,0.5); }
.mic-btn:active { transform: scale(0.97); }
.mic-btn.recording {
    background: linear-gradient(135deg, var(--danger), #B91C1C);
    box-shadow: 0 4px 20px rgba(239,68,68,0.5);
    animation: micPulse 1.2s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(239,68,68,0.5), 0 0 0 0 rgba(239,68,68,0.2); }
    50% { box-shadow: 0 4px 20px rgba(239,68,68,0.5), 0 0 0 16px rgba(239,68,68,0); }
}

.ring-wave {
    position: absolute; inset: 0;
    border-radius: 50%;
    border: 2px solid var(--primary-light);
    opacity: 0; pointer-events: none;
}
.ring-wave.active { animation: ringExpand 1.5s ease-out infinite; }

@keyframes ringExpand {
    0% { transform: scale(0.7); opacity: 0.6; }
    100% { transform: scale(1.4); opacity: 0; }
}

.record-hint { font-size: 13px; color: var(--text-2); text-align: center; }
.error-hint { color: var(--danger); font-size: 12px; }

/* ============================
   文字区域
   ============================ */
.text-section {
    display: grid;
    grid-template-columns: 1fr 36px 1fr;
    align-items: center;
    gap: 8px;
}

.text-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.text-card-header {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 10px 14px 8px;
    border-bottom: 1px solid var(--border);
}

.text-card-lang {
    font-size: 16px; font-weight: 700;
    text-transform: none; letter-spacing: normal;
    padding: 4px 12px; border-radius: var(--radius-full);
    background: var(--surface-2); color: var(--text-2);
}
.source-card .text-card-lang { background: #EEF2FF; color: var(--primary); }
.target-card .text-card-lang { background: #ECFDF5; color: var(--success); }

.text-card-count { font-size: 11px; color: var(--text-3); }

.detect-badge {
    font-size: 10px; font-weight: 600;
    padding: 2px 8px; border-radius: var(--radius-full);
    background: #FEF3C7; color: #92400E;
    cursor: pointer;
    transition: all 0.2s;
}
.detect-badge:hover { background: #FDE68A; }
.detect-badge.high-conf { background: #D1FAE5; color: #065F46; }
.detect-badge.low-conf { background: #FEE2E2; color: #991B1B; }

.text-card-body {
    padding: 14px;
    min-height: 90px; max-height: 160px;
    overflow-y: auto;
    font-size: 15px; line-height: 1.7;
    word-break: break-word;
}

.text-placeholder { color: var(--text-3); font-style: italic; font-size: 13px; }

.source-card { border-left: 3px solid var(--primary); }
.target-card { border-left: 3px solid var(--success); }

.translate-arrow-btn {
    width: 36px; height: 36px;
    border: none; background: var(--primary);
    color: white; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s; flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(79,70,229,0.3);
}
.translate-arrow-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.translate-arrow-btn:active { transform: scale(0.95); }

/* ============================
   操作按钮栏
   ============================ */
.action-bar { display: flex; gap: 8px; justify-content: center; }

.action-btn {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; gap: 4px;
    padding: 12px 8px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    cursor: pointer; font-size: 11px;
    color: var(--text-2); font-weight: 500;
    transition: all 0.15s; box-shadow: var(--shadow);
}
.action-btn i { font-size: 16px; }
.action-btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.action-btn:active { transform: translateY(0); }
.action-btn.disabled { opacity: 0.4; pointer-events: none; }

/* ============================
   手动输入区
   ============================ */
.input-section { display: flex; gap: 8px; align-items: flex-end; }

.input-section textarea {
    flex: 1; padding: 12px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius);
    font-size: 15px; font-family: inherit;
    resize: none; outline: none;
    background: var(--surface); color: var(--text);
    transition: border-color 0.2s;
    box-shadow: var(--shadow); line-height: 1.5;
}
.input-section textarea:focus { border-color: var(--primary); }
.input-section textarea::placeholder { color: var(--text-3); }

.send-btn {
    width: 46px; height: 46px;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    color: white; border-radius: var(--radius-sm);
    cursor: pointer; font-size: 16px;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 2px 12px rgba(79,70,229,0.35); flex-shrink: 0;
}
.send-btn:hover { transform: scale(1.05); box-shadow: 0 4px 16px rgba(79,70,229,0.45); }
.send-btn:active { transform: scale(0.95); }

/* ============================
   面板（历史/设置）
   ============================ */
.overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.3); z-index: 200;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s;
    backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px);
}
.overlay.active { opacity: 1; pointer-events: all; }

.panel {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-radius: 20px 20px 0 0;
    z-index: 300; max-height: 75dvh;
    display: flex; flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -4px 30px rgba(0,0,0,0.12);
}
.panel.active { transform: translateY(0); }

.panel-header {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.panel-header h3 { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.panel-header h3 i { color: var(--primary); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px 16px; }

.panel-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex; gap: 10px; flex-shrink: 0;
}

.text-btn {
    flex: 1; padding: 10px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius-sm);
    cursor: pointer; font-size: 13px; font-weight: 500;
    color: var(--text-2);
    display: flex; align-items: center; justify-content: center;
    gap: 6px; transition: all 0.15s;
}
.text-btn:hover { border-color: var(--danger); color: var(--danger); }

/* 历史列表 */
.history-list { display: flex; flex-direction: column; gap: 8px; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-3); }
.empty-state i { font-size: 32px; margin-bottom: 10px; display: block; }
.empty-state p { font-size: 14px; }

.history-item {
    padding: 12px; background: var(--surface-2);
    border-radius: var(--radius-sm);
    cursor: pointer; transition: all 0.15s;
    border: 1px solid transparent;
}
.history-item:hover { border-color: var(--primary-light); background: #EEF2FF; }
.history-item-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.history-lang-badge { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: var(--radius-full); background: #EEF2FF; color: var(--primary); }
.history-time { font-size: 11px; color: var(--text-3); }
.history-source { font-size: 13px; color: var(--text); margin-bottom: 3px; }
.history-target { font-size: 13px; color: var(--primary); font-weight: 500; }

/* 设置项 */
.setting-item {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.setting-item:last-child { border-bottom: none; }
.setting-label { flex: 1; }
.setting-label span { font-size: 14px; font-weight: 500; color: var(--text); display: block; }
.setting-label small { font-size: 12px; color: var(--text-2); margin-top: 2px; display: block; }
.setting-item-info { opacity: 0.9; }
.setting-badge {
    font-size: 11px; font-weight: 600;
    background: linear-gradient(135deg, #4F46E5, #06B6D4);
    color: #fff;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: 8px;
}

/* Toggle */
.toggle { position: relative; display: inline-block; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
    width: 44px; height: 24px;
    background: var(--border);
    border-radius: var(--radius-full);
    display: block; transition: background 0.2s;
    cursor: pointer; position: relative;
}
.toggle-track::after {
    content: ''; position: absolute;
    top: 3px; left: 3px;
    width: 18px; height: 18px;
    background: white; border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.toggle input:checked + .toggle-track { background: var(--primary); }
.toggle input:checked + .toggle-track::after { transform: translateX(20px); }

/* Range */
.range-input { width: 120px; accent-color: var(--primary); cursor: pointer; }

/* ============================
   Toast
   ============================ */
.toast {
    position: fixed; bottom: 90px; left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: rgba(15,23,42,0.9); color: white;
    padding: 10px 20px;
    border-radius: var(--radius-full);
    font-size: 13px; font-weight: 500; z-index: 500;
    opacity: 0; pointer-events: none;
    transition: all 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    white-space: nowrap;
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: rgba(16,185,129,0.9); }
.toast.error { background: rgba(239,68,68,0.9); }

/* ============================
   响应式
   ============================ */
@media (max-width: 640px) {
    .lang-bar { flex-direction: column; align-items: stretch; }
    .swap-btn { align-self: center; transform: rotate(90deg); }
    .swap-btn:hover { transform: rotate(270deg); }
    .bidirectional-toggle { align-self: center; }
    .lang-pills { gap: 3px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
    .lang-pills::-webkit-scrollbar { display: none; }
    .lang-pills .pill { white-space: nowrap; flex-shrink: 0; }
    .pill { padding: 4px 9px; font-size: 12px; }
    .text-section { grid-template-columns: 1fr 28px 1fr; gap: 6px; }
    .text-card-body { min-height: 70px; font-size: 14px; }
    .translate-arrow-btn { width: 28px; height: 28px; font-size: 12px; }
    .action-btn span { display: none; }
    .action-btn { padding: 10px; }
    .action-btn i { font-size: 18px; }
}

@media (max-width: 400px) {
    .main { padding: 12px 12px 100px; }
    .text-card-body { min-height: 60px; max-height: 120px; font-size: 13px; }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }
