/* ===== JT-EDIT DESIGN SYSTEM - SOLID ARCHITECTURE ===== */

/* ===== DESIGN TOKENS (Single Source of Truth) ===== */
:root {
    /* Spacing System */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;

    /* Typography Scale */
    --font-xs: 10px;
    --font-sm: 11px;
    --font-base: 12px;
    --font-md: 14px;
    --font-lg: 16px;
    --font-xl: 20px;
    --font-2xl: 24px;

    /* Color Palette */
    --color-primary: #2196F3;
    --color-secondary: #FF9800;
    --color-success: #4CAF50;
    --color-warning: #FFC107;
    --color-error: #f44336;
    --color-info: #00BCD4;

    /* Neutral Colors */
    --color-white: #FFFFFF;
    --color-gray-50: #F8F9FA;
    --color-gray-100: #F5F5F5;
    --color-gray-200: #E0E0E0;
    --color-gray-300: #CCCCCC;
    --color-gray-400: #BBBBBB;
    --color-gray-500: #999999;
    --color-gray-600: #666666;
    --color-gray-700: #555555;
    --color-gray-800: #333333;
    --color-gray-900: #000000;

    /* Interactive Colors */
    --color-hover: var(--color-gray-200);
    --color-active: var(--color-primary);
    --color-focus: rgba(33, 150, 243, 0.2);
    --color-disabled: var(--color-gray-300);

    /* Shadow System */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.15);

    /* Border Radius */
    --radius-sm: 2px;
    --radius-md: 4px;
    --radius-lg: 8px;

    /* Z-Index Scale */
    --z-dropdown: 1000;
    --z-modal: 2000;
    --z-tooltip: 3000;

    /* Responsive Scaling */
    --scale-factor: clamp(0.75, 1 + 0.02vw, 1.25);
    --toolbar-height: calc(40px * var(--scale-factor));
    --button-size: calc(32px * var(--scale-factor));
    --icon-size: calc(16px * var(--scale-factor));
}

/* ===== RESET & BASE STYLES ===== */
* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: var(--font-base);
    line-height: 1.4;
    color: var(--color-gray-800);
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    
    /* Modern gradient background */
    background: linear-gradient(135deg, var(--color-gray-50) 0%, var(--color-white) 50%, var(--color-gray-50) 100%);
    
    /* Subtle pixel grid pattern overlay */
    background-image: 
        radial-gradient(circle at 1px 1px, rgba(33, 150, 243, 0.08) 1px, transparent 0);
    background-size: 20px 20px;
    background-attachment: fixed;
    
    /* Subtle texture overlay */
    position: relative;
}

body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="subtle-grid" width="4" height="4" patternUnits="userSpaceOnUse"><rect width="4" height="4" fill="none"/><rect x="0" y="0" width="1" height="1" fill="rgba(33,150,243,0.02)"/></pattern></defs><rect width="100" height="100" fill="url(%23subtle-grid)"/></svg>') repeat;
    pointer-events: none;
    z-index: -1;
}

/* ===== PAGE HEADER STYLES ===== */
.page-header {
    width: 100%;
    text-align: center;
    padding: var(--space-lg) var(--space-xl);
    background: linear-gradient(135deg, var(--color-primary) 0%, #1976D2 100%);
    color: var(--color-white);
    box-shadow: var(--shadow-md);
    margin-bottom: 0;
    position: relative;
    overflow: hidden;
}

.page-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="grid" width="10" height="10" patternUnits="userSpaceOnUse"><path d="M 10 0 L 0 0 0 10" fill="none" stroke="rgba(255,255,255,0.1)" stroke-width="0.5"/></pattern></defs><rect width="100" height="100" fill="url(%23grid)"/></svg>') repeat;
    opacity: 0.3;
    pointer-events: none;
}

.page-header h1 {
    margin: 0;
    font-size: var(--font-2xl);
    font-weight: 700;
    letter-spacing: -0.025em;
    position: relative;
    z-index: 1;
}

.page-header .subtitle {
    margin: var(--space-xs) 0 0 0;
    font-size: var(--font-sm);
    opacity: 0.9;
    font-weight: 400;
    position: relative;
    z-index: 1;
}

/* ===== COMPONENT SYSTEM - BASE CLASSES ===== */

/* Button Base Component */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-sm) var(--space-md);
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    color: var(--color-gray-700);
    font-size: var(--font-base);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: var(--button-size);
    user-select: none;
}

.btn:hover:not(:disabled) {
    background: var(--color-hover);
    border-color: var(--color-gray-400);
}

.btn:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--color-focus);
}

.btn:active:not(:disabled) {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: var(--color-disabled);
}

/* Button Variants */
.btn--primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
}

.btn--primary:hover:not(:disabled) {
    background: #1976D2;
    border-color: #1976D2;
}

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

.btn--secondary:hover:not(:disabled) {
    background: #F57C00;
    border-color: #F57C00;
}

.btn--success {
    background: var(--color-success);
    border-color: var(--color-success);
    color: var(--color-white);
}

.btn--success:hover:not(:disabled) {
    background: #388E3C;
    border-color: #388E3C;
}

/* Button Sizes */
.btn--sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-sm);
    min-height: calc(var(--button-size) * 0.8);
}

.btn--lg {
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-md);
    min-height: calc(var(--button-size) * 1.2);
}

/* Icon Button Component */
.btn--icon {
    padding: var(--space-xs);
    min-width: var(--button-size);
    width: var(--button-size);
    height: var(--button-size);
}

.btn--icon-sm {
    min-width: calc(var(--button-size) * 0.8);
    width: calc(var(--button-size) * 0.8);
    height: calc(var(--button-size) * 0.8);
}

/* Input Component */
.input {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    font-size: var(--font-base);
    color: var(--color-gray-800);
    transition: all 0.2s ease;
    min-height: calc(var(--button-size) * 0.8);
}

.input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-focus);
}

.input--sm {
    padding: 2px var(--space-xs);
    font-size: var(--font-sm);
    min-height: calc(var(--button-size) * 0.7);
}

/* Select Component */
.select {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    font-size: var(--font-base);
    color: var(--color-gray-800);
    cursor: pointer;
    transition: all 0.2s ease;
    min-height: calc(var(--button-size) * 0.8);
}

.select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-focus);
}

.select--sm {
    padding: 2px var(--space-xs);
    font-size: var(--font-sm);
    min-height: calc(var(--button-size) * 0.7);
}

/* ===== TOOLBAR SYSTEM COMPONENTS ===== */

/* Keep existing toolbar styles for top toolbar compatibility */
.toolbar-container {
    display: flex;
    flex-direction: column;
    gap: max(4px, calc(4px * var(--scale-factor)));
    padding: max(12px, calc(12px * var(--scale-factor))) max(12px, calc(12px * var(--scale-factor))) var(--space-xs) max(12px, calc(12px * var(--scale-factor)));
    background: #f8f9fa;
    border-radius: 3px;
    margin: 0 auto;
    width: fit-content;
    max-width: 100%;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.toolbar-row {
    display: flex;
    gap: max(24px, calc(24px * var(--scale-factor)));
    align-items: center;
    flex-wrap: wrap;
    padding: max(8px, calc(8px * var(--scale-factor))) max(12px, calc(12px * var(--scale-factor)));
    background: white;
    border-radius: 2px;
    border: 1px solid #e0e0e0;
    min-height: calc(var(--toolbar-height) + 10px);
}

/* New Toolbar System (SOLID) */
.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    padding: var(--space-sm) var(--space-lg);
    background: var(--color-white);
    border: 1px solid var(--color-gray-200);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin: var(--space-xs) auto;
    width: fit-content;
    max-width: 100%;
    min-height: var(--toolbar-height);
}

/* Toolbar Variants */
.toolbar--primary {
    border-left: 3px solid var(--color-primary);
}

.toolbar--secondary {
    border-left: 3px solid var(--color-secondary);
}

.toolbar--success {
    border-left: 3px solid var(--color-success);
}

.toolbar--warning {
    border-left: 3px solid var(--color-warning);
}

.toolbar--info {
    border-left: 3px solid var(--color-info);
}

/* Tools Row Specific Styling */
.tools-row {
    border-top: 1px solid var(--color-gray-200);
    margin-top: var(--space-xs);
    padding-top: var(--space-sm);
}

/* Group Label Colors for Different Categories */
.tools-group .group-label {
    color: #FF9800; /* Orange for tools (3rd row) */
}

.history-group .group-label {
    color: #FF9800; /* Orange for history tools (3rd row) */
}

.paint-group .group-label {
    color: #FF9800; /* Orange for paint tools (3rd row) */
}

.file-group .group-label {
    color: #2196F3; /* Blue for file operations (1st row) */
}

.view-group .group-label {
    color: #FFC107; /* Yellow for view controls (2nd row) */
}

.canvas-group .group-label {
    color: #2196F3; /* Blue for canvas settings (1st row) */
}

.color-format-group .group-label {
    color: #2196F3; /* Blue for color format (1st row) */
}

.unified-color-group .group-label {
    color: #FFC107; /* Yellow for color selection (2nd row) */
}

/* Tool Group Component */
.tool-group {
    display: flex;
    align-items: center;
    gap: max(10px, calc(10px * var(--scale-factor)));
    min-width: auto;
    padding: 0 max(8px, calc(8px * var(--scale-factor)));
}

.tool-group__label {
    font-weight: 600;
    font-size: var(--font-xs);
    color: var(--color-gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0;
    padding: var(--space-xs) var(--space-md) var(--space-xs) var(--space-xs);
    border-bottom: 1px solid transparent;
    white-space: nowrap;
}

.group-label {
    font-weight: 600;
    font-size: max(10px, calc(10px * var(--scale-factor)));
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.1px;
    margin: 0;
    border-bottom: 1px solid transparent;
    padding: 4px 16px 4px 4px;
    white-space: nowrap;
}

/* Control Group Component */
.control-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.control-pair {
    display: flex;
    flex-direction: column;
    gap: 1px;
    align-items: flex-start;
    padding: 4px 10px 4px 10px;
}

.control-pair label,
.control-pair__label {
    font-size: max(10px, calc(10px * var(--scale-factor)));
    color: #666;
    font-weight: 500;
    line-height: 1;
    margin: 0;
}

/* Keep existing control input styles */
.control-input {
    padding: calc(1px * var(--scale-factor)) calc(3px * var(--scale-factor));
    border: 1px solid #ddd;
    border-radius: 2px;
    font-size: max(12px, calc(12px * var(--scale-factor)));
    background: white;
    transition: border-color 0.2s ease;
    min-width: calc(45px * var(--scale-factor));
    height: calc(18px * var(--scale-factor));
}

.control-input.compact {
    min-width: calc(40px * var(--scale-factor));
    padding: calc(1px * var(--scale-factor)) calc(2px * var(--scale-factor));
    font-size: calc(11px * var(--scale-factor));
    height: calc(16px * var(--scale-factor));
}

.control-input:focus {
    outline: none;
    border-color: #007AFF;
    box-shadow: 0 0 0 1px rgba(0, 122, 255, 0.1);
}

/* Inline controls */
.inline-controls {
    display: flex;
    align-items: center;
    gap: max(10px, calc(10px * var(--scale-factor)));
    flex-wrap: wrap;
    padding: 0 8px;
}

/* Button Group Component */
.btn-group {
    display: flex;
    gap: 2px;
    align-items: center;
}

.btn-group .btn {
    border-radius: 0;
    margin: 0;
}

.btn-group .btn:first-child {
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
}

.btn-group .btn:last-child {
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
}

.btn-group .btn:not(:last-child) {
    border-right: none;
}

/* ===== LEGACY BUTTON STYLES (for compatibility) ===== */
button {
    min-width: 55px;
    min-height: 55px;
    font-size: 25px;
    font-weight: bold;
}

/* Override for toolbar buttons */
.toolbar-container button {
    min-width: calc(26px * var(--scale-factor));
    min-height: calc(23px * var(--scale-factor));
    font-size: calc(15px * var(--scale-factor));
    font-weight: bold;
}

/* Keep existing icon button styles */
.icon-btn-sm {
    background: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 2px;
    padding: calc(1px * var(--scale-factor)) calc(3px * var(--scale-factor));
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: calc(12px * var(--scale-factor));
    font-weight: 500;
    color: #666;
    min-width: calc(18px * var(--scale-factor));
    height: calc(12px * var(--scale-factor));
    line-height: 1;
}

.icon-btn-sm:hover {
    background: #e0e0e0;
    border-color: #bbb;
    color: #333;
}

/* ===== COLOR SYSTEM COMPONENTS ===== */

/* Keep existing unified color selector styles */
.unified-color-selector {
    display: flex;
    gap: 8px;
    align-items: center;
}

.unified-color-selector.compact {
    gap: 6px;
}

.color-preview-container {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px 4px 10px;
}

.color-stack {
    position: relative;
    width: 24px;
    height: 24px;
}

.color-stack.compact {
    width: 20px;
    height: 20px;
}

.foreground-color, .background-color {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 1px solid #ddd;
    border-radius: 2px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.color-stack.compact .foreground-color, 
.color-stack.compact .background-color {
    width: 14px;
    height: 14px;
}

.foreground-color {
    top: 0;
    left: 0;
    background-color: #FFFFFF;
    z-index: 2;
    border-color: #333;
}

.background-color {
    bottom: 0;
    right: 0;
    background-color: #000000;
    z-index: 1;
}

.foreground-color:hover, .background-color:hover {
    transform: scale(1.1);
    border-color: #007AFF;
    z-index: 3;
}

/* ===== ANIMATION CONTROLS ===== */
#controlButtons {
    display: none;
}

#controlButtons.hidden {
    display: none !important;
}

.frame-display {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-weight: 600;
    font-size: var(--font-md);
    color: var(--color-gray-800);
    padding: var(--space-xs) var(--space-sm);
    background: var(--color-gray-100);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-gray-200);
    display: inline-block;
}




/* ===== DIRECTION CONTROLS ===== */
.direction-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    gap: var(--space-xs);
    width: calc(var(--button-size) * 3.5);
    height: calc(var(--button-size) * 3.5);
}

.direction-btn--up {
    grid-column: 2;
    grid-row: 1;
}

.direction-btn--left {
    grid-column: 1;
    grid-row: 2;
}

.direction-btn--right {
    grid-column: 3;
    grid-row: 2;
}

.direction-btn--down {
    grid-column: 2;
    grid-row: 3;
}

/* ===== MODAL & DIALOG SYSTEM ===== */
.modal {
    display: none;
    position: fixed;
    z-index: var(--z-modal);
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.modal--open {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal__content {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 90vw;
    max-height: 90vh;
    overflow: auto;
    animation: modalSlideIn 0.2s ease-out;
    width: 700px;
}

.modal__header {
    padding: var(--space-lg) var(--space-lg) var(--space-md);
    border-bottom: 1px solid var(--color-gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal__title {
    font-size: var(--font-lg);
    font-weight: 600;
    color: var(--color-gray-800);
    margin: 0;
}

.modal__body {
    padding: var(--space-lg);
    max-height: 60vh;
    overflow-y: auto;
}

.modal__footer {
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    border-top: 1px solid var(--color-gray-200);
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
}

/* Help Modal Specific Styles */
.mode-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--color-gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-gray-200);
}

.toggle-label {
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--color-gray-700);
    margin: 0;
}

.mode-toggle-group {
    gap: 0;
}

.mode-toggle-btn {
    border-radius: 0;
    margin: 0;
}

.mode-toggle-btn:first-child {
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
}

.mode-toggle-btn:last-child {
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    border-left: none;
}

.mode-toggle-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: var(--color-white);
}

.help-sections {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
}

/* Mode-specific sections */
.help-section.static-only {
    display: none;
}

.help-section.animation-only {
    display: none;
}

.help-sections.show-static .help-section.static-only {
    display: block;
}

.help-sections.show-animation .help-section.animation-only {
    display: block;
}

.help-section {
    margin-bottom: var(--space-lg);
}

.help-section h3 {
    font-size: var(--font-md);
    font-weight: 600;
    color: var(--color-gray-800);
    margin: 0 0 var(--space-md) 0;
    padding-bottom: var(--space-xs);
    border-bottom: 2px solid var(--color-primary);
}

.shortcut-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.shortcut-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-xs) 0;
}

.shortcut-key {
    font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
    font-size: var(--font-sm);
    font-weight: 600;
    background: var(--color-gray-100);
    color: var(--color-gray-800);
    padding: 2px var(--space-xs);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-gray-300);
    min-width: 80px;
    text-align: center;
    white-space: nowrap;
}

.shortcut-desc {
    font-size: var(--font-sm);
    color: var(--color-gray-700);
    flex: 1;
}

/* Help button styling */
.help-btn {
    background: var(--color-info);
    border-color: var(--color-info);
    color: var(--color-white);
    min-width: calc(var(--button-size) * 0.8);
    height: calc(var(--button-size) * 0.8);
    padding: var(--space-xs);
}

.help-btn:hover {
    background: #0097A7;
    border-color: #0097A7;
}

/* Debug button sizing fix */
.debug-btn {
    min-width: calc(var(--button-size) * 0.8);
    height: calc(var(--button-size) * 0.8);
    padding: var(--space-xs);
}

/* Responsive modal */
@media (max-width: 768px) {
    .modal__content {
        width: 95vw;
        max-height: 95vh;
    }
    
    .help-sections {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }
    
    .modal__header,
    .modal__body,
    .modal__footer {
        padding: var(--space-md);
    }
    
    .shortcut-key {
        min-width: 60px;
        font-size: var(--font-xs);
    }
    
    .shortcut-desc {
        font-size: var(--font-xs);
    }
}

.swapdiag {
    display: none;
    position: fixed;
    z-index: var(--z-modal);
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
}

.swapdiag-content {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-xl);
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border: 2px solid var(--color-primary);
    animation: modalSlideIn 0.2s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.bigbutton {
    font-size: 20px;
    font-weight: bold;
    text-align: center;
    margin: auto;
    min-width: 3ch;
}

/* ===== TOGGLE SWITCH COMPONENT ===== */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    vertical-align: middle;
    margin-left: 8px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .3s;
    border-radius: 24px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
    background-color: #4CAF50;
}

input:checked + .toggle-slider:before {
    transform: translateX(18px);
}

/* Hover effect */
.toggle-slider:hover {
    background-color: #b3b3b3;
}

input:checked + .toggle-slider:hover {
    background-color: #45a049;
}

/* Focus state for accessibility */
.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px var(--color-focus);
}

/* Compact version for toolbar */
.toggle-switch.compact {
    width: 36px;
    height: 20px;
    margin-left: 4px;
}

.toggle-switch.compact .toggle-slider:before {
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
}

.toggle-switch.compact input:checked + .toggle-slider:before {
    transform: translateX(16px);
}

/* Label adjustments when using toggle switches */
.checkbox-label > span:first-child {
    min-width: 30px;
    font-weight: 500;
}

/* ===== UTILITY CLASSES ===== */
.hidden {
    display: none !important;
}

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

/* ===== KEEP EXISTING STYLES FOR COMPATIBILITY ===== */

/* Keep all existing class names and styles below for backward compatibility */
.icon-group {
    display: flex;
    align-items: center;
    margin-bottom: 10px;
}

#imageInput {
    display: none;
}

#arrayOutput {
    padding: 20px;
}

#paletteIcon, #rtclickIcon {
    font-size: 24px;
    cursor: pointer;
}

#pixelCanvasContainer {
    display: flex;
    justify-content: center;
    width: 100%;
}

#pixelCanvas {
    border: 1px solid #000;
    display: grid;
    grid-template-columns: repeat(96, 1fr);
    gap: 1px;
    padding: 0 15px;
    margin-bottom: 10px;
    width: fit-content;
}

#pixelCanvas.no-grid {
    gap: 0;
}

#textDisplay {
    font-family: monospace;
    white-space: pre-wrap;
}

.pixel {
    width: 8px;
    height: 8px;
    cursor: pointer;
    display: inline-block;
    box-sizing: border-box;
}

.fa-palette,
.fa-folder {
    font-size: 24px;
    cursor: pointer;
}

.icons {
    font-size: 14px;
    width: 25px; 
    height: 25px; 
    cursor: pointer;
    padding-left: 5px;
    padding-right: 5px;
}

.icon-group i {
    cursor: pointer;
    padding-right: 10px;
    padding-left: 10px;
}

#debugToggle {
    cursor: pointer;
    margin-left: 10px;
    color: black;
}

#pixelSizeInput {
    width: 40px;
}

/* Row-specific styling with color coding */
.primary-row {
    border-left: 3px solid #2196F3;
}

.primary-row .group-label {
    border-bottom-color: #2196F3;
}

.color-row {
    border-left: 3px solid #FFC107;
}

.color-row .group-label {
    border-bottom-color: #FFC107;
}

.tools-row {
    border-left: 3px solid #FF9800;
}

.tools-row .group-label {
    border-bottom-color: #FF9800;
}

.file-btn {
    padding: 4px;
}

.file-tools {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 10px 4px 10px;
}

.paint-btn {
    padding: 4px;
}

.zoom-controls {
    display: flex;
    gap: 2px;
    align-items: center;
}

.icon-btn-sm.fit {
    background: #e8f4ff;
    border-color: #007AFF;
    color: #333;
    font-weight: bold;
}

.icon-btn-sm.fit:hover {
    background: #d4edff;
    border-color: #0056b3;
    color: #000;
}

.swap-btn {
    background: transparent;
    border: 1px solid #ddd;
    padding: 1px;
    font-size: 10px;
    min-width: 16px;
    height: 12px;
    border-radius: 2px;
}

.color-picker-controls {
    display: flex;
    align-items: center;
    gap: 4px;
}

#colorPicker24bit {
    display: flex;
    gap: 4px;
    align-items: center;
}

#htmlColorPicker {
    width: 24px;
    height: 12px;
    border: none;
    border-radius: 2px;
    cursor: pointer;
}

#hexColorInput {
    width: 55px;
    font-family: monospace;
    font-size: 11px;
    text-transform: uppercase;
    padding: 1px 3px;
    height: 16px;
}

#recentColorsGrid {
    display: flex;
    gap: 3px;
    align-items: center;
}

.recent-color {
    width: 14px;
    height: 14px;
    border: 1px solid #ccc;
    cursor: pointer;
    border-radius: 2px;
    transition: all 0.2s ease;
    position: relative;
}

.recent-color:hover {
    border: 1px solid #007AFF;
}

/* Empty placeholder styling */
.recent-color-empty {
    background-color: transparent !important;
    border: 1px dashed #ccc !important;
    position: relative;
}

.recent-color-empty::before {
    content: '+';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #999;
    font-size: 10px;
    font-weight: bold;
    pointer-events: none;
}

.recent-color-empty:hover {
    border: 1px dashed #007AFF !important;
    background-color: rgba(0, 122, 255, 0.1) !important;
}

.recent-color-empty:hover::before {
    color: #007AFF;
}

.paint-tools {
    display: flex;
    gap: 4px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #666;
}

.checkbox-label input[type="checkbox"] {
    margin: 0;
    transform: scale(0.9);
}

#autoScaleLabel {
    margin-left: 10px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
}

#autoScaleToggle {
    margin: 0;
}


#zoomInButton, #zoomOutButton, #fitToScreenButton {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 4px 8px;
    margin: 0 2px;
    cursor: pointer;
    font-size: 14px;
    font-weight: bold;
    min-width: 25px;
    min-height: 25px;
}

#zoomInButton:hover, #zoomOutButton:hover, #fitToScreenButton:hover {
    background-color: #e0e0e0;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1200px) {
    :root {
        --scale-factor: clamp(0.85, 1 + 0.02vw, 1.1);
    }
    
    .toolbar-container {
        margin: var(--space-xs);
        padding: var(--space-sm);
    }
    
    .toolbar {
        gap: var(--space-md);
        padding: var(--space-xs) var(--space-md);
    }
    
    .tool-group {
        gap: var(--space-sm);
    }
    
    .group-label {
        padding: 6px 20px 6px 6px;
    }
    
    .inline-controls {
        padding: 0 12px;
    }
}

@media (max-width: 768px) {
    :root {
        --scale-factor: 0.9;
    }
    
    .toolbar-container {
        margin: 4px;
        padding: 6px;
    }
    
    .toolbar-row {
        gap: 8px;
        padding: 4px 6px;
        min-height: 36px;
    }
    
    .tool-group {
        gap: 6px;
    }
    
    .inline-controls {
        gap: 6px;
    }
    
    .group-label {
        font-size: 9px;
    }
    
    .control-input {
        font-size: 11px;
        min-width: 50px;
    }
    
    .toolbar {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }
    
    .animation-controls,
    #directionButtons {
        flex-direction: column;
        gap: var(--space-md);
    }
}

@media (max-width: 480px) {
    :root {
        --scale-factor: 0.75;
    }
    
    .toolbar-container {
        margin: 2px;
        padding: 4px;
    }
    
    .toolbar-row {
        gap: 4px;
        padding: 2px 4px;
    }
}

/* ===== NEW FEATURES STYLES ===== */

/* Selection System Styles */
.selection-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.selection-border {
    border: 1px dashed var(--color-gray-800);
    background: transparent;
    pointer-events: auto; /* Enable pointer events for move functionality */
    cursor: move;
}

.marching-ants {
    border: 3px dashed #000;
    background: transparent;
    animation: marchingAnts 0.5s linear infinite;
    outline: 1px dashed #FFF;
    outline-offset: -1px;
    cursor: move;
    
    /* Make the border more substantial and easier to click */
    box-sizing: border-box;
}

@keyframes marchingAnts {
    0% { 
        border-color: #000;
        outline-color: #FFF;
    }
    50% { 
        border-color: #FFF;
        outline-color: #000;
    }
    100% { 
        border-color: #000;
        outline-color: #FFF;
    }
}



/* Scaling Dialog Styles */
.scaling-dialog {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: var(--z-modal);
    align-items: center;
    justify-content: center;
}

.scaling-dialog.modal--open {
    display: flex;
}

.scaling-dialog__content {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 800px;
    max-height: 90vh;
    overflow-y: auto;
}

.scaling-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.option-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.option-group label {
    font-weight: 600;
    color: var(--color-gray-700);
    font-size: var(--font-sm);
}

.preview-section {
    margin-top: var(--space-xl);
    border-top: 1px solid var(--color-gray-200);
    padding-top: var(--space-xl);
}

.preview-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xl);
    text-align: center;
}

.preview-before h4,
.preview-after h4 {
    margin: 0 0 var(--space-md) 0;
    color: var(--color-gray-700);
    font-size: var(--font-md);
}

.preview-canvas {
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-sm);
    background: var(--color-gray-50);
    max-width: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.preview-info {
    margin-top: var(--space-sm);
    font-size: var(--font-sm);
    color: var(--color-gray-600);
}

/* Position Controls Layout */
.position-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--color-gray-50);
    border-radius: var(--radius-sm);
    margin-top: var(--space-md);
    margin-bottom: var(--space-md);
}

.position-controls .option-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.position-controls .option-group label {
    font-weight: 600;
    color: var(--color-gray-700);
    font-size: var(--font-sm);
}

.position-controls .control-input {
    width: 100%;
}

/* Tool Selection Styles */
.tool-selection-group {
    display: flex;
    gap: var(--space-xs);
    padding: var(--space-xs);
    background: var(--color-gray-50);
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-gray-200);
}

.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: calc(var(--button-size) * 0.8);
    width: calc(var(--button-size) * 0.8);
    height: calc(var(--button-size) * 0.8);
    border: 1px solid var(--color-gray-300);
    border-radius: var(--radius-sm);
    background: var(--color-white);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    padding: var(--space-xs);
}

.tool-btn:hover {
    background: var(--color-hover);
    border-color: var(--color-gray-400);
}

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

.tool-btn i {
    font-size: var(--icon-size);
}

/* History Controls */
.history-controls {
    display: flex;
    gap: var(--space-xs);
    align-items: center;
}

.history-btn {
    min-width: 32px;
    height: 32px;
    padding: var(--space-xs);
    display: flex;
    align-items: center;
    justify-content: center;
}

.history-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.history-status {
    font-size: var(--font-xs);
    color: var(--color-gray-600);
    margin: 0 var(--space-sm);
}


/* Progress Bar for Scaling Operations */
.progress-container {
    margin: var(--space-lg) 0;
    display: none;
}

.progress-container.show {
    display: block;
}

.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--color-gray-200);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--color-primary);
    transition: width 0.3s ease;
    border-radius: var(--radius-sm);
}

.progress-text {
    text-align: center;
    margin-top: var(--space-xs);
    font-size: var(--font-sm);
    color: var(--color-gray-600);
}

/* Selection Tools in Toolbar */
.selection-tools {
    display: flex;
    gap: var(--space-xs);
}


/* Tool Tips Enhancement */
.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 120%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-gray-800);
    color: var(--color-white);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: var(--font-xs);
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    z-index: var(--z-tooltip);
    pointer-events: none;
}

.tooltip:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Canvas Container Enhancement for Overlays */
#pixelCanvasContainer {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: var(--space-xs) auto;
    width: 100%;
}

#pixelCanvas {
    display: grid;
    margin: 0 auto;
}

/* Animation for Button State Changes */
.btn--loading {
    position: relative;
    color: transparent;
}

.btn--loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Error States */
.btn--error {
    background: var(--color-error);
    border-color: var(--color-error);
    color: var(--color-white);
}

.btn--error:hover:not(:disabled) {
    background: #d32f2f;
    border-color: #d32f2f;
}

/* Warning States */
.btn--warning {
    background: var(--color-warning);
    border-color: var(--color-warning);
    color: var(--color-gray-800);
}

.btn--warning:hover:not(:disabled) {
    background: #ffa000;
    border-color: #ffa000;
}

/* Info States */
.btn--info {
    background: var(--color-info);
    border-color: var(--color-info);
    color: var(--color-white);
}

.btn--info:hover:not(:disabled) {
    background: #0097a7;
    border-color: #0097a7;
}

/* Mobile Responsiveness for New Features */
@media (max-width: 768px) {
    .scaling-dialog__content {
        width: 95%;
        margin: var(--space-md);
    }
    
    .preview-comparison {
        grid-template-columns: 1fr;
        gap: var(--space-lg);
    }
    
    .scaling-options {
        grid-template-columns: 1fr;
        gap: var(--space-md);
    }
    
    .tool-selection-group {
        flex-wrap: wrap;
    }
    
}

/* Accessibility Improvements */
@media (prefers-reduced-motion: reduce) {
    .marching-ants {
        animation: none;
    }
    
    .btn--loading::after {
        animation: none;
        border: 2px solid currentColor;
    }
    
    * {
        transition: none !important;
    }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
    .selection-border {
        border-width: 2px;
        border-color: var(--color-gray-900);
    }
    
    .marching-ants {
        background-image: 
            linear-gradient(45deg, 
                transparent 25%, 
                var(--color-gray-900) 25%,
                var(--color-gray-900) 50%, 
                transparent 50%,
                transparent 75%, 
                var(--color-gray-900) 75%);
    }
}

@media (min-width: 1600px) {
    .group-label {
        padding: 8px 24px 8px 8px;
    }
    
    .inline-controls {
        padding: 0 16px;
    }
    
    .tool-group {
        gap: 18px;
    }
}

@media (min-width: 1800px) {
    .toolbar-container {
        flex-direction: row;
        align-items: stretch;
        gap: 0;
    }
    
    .toolbar-row {
        display: flex;
        flex-wrap: nowrap;
        flex: 1;
        border-radius: 0;
        border-right: none;
        padding: 6px 12px;
    }
    
    .toolbar-row.primary-row {
        border-radius: 2px 0 0 2px;
        border-right: 1px solid #e0e0e0;
    }
    
    .toolbar-row.color-row {
        border-radius: 0 2px 2px 0;
        border-left: none;
    }
    
    .primary-row {
        border-left: none;
    }
    
    .color-row {
        border-left: none;
    }
    
    .tool-group {
        flex: 0 1 auto;
    }
    
    .icon-btn-sm {
        min-width: calc(32px * var(--scale-factor));
        height: calc(28px * var(--scale-factor));
        padding: calc(6px * var(--scale-factor)) calc(8px * var(--scale-factor));
        font-size: calc(15px * var(--scale-factor));
        margin: 0 2px;
    }
    
    .icon-btn-sm i {
        font-size: calc(16px * var(--scale-factor));
    }
    
    .icon-btn-sm svg {
        width: calc(18px * var(--scale-factor));
        height: calc(18px * var(--scale-factor));
    }
    
    .zoom-controls {
        gap: calc(4px * var(--scale-factor));
    }
    
    .zoom-controls .icon-btn-sm {
        margin: 0;
    }
}

/* Enhanced tooltips for control and direction buttons */
#controlButtons button[title],
#directionButtons button[title] {
    position: relative;
}

#controlButtons button[title]:hover::after,
#directionButtons button[title]:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 5px;
    padding: 6px 10px;
    background-color: rgba(0, 0, 0, 0.9);
    color: white;
    font-size: 13px;
    font-weight: normal;
    border-radius: 4px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    animation: tooltipFade 0.2s ease-in;
}

#controlButtons button[title]:hover::before,
#directionButtons button[title]:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: -5px;
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    z-index: 1001;
    pointer-events: none;
}

@keyframes tooltipFade {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

/* ===== TOOLTIP SYSTEM ===== */
.tooltip {
    position: relative;
}

/* Help cursor only for help button */
.help-btn {
    cursor: help !important;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 8px;
    padding: var(--space-xs) var(--space-sm);
    background: rgba(0, 0, 0, 0.9);
    color: var(--color-white);
    font-size: var(--font-xs);
    font-weight: 500;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    z-index: var(--z-tooltip);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
    max-width: 300px;
    white-space: normal;
    text-align: center;
    line-height: 1.2;
}

/* Top toolbar tooltips - show below to avoid clipping */
.toolbar-row .tooltip::after {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 8px;
}

.toolbar-row .tooltip::before {
    bottom: auto;
    top: 100%;
    margin-bottom: 0;
    margin-top: 2px;
    border: 4px solid transparent;
    border-bottom-color: rgba(0, 0, 0, 0.9);
    border-top-color: transparent;
}

.toolbar-row .tooltip:hover::after,
.toolbar-row .tooltip:focus::after {
    margin-top: calc(var(--space-xs) + 2px);
    margin-bottom: 0;
}

.toolbar-row .tooltip:hover::before,
.toolbar-row .tooltip:focus::before {
    margin-top: calc(var(--space-xs) + 2px);
    margin-bottom: 0;
}

.tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 2px;
    border: 4px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    z-index: var(--z-tooltip);
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
    pointer-events: none;
}

.tooltip:hover::after,
.tooltip:hover::before {
    opacity: 1;
    visibility: visible;
    margin-bottom: calc(var(--space-xs) + 2px);
}

.tooltip:focus::after,
.tooltip:focus::before {
    opacity: 1;
    visibility: visible;
    margin-bottom: calc(var(--space-xs) + 2px);
}


/* ===== ACCESSIBILITY ENHANCEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

@media (prefers-contrast: high) {
    :root {
        --color-gray-300: #999999;
        --color-gray-400: #777777;
        --color-primary: #0066CC;
        --color-secondary: #CC6600;
    }
    
    .btn {
        border-width: 2px;
    }
    
    .input,
    .select {
        border-width: 2px;
    }
}

/* Focus indicators for keyboard navigation */
.btn:focus-visible,
.input:focus-visible,
.select:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}