/* Main Styles */
:root {
    --primary-color: #2D7D46;
    --secondary-color: #7D2D5E;
    --bg-color: #2C2C2C;
    --panel-bg: #1A1A1A;
    --text-color: #E0E0E0;
    --border-color: #444;
}

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

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on mobile */
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

header {
    text-align: center;
    margin-bottom: 20px;
}

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

.subtitle {
    font-size: 1.1rem;
    opacity: 0.8;
}

/* Tabs */
.tabs {
    display: flex;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto; /* Allow horizontal scrolling on small screens */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.tab-btn {
    background: none;
    border: none;
    color: var(--text-color);
    padding: 12px 30px;
    font-size: 1.1rem;
    cursor: pointer;
    position: relative;
    opacity: 0.7;
    transition: opacity 0.3s;
    white-space: nowrap; /* Prevent wrapping */
    flex: 1; /* Equal width tabs */
}

.tab-btn:hover {
    opacity: 1;
}

.tab-btn:active {
    background-color: rgba(255, 255, 255, 0.05); /* Subtle feedback on touch */
}

.tab-btn.active {
    opacity: 1;
}

.tab-btn.active:after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 3px;
    background-color: var(--primary-color);
}

.tab-btn[data-tab="decode"].active:after {
    background-color: var(--secondary-color);
}

.tab-content {
    display: none;
    flex: 1;
}

.tab-content.active {
    display: block;
}

/* Main Content Layout */
.main-content {
    display: flex;
    flex-direction: column; /* Stack on mobile */
    gap: 20px;
    margin-bottom: 20px;
}

.left-panel, .right-panel {
    padding: 20px;
    background-color: var(--panel-bg);
    border-radius: 8px;
    width: 100%; /* Full width on mobile */
}

h2 {
    margin-bottom: 20px;
    font-size: 1.4rem;
}

/* Form Elements */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
}

.file-input {
    display: flex;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
    flex-wrap: wrap; /* Allow wrapping on very small screens */
}

.file-input input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 0.1px;
    height: 0.1px;
}

.browse-btn {
    background-color: var(--border-color);
    color: var(--text-color);
    border: none;
    padding: 12px 15px; /* Larger touch target */
    cursor: pointer;
    transition: background-color 0.3s;
    touch-action: manipulation; /* Optimization for touch */
    min-width: 80px; /* Ensure minimum button size for touch */
}

.browse-btn:hover {
    background-color: #555;
}

.browse-btn:active {
    background-color: #666; /* Visual feedback on touch */
}

.file-name {
    padding: 12px 15px;
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.radio-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap; /* Allow wrapping on very small screens */
}

.radio {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 8px 0; /* Larger touch target */
    min-height: 44px; /* Minimum height for touch targets */
}

.radio input {
    margin-right: 8px;
    width: 20px; /* Larger for touch */
    height: 20px; /* Larger for touch */
}

textarea {
    width: 100%;
    background-color: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-color);
    padding: 12px;
    font-family: inherit;
    resize: vertical;
    min-height: 100px;
    font-size: 16px; /* Prevent zoom on iOS */
}

.small-text {
    font-size: 0.85rem;
    opacity: 0.7;
    margin-top: 5px;
    font-style: italic;
}

.info-box {
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 15px;
    margin-bottom: 20px;
}

.info-box h3 {
    font-size: 1rem;
    margin-bottom: 8px;
}

.info-box ul {
    padding-left: 20px;
}

/* Buttons */
.primary-btn, .secondary-btn {
    display: block;
    width: 100%;
    padding: 15px; /* Larger for touch */
    border: none;
    border-radius: 4px;
    color: white;
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s;
    touch-action: manipulation; /* Optimization for touch */
    min-height: 50px; /* Minimum height for touch targets */
}

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

.primary-btn:hover {
    background-color: #235E35;
}

.primary-btn:active {
    background-color: #1a472a; /* Visual feedback on touch */
}

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

.secondary-btn:hover {
    background-color: #5E2346;
}

.secondary-btn:active {
    background-color: #461a34; /* Visual feedback on touch */
}

/* Preview */
.preview-container {
    height: 250px; /* Smaller on mobile */
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 10px;
}

#encode-preview-image, #decode-preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 100;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    overflow-y: auto; /* Allow scrolling on mobile */
}

.modal-content {
    position: relative;
    background-color: var(--panel-bg);
    margin: 10% auto;
    padding: 20px;
    width: 90%; /* Wider on mobile */
    max-width: 700px;
    border-radius: 8px;
    max-height: 80%;
    overflow-y: auto;
}

.close-modal {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 24px;
    cursor: pointer;
    padding: 10px; /* Larger touch target */
    line-height: 24px;
    height: 44px;
    width: 44px;
    text-align: center;
}

#modal-body {
    margin-top: 20px;
}

#modal-body pre {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 4px;
    overflow-x: auto;
    white-space: pre-wrap;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Loading Overlay */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.spinner {
    border: 5px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top: 5px solid var(--primary-color);
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 15px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Footer */
footer {
    margin-top: auto;
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
}

#status-text {
    opacity: 0.7;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Responsive */
@media (min-width: 768px) {
    .main-content {
        flex-direction: row; /* Side-by-side on tablets and up */
    }
    
    .left-panel {
        flex: 1;
    }
    
    .right-panel {
        flex: 0 0 300px;
        width: auto;
    }
    
    .container {
        padding: 20px;
    }
    
    h1 {
        font-size: 2.5rem;
    }
    
    .preview-container {
        height: 300px; /* Taller on desktop */
    }
}

/* Small phones */
@media (max-width: 380px) {
    .tab-btn {
        padding: 10px 20px;
        font-size: 1rem;
    }
    
    h1 {
        font-size: 1.8rem;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    .preview-container {
        height: 200px;
    }
    
    .left-panel, .right-panel {
        padding: 15px;
    }
}

/* Fix for iOS input zoom */
@media screen and (-webkit-min-device-pixel-ratio:0) { 
    select,
    textarea,
    input[type="text"],
    input[type="password"],
    input[type="datetime"],
    input[type="datetime-local"],
    input[type="date"],
    input[type="month"],
    input[type="time"],
    input[type="week"],
    input[type="number"],
    input[type="email"],
    input[type="url"],
    input[type="search"],
    input[type="tel"],
    input[type="color"] {
        font-size: 16px;
    }
}