/**
 * Translator App - Premium Design System
 * Inspired by Apple Human Interface & Google Material Design 3
 */

/* ==================== */
/* DESIGN TOKENS */
/* ==================== */

:root {
    /* Core Colors - Refined Palette */
    --color-bg: #000000;
    --color-surface: #1c1c1e;
    --color-surface-elevated: #2c2c2e;
    --color-surface-overlay: rgba(28, 28, 30, 0.8);
    
    /* Text Colors */
    --color-text-primary: #ffffff;
    --color-text-secondary: rgba(255, 255, 255, 0.7);
    --color-text-tertiary: rgba(255, 255, 255, 0.5);
    --color-text-quaternary: rgba(255, 255, 255, 0.3);
    
    /* Accent Colors */
    --color-accent: #0a84ff;
    --color-accent-light: #409cff;
    --color-accent-dark: #0066cc;
    --color-success: #30d158;
    --color-warning: #ffd60a;
    --color-error: #ff453a;
    
    /* Gradients */
    --gradient-accent: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --gradient-warm: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    --gradient-cool: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
    --gradient-sunset: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
    --gradient-ocean: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    
    /* Shadows - Apple-style depth */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 40px rgba(102, 126, 234, 0.3);
    
    /* Border Radius - Consistent rounding */
    --radius-xs: 6px;
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 9999px;
    
    /* Spacing Scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-7: 32px;
    --space-8: 40px;
    --space-9: 48px;
    --space-10: 64px;
    
    /* Typography */
    --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-japanese: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
    
    /* Font Sizes */
    --text-xs: 11px;
    --text-sm: 13px;
    --text-base: 15px;
    --text-lg: 17px;
    --text-xl: 20px;
    --text-2xl: 24px;
    --text-3xl: 32px;
    
    /* Font Weights */
    --weight-regular: 400;
    --weight-medium: 500;
    --weight-semibold: 600;
    --weight-bold: 700;
    
    /* Transitions */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
    --duration-fast: 150ms;
    --duration-normal: 250ms;
    --duration-slow: 400ms;
    
    /* Safe Areas */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
}

/* ==================== */
/* RESET & BASE */
/* ==================== */

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

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: 1.5;
    color: var(--color-text-primary);
    background: var(--color-bg);
    letter-spacing: -0.01em;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* ==================== */
/* APP LAYOUT */
/* ==================== */

.translator-app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

.hidden {
    display: none !important;
}

/* ==================== */
/* CAMERA VIEW */
/* ==================== */

.camera-container {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000;
    overflow: hidden;
}

.camera-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-video.mirror {
    transform: scaleX(-1);
}

.camera-canvas {
    display: none;
}

/* ==================== */
/* VIEWFINDER */
/* ==================== */

.viewfinder-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 10;
}

.viewfinder-frame {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 88%;
    max-width: 380px;
    aspect-ratio: 16/10;
    border-radius: var(--radius-lg);
    box-shadow: 
        0 0 0 2000px rgba(0, 0, 0, 0.5),
        inset 0 0 0 2px rgba(255, 255, 255, 0.2);
    transition: all var(--duration-normal) var(--ease-out);
}

.viewfinder-frame.scanning {
    box-shadow: 
        0 0 0 2000px rgba(0, 0, 0, 0.5),
        inset 0 0 0 2px var(--color-accent);
}

.viewfinder-corners {
    position: absolute;
    inset: -1px;
}

.corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border-color: var(--color-text-primary);
    border-style: solid;
    border-width: 0;
    transition: border-color var(--duration-fast);
}

.viewfinder-frame.scanning .corner {
    border-color: var(--color-accent);
}

.corner.tl { top: 0; left: 0; border-top-width: 3px; border-left-width: 3px; border-radius: var(--radius-sm) 0 0 0; }
.corner.tr { top: 0; right: 0; border-top-width: 3px; border-right-width: 3px; border-radius: 0 var(--radius-sm) 0 0; }
.corner.bl { bottom: 0; left: 0; border-bottom-width: 3px; border-left-width: 3px; border-radius: 0 0 0 var(--radius-sm); }
.corner.br { bottom: 0; right: 0; border-bottom-width: 3px; border-right-width: 3px; border-radius: 0 0 var(--radius-sm) 0; }

.viewfinder-hint {
    position: absolute;
    bottom: -36px;
    left: 50%;
    transform: translateX(-50%);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    white-space: nowrap;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.8);
}

/* Scan Line Animation */
.scan-line {
    position: absolute;
    top: 0;
    left: 10%;
    width: 80%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--color-accent), transparent);
    opacity: 0;
    border-radius: var(--radius-full);
}

.viewfinder-frame.scanning .scan-line {
    opacity: 1;
    animation: scanMove 2s ease-in-out infinite;
}

@keyframes scanMove {
    0%, 100% { top: 5%; }
    50% { top: 95%; }
}

/* ==================== */
/* HEADER BAR */
/* ==================== */

.header-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: calc(var(--safe-top) + var(--space-4)) var(--space-4) var(--space-4);
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.7) 0%, transparent 100%);
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 20;
}

.back-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--color-surface-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--color-text-primary);
    font-size: var(--text-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-out);
}

.back-btn:hover {
    background: var(--color-surface-elevated);
    transform: scale(1.05);
}

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

.header-title {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    letter-spacing: -0.02em;
}

.header-title .icon {
    font-size: var(--text-xl);
}

.header-actions {
    display: flex;
    gap: var(--space-2);
}

.header-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    background: var(--color-surface-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--color-text-primary);
    font-size: var(--text-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-out);
}

.header-btn:hover {
    background: var(--color-surface-elevated);
}

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

.header-btn.active {
    background: var(--color-accent);
}

/* ==================== */
/* STATUS BAR */
/* ==================== */

.status-bar {
    position: absolute;
    top: calc(var(--safe-top) + 70px);
    left: var(--space-4);
    right: var(--space-4);
    z-index: 15;
    display: flex;
    justify-content: center;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--color-surface-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-primary);
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
    transition: all var(--duration-normal) var(--ease-out);
}

.status-pill.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.status-pill.error {
    background: rgba(255, 69, 58, 0.9);
}

.status-pill.success {
    background: rgba(48, 209, 88, 0.9);
}

/* ==================== */
/* CONTROL BAR */
/* ==================== */

.control-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: var(--space-5) var(--space-4) calc(var(--safe-bottom) + 110px);
    background: linear-gradient(0deg, rgba(0, 0, 0, 0.8) 0%, transparent 100%);
    z-index: 20;
}

/* Mode Toggle - Segmented Control Style */
.mode-toggle {
    display: flex;
    justify-content: center;
    margin-bottom: var(--space-5);
}

.mode-toggle {
    display: inline-flex;
    background: var(--color-surface);
    border-radius: var(--radius-sm);
    padding: 3px;
}

.mode-btn {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
    border-radius: var(--radius-xs);
    transition: all var(--duration-fast) var(--ease-out);
}

.mode-btn.active {
    background: var(--color-surface-elevated);
    color: var(--color-text-primary);
}

.mode-btn:not(.active):hover {
    color: var(--color-text-primary);
}

/* Control Row */
.control-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-7);
}

.control-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    background: var(--color-surface-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--color-text-primary);
    font-size: var(--text-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast) var(--ease-out);
}

.control-btn:hover {
    background: var(--color-surface-elevated);
    transform: scale(1.08);
}

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

.control-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Capture Button - Hero Element */
.capture-btn {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: var(--radius-full);
    background: transparent;
    border: 4px solid var(--color-text-primary);
    transition: all var(--duration-fast) var(--ease-out);
}

.capture-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--color-text-primary);
    transition: all var(--duration-fast) var(--ease-out);
}

.capture-btn:hover::before {
    transform: translate(-50%, -50%) scale(1.05);
}

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

.capture-btn:active::before {
    transform: translate(-50%, -50%) scale(0.9);
}

.capture-btn.processing::before {
    background: var(--color-accent);
    animation: captureGlow 1.2s ease-in-out infinite;
}

@keyframes captureGlow {
    0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(10, 132, 255, 0.4); }
    50% { opacity: 0.7; box-shadow: 0 0 20px 4px rgba(10, 132, 255, 0.4); }
}

/* ==================== */
/* TRANSLATION OVERLAY */
/* ==================== */

.translation-overlay {
    position: absolute;
    bottom: 220px;
    left: var(--space-4);
    right: var(--space-4);
    max-height: 40%;
    z-index: 15;
    pointer-events: none;
    opacity: 0;
    transform: translateY(16px);
    transition: all var(--duration-normal) var(--ease-out);
}

.translation-overlay.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Translation Card - Enhanced for Clarity */
.translation-card {
    background: var(--color-surface-overlay);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    box-shadow: var(--shadow-xl);
    max-height: 80vh;
    overflow-y: auto;
}

.translation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: rgba(52, 199, 89, 0.1);
    border-bottom: 1px solid rgba(52, 199, 89, 0.2);
}

.translation-badge {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-success);
}

.badge-icon {
    width: 20px;
    height: 20px;
    background: var(--color-success);
    color: white;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
}

.dismiss-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

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

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

/* Translation Sections */
.translation-section {
    padding: var(--space-4);
}

.translation-section.original {
    background: rgba(0, 0, 0, 0.15);
}

.translation-section.result {
    background: rgba(52, 199, 89, 0.05);
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

.lang-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--color-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.section-actions {
    display: flex;
    gap: var(--space-1);
}

.mini-btn {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

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

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

/* Text Content */
.text-content {
    font-size: var(--text-lg);
    line-height: 1.6;
}

.text-content.original-text {
    font-family: var(--font-japanese);
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
}

.text-content.translated-text {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--color-success);
}

/* Divider */
.translation-divider {
    display: flex;
    align-items: center;
    padding: 0 var(--space-4);
    background: var(--color-surface);
}

.divider-line {
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.divider-arrow {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-lg);
    color: var(--color-accent);
    font-weight: var(--weight-bold);
}

/* Confidence Section */
.confidence-section {
    padding: var(--space-3) var(--space-4);
    background: rgba(0, 0, 0, 0.2);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.confidence-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-2);
}

.confidence-label {
    font-size: var(--text-xs);
    color: var(--color-text-quaternary);
}

.confidence-value {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--color-success);
}

.confidence-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.confidence-fill {
    height: 100%;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    transition: width var(--duration-normal) var(--ease-out);
}

/* Quick Phrases */
.quick-phrases {
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(0, 0, 0, 0.15);
}

.quick-phrases-title {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-2);
}

.phrase-chips {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.phrase-chip {
    padding: var(--space-1) var(--space-3);
    background: rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--color-text-secondary);
}

.phrase-chip .meaning {
    color: var(--color-text-quaternary);
    margin-left: var(--space-1);
}

/* Legacy action btn for compatibility */
.action-btn {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-secondary);
    font-size: var(--text-base);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

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

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

/* ==================== */
/* MAIN MODE TOGGLE */
/* ==================== */

.main-mode-toggle {
    position: fixed;
    bottom: calc(var(--safe-bottom) + var(--space-6));
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    padding: var(--space-1);
    gap: var(--space-1);
    z-index: 50;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.main-mode-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: var(--space-3) var(--space-6);
    border-radius: var(--radius-lg);
    color: var(--color-text-tertiary);
    transition: all var(--duration-normal) var(--ease-out);
}

.main-mode-btn .mode-icon {
    font-size: var(--text-2xl);
    transition: transform var(--duration-normal) var(--ease-spring);
}

.main-mode-btn .mode-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.main-mode-btn.active {
    background: var(--gradient-accent);
    color: var(--color-text-primary);
    box-shadow: var(--shadow-glow);
}

.main-mode-btn.active .mode-icon {
    transform: scale(1.1);
}

.main-mode-btn:not(.active):hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--color-text-secondary);
}

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

/* ==================== */
/* VOICE CONTAINER - Redesigned */
/* ==================== */

.voice-container {
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, #0a0a12 0%, #1a1a2e 100%);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: calc(var(--safe-top) + 70px) var(--space-4) calc(var(--safe-bottom) + 100px);
    overflow: hidden;
}

/* Language Toggle at Top */
.voice-lang-toggle {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-6);
    z-index: 1;
}

.lang-btn {
    padding: var(--space-2) var(--space-4);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--color-text-tertiary);
    transition: all var(--duration-fast);
}

.lang-btn.active {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: white;
}

.lang-btn:not(.active):hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Main Status Display */
.voice-main-status {
    text-align: center;
    margin-bottom: var(--space-6);
    z-index: 1;
}

.voice-main-status .status-icon {
    font-size: 48px;
    margin-bottom: var(--space-2);
}

.voice-main-status .status-message {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
}

/* Waveform Container */
.voice-waveform-container {
    width: 100%;
    max-width: 400px;
    height: 120px;
    margin-bottom: var(--space-5);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-xl);
    border: 1px solid rgba(255, 255, 255, 0.06);
    overflow: hidden;
    z-index: 1;
}

.waveform-bars {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    height: 100%;
    padding: 0 var(--space-4);
}

.waveform-bar {
    width: 6px;
    height: 8px;
    min-height: 8px;
    background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
    border-radius: 3px;
    transition: height 60ms ease-out;
}

.voice-container.listening .waveform-bar {
    background: linear-gradient(180deg, #ff6b6b 0%, #ff8e53 100%);
}

/* Idle animation for waveform */
.voice-container:not(.listening) .waveform-bar {
    animation: idleWave 2s ease-in-out infinite;
}

.waveform-bar:nth-child(1) { animation-delay: 0s; }
.waveform-bar:nth-child(2) { animation-delay: 0.1s; }
.waveform-bar:nth-child(3) { animation-delay: 0.2s; }
.waveform-bar:nth-child(4) { animation-delay: 0.3s; }
.waveform-bar:nth-child(5) { animation-delay: 0.4s; }
.waveform-bar:nth-child(6) { animation-delay: 0.5s; }
.waveform-bar:nth-child(7) { animation-delay: 0.6s; }
.waveform-bar:nth-child(8) { animation-delay: 0.7s; }
.waveform-bar:nth-child(9) { animation-delay: 0.8s; }
.waveform-bar:nth-child(10) { animation-delay: 0.9s; }
.waveform-bar:nth-child(11) { animation-delay: 0.8s; }
.waveform-bar:nth-child(12) { animation-delay: 0.7s; }
.waveform-bar:nth-child(13) { animation-delay: 0.6s; }
.waveform-bar:nth-child(14) { animation-delay: 0.5s; }
.waveform-bar:nth-child(15) { animation-delay: 0.4s; }
.waveform-bar:nth-child(16) { animation-delay: 0.3s; }
.waveform-bar:nth-child(17) { animation-delay: 0.2s; }
.waveform-bar:nth-child(18) { animation-delay: 0.1s; }
.waveform-bar:nth-child(19) { animation-delay: 0s; }
.waveform-bar:nth-child(20) { animation-delay: 0.1s; }

@keyframes idleWave {
    0%, 100% { height: 8px; opacity: 0.4; }
    50% { height: 20px; opacity: 0.6; }
}

/* Live Transcription Text */
.voice-live-text {
    width: 100%;
    max-width: 400px;
    min-height: 60px;
    padding: var(--space-3) var(--space-4);
    background: rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-5);
    z-index: 1;
    display: none;
}

.voice-container.listening .voice-live-text {
    display: block;
}

.voice-live-text .live-label {
    display: block;
    font-size: var(--text-xs);
    color: var(--color-text-quaternary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-1);
}

.voice-live-text .live-content {
    font-size: var(--text-lg);
    color: var(--color-text-primary);
    font-style: italic;
}

/* Conversation Display */
.voice-conversation {
    flex: 1;
    width: 100%;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    overflow-y: auto;
    z-index: 1;
    -webkit-overflow-scrolling: touch;
}

.convo-bubble {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    position: relative;
    animation: bubbleSlide 0.3s var(--ease-out);
}

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

.convo-bubble.you-said {
    border-left: 3px solid var(--color-accent);
}

.convo-bubble.translation {
    border-left: 3px solid var(--color-success);
    background: rgba(48, 209, 88, 0.1);
}

.convo-bubble .bubble-label {
    font-size: var(--text-xs);
    color: var(--color-text-quaternary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-2);
}

.convo-bubble .bubble-content {
    font-size: var(--text-lg);
    color: var(--color-text-primary);
    line-height: 1.5;
}

.convo-bubble.translation .bubble-content {
    color: var(--color-success);
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
}

.convo-bubble .replay-btn {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.1);
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

.convo-bubble .replay-btn:hover {
    background: var(--color-accent);
    transform: scale(1.1);
}

/* Voice Action Area - Single Button */
.voice-action-area {
    width: 100%;
    max-width: 400px;
    padding-top: var(--space-5);
    z-index: 1;
}

.voice-action-btn {
    width: 100%;
    padding: var(--space-5) var(--space-6);
    background: var(--gradient-accent);
    border-radius: var(--radius-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: white;
    transition: all var(--duration-normal) var(--ease-out);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(102, 126, 234, 0.3);
}

.voice-action-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl), 0 0 40px rgba(102, 126, 234, 0.4);
}

.voice-action-btn:active {
    transform: scale(0.98);
}

.voice-action-btn .btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Button States */
.voice-action-btn[data-state="listening"] {
    background: linear-gradient(135deg, #ff6b6b 0%, #ff8e53 100%);
    box-shadow: var(--shadow-lg), 0 0 40px rgba(255, 107, 107, 0.4);
    animation: pulseBtn 1.5s ease-in-out infinite;
}

@keyframes pulseBtn {
    0%, 100% { box-shadow: var(--shadow-lg), 0 0 30px rgba(255, 107, 107, 0.4); }
    50% { box-shadow: var(--shadow-lg), 0 0 50px rgba(255, 107, 107, 0.6); }
}

.voice-action-btn[data-state="processing"] {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    pointer-events: none;
}

.voice-action-btn[data-state="speaking"] {
    background: linear-gradient(135deg, #30d158 0%, #34c759 100%);
    pointer-events: none;
}

/* Voice Permission Prompt */
.voice-permission-prompt {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.permission-content {
    text-align: center;
    padding: var(--space-8);
    max-width: 340px;
}

.permission-content .permission-icon {
    font-size: 72px;
    margin-bottom: var(--space-6);
}

.permission-content h3 {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-3);
}

.permission-content p {
    color: var(--color-text-secondary);
    margin-bottom: var(--space-6);
}

.permission-grant-btn {
    padding: var(--space-4) var(--space-7);
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: white;
    box-shadow: var(--shadow-lg);
}

.permission-grant-btn:hover {
    transform: scale(1.03);
}

.permission-hint {
    font-size: var(--text-xs) !important;
    color: var(--color-text-quaternary) !important;
    margin-top: var(--space-4) !important;
}

/* Spin animation for processing icon */
.voice-action-btn .spin {
    animation: spinAnim 1s linear infinite;
}

@keyframes spinAnim {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Voice Permission Prompt */
.voice-permission-prompt {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.permission-content {
    text-align: center;
    padding: var(--space-8);
    max-width: 340px;
}

.permission-content .permission-icon {
    font-size: 72px;
    margin-bottom: var(--space-6);
    animation: permIconFloat 3s ease-in-out infinite;
}

@keyframes permIconFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.permission-content h3 {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-3);
    color: var(--color-text-primary);
    letter-spacing: -0.02em;
}

.permission-content p {
    font-size: var(--text-base);
    color: var(--color-text-secondary);
    line-height: 1.6;
    margin-bottom: var(--space-6);
}

.permission-grant-btn {
    padding: var(--space-4) var(--space-7);
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    transition: all var(--duration-normal) var(--ease-out);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.permission-grant-btn:hover {
    transform: scale(1.03);
}

.permission-grant-btn:active {
    transform: scale(0.97);
}

.permission-hint {
    font-size: var(--text-xs) !important;
    color: var(--color-text-quaternary) !important;
    margin-top: var(--space-5) !important;
    margin-bottom: 0 !important;
}

/* ==================== */
/* LOADING SCREEN */
/* ==================== */

.loading-screen {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity var(--duration-slow) var(--ease-out);
}

.loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-icon {
    font-size: 64px;
    margin-bottom: var(--space-6);
    animation: loadingBounce 2s ease-in-out infinite;
}

@keyframes loadingBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-12px) scale(1.05); }
}

.loading-text {
    font-size: var(--text-xl);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    margin-bottom: var(--space-2);
    letter-spacing: -0.01em;
}

.loading-subtext {
    font-size: var(--text-sm);
    color: var(--color-text-tertiary);
    margin-bottom: var(--space-6);
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: var(--color-surface);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.loading-progress-fill {
    height: 100%;
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    width: 0%;
    transition: width var(--duration-normal) var(--ease-out);
}

/* ==================== */
/* PERMISSION SCREEN */
/* ==================== */

.permission-screen {
    position: fixed;
    inset: 0;
    background: var(--color-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    z-index: 1000;
    text-align: center;
}

.permission-icon {
    font-size: 80px;
    margin-bottom: var(--space-6);
}

.permission-title {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    margin-bottom: var(--space-3);
    letter-spacing: -0.02em;
}

.permission-desc {
    font-size: var(--text-base);
    color: var(--color-text-secondary);
    margin-bottom: var(--space-8);
    max-width: 320px;
    line-height: 1.6;
}

.permission-btn {
    padding: var(--space-4) var(--space-8);
    background: var(--gradient-accent);
    border-radius: var(--radius-full);
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--color-text-primary);
    transition: all var(--duration-normal) var(--ease-out);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.permission-btn:hover {
    transform: scale(1.03);
}

.permission-btn:active {
    transform: scale(0.97);
}

.permission-back {
    margin-top: var(--space-6);
    color: var(--color-text-tertiary);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    transition: color var(--duration-fast);
}

.permission-back:hover {
    color: var(--color-text-secondary);
}

/* ==================== */
/* HISTORY PANEL */
/* ==================== */

.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-normal);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.history-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.history-panel {
    position: fixed;
    top: 0;
    right: -100%;
    width: 100%;
    max-width: 400px;
    height: 100%;
    background: var(--color-bg);
    z-index: 100;
    transition: right var(--duration-slow) var(--ease-out);
    display: flex;
    flex-direction: column;
}

.history-panel.open {
    right: 0;
}

.history-header {
    padding: calc(var(--safe-top) + var(--space-4)) var(--space-4) var(--space-4);
    background: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.history-header h2 {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    display: flex;
    align-items: center;
    gap: var(--space-2);
    letter-spacing: -0.01em;
}

.close-history {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--color-surface-elevated);
    color: var(--color-text-secondary);
    font-size: var(--text-xl);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--duration-fast);
}

.close-history:hover {
    background: var(--color-error);
    color: var(--color-text-primary);
}

.history-list {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
    -webkit-overflow-scrolling: touch;
}

.history-item {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    cursor: pointer;
    transition: all var(--duration-fast);
    border: 1px solid rgba(255, 255, 255, 0.04);
}

.history-item:hover {
    background: var(--color-surface-elevated);
    transform: translateX(-4px);
}

.history-item:active {
    transform: scale(0.98);
}

.history-japanese {
    font-family: var(--font-japanese);
    font-size: var(--text-lg);
    font-weight: var(--weight-medium);
    margin-bottom: var(--space-1);
}

.history-english {
    font-size: var(--text-base);
    color: var(--color-success);
}

.history-meta {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-3);
    font-size: var(--text-xs);
    color: var(--color-text-quaternary);
}

.history-empty {
    text-align: center;
    padding: var(--space-10) var(--space-5);
    color: var(--color-text-tertiary);
}

.history-empty-icon {
    font-size: 56px;
    margin-bottom: var(--space-4);
    opacity: 0.4;
}

/* ==================== */
/* TOAST */
/* ==================== */

.toast {
    position: fixed;
    bottom: 200px;
    left: 50%;
    transform: translateX(-50%) translateY(24px);
    background: var(--color-surface-elevated);
    color: var(--color-text-primary);
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-full);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all var(--duration-normal) var(--ease-spring);
    z-index: 200;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success {
    background: var(--color-success);
    color: #000;
    border-color: transparent;
}

/* ==================== */
/* UTILITY */
/* ==================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ==================== */
/* RESPONSIVE */
/* ==================== */

@media (min-width: 768px) {
    .viewfinder-frame {
        max-width: 460px;
    }
    
    .translation-overlay {
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(16px);
        width: 90%;
        max-width: 480px;
    }
    
    .translation-overlay.visible {
        transform: translateX(-50%) translateY(0);
    }
    
    .voice-orb {
        width: 200px;
        height: 200px;
    }
    
    .orb-core {
        width: 150px;
        height: 150px;
    }
    
    .orb-icon {
        font-size: 56px;
    }
    
    .voice-mic-btn {
        width: 96px;
        height: 96px;
    }
    
    .mic-icon {
        font-size: 40px;
    }
}

@media (max-height: 700px) {
    .voice-container {
        padding-top: calc(var(--safe-top) + 80px);
    }
    
    .voice-orb {
        width: 120px;
        height: 120px;
    }
    
    .orb-core {
        width: 90px;
        height: 90px;
    }
    
    .orb-icon {
        font-size: 36px;
    }
    
    .voice-waveform {
        margin-top: var(--space-3);
        height: 32px;
    }
    
    .voice-mic-btn {
        width: 72px;
        height: 72px;
    }
    
    .mic-icon {
        font-size: 28px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
