/*
 * Shader Forge - Interactive Code
 * Syntax highlighting and interactive value editing
 */

/* Code Display Container */
.code-display {
    flex: 1;
    min-width: 0;
    background: var(--bg-deep);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-primary);
    padding: var(--space-md);
    overflow: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    tab-size: 4;
    cursor: text;
}

.code-display:focus {
    outline: none;
}

/* Code with lines wrapper */
.code-with-lines {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* Syntax Highlighting */
.syntax-comment {
    color: #6a737d;
    font-style: italic;
}

.syntax-keyword {
    color: #ff79c6;
}

.syntax-type {
    color: #8be9fd;
}

.syntax-function {
    color: #50fa7b;
}

.syntax-builtin {
    color: #ffb86c;
}

.syntax-number {
    color: #bd93f9;
    cursor: pointer;
    border-radius: 3px;
    padding: 0 2px;
    margin: 0 -2px;
    transition: all var(--transition-fast);
    position: relative;
}

.syntax-number:hover {
    background: rgba(189, 147, 249, 0.2);
}

.syntax-number.active {
    background: rgba(189, 147, 249, 0.3);
    box-shadow: 0 0 0 2px rgba(189, 147, 249, 0.4);
}

.syntax-string {
    color: #f1fa8c;
}

.syntax-operator {
    color: #ff79c6;
}

.syntax-punctuation {
    color: var(--text-secondary);
}

/* Interactive Slider Popup */
.value-popup {
    position: fixed;
    z-index: 1000;
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    border-radius: 12px;
    padding: var(--space-md);
    box-shadow: var(--shadow-soft), 0 0 30px rgba(167, 139, 250, 0.1);
    min-width: 240px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    transition: all var(--transition-smooth);
    touch-action: manipulation;
}

.value-popup.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.value-popup::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 20px;
    width: 12px;
    height: 12px;
    background: var(--bg-elevated);
    border-left: 1px solid var(--border-medium);
    border-top: 1px solid var(--border-medium);
    transform: rotate(45deg);
}

/* When popup is above the element, arrow points down */
.value-popup.above::before {
    top: auto;
    bottom: -6px;
    border-left: none;
    border-top: none;
    border-right: 1px solid var(--border-medium);
    border-bottom: 1px solid var(--border-medium);
}

.popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-sm);
}

.popup-title {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.popup-value {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--accent-primary);
    font-weight: 500;
}

/* Custom Slider */
.value-slider-container {
    margin: var(--space-sm) 0;
}

.value-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-surface);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    touch-action: manipulation;
}

.value-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(167, 139, 250, 0.4);
    transition: transform var(--transition-fast);
}

.value-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
}

.value-slider::-webkit-slider-thumb:active {
    cursor: grabbing;
    transform: scale(0.95);
}

.value-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--accent-primary);
    border: none;
    border-radius: 50%;
    cursor: grab;
    box-shadow: 0 2px 8px rgba(167, 139, 250, 0.4);
}

/* Slider Range Labels */
.slider-labels {
    display: flex;
    justify-content: space-between;
    margin-top: var(--space-xs);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-ghost);
}

/* Value adjustment with arrows */
.value-adjust-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-sm);
}

.adjust-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 14px;
    font-weight: 600;
    touch-action: manipulation; /* Prevent double-tap zoom on mobile */
    -webkit-user-select: none;
    user-select: none;
}

.adjust-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.adjust-btn:active {
    transform: scale(0.95);
}

.value-input-wrapper {
    flex: 1;
    display: flex;
    justify-content: center;
}

.value-input {
    width: 100%;
    max-width: 100px;
    padding: 4px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--accent-primary);
    text-align: center;
    outline: none;
    transition: border-color var(--transition-fast);
}

.value-input:focus {
    border-color: var(--accent-primary);
}

/* Quick Value Buttons */
.quick-values {
    display: flex;
    gap: var(--space-xs);
    margin-top: var(--space-sm);
    flex-wrap: wrap;
}

.quick-value-btn {
    padding: 4px 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
}

.quick-value-btn:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

/* Info Tooltip */
.info-tooltip {
    position: fixed;
    z-index: 999;
    background: var(--bg-elevated);
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    padding: var(--space-sm) var(--space-md);
    max-width: 300px;
    box-shadow: var(--shadow-soft);
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: all var(--transition-fast);
    pointer-events: none;
}

.info-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.info-tooltip-title {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-cool);
    margin-bottom: var(--space-xs);
}

.info-tooltip-desc {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.info-tooltip-syntax {
    font-family: var(--font-mono);
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--bg-surface);
    padding: var(--space-xs) var(--space-sm);
    border-radius: 4px;
    margin-top: var(--space-sm);
}

/* Function hover highlight */
.syntax-function:hover,
.syntax-builtin:hover {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

/* Line numbers */
.line-numbers {
    padding: var(--space-md) var(--space-sm);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    color: var(--text-ghost);
    text-align: right;
    user-select: none;
    min-width: 40px;
    flex-shrink: 0;
    overflow: hidden;
}

.line-numbers span {
    display: block;
}

/* Hidden textarea for actual editing */
.code-input-hidden {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

/* Responsive - Mobile */
@media (max-width: 768px) {
    .code-display {
        font-size: 11px;
        padding: var(--space-sm);
        line-height: 1.6;
    }

    .line-numbers {
        font-size: 11px;
        min-width: 28px;
        padding: var(--space-sm) 4px;
    }

    /* Popup - centered on mobile */
    .value-popup {
        position: fixed;
        left: 50% !important;
        transform: translateX(-50%) translateY(0);
        bottom: auto;
        top: auto;
        min-width: 280px;
        max-width: calc(100vw - 32px);
    }

    .value-popup.visible {
        transform: translateX(-50%) translateY(0);
    }

    .value-popup::before {
        display: none;
    }

    .value-popup.above::before {
        display: none;
    }

    /* Larger touch targets */
    .adjust-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .value-slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    .value-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    .quick-value-btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    /* Syntax highlighting - slightly larger touch area */
    .syntax-number {
        padding: 1px 4px;
        margin: 0 -4px;
    }
}

/* Responsive - Small phones */
@media (max-width: 480px) {
    .value-popup {
        min-width: calc(100vw - 32px);
    }
}
