/* frontend/css/main.css */

/* CSS Variables and Theme */
:root {
    /* Color Palette */
    --primary-color: #1E88E5;
    --primary-dark: #1565C0;
    --primary-light: #42A5F5;
    --secondary-color: #FFC107;
    --secondary-dark: #F9A825;
    --success-color: #4CAF50;
    --error-color: #F44336;
    --warning-color: #FF9800;
    --info-color: #2196F3;
    
    /* Neutral Colors */
    --background: #F5F5F5;
    --surface: #FFFFFF;
    --text-primary: #212121;
    --text-secondary: #757575;
    --text-disabled: #BDBDBD;
    --border-color: #E0E0E0;
    
    /* Shadows */
    --shadow-sm: 0 2px 4px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 8px rgba(0,0,0,0.15);
    --shadow-lg: 0 8px 16px rgba(0,0,0,0.2);
    --shadow-xl: 0 12px 24px rgba(0,0,0,0.25);
    
    /* Layout */
    --border-radius: 12px;
    --border-radius-sm: 8px;
    --border-radius-lg: 16px;
    --border-radius-pill: 50px;
    
    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 14px;
    --font-size-base: 16px;
    --font-size-lg: 18px;
    --font-size-xl: 20px;
    --font-size-2xl: 24px;
    --font-size-3xl: 30px;
    
    /* Animation */
    --transition-fast: 150ms;
    --transition-base: 300ms;
    --transition-slow: 500ms;
    
    /* Z-index layers */
    --z-base: 1;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-tooltip: 700;
    
    /* Safe areas for iOS */
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-right: env(safe-area-inset-right);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
}

/* Dark Theme */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #121212;
        --surface: #1E1E1E;
        --text-primary: #FFFFFF;
        --text-secondary: #B0B0B0;
        --text-disabled: #666666;
        --border-color: #333333;
        
        --shadow-sm: 0 2px 4px rgba(0,0,0,0.3);
        --shadow-md: 0 4px 8px rgba(0,0,0,0.4);
        --shadow-lg: 0 8px 16px rgba(0,0,0,0.5);
        --shadow-xl: 0 12px 24px rgba(0,0,0,0.6);
    }
}

/* Reset and Base Styles */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    min-height: 100vh;
    position: relative;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 0.5em;
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-base); }
h6 { font-size: var(--font-size-sm); }

p {
    margin-bottom: 1em;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--primary-dark);
}

/* Layout Components */
.container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0 var(--spacing-md);
}

.flex {
    display: flex;
}

.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.flex-column {
    display: flex;
    flex-direction: column;
}

.grid {
    display: grid;
}

/* Cards */
.card {
    background: var(--surface);
    border-radius: var(--border-radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.card-interactive:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-xs);
}

.card-header {
    margin-bottom: var(--spacing-md);
    padding-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--border-color);
}

.card-body {
    flex: 1;
}

.card-footer {
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-color);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-sm) var(--spacing-lg);
    border: none;
    border-radius: var(--border-radius-pill);
    font-size: var(--font-size-base);
    font-weight: 500;
    font-family: inherit;
    line-height: 1.5;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    transition: background-color var(--transition-base), border-color var(--transition-base), transform var(--transition-base), box-shadow var(--transition-base);
    position: relative;
    overflow: hidden;
    /* --- FINAL iOS RENDERING FIX START --- */
    /* These properties are a common and effective fix for WebKit (iOS Safari) rendering glitches. 
       They force the element onto its own hardware-accelerated layer in a more stable way, 
       which resolves repaint bugs during complex state changes and transitions. */
    -webkit-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* --- FINAL iOS RENDERING FIX END --- */
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transition: none; /* Add this line */
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark);
}

.btn-primary:active:not(:disabled) {
    transform: scale(0.95);
}

/* This rule provides a specific, stable appearance for a disabled primary button, 
   overriding browser defaults that can cause focus state conflicts. */
.btn-primary:disabled {
    background-color: var(--primary-light); /* Use a lighter shade of the primary color */
    color: rgba(255, 255, 255, 0.75);     /* Make the white text slightly transparent */
    opacity: 1; /* Override the generic opacity to have full control */
}

/*
  This provides a specific style for a primary button in its 'loading' state.
  This high-specificity rule overrides the iOS Safari rendering bug by giving it
  an explicit, stable style to render, matching the working "Explain" button.
*/
.btn-primary.active:disabled {
    background-color: var(--primary-dark);
    color: white;
    opacity: 0.7;
}

.btn-secondary {
    background-color: var(--secondary-color);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--secondary-dark);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}

.btn-error {
    background-color: var(--error-color);
    color: white;
}

.btn-outline {
    background-color: transparent;
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--primary-color);
    color: white;
}

.btn-ghost {
    background-color: transparent;
    color: var(--text-primary);
}

.btn-ghost:hover:not(:disabled) {
    background-color: rgba(0, 0, 0, 0.05);
}

.btn-sm {
    padding: var(--spacing-xs) var(--spacing-md);
    font-size: var(--font-size-sm);
}

.btn-lg {
    padding: var(--spacing-md) var(--spacing-xl);
    font-size: var(--font-size-lg);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 40px;
    height: 40px;
    padding: 0;
    border-radius: 50%;
}

/* Forms */
.form-group {
    margin-bottom: var(--spacing-md);
}

.form-label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-sm);
    font-family: inherit;
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--text-primary);
    background-color: var(--surface);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.1);
}

.form-textarea {
    resize: vertical;
    min-height: 100px;
}

/* Loading States */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--border-radius-sm);
}

/* --- ADD THIS NEW RULE START --- */
#translator-loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    padding: var(--spacing-sm);
    color: var(--text-secondary);
    font-size: var(--font-size-sm);
}
/* --- ADD THIS NEW RULE END --- */

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

.spinner-white {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: white;
}

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

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-xs) var(--spacing-sm);
    border-radius: var(--border-radius-pill);
    font-size: var(--font-size-xs);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}

/*
  This rule explicitly defines a custom focus style for all buttons.
  It removes the browser's default outline which causes rendering glitches,
  and replaces it with a modern, non-conflicting box-shadow to maintain accessibility.
*/
.btn:focus {
    outline: none; /* Completely disable the default browser outline */
    box-shadow: 0 0 0 3px rgba(30, 136, 229, 0.25); /* Add a soft, blue glow as a focus indicator */
}
/* --- ADD THIS NEW RULE END --- */

.badge-primary {
    background-color: var(--primary-color);
    color: white;
}

.badge-success {
    background-color: var(--success-color);
    color: white;
}

.badge-error {
    background-color: var(--error-color);
    color: white;
}

.badge-warning {
    background-color: var(--warning-color);
    color: white;
}

/* Utilities */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--success-color); }
.text-error { color: var(--error-color); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--spacing-xs); }
.mt-2 { margin-top: var(--spacing-sm); }
.mt-3 { margin-top: var(--spacing-md); }
.mt-4 { margin-top: var(--spacing-lg); }
.mt-5 { margin-top: var(--spacing-xl); }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--spacing-xs); }
.mb-2 { margin-bottom: var(--spacing-sm); }
.mb-3 { margin-bottom: var(--spacing-md); }
.mb-4 { margin-bottom: var(--spacing-lg); }
.mb-5 { margin-bottom: var(--spacing-xl); }

.p-0 { padding: 0; }
.p-1 { padding: var(--spacing-xs); }
.p-2 { padding: var(--spacing-sm); }
.p-3 { padding: var(--spacing-md); }
.p-4 { padding: var(--spacing-lg); }
.p-5 { padding: var(--spacing-xl); }

.hidden { display: none; }
.visible { display: block; }

/* Animations */
@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

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

@keyframes scale-in {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.animate-fade-in {
    animation: fade-in var(--transition-base) ease-out;
}

.animate-slide-up {
    animation: slide-up var(--transition-base) ease-out;
}

.animate-slide-down {
    animation: slide-down var(--transition-base) ease-out;
}

.animate-scale-in {
    animation: scale-in var(--transition-base) ease-out;
}

/* Example Dialog Styles */
.example-dialog-content {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;
    line-height: 1.8;
    color: var(--text-primary);
}

.example-dialog-content div {
    padding: 4px 0;
    word-wrap: break-word;
}

.example-dialog-content strong {
    font-weight: 600;
}

/* === START: Add these styles for the new dropdown menu === */

/* Position the nav container to anchor the dropdown */
.main-nav {
    position: relative;
}

/* Style the dropdown panel */
.menu-dropdown {
    display: none; /* Add this line to hide the dropdown by default */
    position: absolute;
    top: calc(100% + 8px); /* Position below the header */
    right: 0;
    background: var(--surface);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-lg);
    padding: var(--spacing-sm);
    z-index: var(--z-dropdown);
    width: 200px; /* Or a width that fits your content */
    border: 1px solid var(--border-color);
}

/* Show the dropdown when it has the .active class */
.menu-dropdown.active {
    display: block;
}

/* Style the items inside the dropdown for a vertical layout */
.menu-dropdown .nav-link,
.menu-dropdown .language-selector-container {
    display: flex;
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--border-radius-sm);
    border-left: none; /* Overriding old styles */
    margin-left: 0;
    padding-left: var(--spacing-md);
}

.menu-dropdown .nav-link:hover {
    background-color: var(--background);
}

/* Adjust the language selector for the vertical menu */
.menu-dropdown .language-selector-container {
    border-bottom: 1px solid var(--border-color);
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-md);
}

.menu-dropdown .language-label {
    flex-grow: 1; /* Make the label take up available space */
}

/* Override the active link style for the dropdown */
.menu-dropdown .nav-link.active {
    background-color: rgba(30, 136, 229, 0.1);
    border-bottom-color: transparent; /* Remove the bottom border */
    color: var(--primary-color);
}

/* Style the menu button */
#menu-toggle-btn {
    background-color: transparent;
    border: none;
    color: var(--text-secondary);
}

#menu-toggle-btn:hover {
    color: var(--text-primary);
    background-color: var(--background);
}

/* === END: New dropdown menu styles === */

/* 隐藏 Practice 导航链接 */
#nav-practice,
#nav-practice-desktop {
    display: none !important;
}