@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=Noto+Sans+TC:wght@400;500;600;700&display=swap');

:root {
    --bg: #000;
    --surface: rgba(18, 18, 24, 0.88);
    --surface-light: rgba(40, 40, 55, 0.6);
    --border: rgba(255, 255, 255, 0.08);
    --text-1: #F0F0F5;
    --text-2: rgba(240, 240, 245, 0.55);
    --text-3: rgba(240, 240, 245, 0.28);
    --accent: #6366F1;
    --accent-glow: rgba(99, 102, 241, 0.35);
    --cyan: #06B6D4;
    --success: #22C55E;
    --warning: #F59E0B;
    --danger: #EF4444;
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 28px;
    --radius-xl: 36px;
    --font: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
}

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

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

#app {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
}

/* ===== 相機背景 ===== */
#camera-feed {
    position: absolute; inset: 0;
    width: 100%; height: 100%;
    object-fit: cover;
    z-index: 1;
}

/* ===== 掃描框覆蓋 ===== */
.scan-overlay {
    position: absolute; inset: 0;
    z-index: 5;
    display: flex; flex-direction: column; align-items: center;
    pointer-events: none;
}

.scan-frame {
    position: absolute;
    top: 8%;
    left: 5%;
    right: 5%;
    height: 36%;
    border: 2px solid rgba(99, 102, 241, 0.45);
    border-radius: var(--radius-md);
    transition: border-color 0.4s, box-shadow 0.4s;
}
.scan-frame.active {
    border-color: var(--accent);
    box-shadow: 0 0 24px var(--accent-glow), inset 0 0 24px rgba(99,102,241,0.05);
}
.scan-frame.success {
    border-color: var(--success);
    box-shadow: 0 0 24px rgba(34,197,94,0.3);
}

/* 四角裝飾 */
.corner { position: absolute; width: 26px; height: 26px; }
.corner::before, .corner::after {
    content: ''; position: absolute;
    background: var(--accent); border-radius: 2px;
    transition: background 0.4s;
}
.scan-frame.success .corner::before,
.scan-frame.success .corner::after { background: var(--success); }

.corner::before { width: 26px; height: 3.5px; }
.corner::after  { width: 3.5px; height: 26px; }
.tl { top: -2px; left: -2px; }
.tr { top: -2px; right: -2px; }
.tr::before { right: 0; }
.tr::after { right: 0; }
.bl { bottom: -2px; left: -2px; }
.bl::before { bottom: 0; }
.bl::after { bottom: 0; }
.br { bottom: -2px; right: -2px; }
.br::before { bottom: 0; right: 0; }
.br::after { bottom: 0; right: 0; }

/* 脈動效果 */
.scan-pulse {
    position: absolute; inset: -6px;
    border: 2px solid var(--accent);
    border-radius: calc(var(--radius-md) + 4px);
    opacity: 0;
    animation: pulse 2.5s ease-out infinite;
    pointer-events: none;
}
@keyframes pulse {
    0%   { transform: scale(1); opacity: 0.5; }
    100% { transform: scale(1.03); opacity: 0; }
}

/* 提示文字 */
.scan-hint {
    position: absolute;
    top: 47%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 10px 24px;
    border-radius: 100px;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255,255,255,0.8);
    letter-spacing: 0.3px;
    transition: all 0.3s;
}

/* ===== iPhone 風格縮放選擇器 ===== */
.zoom-picker {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 11;
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    padding: 4px;
    border-radius: 100px;
    border: 1px solid rgba(255,255,255,0.1);
}

.zoom-preset {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: rgba(255,255,255,0.6);
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.zoom-preset.active {
    background: rgba(245, 158, 11, 0.9);
    color: #000;
    transform: scale(1.1);
    box-shadow: 0 2px 12px rgba(245, 158, 11, 0.4);
}

.zoom-preset:active {
    transform: scale(0.9);
}


/* ===== 底部面板 ===== */
.bottom-panel {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    z-index: 10;
    background: var(--surface);
    backdrop-filter: blur(40px) saturate(1.5);
    -webkit-backdrop-filter: blur(40px) saturate(1.5);
    border-top: 1px solid var(--border);
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    padding: 12px 20px 30px;
    display: flex; flex-direction: column;
    gap: 14px;
    max-height: 54vh;
    box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
}

.panel-handle {
    width: 40px; height: 4px;
    background: rgba(255,255,255,0.18);
    border-radius: 2px;
    margin: 0 auto 2px;
}

.panel-header {
    display: flex; align-items: center;
    justify-content: space-between;
}

/* 狀態 */
.status-indicator {
    display: flex; align-items: center;
    gap: 8px;
    font-size: 13px; font-weight: 600;
    color: var(--text-2);
}
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-3);
    transition: all 0.3s;
}
.status-indicator.ready .status-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status-indicator.scanning .status-dot { background: var(--accent); box-shadow: 0 0 8px var(--accent); animation: blink 0.8s infinite; }
.status-indicator.error .status-dot { background: var(--danger); box-shadow: 0 0 6px var(--danger); }

@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.25} }

/* 按鈕組 */
.panel-actions { display: flex; gap: 10px; }

.action-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-light);
    color: var(--text-2);
    font-size: 13px; font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
}
.action-btn:active { transform: scale(0.93); }
.action-btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.action-btn.capture {
    background: var(--accent); border-color: var(--accent); color: #fff;
}
.action-btn.auto.active {
    background: rgba(34,197,94,0.15);
    border-color: rgba(34,197,94,0.3);
    color: var(--success);
}

/* 結果區 */
.result-area {
    display: flex; flex-direction: column;
    overflow-y: auto; flex: 1;
}

.result-block { display: flex; flex-direction: column; gap: 8px; }

.result-label {
    display: flex; align-items: center; gap: 8px;
    font-size: 11px; font-weight: 700;
    color: var(--text-3);
    text-transform: uppercase; letter-spacing: 1.2px;
}

.lang-tag {
    padding: 3px 8px;
    background: rgba(99,102,241,0.15);
    color: var(--accent);
    border-radius: 6px;
    font-size: 11px; font-weight: 700;
}
.lang-tag.tw { background: rgba(6,182,212,0.15); color: var(--cyan); }

.result-text {
    font-size: 16px; line-height: 1.6;
    color: var(--text-1);
    word-break: break-word;
    min-height: 24px;
}
.result-text.placeholder {
    color: var(--text-3); font-style: italic;
}

.translated-content {
    font-size: 22px; font-weight: 700; line-height: 1.5;
    background: linear-gradient(135deg, #c7d2fe, #a5f3fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.translated-content.placeholder {
    background: none;
    -webkit-text-fill-color: var(--text-3);
    font-weight: 400;
}

.result-divider {
    display: flex; align-items: center; justify-content: center;
    padding: 6px 0; color: var(--text-3);
}
.result-divider svg { width: 16px; height: 16px; }

/* 補充說明 */
.note-block {
    margin-top: 10px;
    padding: 10px 14px;
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: 10px;
}
.note-block p {
    font-size: 13px;
    line-height: 1.6;
    color: var(--warning);
    font-weight: 500;
}

/* ===== 錯誤覆蓋 ===== */
.error-overlay {
    position: fixed; inset: 0;
    z-index: 100;
    background: var(--bg);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.error-card {
    text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 20px;
    max-width: 360px;
}
.error-icon { font-size: 56px; }
.error-card h2 { font-size: 22px; font-weight: 700; }
.error-card p { color: var(--text-2); line-height: 1.6; font-size: 15px; }

.primary-btn {
    display: flex; align-items: center; justify-content: center;
    gap: 8px; width: 100%; padding: 16px;
    background: linear-gradient(135deg, #6366F1, #4F46E5);
    border: none; border-radius: var(--radius-sm);
    color: #fff; font-size: 16px; font-weight: 700;
    font-family: var(--font); cursor: pointer;
    transition: all 0.2s;
}
.primary-btn:active { transform: scale(0.97); }

/* ===== RWD ===== */
@media (min-width: 768px) {
    .scan-frame { left: 15%; right: 15%; height: 38%; }
    .bottom-panel {
        max-width: 540px;
        left: 50%; transform: translateX(-50%);
    }
}
