/* ============================================
   LinguaFlow — AI Translation Tool
   Premium Design System
   ============================================ */

/* ---- CSS Custom Properties (Design Tokens) ---- */
:root {
    /* Colors — Dark Mode (Default) */
    --bg-primary: #0a0a1a;
    --bg-secondary: #12122a;
    --bg-card: rgba(20, 20, 50, 0.6);
    --bg-card-solid: #14143280;
    --bg-panel: rgba(25, 25, 60, 0.45);
    --bg-input: rgba(30, 30, 70, 0.5);
    --bg-hover: rgba(129, 140, 248, 0.08);

    --border-color: rgba(129, 140, 248, 0.15);
    --border-focus: rgba(129, 140, 248, 0.5);

    --text-primary: #e8e8f0;
    --text-secondary: #9595b8;
    --text-muted: #6b6b8a;
    --text-placeholder: #555577;

    --accent-primary: #818cf8;
    --accent-secondary: #c084fc;
    --accent-gradient: linear-gradient(135deg, #818cf8 0%, #c084fc 100%);
    --accent-gradient-hover: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent-glow: rgba(129, 140, 248, 0.25);

    --success: #34d399;
    --error: #f87171;
    --warning: #fbbf24;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 40px rgba(129, 140, 248, 0.15);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);

    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}

/* Light Mode */
[data-theme="light"] {
    --bg-primary: #f0f0f8;
    --bg-secondary: #e8e8f4;
    --bg-card: rgba(255, 255, 255, 0.75);
    --bg-card-solid: rgba(255, 255, 255, 0.75);
    --bg-panel: rgba(255, 255, 255, 0.65);
    --bg-input: rgba(240, 240, 252, 0.8);
    --bg-hover: rgba(99, 102, 241, 0.06);

    --border-color: rgba(99, 102, 241, 0.15);
    --border-focus: rgba(99, 102, 241, 0.4);

    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #7a7a9a;
    --text-placeholder: #9a9abc;

    --accent-primary: #6366f1;
    --accent-secondary: #a855f7;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%);
    --accent-gradient-hover: linear-gradient(135deg, #4f46e5 0%, #9333ea 100%);
    --accent-glow: rgba(99, 102, 241, 0.2);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 16px 64px rgba(0, 0, 0, 0.1);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.1);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    transition: background var(--transition-slow), color var(--transition-slow);
}

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

/* ---- Animated Background Orbs ---- */
.bg-animation {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.35;
    animation: orbFloat 20s ease-in-out infinite;
}

[data-theme="light"] .bg-orb {
    opacity: 0.18;
}

.bg-orb-1 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, #818cf8 0%, transparent 70%);
    top: -10%;
    left: -5%;
    animation-duration: 22s;
}

.bg-orb-2 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, #c084fc 0%, transparent 70%);
    top: 50%;
    right: -8%;
    animation-duration: 18s;
    animation-delay: -5s;
}

.bg-orb-3 {
    width: 350px;
    height: 350px;
    background: radial-gradient(circle, #6366f1 0%, transparent 70%);
    bottom: -5%;
    left: 30%;
    animation-duration: 25s;
    animation-delay: -10s;
}

.bg-orb-4 {
    width: 250px;
    height: 250px;
    background: radial-gradient(circle, #a78bfa 0%, transparent 70%);
    top: 25%;
    left: 55%;
    animation-duration: 15s;
    animation-delay: -7s;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25%      { transform: translate(40px, -30px) scale(1.05); }
    50%      { transform: translate(-20px, 50px) scale(0.95); }
    75%      { transform: translate(30px, 20px) scale(1.02); }
}

/* ---- App Container ---- */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 20px 40px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    margin-bottom: 24px;
    animation: fadeSlideDown 0.6s ease-out;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.08); }
}

.logo-text h1 {
    font-size: 1.6rem;
    font-weight: 800;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    line-height: 1.2;
}

.logo-subtitle {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.theme-toggle, .github-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-panel);
    backdrop-filter: blur(12px);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
    text-decoration: none;
}

.theme-toggle:hover, .github-link:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

/* Theme toggle icon visibility */
.icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }
[data-theme="light"] .icon-moon { display: block; }

/* ---- Translator Card (Glassmorphism) ---- */
.translator-card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-xl);
    padding: 28px;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: fadeSlideUp 0.7s ease-out;
    flex: 1;
}

/* ---- Language Selector Bar ---- */
.language-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.lang-select-wrapper {
    flex: 1;
}

.lang-select {
    width: 100%;
    padding: 12px 16px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239595b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

.lang-select:hover {
    border-color: var(--accent-primary);
    background-color: var(--bg-hover);
}

.lang-select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.lang-select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 8px;
}

/* Swap Button */
.swap-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: var(--bg-panel);
    backdrop-filter: blur(8px);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-base);
    flex-shrink: 0;
}

.swap-btn:hover {
    background: var(--accent-gradient);
    color: #fff;
    border-color: transparent;
    transform: rotate(180deg) scale(1.05);
    box-shadow: 0 0 20px var(--accent-glow);
}

/* ---- Translation Panels ---- */
.translation-panels {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 0;
    align-items: stretch;
}

.panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-panel);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color var(--transition-base), box-shadow var(--transition-base);
}

.panel:hover, .panel:focus-within {
    border-color: rgba(129, 140, 248, 0.25);
    box-shadow: 0 0 24px rgba(129, 140, 248, 0.05);
}

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

.panel-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.char-counter {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    transition: color var(--transition-fast);
}

.char-counter.near-limit {
    color: var(--warning);
}

.char-counter.at-limit {
    color: var(--error);
}

.match-badge {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    background: rgba(52, 211, 153, 0.15);
    color: var(--success);
    display: none;
}

.match-badge.visible {
    display: inline-block;
    animation: fadeIn 0.3s ease;
}

/* Text Areas */
.text-area {
    flex: 1;
    min-height: 200px;
    padding: 16px;
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 400;
    line-height: 1.7;
    color: var(--text-primary);
    background: transparent;
    border: none;
    resize: none;
    outline: none;
    transition: color var(--transition-base);
}

.text-area::placeholder {
    color: var(--text-placeholder);
}

.target-display {
    cursor: default;
    user-select: text;
    overflow-y: auto;
    word-wrap: break-word;
}

.placeholder-text {
    color: var(--text-placeholder);
    font-style: italic;
}

/* Panel Actions */
.panel-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    border-top: 1px solid var(--border-color);
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.action-btn:hover {
    background: var(--bg-hover);
    color: var(--accent-primary);
    transform: scale(1.1);
}

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

/* Copy feedback tooltip */
.copy-feedback {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%) scale(0.8);
    background: var(--success);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.copy-feedback.show {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

/* ---- Translate Button ---- */
.translate-btn-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
}

.translate-btn {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-base);
    white-space: nowrap;
    overflow: hidden;
    box-shadow: 0 4px 20px var(--accent-glow);
}

.translate-btn:hover {
    background: var(--accent-gradient-hover);
    transform: scale(1.05);
    box-shadow: 0 8px 30px rgba(129, 140, 248, 0.4);
}

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

.translate-btn.loading .btn-text,
.translate-btn.loading .btn-icon {
    opacity: 0;
}

.translate-btn.loading .btn-loader {
    opacity: 1;
}

.btn-loader {
    position: absolute;
    width: 22px;
    height: 22px;
    border: 2.5px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    opacity: 0;
    animation: spin 0.7s linear infinite;
    transition: opacity var(--transition-fast);
}

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

/* ---- History Section ---- */
.history-section {
    margin-top: 28px;
    border-top: 1px solid var(--border-color);
    padding-top: 24px;
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.history-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.clear-history-btn {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: none;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.clear-history-btn:hover {
    color: var(--error);
    border-color: var(--error);
    background: rgba(248, 113, 113, 0.08);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.history-list::-webkit-scrollbar {
    width: 5px;
}

.history-list::-webkit-scrollbar-track {
    background: transparent;
}

.history-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.history-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.history-item {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    animation: fadeSlideUp 0.3s ease-out;
}

.history-item:hover {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.history-item-text {
    font-size: 0.85rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-arrow {
    color: var(--accent-primary);
    font-size: 0.75rem;
    flex-shrink: 0;
}

.history-item-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.history-item-delete:hover {
    background: rgba(248, 113, 113, 0.1);
    color: var(--error);
}

/* ---- Footer ---- */
.app-footer {
    text-align: center;
    padding: 24px 0 0;
    color: var(--text-muted);
    font-size: 0.78rem;
    animation: fadeIn 1s ease-out;
}

.app-footer strong {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ---- Toast Notification ---- */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 24px;
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    box-shadow: var(--shadow-md);
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--error); }
.toast.info { border-color: var(--accent-primary); }

/* ---- Animations ---- */
@keyframes fadeSlideDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

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

/* Shimmer loading effect for target panel */
.target-display.loading {
    background: linear-gradient(
        90deg,
        transparent 0%,
        var(--bg-hover) 50%,
        transparent 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s ease-in-out infinite;
}

/* ---- Responsive Design ---- */
@media (max-width: 768px) {
    .app-container {
        padding: 16px 12px 32px;
    }

    .translator-card {
        padding: 18px;
        border-radius: var(--radius-lg);
    }

    .language-bar {
        flex-direction: column;
        gap: 8px;
    }

    .swap-btn {
        transform: rotate(90deg);
    }

    .swap-btn:hover {
        transform: rotate(270deg) scale(1.05);
    }

    .translation-panels {
        grid-template-columns: 1fr;
        gap: 0;
    }

    .translate-btn-wrapper {
        padding: 16px 0;
    }

    .translate-btn {
        width: 100%;
        justify-content: center;
        padding: 16px 28px;
    }

    .text-area {
        min-height: 150px;
    }

    .history-item {
        grid-template-columns: 1fr;
        gap: 6px;
    }

    .history-item-arrow {
        display: none;
    }

    .logo-text h1 {
        font-size: 1.3rem;
    }
}

@media (max-width: 480px) {
    .app-header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .translator-card {
        padding: 14px;
    }

    .lang-select {
        padding: 10px 14px;
        font-size: 0.85rem;
    }

    .text-area {
        min-height: 120px;
        font-size: 0.9rem;
    }
}

/* ---- Scrollbar Styling ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

/* Focus-visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Selection color */
::selection {
    background: rgba(129, 140, 248, 0.3);
    color: var(--text-primary);
}
