/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, Arial, Helvetica, sans-serif;
    background-color: #f5f5f5;
    padding: 20px;
    color: #333;
    line-height: 1.4;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
}

.header {
    padding: 12px;
    background-color: #4285f4;
    color: white;
    text-align: center;
}

h1 {
    font-size: 24px;
    margin-bottom: 10px;
}

.translation-panels {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    min-height: 300px;
}

.panel {
    flex: 1 1 50%;
    padding: 20px;
    position: relative;
    border-right: 0px solid #e0e0e0;
}

.panel:last-child {
    border-right: none;
}

.language-bar {
    width: 100%;
    margin-bottom: 15px;
    overflow: hidden;
}

.language-select {
    width: 99%;
    padding: 8px 12px;
    margin: 2px;
    border-radius: 4px;
    border: 1px solid #ddd;
    background-color: #f9f9f9;
    font-size: 14px;
    cursor: pointer;
    appearance: menulist; /* Ensuring dropdown appears correctly in Safari */
}

.swap-btn {
    margin: 0 15px;
    width: 40px;
    height: 40px;
    border-radius: 20px;
    background-color: #f1f1f1;
    border: 1px solid #ddd;
    cursor: pointer;
    display: inline-block;
    text-align: center;
    line-height: 40px;
    vertical-align: middle;
    transition: background-color 0.2s;
}

.swap-btn:hover {
    background-color: #e5e5e5;
}

.textarea-container {
    width: 100%;
    position: relative;
}

/* Update textarea and output-area font size */
textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 18px; /* Increased from 16px */
    resize: none;
    overflow: auto;
    font-family: -apple-system, BlinkMacSystemFont, Arial, Helvetica, sans-serif;
}

.output-area {
    width: 100%;
    min-height: 150px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 18px; /* Increased from 16px */
    background-color: #f9f9f9;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.script-selection {
    margin-bottom: 10px;
    display: block;
    width: 99%;
    overflow: hidden;
}

.script-select {
    margin-left: 10px;
    padding: 6px 10px;
    border-radius: 4px;
    border: 1px solid #ddd;
    background-color: #f9f9f9;
    font-size: 14px;
    cursor: pointer;
    appearance: menulist; /* Ensuring dropdown appears correctly in Safari */
}

.script-select:disabled {
    background-color: #eee;
    color: #999;
    cursor: not-allowed;
}

select option:disabled {
    color: #999;
    font-style: italic;
}

.btn {
    padding: 8px 16px;
    background-color: #4285f4;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 10px;
    font-size: 14px;
    transition: background-color 0.2s;
    -webkit-appearance: none; /* Fixing button appearance in Safari */
}

/* Remove hover effect */
.btn:hover {
    background-color: #4285f4; /* Same as default */
}

/* Add highlight only on mouse down */
.btn:active {
    background-color: #3367d6; /* Darker blue when pressed */
}

.loading {
    display: none;
    margin-top: 10px;
    font-style: italic;
    color: #666;
}

/* Script-specific font classes */
.Glag-text {
    font-family: 'Glagolica', 'Noto Sans Glagolitic', sans-serif;
}

.Cyrl-text {
    font-family: 'Times New Roman', 'Noto Serif', serif;
}

.Latn-text {
    font-family: 'Arial', 'Noto Sans', sans-serif;
}

.Arab-text {
    font-family: 'Amiri', 'Scheherazade New', serif;
}

.Qslv-text {
    font-family: 'Slavenica', 'Arial', sans-serif;
}

/* Version lang container styles */
.version-lang-container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 10px;
    gap: 15px;
}

.version-info {
    font-size: 0.9em;
    opacity: 0.8;
}

.language-selector {
    background-color: rgba(255, 255, 255, 0.2);
    padding: 5px 10px;
    border-radius: 5px;
    display: none; /* Hide UI language box */
    flex-direction: row;
    align-items: center;
    gap: 8px;
}

.language-selector label {
    color: white;
    font-size: 0.9em;
    white-space: nowrap;
}

.language-selector select {
    padding: 3px 5px;
    border-radius: 3px;
    border: 1px solid #ccc;
    background-color: white;
    font-size: 0.9em;
}

/* Safari-specific fixes */
@supports (-webkit-touch-callout: none) {
    select {
        background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23333'><path d='M3,4 L9,4 L6,8 Z'/></svg>");
        background-repeat: no-repeat;
        background-position: right 8px center;
        background-size: 12px;
        padding-right: 25px;
    }
    
    textarea, select, button {
        -webkit-appearance: none;
        border-radius: 4px;
    }
    
    /* Safari 17 specific fixes */
    @media not all and (min-resolution:.001dpcm) { 
        @supports (-webkit-appearance:none) and (stroke-color:transparent) {
            /* Fix Safari 17 grid layout issues */
            .grid-container {
                display: -webkit-grid;
                display: grid;
                grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
                grid-gap: 20px;
            }
            
            /* Fix Safari flexbox issues */
            .flex-container {
                display: -webkit-box;
                display: -webkit-flex;
                display: flex;
                -webkit-flex-wrap: wrap;
                flex-wrap: wrap;
            }
            
            /* Fix Safari sticky position */
            .sticky-header {
                position: -webkit-sticky;
                position: sticky;
                top: 0;
                z-index: 100;
            }
        }
    }
}

/* RTL Support */
[lang="ar"], [lang="ar-classic"], 
[lang="fa"], [lang="fa-AF"], [lang="fa-classic"], 
[lang="he"], [lang="he-classic"] {
    direction: rtl;
    text-align: right;
}

/* Improved responsive design */
@media (max-width: 768px) {
    /* Remove margins and padding for mobile */
    html, body {
        padding: 0;
        margin: 0;
        -webkit-text-size-adjust: 100%; /* Prevent iOS text size adjustment */
    }
    
    .container {
        margin: 0;
        padding: 0;
        max-width: 100%;
        width: 100%;
        border-radius: 0;
        box-shadow: none;
        overflow: hidden;
    }
    
    .translation-panels {
        flex-direction: column;
        margin: 0;
        width: 100%;
    }
    
    .panel {
        flex: 1 1 100%;
        border-right: none;
        border-bottom: 1px solid #e0e0e0;
        padding: 10px;
        margin: 0;
        width: 100%;
        box-sizing: border-box;
    }
    
    .panel:last-child {
        border-bottom: none;
    }
    
    /* Ensure all menus and options fit within screen */
    .language-bar {
        display: block;
        margin-bottom: 10px;
        width: 100%;
        box-sizing: border-box;
    }
    
    .language-select {
        width: 100%;
        max-width: 100%;
        margin: 2px 0;
        box-sizing: border-box;
        font-size: 16px; /* Optimal size to prevent iOS zoom */
    }
    
    .script-selection {
        margin-bottom: 5px;
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
    }
    
    .script-select {
        flex-grow: 1;
        width: auto;
        margin-left: 5px;
        margin-right: 0;
        font-size: 16px; /* Optimal size to prevent iOS zoom */
    }
    
    /* Optimize buttons and controls */
    .swap-btn {
        transform: rotate(90deg);
        margin: 5px auto;
        display: block;
    }
    
    .text-options-buttons {
        margin-left: 0 !important;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    
    .icon-button {
        padding: 8px !important; /* Larger touch target */
    }
    
    /* Language options */
    .language-specific-options {
        width: 100% !important;
        max-width: 100%;
        box-sizing: border-box;
        /* Removing overflow: visible which was causing issues */
    }
    
    /* Fix option containers */
    .options-animated {
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Make sure expanded state works correctly */
    .options-animated.expanded {
        max-height: 2000px !important; /* Increased height to accommodate all options */
        opacity: 1 !important;
        padding: 12px !important;
        margin-bottom: 10px !important;
        border-width: 1px !important;
        overflow: visible !important; /* Only make visible after expansion */
    }
    
    /* Radio button groups */
    [class*="Container"] div {
        width: 100%;
        box-sizing: border-box;
    }
    
    /* Fix radio groups and checkboxes */
    input[type="radio"],
    input[type="checkbox"] {
        width: auto;
        min-width: 16px;
        height: 16px;
    }
    
    /* Ensure labels don't overflow */
    label {
        max-width: 85%;
        display: inline-block;
        vertical-align: middle;
    }
    
    /* Fix replacement menus */
    .replacement-menu {
        max-width: 90vw !important; /* Ensure menu doesn't exceed viewport */
        left: 5vw !important; /* Position menu with margins */
        right: 5vw !important;
        box-sizing: border-box;
    }
    
    /* Fix dropdown widths */
    select {
        max-width: 100%;
        width: 100%;
    }
    
    /* Header and text elements */
    .version-lang-container {
        flex-direction: column;
        gap: 5px;
        margin-top: 5px;
        width: 100%;
    }
    
    .language-selector {
        width: 100%;
        justify-content: center;
        margin: 0;
        padding: 3px 5px;
        box-sizing: border-box;
    }
    
    .language-selector select {
        max-width: 70%;
    }
    
    h1 {
        margin-bottom: 5px;
        font-size: 20px;
    }
    
    textarea, .output-area, .notes-content {
        border-radius: 0;
        min-height: 120px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        font-size: 18px; /* Increased from 16px for better readability */
        line-height: 1.5; /* Improved line spacing for readability */
    }
}

/* Override the iPhone safe area settings for mobile */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        html, body {
            padding: 0;
        }
        
        /* Fix notch and rounded corner issues on newer devices */
        .container {
            padding-left: env(safe-area-inset-left, 0);
            padding-right: env(safe-area-inset-right, 0);
            padding-bottom: env(safe-area-inset-bottom, 0);
        }
    }
}

/* Options animation styles - restored for desktop version */
.options-animated {
    transition: max-height 0.3s ease-in-out, 
                opacity 0.25s ease-in-out,
                padding 0.3s ease-in-out,
                margin-bottom 0.3s ease-in-out;
    overflow: hidden;
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    box-sizing: border-box;
    border-width: 0;
    display: block !important; /* Ensure visibility in desktop mode */
}

.options-animated.expanded {
    opacity: 1;
    max-height: 1000px;
    padding: 12px;
    margin-bottom: 10px;
    border-width: 1px;
}

/* Prevent menus from being cut off by viewport boundaries */
.language-specific-options {
    z-index: 100;
    overflow: hidden;
}

/* Fix dropdown positioning */
@media (max-width: 768px) {
    /* Ensure dropdowns appear above other content */
    select {
        position: relative;
        z-index: 10;
    }
    
    /* Fix popup menus */
    .replacement-option {
        padding: 12px; /* Larger touch targets */
    }
    
    /* Prevent fixed-width elements */
    [style*="width"] {
        max-width: 100% !important;
    }
    
    /* Make settings button more responsive */
    #settingsBtn, .icon-button {
        min-width: 32px;
        min-height: 32px;
        z-index: 20;
    }
    
    /* Options panel mobile fix - ONLY apply these in mobile mode */
    .language-specific-options {
        display: none; /* Only hide in mobile mode */
        width: 100% !important;
        padding: 0;
        margin: 0;
        box-sizing: border-box;
    }
    
    .language-specific-options.expanded {
        display: block !important;
        padding: 10px !important;
        margin: 10px 0 !important;
        border: 1px solid #ddd !important;
        background-color: #f9f9f9 !important;
    }
    
    /* Override the desktop animations for mobile */
    .options-animated {
        transition: none !important;
    }
    
    /* Ensure radio buttons and checkboxes are visible */
    input[type="radio"], 
    input[type="checkbox"] {
        opacity: 1 !important;
        position: static !important;
        width: auto !important;
        height: auto !important;
        appearance: auto !important;
        -webkit-appearance: auto !important;
    }
}

/* Clearfix */
.clearfix:after {
    content: "";
    display: table;
    clear: both;
}

/* Add to styles.css to preserve newlines in output */
.output-area {
    white-space: pre-wrap;
}

/* Hide UI selection panel always - with maximum specificity */
html body .ui-interface-panel,
html body .ui-container,
html body .ui-panel,
html body .language-options-panel,
html body .ui-selection-panel,
html body .ui-options-panel,
html body .ui-menu,
html body .ui-selection,
html body #ui-interface-panel,
html body #ui-container,
html body #ui-panel,
html body #language-options-panel,
html body #ui-selection-panel,
html body #ui-options-panel,
html body #ui-menu,
html body #ui-selection,
html body div[class*="ui-"],
html body div[id*="ui-"],
html body [class*="interface-menu"],
html body [id*="interface-menu"],
html body .interface-menu-panel {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    height: 0 !important;
    width: 0 !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
    position: absolute !important;
    pointer-events: none !important;
    z-index: -1 !important;
    clip: rect(0, 0, 0, 0) !important;
    clip-path: inset(50%) !important;
}

/* Ensure newlines are preserved in notes content */
.notes-content {
    white-space: pre-wrap;       /* Preserve newlines and wrap text */
    word-wrap: break-word;       /* Break long words */
    overflow-wrap: break-word;   /* Alternative to word-wrap for better browser support */
}


/* 
 * Additional CSS overrides to ensure info and download buttons
 * are properly displayed in non-mobile mode
 */

/* Ensure buttons are visible on larger screens */
@media (min-width: 481px) {
    .info-button, .download-button {
        display: flex !important;
        visibility: visible !important;
    }
}


/* 
 * Force visibility styles for info and download buttons
 * Add this file to your HTML to ensure buttons are visible in non-mobile mode
 */

/* Force buttons to be visible in non-mobile mode with maximum specificity */
@media (min-width: 769px) {
    body .info-button, 
    .header .info-button,
    .version-lang-container .info-button {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        position: relative !important;
        z-index: 9999 !important;
        margin-left: 10px !important;
        background-color: transparent !important;
    }
    
    /* Hide download button */
    body .download-button,
    .header .download-button,
    .version-lang-container .download-button {
        display: none !important;
    }
    
    /* Ensure buttons have correct styles */
    body .info-button,
    body .download-button {
        border: none !important;
        cursor: pointer !important;
        padding: 5px !important;
        color: white !important;
        border-radius: 3px !important;
        align-items: center !important;
        justify-content: center !important;
    }
    
    /* Ensure SVG icons are visible */
    body .info-button svg,
    body .download-button svg {
        fill: none !important;
        stroke: currentColor !important;
        width: 24px !important;
        height: 24px !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* Ensure the info panel can be displayed properly */
    body .info-panel {
        width: 100% !important;
        background-color: white !important;
        z-index: 100 !important;
        position: relative !important;
        box-sizing: border-box !important;
    }
}

/* Only use this rule on actual mobile screens */
@media (max-width: 768px) {
    body .info-button, 
    body .download-button,
    body .info-panel {
        display: none !important;
    }
}

/* Safari-specific compatibility fixes */
@supports (-webkit-touch-callout: none) {
    /* Fix button color transitions */
    button, .btn, #copyBtn {
        -webkit-transition: none !important;
        transition: none !important;
    }
    
    /* Ensure copy button never turns green */
    #copyBtn.mobile-copy-btn {
        background-color: #4285f4 !important; 
    }
    
    #copyBtn.mobile-copy-btn:active,
    #copyBtn.mobile-copy-btn:hover,
    #copyBtn.mobile-copy-btn:focus {
        background-color: #3367d6 !important;
        color: white !important;
    }
    
    /* Force hardware acceleration for smoother transitions */
    #copyBtn.mobile-copy-btn {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
    
    /* Override any other styles that might set the button to green */
    #copyBtn.mobile-copy-btn[style*="background-color: #4caf50"],
    #copyBtn.mobile-copy-btn[style*="background-color:rgb(76, 175, 80)"] {
        background-color: #3367d6 !important;
    }
}

/* Global override for copy buttons to ensure they never turn green */
button[id="copyBtn"], 
#copyBtn, 
.copy-btn, 
.mobile-copy-btn {
    background-color: #4285f4 !important;
}

button[id="copyBtn"]:active, 
#copyBtn:active, 
.copy-btn:active, 
.mobile-copy-btn:active {
    background-color: #3367d6 !important;
}

/* Ensure copy button always remains visible in mobile mode */
@media (max-width: 768px) {
    #copyBtn.mobile-copy-btn {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
}

/* Safari-specific forced visibility */
@supports (-webkit-touch-callout: none) {
    @media (max-width: 768px) {
        #copyBtn.mobile-copy-btn {
            display: block !important;
            visibility: visible !important;
            opacity: 1 !important;
            position: relative !important;
            z-index: 10 !important;
        }
    }
}