:root {
    /* Light mode colors */
    --bg-gradient-start: #667eea;
    --bg-gradient-end: #764ba2;
    --container-bg: #fff;
    --container-shadow: rgba(0, 0, 0, 0.1);
    --text-primary: #333;
    --text-secondary: #666;
    --text-muted: #555;
    --primary-color: #4CAF50;
    --primary-hover: #45a049;
    --secondary-color: #f44336;
    --secondary-hover: #d32f2f;
    --tertiary-color: #2196F3;
    --tertiary-hover: #1976D2;
    --border-color: #e0e0e0;
    --border-color-focus: #4CAF50;
    --input-bg: #f9f9f9;
    --input-border: #ddd;
    --button-bg: #e0e0e0;
    --button-text: #666;
    --success-bg: #e8f5e8;
    --success-border: #4CAF50;
    --success-text: #4CAF50;
    --error-bg: #ffebee;
    --error-border: #f44336;
    --error-text: #f44336;
    --info-bg: #e3f2fd;
    --info-text: #1976D2;
    --disabled-bg: #f0f0f0;
    --disabled-border: #ccc;
    --disabled-text: #666;
    --white: #fff;
}

[data-theme="dark"] {
    /* Dark mode colors */
    --bg-gradient-start: #1a1a2e;
    --bg-gradient-end: #16213e;
    --container-bg: #1e1e1e;
    --container-shadow: rgba(0, 0, 0, 0.3);
    --text-primary: #e0e0e0;
    --text-secondary: #b0b0b0;
    --text-muted: #888;
    --primary-color: #6BC76E;
    --primary-hover: #5fb862;
    --secondary-color: #f66;
    --secondary-hover: #e55;
    --tertiary-color: #4FC3F7;
    --tertiary-hover: #29B6F6;
    --border-color: #333;
    --border-color-focus: #6BC76E;
    --input-bg: #2a2a2a;
    --input-border: #404040;
    --button-bg: #333;
    --button-text: #ccc;
    --success-bg: #1b2f1c;
    --success-border: #6BC76E;
    --success-text: #6BC76E;
    --error-bg: #2f1b1b;
    --error-border: #f66;
    --error-text: #f66;
    --info-bg: #1b252f;
    --info-text: #4FC3F7;
    --disabled-bg: #2a2a2a;
    --disabled-border: #444;
    --disabled-text: #666;
    --white: #2a2a2a;
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    transition: all 0.3s ease;
}

/* App Layout */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styles */
.sidebar {
    width: 220px;
    background: var(--container-bg);
    border-right: 2px solid var(--border-color);
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px var(--container-shadow);
    transition: all 0.3s ease;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.sidebar-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    gap: 0.5rem;
}

.sidebar-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
    text-align: center;
}

.sidebar-menu {
    flex: 1;
    padding: 1rem 0;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    transition: all 0.3s ease;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    font-size: 0.9rem;
}

.nav-item:hover {
    background: var(--input-bg);
    color: var(--primary-color);
}

.nav-item.active {
    background: var(--primary-color);
    color: var(--white);
    border-right: 4px solid var(--primary-hover);
}

.nav-icon {
    font-size: 1.1rem;
    margin-right: 0.5rem;
    min-width: 20px;
}

.nav-text {
    font-weight: 500;
}


/* Main Container */
.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-header {
    background: var(--container-bg);
    border-bottom: 2px solid var(--primary-color);
    padding: 1.5rem 2rem;
}

.header-content {
    text-align: center;
}

.feature-container {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
    background: var(--container-bg);
    box-shadow: 0 0 20px var(--container-shadow);
    border-radius: 10px;
    margin-top: 20px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

header {
    margin-bottom: 30px;
    padding: 20px 0;
    border-bottom: 2px solid var(--primary-color);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.language-selector {
    position: relative;
}

.language-select {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 60px;
}

.language-select:hover {
    border-color: var(--border-color-focus);
}

.language-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.2);
}

.title-section {
    flex: 1;
}

.title-section h1 {
    color: var(--primary-color);
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-align: center;
}

.title-section p {
    font-size: 1.1rem;
    color: var(--text-secondary);
    max-width: 800px;
    margin: 0 auto;
    text-align: center;
}

.theme-toggle {
    display: flex;
    align-items: center;
}

.theme-toggle-btn {
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
}

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

.theme-toggle-btn:hover .theme-icon {
    transform: rotate(180deg);
}

.theme-icon {
    transition: transform 0.3s ease;
}

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 40px;
}

.input-section, .output-section {
    background: var(--input-bg);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.tab-buttons {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.tab-btn {
    padding: 10px 20px;
    border: none;
    background: var(--button-bg);
    color: var(--button-text);
    border-radius: 5px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
}

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

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

.input-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--container-bg);
    border-radius: 5px;
    border: 1px solid var(--input-border);
    transition: all 0.3s ease;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-group label {
    font-weight: 500;
    color: var(--text-muted);
}

.control-group select {
    padding: 5px 10px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    font-size: 14px;
    background: var(--container-bg);
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.control-group select:focus {
    outline: none;
    border-color: var(--border-color-focus);
}

.control-group input[type="checkbox"] {
    transform: scale(1.2);
    accent-color: var(--primary-color);
}

.file-upload-section {
    margin-bottom: 20px;
}

.file-upload-label {
    display: inline-block;
    padding: 10px 20px;
    background: var(--tertiary-color);
    color: var(--white);
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.3s ease;
}

.file-upload-label:hover {
    background: var(--tertiary-hover);
}

.file-upload-label input[type="file"] {
    display: none;
}

.file-info {
    margin-top: 10px;
    padding: 10px;
    background: var(--info-bg);
    border-radius: 4px;
    font-size: 14px;
    color: var(--info-text);
    transition: all 0.3s ease;
}

textarea {
    width: 100%;
    min-height: 200px;
    padding: 15px;
    border: 2px solid var(--input-border);
    border-radius: 5px;
    font-family: 'Courier New', monospace;
    font-size: 14px;
    resize: vertical;
    transition: all 0.3s ease;
    background: var(--container-bg);
    color: var(--text-primary);
}

textarea:focus {
    outline: none;
    border-color: var(--border-color-focus);
}

textarea::placeholder {
    color: var(--text-secondary);
}

.action-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.action-btn {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

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

.action-btn.primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

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

.action-btn.secondary:hover {
    background: var(--secondary-hover);
    transform: translateY(-1px);
}

.output-section h3 {
    color: var(--primary-color);
    margin-bottom: 15px;
}

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

.output-controls {
    display: flex;
    gap: 10px;
}

.control-btn {
    padding: 8px 16px;
    border: 1px solid var(--primary-color);
    background: var(--container-bg);
    color: var(--primary-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

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

#binary-output {
    padding: 40px;
    text-align: center;
    background: var(--disabled-bg);
    border: 2px dashed var(--disabled-border);
    border-radius: 5px;
    color: var(--disabled-text);
    transition: all 0.3s ease;
}

.info-section {
    background: var(--input-bg);
    padding: 30px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

.info-section h2 {
    color: var(--primary-color);
    margin-bottom: 15px;
    font-size: 1.8rem;
}

.info-section h3 {
    color: var(--primary-color);
    margin: 20px 0 10px 0;
    font-size: 1.3rem;
}

.info-section p {
    margin-bottom: 15px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.info-section ul {
    list-style: none;
    padding-left: 0;
}

.info-section li {
    padding: 8px 0;
    color: var(--text-secondary);
    position: relative;
    padding-left: 25px;
}

.info-section li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: var(--primary-color);
    font-weight: bold;
}

.error {
    color: var(--error-text);
    background: var(--error-bg);
    border: 1px solid var(--error-border);
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.success {
    color: var(--success-text);
    background: var(--success-bg);
    border: 1px solid var(--success-border);
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
    font-size: 14px;
    transition: all 0.3s ease;
}

@media (max-width: 768px) {
    .app-layout {
        flex-direction: column;
        min-height: 100vh;
    }
    
    .sidebar {
        width: 100%;
        position: sticky;
        top: 0;
        z-index: 100;
        order: 1;
        border-right: none;
        border-bottom: 2px solid var(--border-color);
        box-shadow: 0 2px 10px var(--container-shadow);
        background: var(--container-bg);
    }
    
    .sidebar-header {
        padding: 0.75rem 1rem;
    }
    
    .sidebar-menu {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        padding: 0 0.5rem;
        margin: 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        gap: 0;
        width: 100%;
    }
    
    .sidebar-menu::-webkit-scrollbar {
        display: none;
    }
    
    .nav-item {
        flex-shrink: 0;
        min-width: 80px;
        max-width: 120px;
        padding: 0.75rem 0.5rem;
        text-align: center;
        border-right: none;
        border-bottom: 3px solid transparent;
        white-space: nowrap;
        font-size: 12px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        text-decoration: none;
        color: var(--text-secondary);
    }
    
    .nav-item:hover {
        background-color: var(--input-bg);
    }
    
    .nav-item.active {
        border-right: none;
        border-bottom: 3px solid var(--primary-hover);
        background-color: var(--input-bg);
        color: var(--primary-color);
    }
    
    .nav-icon {
        font-size: 16px;
        margin-right: 0;
        margin-bottom: 2px;
    }
    
    .nav-text {
        font-size: 10px;
        font-weight: 500;
        line-height: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 100%;
    }
    
    .sidebar-controls {
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.5rem;
        gap: 1rem;
    }
    
    .theme-toggle-btn,
    .language-select {
        font-size: 14px;
        padding: 0.5rem;
        min-height: 44px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .main-container {
        order: 2;
        flex: 1;
        overflow-x: hidden;
    }
    
    .feature-container {
        padding: 1rem;
    }
    
    .main-content {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    
    .title-section h1 {
        font-size: 2rem;
    }
    
    .input-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .control-group {
        justify-content: space-between;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .output-header {
        flex-direction: column;
        gap: 15px;
        align-items: stretch;
    }
}

/* Image Editor Specific Styles */
.editor-layout {
    display: flex;
    flex-direction: column;
    gap: 20px;
    max-width: 100%;
}

.top-controls {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
    background: var(--input-bg);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.file-upload-section {
    flex: 0 0 auto;
}

.tool-section {
    flex: 0 0 auto;
}

.control-section {
    flex: 1;
    display: flex;
    gap: 20px;
    align-items: center;
}

.canvas-size-section {
    flex: 0 0 auto;
}

.zoom-section {
    flex: 0 0 auto;
}

.canvas-section {
    flex: 1;
    background: var(--input-bg);
    border-radius: 8px;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 500px;
}

.canvas-container {
    position: relative;
    max-width: 100%;
    max-height: 70vh;
    overflow: auto;
    border: 2px solid var(--border-color);
    border-radius: 4px;
    background: white;
}

#image-canvas {
    display: block;
    max-width: 100%;
    cursor: crosshair;
    touch-action: none; /* Prevent default touch behaviors like scrolling */
    -webkit-touch-callout: none; /* Disable callout on iOS */
    -webkit-user-select: none; /* Disable text selection */
    user-select: none;
}


.bottom-controls {
    display: flex;
    gap: 15px;
    justify-content: center;
    background: var(--input-bg);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.tool-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--button-bg);
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.tool-btn:hover {
    background: var(--primary-color);
    border-color: var(--primary-color);
    transform: scale(1.05);
}

.tool-btn.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.control-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    min-width: 50px;
}

#color-picker {
    width: 40px;
    height: 30px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
}

#brush-size {
    flex: 1;
    max-width: 100px;
}

#brush-size-value {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 20px;
    text-align: center;
}

#text-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--container-bg);
    color: var(--text-primary);
    font-size: 12px;
}

.zoom-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.zoom-buttons button {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

#zoom-level {
    font-size: 12px;
    color: var(--text-secondary);
    min-width: 50px;
    text-align: center;
}

.canvas-size-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.size-presets select {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--container-bg);
    color: var(--text-primary);
    font-size: 12px;
    min-width: 120px;
}

.size-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
}

.size-input-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.size-input-group label {
    font-size: 11px;
    color: var(--text-secondary);
    min-width: 15px;
    font-weight: 500;
}

.size-input-group input {
    width: 60px;
    padding: 3px 6px;
    border: 1px solid var(--border-color);
    border-radius: 3px;
    background: var(--container-bg);
    color: var(--text-primary);
    font-size: 11px;
    text-align: center;
}

#apply-canvas-size {
    font-size: 11px;
    padding: 4px 8px;
    min-width: auto;
}

/* Mobile responsive improvements */
@media (max-width: 768px) {
    .feature-container {
        padding: 0.5rem;
    }
    
    .main-header {
        padding: 1rem 0.5rem;
    }
    
    .title-section h1 {
        font-size: 1.5rem;
    }
    
    .title-section p {
        font-size: 0.9rem;
    }
    
    /* Image editor mobile improvements */
    .top-controls {
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
        padding: 10px;
    }
    
    .file-upload-section {
        order: 1;
    }
    
    .tool-section {
        order: 2;
    }
    
    .control-section {
        order: 3;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    
    .canvas-size-section {
        order: 4;
    }
    
    .zoom-section {
        order: 5;
    }
    
    .canvas-section {
        min-height: 300px;
        padding: 10px;
    }
    
    .canvas-container {
        max-height: 60vh;
    }
    
    .tool-buttons {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .tool-btn {
        min-width: 50px;
        min-height: 50px;
        font-size: 18px;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .zoom-buttons {
        justify-content: center;
        gap: 10px;
    }
    
    .zoom-buttons button {
        min-width: 44px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    .bottom-controls {
        flex-direction: row;
        justify-content: space-around;
        padding: 15px 10px;
        gap: 10px;
    }
    
    .bottom-controls button {
        flex: 1;
        max-width: 150px;
        min-height: 44px;
        touch-action: manipulation;
    }
    
    /* Canvas size controls mobile */
    .canvas-size-controls {
        gap: 10px;
    }
    
    .size-inputs {
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }
    
    .size-input-group input {
        width: 70px;
        font-size: 14px;
        padding: 6px;
        min-height: 36px;
    }
    
    .size-presets select {
        font-size: 14px;
        padding: 6px 8px;
        min-height: 36px;
        width: 100%;
    }
    
    #apply-canvas-size {
        min-height: 36px;
        padding: 6px 12px;
    }
    
    /* Control inputs mobile-friendly */
    #color-picker {
        width: 50px;
        height: 40px;
        min-height: 40px;
    }
    
    #brush-size {
        min-height: 36px;
    }
    
    #text-input {
        font-size: 16px; /* Prevents zoom on iOS */
        min-height: 36px;
        padding: 8px;
    }
    
    .control-group {
        margin-bottom: 15px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .control-group label {
        font-size: 14px;
        min-width: auto;
        flex-basis: 100%;
    }
    
    /* File upload mobile */
    .file-upload-label {
        padding: 12px;
        text-align: center;
        font-size: 14px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .file-info {
        font-size: 12px;
        padding: 8px;
        text-align: center;
    }
}