/* Custom CSS for ASCII Art Generator - Luxury Minimalist Theme */

@import url('https://fonts.googleapis.com/css2?family=Special+Elite&family=Courier+Prime:wght@400;700&family=IBM+Plex+Mono:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

:root {
    --char-width: 0.6em;
    --char-height: 1.2em;

    /* Luxury Color Palette */
    --bg-primary: #1A1A1D;
    --bg-secondary: #2D2D30;
    --bg-tertiary: #3A3A3D;

    --accent-primary: #8B5CF6;
    --accent-secondary: #A78BFA;
    --accent-gold: #D4AF37;
    --accent-rose: #E91E63;
    --accent-burgundy: #892C54;

    --text-primary: #FAF9F6;
    --text-secondary: #C7C7C7;
    --text-muted: #8A8A8A;

    --border-subtle: rgba(139, 92, 246, 0.1);
    --border-medium: rgba(139, 92, 246, 0.3);
    --border-strong: rgba(139, 92, 246, 0.6);

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(139, 92, 246, 0.4);
}

/* Global Styles */
* {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
    box-sizing: border-box;
}

/* Enable smooth scrolling and hardware acceleration */
html {
    scroll-behavior: smooth;
    height: 100%;
    overflow: hidden;
}

body {
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100vh;
    overflow: hidden;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

/* Improve rendering performance */
.canvas-row,
.char-cell {
    will-change: auto;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Disable animations for large outputs to improve performance */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

h1, h2, h3, h4, h5, h6 {
    font-family: 'Special Elite', 'Courier Prime', 'Courier New', monospace;
    font-weight: 400;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* All text elements */
p, span, label, button, input, select, textarea, a, div {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
}

/* Button and interactive elements */
button, input[type="button"], input[type="submit"] {
    font-family: 'Space Mono', 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 1px;
}

/* Form elements */
input, select, textarea, option {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace !important;
}

/* Labels and small text */
label, .text-sm, .text-xs {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
    letter-spacing: 0.5px;
}

/* Placeholder text */
::placeholder {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
    font-style: italic;
}

/* Ensure all children inherit monospace */
body * {
    font-family: inherit;
}

/* Settings/Controls panels */
.bg-dark-surface h2,
.bg-dark-surface label {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
    letter-spacing: 0.8px;
}

/* Canvas size inputs and other number inputs */
input[type="number"] {
    font-family: 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: 500;
}

/* Character input in editor */
input[type="text"] {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-weight: 500;
}

/* Select dropdowns */
select option {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
}

/* Checkboxes and their labels */
input[type="checkbox"] + span,
input[type="checkbox"] + label {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
    font-weight: 500;
    letter-spacing: 0.5px;
}

/* Preview and Canvas headings */
#converterSection h2,
#editorSection h2 {
    font-family: 'Special Elite', 'Courier Prime', 'Courier New', monospace;
    letter-spacing: 2px;
}

/* Settings heading */
.bg-dark-surface > h2 {
    font-family: 'Special Elite', 'Courier Prime', 'Courier New', monospace;
    font-weight: 400;
    letter-spacing: 2.5px;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 6px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, var(--accent-primary) 0%, var(--accent-burgundy) 100%);
    border-radius: 6px;
    border: 2px solid var(--bg-secondary);
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, var(--accent-secondary) 0%, var(--accent-rose) 100%);
}

/* Tab Styling */
.tab-btn {
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--text-secondary);
    font-family: 'Space Mono', 'Courier New', monospace;
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.tab-btn:hover {
    color: var(--accent-secondary);
}

.tab-btn.active {
    color: var(--accent-gold);
    border-bottom-color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.5);
}

.tab-btn.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 50%;
    transform: translateX(-50%);
    width: 80%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent-gold), transparent);
    border-radius: 2px;
    box-shadow: 0 0 10px var(--accent-gold);
}

/* Tool Buttons */
.tool-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--bg-secondary);
    border: 2px solid var(--border-subtle);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'Space Mono', 'Courier Prime', 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 1px;
    font-size: 0.875rem;
    text-transform: uppercase;
}

.tool-btn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0);
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.2) 0%, transparent 70%);
    transition: transform 0.4s ease;
    border-radius: 12px;
}

.tool-btn:hover::before {
    transform: translate(-50%, -50%) scale(1);
}

.tool-btn:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-medium);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.tool-btn.active {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2) 0%, rgba(137, 44, 84, 0.2) 100%);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
    color: var(--accent-gold);
}

/* Range Sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-rose));
    cursor: pointer;
    border-radius: 50%;
    border: 3px solid var(--bg-primary);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5), var(--shadow-sm);
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.8), var(--shadow-md);
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-rose));
    cursor: pointer;
    border-radius: 50%;
    border: 3px solid var(--bg-primary);
    box-shadow: 0 0 10px rgba(139, 92, 246, 0.5), var(--shadow-sm);
    transition: all 0.2s ease;
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.2);
    box-shadow: 0 0 15px rgba(139, 92, 246, 0.8), var(--shadow-md);
}

/* ASCII Output - Fit to Container (No Scrolling) */
#asciiOutput {
    font-family: 'Courier Prime', 'Courier New', monospace;
    background: var(--bg-primary);
    border: 2px solid var(--border-medium);
    border-radius: 12px;

    /* Fixed height to prevent overflow */
    height: calc(100vh - 280px);
    max-height: calc(100vh - 280px);
    min-height: 400px;
    width: 100%;

    /* NO SCROLLING - Content must fit */
    overflow: hidden;

    /* Flexbox for centering scaled content */
    display: flex;
    align-items: center;
    justify-content: center;

    /* Prevent text selection for better performance */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;

    /* Hardware acceleration */
    transform: translateZ(0);
    -webkit-transform: translateZ(0);

    /* Optimize text rendering for performance */
    text-rendering: optimizeSpeed;
}

#asciiOutput pre {
    font-family: 'Courier Prime', 'Courier New', monospace;
    white-space: pre;
    margin: 0;
    line-height: 1;
    padding: 1rem;

    /* Dynamic scaling applied via JavaScript */
    transform-origin: center center;

    /* GPU acceleration */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;

    /* Optimize font rendering */
    -webkit-font-smoothing: subpixel-antialiased;
    -moz-osx-font-smoothing: auto;
}

#asciiOutput.colored {
    /* Wrapper for scaled content */
    display: flex;
    align-items: center;
    justify-content: center;
}

#asciiOutput.colored > div {
    /* Container that will be scaled */
    transform-origin: center center;
    padding: 1rem;
}

#asciiOutput.colored div div {
    /* Individual rows */
    line-height: 1;
    white-space: nowrap;
}

#asciiOutput.colored span {
    display: inline;
}

/* Optimize for very large outputs */
@media screen and (min-width: 1920px) {
    #asciiOutput {
        font-size: 10px;
    }
}

/* Further optimize for ultra-wide displays */
@media screen and (min-width: 2560px) {
    #asciiOutput {
        font-size: 9px;
    }
}


/* Drawing Canvas - Fit to Container (No Scrolling) */
#drawingCanvas {
    font-family: 'Courier Prime', 'Courier New', monospace;
    line-height: 1;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;

    /* Fixed height to prevent overflow */
    height: calc(100vh - 280px);
    max-height: calc(100vh - 280px);
    min-height: 400px;
    width: 100%;

    /* NO SCROLLING - Content must fit */
    overflow: hidden;

    background: var(--bg-primary);
    border: 2px solid var(--border-medium);
    border-radius: 12px;
    padding: 1rem;

    /* Flexbox for centering scaled content */
    display: flex;
    align-items: center;
    justify-content: center;
}

.canvas-cell {
    display: inline-block;
    width: var(--char-width);
    text-align: center;
    cursor: crosshair;
}

.canvas-row {
    white-space: nowrap;
    height: var(--char-height);
}

/* Drop Zone Hover State */
#dropZone {
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
}

#dropZone p, #dropZone svg {
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
}

#dropZone::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(139, 92, 246, 0.1), transparent);
    transition: left 0.5s ease;
}

#dropZone:hover::before {
    left: 100%;
}

#dropZone:hover {
    border-color: var(--accent-secondary);
    background: rgba(139, 92, 246, 0.05);
    transform: scale(1.02);
}

#dropZone.drag-over {
    border-color: var(--accent-gold);
    background: rgba(212, 175, 55, 0.1);
    box-shadow: var(--shadow-glow), inset 0 0 20px rgba(212, 175, 55, 0.2);
}

/* Modal Styling */
#galleryModal,
#helpModal {
    position: fixed;
    inset: 0;
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
    z-index: 100;
}

#galleryModal.active,
#helpModal.active {
    display: flex;
}

#galleryModal > div,
#helpModal > div {
    max-height: 90vh;
    overflow-y: auto;
}

#galleryModal h2, #helpModal h2,
#galleryModal h3, #helpModal h3 {
    font-family: 'Special Elite', 'Courier Prime', 'Courier New', monospace;
    letter-spacing: 2px;
}

/* Gallery Items */
.gallery-item {
    background: var(--bg-secondary);
    border: 2px solid var(--border-subtle);
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    font-family: 'IBM Plex Mono', 'Courier Prime', 'Courier New', monospace;
}

.gallery-item h3 {
    font-family: 'Special Elite', 'Courier Prime', 'Courier New', monospace;
    letter-spacing: 1.5px;
}

.gallery-item button {
    font-family: 'Space Mono', 'Courier Prime', 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 1px;
}

.gallery-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-rose), var(--accent-gold));
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.gallery-item:hover::after {
    transform: scaleX(1);
}

.gallery-item:hover {
    border-color: var(--accent-primary);
    background: var(--bg-tertiary);
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.gallery-preview {
    font-family: 'Courier Prime', 'Courier New', monospace;
    font-size: 0.5rem;
    line-height: 1;
    white-space: pre;
    overflow: hidden;
    max-height: 150px;
    background: #000;
    padding: 0.5rem;
    border-radius: 0.25rem;
    margin-bottom: 0.5rem;
}

/* Toast Notifications */
#toast {
    font-family: 'Space Mono', 'Courier Prime', 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 0.5px;
}

#toast.show {
    display: block;
    animation: slideIn 0.3s ease, slideOut 0.3s ease 2.7s;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Loading Indicator */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Keyboard Shortcut Display */
kbd {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    background: linear-gradient(135deg, var(--bg-tertiary), var(--bg-secondary));
    border: 2px solid var(--border-medium);
    border-radius: 6px;
    font-family: 'Space Mono', 'Courier Prime', 'Courier New', monospace;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-gold);
    box-shadow: var(--shadow-sm), inset 0 1px 2px rgba(139, 92, 246, 0.2);
    letter-spacing: 1px;
}

/* Export Bar Visibility */
#exportBar {
    font-family: 'Space Mono', 'Courier Prime', 'Courier New', monospace;
    /* Ensure export bar doesn't cause page overflow */
    pointer-events: auto;
}

#exportBar button {
    font-family: 'Space Mono', 'IBM Plex Mono', 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 1px;
}

#exportBar.show {
    display: block;
}

/* Adjust main content padding when export bar is visible */
body:has(#exportBar.show) main {
    padding-bottom: 70px;
}

/* Main content area with proper constraints */
main {
    display: flex;
    flex-direction: column;
}

main > section {
    height: 100%;
    overflow: hidden;
}

/* Grid containers within sections */
section .grid {
    height: 100%;
}

section .lg\:grid-cols-\[350px_1fr\],
section .lg\:grid-cols-\[300px_1fr\] {
    height: 100%;
    overflow: hidden;
}

/* Controls panels with fixed height */
.bg-dark-surface {
    max-height: calc(100vh - 250px);
    overflow-y: auto;
    overflow-x: hidden;
}

/* When export bar is shown, adjust container heights */
body:has(#exportBar.show) .bg-dark-surface {
    max-height: calc(100vh - 320px);
}

body:has(#exportBar.show) #asciiOutput,
body:has(#exportBar.show) #drawingCanvas {
    height: calc(100vh - 350px);
    max-height: calc(100vh - 350px);
}

/* Responsive Design */
@media (max-width: 1024px) {
    .grid {
        grid-template-columns: 1fr;
    }

    .bg-dark-surface {
        max-height: 350px;
    }

    #asciiOutput,
    #drawingCanvas {
        height: 400px;
        max-height: 400px;
        min-height: 300px;
    }

    body:has(#exportBar.show) #asciiOutput,
    body:has(#exportBar.show) #drawingCanvas {
        height: 350px;
        max-height: 350px;
    }
}

@media (max-width: 640px) {
    #exportBar .flex {
        flex-direction: column;
    }

    #exportBar button {
        width: 100%;
    }

    .tab-btn {
        font-size: 0.875rem;
        padding: 0.75rem 1rem;
    }
}

/* Canvas Grid */
.canvas-grid {
    display: inline-block;
}

/* Character Cell in Editor */
.char-cell {
    display: inline-block;
    width: 1ch;
    height: 1.2em;
    line-height: 1.2em;
    text-align: center;
    cursor: crosshair;
}

/* Selection Highlight */
.char-cell.selected {
    background: rgba(74, 222, 128, 0.2);
}

/* Color Mode Styling */
.ascii-colored {
    display: inline;
}

/* Mobile Touch Improvements */
@media (hover: none) and (pointer: coarse) {
    .tool-btn {
        padding: 1.5rem;
    }

    #drawingCanvas {
        cursor: default;
    }

    .char-cell {
        width: 1.2ch;
        height: 1.5em;
        line-height: 1.5em;
    }
}

/* Print Styles */
@media print {
    header,
    #exportBar,
    .controls-panel {
        display: none;
    }

    #asciiOutput {
        background: white;
        color: black;
        max-height: none;
    }
}
