:root {
    /* Theme-independent variables */
    --primary-color-base: #7B4BFF;
    --hover-color-base: #5d3dff;

    /* Light Theme (Default) */
    --primary-color: var(--primary-color-base);
    --hover-color: var(--hover-color-base);
    --bg-gradient: linear-gradient(135deg, #7B4BFF, #6a3dff);
    --container-bg: #ffffff;
    --text-color: #34495e;
    --text-light: #7f8c8d;
    --header-color: #34495e;
    --border-color: #e0e0e0;
    --input-bg: #f9f9f9;
    --button-secondary-bg: #f1f3f4;
    --button-secondary-hover-bg: #e8eaed;
    --history-item-hover-bg: #ffffff;
    --footer-text-color: rgba(255, 255, 255, 0.8);
    --footer-link-color: #ffffff;
    --settings-panel-bg: #ffffff;
    --settings-text-light: #7f8c8d;
    --radio-border-color: #34495e;
}

body.dark-mode {
    /* Dark Theme */
    --primary-color: #8a63ff;
    --hover-color: #9773ff;
    --bg-gradient: linear-gradient(135deg, #1d2b38, #11181f);
    --container-bg: #23313f;
    --text-color: #f0f2f5;
    --text-light: #a8b2c0;
    --header-color: #f0f2f5;
    --border-color: #3a4a5b;
    --input-bg: #2c3e50;
    --button-secondary-bg: #3a4a5b;
    --button-secondary-hover-bg: #4a617a;
    --history-item-hover-bg: color-mix(in srgb, var(--text-color) 5%, var(--container-bg));
    --footer-text-color: rgba(240, 242, 245, 0.7);
    --footer-link-color: #f0f2f5;
    --settings-panel-bg: #2c3e50;
    --settings-text-light: #a8b2c0;
    --radio-border-color: #f0f2f5;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Roboto', 'Noto Sans Sinhala', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    color: var(--text-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
    transition: background 0.4s ease;
}

.container {
    max-width: 900px;
    width: 100%;
    background-color: var(--container-bg);
    padding: 30px 40px;
    border-radius: 20px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.12);
    margin-bottom: 30px;
    transition: background-color 0.4s ease, box-shadow 0.4s ease;
}

header {
    position: relative;
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--header-color);
    margin-bottom: 8px;
}

header h1 i {
    color: var(--primary-color);
    margin-right: 10px;
}

header p {
    font-size: 1.1rem;
    color: var(--text-light);
}

.premium-badge {
    background-color: #f1c40f;
    color: #333;
    padding: 3px 8px;
    font-size: 0.8rem;
    font-weight: 700;
    border-radius: 5px;
    margin-left: 10px;
    display: inline-block;
    vertical-align: middle;
}

.hidden {
    display: none !important;
}

.settings-btn {
    position: absolute;
    top: -10px;
    right: -15px;
    background: transparent;
    border: none;
    font-size: 1.4rem;
    color: var(--text-light);
    cursor: pointer;
    padding: 10px;
    transition: all 0.3s ease;
}

.settings-btn:hover {
    color: var(--primary-color);
    transform: rotate(45deg);
}


.settings-panel {
    position: absolute;
    top: 50px; 
    right: -5px;
    background: var(--settings-panel-bg);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.15);
    padding: 20px;
    width: 280px;
    z-index: 1100;
    border: 1px solid var(--border-color);
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.settings-panel.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

.settings-panel-header {
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 15px;
}

.settings-panel-header h3 {
    font-size: 1.2rem;
    color: var(--text-color);
}

.settings-section {
    margin-bottom: 20px;
}

.settings-section:last-child {
    margin-bottom: 0;
}

.settings-section h4 {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--settings-text-light);
    margin-bottom: 15px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* New Animated Theme Toggle */
.theme-toggle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px 0;
}

.theme-toggle-btn {
    position: relative;
    background-color: color-mix(in srgb, var(--primary-color) 15%, transparent);
    border: 2px solid var(--border-color);
    border-radius: 30px;
    width: 70px;
    height: 35px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.4s ease;
}

.theme-toggle-btn:hover {
    border-color: var(--primary-color);
}

.sun-icon-wrapper, .moon-icon-wrapper {
    position: absolute;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.1rem;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

.sun-icon-wrapper {
    color: #f39c12;
    opacity: 1;
    transform: translateX(-15px) rotate(0deg) scale(1);
}

.moon-icon-wrapper {
    color: #f1c40f;
    opacity: 0;
    transform: translateX(15px) rotate(90deg) scale(0);
}

body.dark-mode .sun-icon-wrapper {
    opacity: 0;
    transform: translateX(-15px) rotate(-90deg) scale(0);
}

body.dark-mode .moon-icon-wrapper {
    color: #e67e22;
    opacity: 1;
    transform: translateX(15px) rotate(0deg) scale(1);
}

/* Voice Speed Radio Buttons */
.voice-speed-option {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.voice-speed-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.voice-speed-options label {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-color);
}
.voice-speed-options input[type="radio"] {
    -webkit-appearance: none;
    appearance: none;
    background-color: transparent;
    margin-right: 12px;
    font: inherit;
    color: var(--radio-border-color);
    width: 1.15em;
    height: 1.15em;
    border: 0.15em solid currentColor;
    border-radius: 50%;
    transform: translateY(-0.075em);
    display: grid;
    place-content: center;
}
.voice-speed-options input[type="radio"]::before {
    content: "";
    width: 0.65em;
    height: 0.65em;
    border-radius: 50%;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em var(--primary-color);
}
.voice-speed-options input[type="radio"]:checked::before {
    transform: scale(1);
}

.test-speed-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 30px;
    height: 30px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-light);
    transition: all 0.2s ease;
}

.test-speed-btn:hover {
    background-color: color-mix(in srgb, var(--text-color) 8%, transparent);
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.test-speed-btn i {
    font-size: 0.8rem;
    margin-left: 2px;
}

.custom-speed-control {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 15px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    transition: background 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--container-bg);
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
    transition: background-color 0.2s ease;
}

input[type="range"]::-moz-range-thumb {
    width: 15px;
    height: 15px;
    background: var(--primary-color);
    border-radius: 50%;
    cursor: pointer;
    border: 3px solid var(--container-bg);
    box-shadow: 0 0 5px rgba(0,0,0,0.2);
}

input[type="range"]:hover {
    background: color-mix(in srgb, var(--primary-color) 40%, var(--border-color));
}

input[type="range"]:hover::-webkit-slider-thumb {
    background: var(--hover-color);
}

input[type="range"]:hover::-moz-range-thumb {
    background: var(--hover-color);
}

#customSpeedValue {
    font-weight: 500;
    color: var(--text-color);
    min-width: 40px; /* To prevent layout shift */
    text-align: right;
    font-size: 0.9rem;
}

footer {
    text-align: center;
    color: var(--footer-text-color);
}

footer p {
    display: inline-flex;
    align-items: center;
    gap: 0.5em;
}

.about-btn-footer {
    background: none;
    border: none;
    color: var(--footer-link-color);
    cursor: pointer;
    font-size: inherit;
    font-family: inherit;
    padding: 0;
    font-weight: 600;
    text-decoration: underline;
    transition: all 0.3s ease;
}

.about-btn-footer:hover {
    opacity: 0.8;
}

.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255,255,255,.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

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

/* Responsive Design */
@media (max-width: 768px) {
    body {
        padding: 15px;
        justify-content: flex-start;
    }
    .container {
        padding: 25px;
        margin: 15px 0;
    }
    header h1 {
        font-size: 2rem;
    }
    header p {
        font-size: 1rem;
    }

    /* Stack language selectors and translation areas on tablets and smaller */
    .language-selector {
        flex-direction: column;
        gap: 1rem;
    }

    .swap-btn {
        transform: rotate(90deg);
        margin: 0.5rem 0;
    }

    .translation-area {
        grid-template-columns: 1fr; /* Key change for stacking */
        gap: 1.5rem;
    }

    .text-area-container textarea {
        min-height: 200px;
    }
    .translate-btn {
        width: 100%;
        padding: 16px;
        font-size: 1.1rem;
    }
    .history-item {
        padding: 15px;
    }
    .modal-content {
        width: 90%;
        padding: 25px;
        margin: 20% auto;
    }
    .modal-content h2 {
        font-size: 1.5rem;
    }
    .settings-panel {
        right: 0;
        width: 260px;
    }
}

/* For smaller mobile devices */
@media (max-width: 480px) {
    /* Hide desktop panels on mobile */
    .container, .translation-area, .output-section, .input-section, .text-area-container, .action-buttons, .history-section, .mic-fab, .bottom-nav, footer, .ad-banner {
        display: none !important;
    }
    body {
        background: #181a1b !important;
        color: #fff !important;
        padding: 0 !important;
        margin: 0 !important;
    }
    .gt-mobile {
        display: flex !important;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        background: #181a1b;
        border-radius: 18px;
        box-shadow: 0 8px 32px rgba(0,0,0,0.18);
        padding: 24px 8px 32px 8px;
        margin: 0 auto;
        max-width: 98vw;
        width: 100vw;
        min-height: 100vh;
        gap: 22px;
    }
    .gt-mobile header, .gt-mobile .header {
        width: 100%;
        text-align: center;
        font-size: 2rem;
        font-weight: 800;
        color: #fff;
        margin-bottom: 8px;
        letter-spacing: 0.5px;
        padding-top: 10px;
    }
    .gt-mobile .gt-lang-row {
        width: 100%;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 10px;
        margin-bottom: 10px;
    }
    .gt-mobile .gt-lang-select {
        background: #23272a;
        color: #fff;
        border: none;
        border-radius: 14px;
        font-size: 1.1rem;
        padding: 12px 18px;
        font-weight: 600;
        box-shadow: 0 2px 8px rgba(0,0,0,0.04);
        max-width: 44vw;
        transition: border 0.2s;
    }
    .gt-mobile .gt-swap-btn {
        background: #23272a;
        color: #fff;
        border: none;
        border-radius: 50%;
        width: 44px;
        height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.3rem;
        box-shadow: 0 2px 8px rgba(0,0,0,0.04);
        transition: border 0.2s, background 0.2s;
    }
    .gt-mobile .gt-swap-btn:active {
        background: #7B4BFF;
        color: #fff;
    }
    .gt-mobile .gt-input {
        width: 100%;
        max-width: 420px;
        background: #23272a;
        color: #fff;
        border: none;
        border-radius: 18px;
        font-size: 1.2rem;
        padding: 26px 16px;
        margin-bottom: 0;
        outline: none;
        resize: none;
        text-align: center;
        box-shadow: 0 2px 12px rgba(0,0,0,0.09);
        font-family: inherit;
        transition: border 0.2s;
    }
    .gt-mobile .gt-input:focus {
        border: 2px solid #7B4BFF;
    }
    .gt-mobile .gt-translate-btn {
        width: 100%;
        max-width: 420px;
        background: linear-gradient(135deg, #7B4BFF, #5d3dff);
        color: #fff;
        border: none;
        border-radius: 100px;
        padding: 18px 0;
        font-size: 1.2rem;
        font-weight: 700;
        margin-bottom: 0;
        cursor: pointer;
        box-shadow: 0 4px 18px rgba(123,75,255,0.13);
        transition: background 0.2s, transform 0.2s;
        letter-spacing: 0.5px;
    }
    .gt-mobile .gt-translate-btn:active {
        background: #5d3dff;
        transform: scale(0.98);
    }
    .gt-mobile .gt-result {
        width: 100%;
        max-width: 420px;
        min-height: 60px;
        background: #23272a;
        color: #fff;
        border-radius: 18px;
        border: none;
        font-size: 1.2rem;
        padding: 26px 16px;
        text-align: center;
        margin-top: 0;
        word-break: break-word;
        box-shadow: 0 2px 12px rgba(0,0,0,0.09);
        font-family: inherit;
        display: none;
    }
    .gt-mobile .gt-result.show {
        display: block;
    }
    /* Bottom nav (optional) */
    .gt-mobile .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100vw;
        background: #23272a;
        display: flex;
        justify-content: space-around;
        align-items: center;
        padding: 10px 0 6px 0;
        border-top-left-radius: 18px;
        border-top-right-radius: 18px;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.09);
        z-index: 100;
    }
    .gt-mobile .bottom-nav button {
        background: none;
        border: none;
        color: #fff;
        font-size: 1.3rem;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        cursor: pointer;
    }
}

@media (max-width: 400px) {
    html, body {
        font-size: 15px;
        overflow-x: hidden;
    }
    .container {
        padding: 2px 1px;
        border-radius: 6px;
    }
    header h1 {
        font-size: 0.95rem;
    }
    .settings-btn {
        font-size: 1rem;
        padding: 4px;
    }
    .language-box label, .settings-panel-header h3, .settings-section h4 {
        font-size: 0.9rem;
    }
    .language-box select {
        font-size: 0.9rem;
        padding: 6px;
        border-radius: 5px;
    }
    .swap-btn {
        width: 30px;
        height: 30px;
        margin: 0.2rem 0;
    }
    .translation-area {
        gap: 0.4rem;
    }
    .text-area-container textarea {
        font-size: 0.9rem;
        min-height: 60px;
        padding: 6px 30px 18px 6px;
        border-radius: 6px;
    }
    .char-counter {
        left: 6px;
        bottom: 4px;
        font-size: 0.8rem;
    }
    .text-controls {
        right: 2px;
        top: 2px;
        gap: 4px;
    }
    .clear-btn, .copy-btn, .speak-btn, .dictate-btn, .ai-voice-btn, .upload-file-btn, .download-pdf-btn, .download-txt-btn, .batch-translate-btn {
        width: 22px;
        height: 22px;
        font-size: 0.95rem;
    }
    .action-buttons {
        margin-top: 8px;
    }
    .translate-btn {
        font-size: 0.95rem;
        padding: 8px;
        border-radius: 20px;
    }
    .history-section {
        margin-top: 6px;
    }
    .history-header h3 {
        font-size: 0.95rem;
    }
    .clear-history-btn, .export-history-btn, .show-favorites-btn {
        font-size: 0.8rem;
        padding: 4px 7px;
        border-radius: 5px;
    }
    .history-list {
        max-height: 80px;
        padding-right: 1px;
    }
    .history-item {
        font-size: 0.9rem;
        padding: 4px;
        border-radius: 5px;
        margin-bottom: 3px;
    }
    .modal-content {
        width: 100vw;
        max-width: 100vw;
        padding: 4px 2px;
        border-radius: 8px;
    }
    .modal-content h2, .modal-content h3 {
        font-size: 0.95rem;
    }
    .modal-content p, .modal-content ul li {
        font-size: 0.9rem;
    }
    .modal-close-button, .modal-button-secondary, .modal-button-danger, .modal-button-primary {
        font-size: 0.9rem;
        padding: 7px 12px;
        border-radius: 5px;
    }
    .settings-panel {
        width: 100vw;
        min-width: unset;
        right: 0;
        left: 0;
        border-radius: 8px;
        padding: 4px 2px;
    }
    .unlock-premium-btn, .logout-premium-btn {
        font-size: 0.9rem;
        padding: 7px;
        border-radius: 5px;
    }
    .voice-speed-options label {
        font-size: 0.9rem;
    }
    .custom-speed-control {
        gap: 4px;
    }
    #customSpeedValue {
        font-size: 0.85rem;
        min-width: 20px;
    }
    .activation-input-group input {
        font-size: 0.9rem;
        padding: 6px;
        border-radius: 5px;
    }
    .activation-input-group button {
        font-size: 0.9rem;
        padding: 6px 8px;
        border-radius: 5px;
    }
    .activation-error-msg {
        font-size: 0.8rem;
    }
    footer p {
        font-size: 0.9rem;
    }
    .theme-toggle-btn {
        width: 28px;
        height: 16px;
        border-radius: 10px;
    }
    .sun-icon-wrapper, .moon-icon-wrapper {
        font-size: 0.8rem;
    }
}

@media (max-width: 360px) {
    html, body {
        font-size: 14px;
    }
    header h1 {
        font-size: 0.85rem;
    }
    .modal-content h2, .modal-content h3 {
        font-size: 0.85rem;
    }
    .translate-btn, .unlock-premium-btn, .logout-premium-btn {
        font-size: 0.85rem;
    }
    .history-header h3 {
        font-size: 0.85rem;
    }
    .history-item {
        font-size: 0.85rem;
    }
}

@media (max-width: 320px) {
    html, body {
        font-size: 13px;
    }
    .container, .settings-panel, .modal-content {
        padding: 2px 0;
        border-radius: 5px;
    }
    header h1 {
        font-size: 0.7rem;
    }
    .translate-btn, .unlock-premium-btn, .logout-premium-btn {
        font-size: 0.7rem;
        padding: 5px;
    }
    .history-header h3 {
        font-size: 0.7rem;
    }
    .history-item {
        font-size: 0.7rem;
        padding: 3px;
    }
    .modal-content h2, .modal-content h3 {
        font-size: 0.7rem;
    }
    .modal-close-button, .modal-button-secondary, .modal-button-danger, .modal-button-primary {
        font-size: 0.7rem;
        padding: 4px 6px;
    }
    footer p {
        font-size: 0.7rem;
    }
}

.history-list::-webkit-scrollbar { width: 6px; }
.history-list::-webkit-scrollbar-track { background: #f1f1f1; }
.history-list::-webkit-scrollbar-thumb { background: #dcdcdc; border-radius: 3px; }
.history-list::-webkit-scrollbar-thumb:hover { background: #c1c1c1; }

.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; overflow: auto; background-color: rgba(0,0,0,0.6); animation: fadeIn 0.3s; backdrop-filter: blur(5px); }
.modal-content { background-color: var(--container-bg); margin: 10% auto; padding: 40px; border: none; width: 90%; max-width: 500px; border-radius: 20px; text-align: center; position: relative; box-shadow: 0 20px 40px rgba(0,0,0,0.2); animation: slideInFromTop 0.4s; }
.modal-content h2 { color: var(--primary-color); margin-bottom: 20px; }
.modal-content p { margin-bottom: 10px; font-size: 1rem; line-height: 1.6; color: var(--text-color); }
.modal-content h3 { margin-top: 25px; margin-bottom: 15px; color: var(--text-color); font-weight: 500; }
.modal-content ul { list-style: none; padding: 0; margin-bottom: 30px; text-align: left; display: inline-block; }
.modal-content ul li { margin-bottom: 10px; font-size: 1rem; color: var(--text-light); }
.modal-content ul li::before { content: '✓'; color: var(--primary-color); font-weight: bold; display: inline-block; width: 1em; margin-left: -1em; }
.modal-close-button { background: var(--primary-color); color: white; padding: 14px 35px; border: none; border-radius: 100px; cursor: pointer; font-size: 1rem; transition: all 0.3s; }
.modal-close-button:hover { background: var(--hover-color); transform: scale(1.05); }
.close-modal-span { color: #ccc; position: absolute; top: 15px; right: 20px; font-size: 28px; font-weight: normal; }
.close-modal-span:hover, .close-modal-span:focus { color: var(--text-color); text-decoration: none; cursor: pointer; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInFromTop { from { transform: translateY(-50px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-15px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.new-item-animation {
    animation: slideInDown 0.5s ease-out;
}

/* Confirmation Modal Buttons */
.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 30px;
}

.modal-button-secondary, .modal-button-danger {
    padding: 12px 25px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.modal-button-secondary {
    background-color: var(--button-secondary-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.modal-button-secondary:hover {
    background-color: var(--button-secondary-hover-bg);
}

.modal-button-danger {
    background-color: #d93025;
    color: white;
}

.modal-button-danger:hover {
    background-color: #c5221f;
    box-shadow: 0 2px 10px rgba(217, 48, 37, 0.3);
}

/* Toast Notification */
.toast-notification {
    position: fixed;
    left: 50%;
    bottom: 40px;
    transform: translateX(-50%) scale(0.95);
    min-width: 240px;
    max-width: 90vw;
    background: var(--container-bg);
    color: var(--text-color);
    padding: 16px 32px;
    border-radius: 16px;
    font-size: 1.08rem;
    box-shadow: 0 6px 32px rgba(0,0,0,0.18);
    opacity: 0;
    pointer-events: none;
    z-index: 3000;
    transition: opacity 0.3s, transform 0.3s;
    display: block;
    text-align: center;
    font-weight: 500;
    border: 1.5px solid var(--border-color);
}
.toast-notification.show {
    opacity: 0.97;
    pointer-events: auto;
    transform: translateX(-50%) scale(1);
    animation: toastPop 0.4s;
}
@keyframes toastPop {
    0% { transform: translateX(-50%) scale(0.8); opacity: 0; }
    60% { transform: translateX(-50%) scale(1.05); opacity: 1; }
    100% { transform: translateX(-50%) scale(1); opacity: 0.97; }
}
body.dark-mode .toast-notification {
    background: #222b3a;
    color: #f0f2f5;
    border-color: #3a4a5b;
}
/* Remaining styles for language selector, text areas, buttons etc. */
.language-selector {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
}

.language-box {
    flex: 1;
}

.language-box label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-color);
}

.language-box select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background-color: var(--input-bg);
    color: var(--text-color);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.swap-btn {
    background: var(--button-secondary-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 45px;
    height: 45px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0 20px;
    margin-top: 25px; /* to align with selects */
    transition: all 0.3s ease;
}

.swap-btn:hover {
    background: var(--button-secondary-hover-bg);
    transform: rotate(180deg);
}

.swap-btn i {
    font-size: 1.1rem;
    color: #5f6368;
}

body.dark-mode .swap-btn i {
    color: var(--text-light);
}

.translation-area {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 25px;
}

.text-area-container {
    position: relative;
}

.text-area-container textarea {
    width: 100%;
    padding: 20px 95px 40px 20px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 1.1rem;
    line-height: 1.6;
    resize: vertical;
    min-height: 250px;
    font-family: inherit;
    background-color: var(--container-bg);
    color: var(--text-color);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.text-area-container textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 20%, transparent);
}

.char-counter {
    position: absolute;
    bottom: 15px;
    left: 20px;
    font-size: 0.85rem;
    color: var(--text-light);
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.5px;
    transition: color 0.2s;
}
body:not(.dark-mode) .char-counter.limit-reached {
    color: #e67e22;
}
body:not(.dark-mode) .char-counter.premium {
    color: #28a745;
}
body.dark-mode .char-counter.limit-reached {
    color: #ffb366;
}
body.dark-mode .char-counter.premium {
    color: #6fff8f;
}

.text-controls {
    position: absolute;
    top: 15px;
    right: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.clear-btn, .copy-btn, .speak-btn, .dictate-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: var(--text-light);
    transition: all 0.2s ease;
}

.clear-btn:hover, .copy-btn:hover, .speak-btn:hover, .dictate-btn:hover {
    background-color: var(--button-secondary-bg);
    color: var(--text-color);
}

.copy-btn.success {
    color: #28a745; /* Green color for success */
    background-color: color-mix(in srgb, #28a745 15%, transparent);
}

.dictate-btn.locked {
    cursor: not-allowed;
    color: var(--border-color);
}

.dictate-btn.locked:hover {
    background-color: transparent;
    color: var(--border-color);
}

.dictate-btn.listening {
    color: #e74c3c; /* Red color for listening state */
    background-color: color-mix(in srgb, #e74c3c 15%, transparent);
    animation: pulse 1.5s infinite;
}

.action-buttons {
    text-align: center;
    margin-top: 30px;
}

.translate-btn {
    background: linear-gradient(135deg, var(--primary-color), var(--hover-color));
    color: white;
    padding: 15px 40px;
    border: none;
    border-radius: 100px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.translate-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 25px color-mix(in srgb, var(--primary-color) 30%, transparent);
}

.translate-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.history-section {
    margin-top: 40px;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
}

.history-header h3 {
    font-size: 1.4rem;
    color: var(--text-color);
}

.clear-history-btn {
    background-color: var(--button-secondary-bg);
    border: 1px solid var(--border-color);
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-color);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

.clear-history-btn:hover {
    background-color: var(--button-secondary-hover-bg);
}

.history-list {
    max-height: 300px;
    overflow-y: auto;
    padding-right: 10px;
}

.history-item {
    background-color: var(--input-bg);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 15px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.3s ease;
}

.history-item:hover {
    border-color: var(--primary-color);
    background-color: var(--history-item-hover-bg);
    transform: translateY(-3px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.05);
}

.history-item .source-text {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 8px;
}

.history-item .target-text {
    color: var(--text-light);
    margin-bottom: 12px;
}

.history-item .timestamp {
    font-size: 0.8rem;
    color: #999;
    text-align: right;
}

body.dark-mode .history-item .timestamp {
    color: var(--text-light);
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 color-mix(in srgb, #e74c3c 40%, transparent);
    }
    70% {
        box-shadow: 0 0 0 10px color-mix(in srgb, #e74c3c 0%, transparent);
    }
    100% {
        box-shadow: 0 0 0 0 color-mix(in srgb, #e74c3c 0%, transparent);
    }
}

.modal-button-primary {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.modal-button-primary:hover {
    background-color: var(--hover-color);
}

.unlock-premium-btn, .logout-premium-btn {
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.unlock-premium-btn {
    background-color: color-mix(in srgb, var(--primary-color) 15%, transparent);
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

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

.logout-premium-btn {
    background-color: color-mix(in srgb, #e74c3c 15%, transparent);
    color: #e74c3c;
    border: 1px solid #e74c3c;
    margin-top: 10px; /* Add some space between buttons */
}

.logout-premium-btn:hover {
    background-color: #e74c3c;
    color: white;
}

.unlock-premium-btn i, .logout-premium-btn i {
    margin-right: 8px;
}

.activation-input-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.activation-input-group input {
    flex-grow: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background-color: var(--input-bg);
    color: var(--text-color);
}

.activation-error-msg {
    color: #e74c3c;
    font-size: 0.9rem;
    margin-top: 15px;
    height: 1.2em; /* Reserve space to prevent layout shift */
}

.char-limit-warning {
    background: #e74c3c;
    color: #fff;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 3000;
    box-shadow: 0 2px 10px rgba(231,76,60,0.15);
    animation: fadeIn 0.3s;
    display: none;
}
.char-limit-warning.show {
    display: block;
    opacity: 1;
}

/* Voice Gender Options */
.voice-gender-section {
    margin-bottom: 18px;
}
.voice-gender-options {
    display: flex;
    gap: 18px;
    margin-top: 8px;
}
.voice-gender-options label {
    font-size: 1rem;
    color: var(--text-color);
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    opacity: 1;
    transition: opacity 0.2s;
}
.voice-gender-options input[type="radio"] {
    accent-color: var(--primary-color);
    width: 1.1em;
    height: 1.1em;
    margin-right: 4px;
}
.voice-gender-section.disabled, .voice-gender-section.hidden {
    display: none !important;
}
@media (max-width: 480px) {
    .voice-gender-options label {
        font-size: 0.95rem;
    }
    .voice-gender-options {
        gap: 10px;
    }
}

.voice-select-section {
    margin-bottom: 18px;
}
#voiceSelect {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 1rem;
    color: var(--text-color);
    background: var(--input-bg);
    margin-top: 8px;
    margin-bottom: 4px;
    transition: border-color 0.2s;
}
#voiceSelect:disabled {
    background: #f5f5f5;
    color: #aaa;
    cursor: not-allowed;
}
.voice-select-section.disabled {
    opacity: 0.6;
    pointer-events: none;
    cursor: not-allowed;
}
.voice-select-disabled-text {
    font-size: 0.92em;
    color: #e74c3c;
    font-style: italic;
    margin-top: 4px;
    display: block;
}
@media (max-width: 480px) {
    #voiceSelect {
        font-size: 0.95rem;
        padding: 8px;
        border-radius: 6px;
    }
}

.ai-voice-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #6c63ff;
    transition: background 0.2s, color 0.2s;
    font-size: 1.1rem;
    margin-top: 2px;
}
.ai-voice-btn:hover {
    background: color-mix(in srgb, #6c63ff 15%, transparent);
    color: #4834d4;
}
.ai-voice-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    cursor: not-allowed;
}
@media (max-width: 480px) {
    .ai-voice-btn {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
}

.upload-file-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #27ae60;
    transition: background 0.2s, color 0.2s;
    font-size: 1.1rem;
    margin-top: 2px;
}
.upload-file-btn:hover {
    background: color-mix(in srgb, #27ae60 15%, transparent);
    color: #145a32;
}
.upload-file-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    cursor: not-allowed;
}
@media (max-width: 480px) {
    .upload-file-btn {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
}

.ad-banner {
    width: 100%;
    background: linear-gradient(90deg, #ffe259 0%, #ffa751 100%);
    color: #333;
    text-align: center;
    padding: 14px 0;
    font-size: 1.05rem;
    font-weight: 600;
    border-radius: 10px;
    margin-bottom: 18px;
    box-shadow: 0 2px 10px rgba(255, 174, 81, 0.12);
    letter-spacing: 0.5px;
}

.ad-label {
    background: #e74c3c;
    color: #fff;
    font-size: 0.92em;
    font-weight: 700;
    border-radius: 4px;
    padding: 2px 8px;
    margin-right: 10px;
    letter-spacing: 1px;
    vertical-align: middle;
}

.custom-voice-settings {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 10px;
}
.custom-voice-settings label {
    font-size: 1rem;
    color: var(--text-color);
    margin-bottom: 2px;
}
.custom-voice-settings input[type="range"] {
    width: 100%;
    margin-bottom: 6px;
}
.test-voice-btn {
    display: block;
    margin-left: auto;
    margin-top: 12px;
    padding: 8px 18px;
    font-size: 1rem;
    border-radius: 8px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
}
.test-voice-btn:hover:not(:disabled) {
    background: var(--hover-color);
    color: #fff;
}
.test-voice-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    cursor: not-allowed;
}

.export-history-btn {
    background-color: #e3f0ff;
    color: #2980ef;
    border: 1px solid #2980ef;
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.export-history-btn:hover:not(:disabled) {
    background-color: #2980ef;
    color: #fff;
}
.export-history-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    border-color: #ccc;
    cursor: not-allowed;
}

.batch-translate-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #8e44ad;
    transition: background 0.2s, color 0.2s;
    font-size: 1.1rem;
    margin-top: 2px;
}
.batch-translate-btn:hover {
    background: color-mix(in srgb, #8e44ad 15%, transparent);
    color: #5e3370;
}
.batch-translate-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    cursor: not-allowed;
}
@media (max-width: 480px) {
    .batch-translate-btn {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
}

.favorite-btn {
    background: transparent;
    border: none;
    color: #f1c40f;
    font-size: 1.2rem;
    cursor: pointer;
    margin-right: 8px;
    transition: color 0.2s;
    vertical-align: middle;
}
.favorite-btn.favorited {
    color: #e67e22;
}
.favorite-btn:disabled {
    color: #ccc;
    cursor: not-allowed;
}
.show-favorites-btn {
    background-color: #fffbe6;
    color: #e67e22;
    border: 1px solid #e67e22;
    padding: 8px 15px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.show-favorites-btn.active, .show-favorites-btn:hover:not(:disabled) {
    background-color: #e67e22;
    color: #fff;
}
.show-favorites-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    border-color: #ccc;
    cursor: not-allowed;
}

.download-pdf-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #e74c3c;
    transition: background 0.2s, color 0.2s;
    font-size: 1.1rem;
    margin-top: 2px;
}
.download-pdf-btn:hover {
    background: color-mix(in srgb, #e74c3c 15%, transparent);
    color: #b71c1c;
}
.download-pdf-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    cursor: not-allowed;
}
.download-txt-btn {
    background: transparent;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #2980ef;
    transition: background 0.2s, color 0.2s;
    font-size: 1.1rem;
    margin-top: 2px;
}
.download-txt-btn:hover {
    background: color-mix(in srgb, #2980ef 15%, transparent);
    color: #145a32;
}
.download-txt-btn:disabled {
    color: #aaa;
    background: #f5f5f5;
    cursor: not-allowed;
}
@media (max-width: 480px) {
    .download-pdf-btn, .download-txt-btn {
        width: 28px;
        height: 28px;
        font-size: 1rem;
    }
}

.install-app-btn {
    background: linear-gradient(135deg, #7B4BFF, #5d3dff);
    color: #fff;
    border: none;
    border-radius: 100px;
    padding: 10px 28px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    margin: 10px 0;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 2px 8px rgba(123,75,255,0.08);
    transition: background 0.2s, transform 0.2s;
}
.install-app-btn:hover {
    background: #5d3dff;
    transform: scale(1.04);
}