/* ==========================================================================
   BASE STYLES
   ========================================================================== */

html,
body {
    margin: 0;
    background: #222;
    color: #eee;
    font-family: "KaTeX_Main", "Latin Modern Roman", serif;
    font-size: 12px;
    padding: 10px;
}

.katex {
    font-size: 1.2rem;
}



/* ==========================================================================
   FORM CONTROLS
   ========================================================================== */

button,
select,
input[type="number"] {
    font: inherit;
    background: #444;
    color: #eee;
    border: 1px solid #666;
    padding: 3px 6px;
    margin: 1px;
    cursor: pointer;
    height: 24px;
    box-sizing: border-box;
    transition: background-color 0.2s, border-color 0.2s;
    font-size: 1rem;
}

button:hover,
select:hover,
input[type="number"]:hover {
    background: #555;
    border-color: #777;
}

button:active {
    background: #333;
}

/* Number inputs */
input[type="number"] {
    width: 60px;
    text-align: center;
}

/* Labels */
label {
    display: block;
    margin-bottom: 2px;
    color: #ccc;
    font-size: 1rem;
}

/* Number input spinner controls */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    background-color: #666;
    filter: invert(80%) brightness(150%);
    height: 14px;
    margin: 2px;
}

/* Range inputs */
input[type="range"] {
    appearance: none;
    background: #444;
    height: 6px;
    border: 1px solid #666;
    margin: 4px 0;
    width: 100%;
    vertical-align: middle;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    background: #fff;
    cursor: pointer;
    border: 2px solid #666;
}

input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    background: #fff;
    cursor: pointer;
    border: 2px solid #666;
}

/* ==========================================================================
   SPECIFIC BUTTONS
   ========================================================================== */

/* Play/Pause Button */
#play-pause-btn {
    background: #0a6e0a;
    color: white;
    font-weight: bold;
}

#play-pause-btn:hover {
    background: #0a8e0a;
}

#play-pause-btn[aria-pressed="true"] {
    background: #c44a00;
}

#play-pause-btn[aria-pressed="true"]:hover {
    background: #e55a10;
}

/* Clear buttons - destructive action styling */
.control-section:has(.section-title:contains("Clear")) button,
.control-section .section-title+.control-group button[onclick*="CLEAR_FIELDS"],
.control-section .section-title+.control-group button[onclick*="canvas_overlay.clear"] {
    background: #8b0000;
    color: white;
}

.control-section .section-title+.control-group button[onclick*="CLEAR_FIELDS"]:hover,
.control-section .section-title+.control-group button[onclick*="canvas_overlay.clear"]:hover {
    background: #a50000;
}

/* Averaging button styles */
.averaging-on {
    background-color: #3399ff;
    color: #fff;
    border: 1px solid #2277cc;
}

/* Averaging button styles */
.averaging-on:hover {
    background-color: #3399ff;
    color: #fff;
    border: 1px solid #2277cc;
}

/* ==========================================================================
   COMPONENTS
   ========================================================================== */

/* Preset description */
#preset_description {
    font-style: italic;
    color: #aaa;
    padding: 5px 0;
    font-size: 1rem;
    line-height: 1.3;
}

/* Colormap dropdown */
.colormap-control {
    display: flex;
    align-items: center;
}

#colormap-selector {
    width: 100%;
    max-width: 200px;
}

/* Scale Control */
.scale-control {
    display: flex;
    align-items: center;
    gap: 3px;
    margin: 3px 0;
}

.scale-control button {
    width: 24px;
    height: 24px;
    padding: 0;
    font-size: 1rem;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scale-control input[type="range"] {
    flex: 1;
    margin: 0;
    min-width: 80px;
}

.scale-control input[type="number"] {
    width: 65px;
}

/* Segmented Control */
.segmented-control {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 1px;
    background: #333;
    padding: 1px;
    margin: 3px 0;
}

.mode-btn {
    background: #555;
    border: none;
    padding: 4px 2px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    min-height: 24px;
}

.mode-btn:hover {
    background: #666;
}

.mode-btn.selected {
    background: #0078d4;
    color: white;
}

.mode-btn.selected:hover {
    background: #106ebe;
}

/* ==========================================================================
   LAYOUT
   ========================================================================== */

/* Main container - Two column layout */
#main-container {
    display: flex;
    height: auto;
    gap: 15px;
    max-width: 1600px;
    margin: 0 auto;
    box-sizing: border-box;
}

#canvas-container {
    position: relative;
    flex: 0 0 1024px;
    min-height: 1024px;
    border: 1px solid #444;
}

#info-sidebar,
#controls-sidebar {
    flex: 0 0 auto;
    width: 280px;
    overflow-y: auto;
    background: #333;
    padding: 10px;
    box-sizing: border-box;
    align-self: flex-start;
    z-index: 100;
    border: 1px solid #444;
    min-height: 1024px;
    max-height: 1024px;
}

#info-sidebar {
    font-size: 1.25rem;
    padding: 1.5rem;
    padding-top: 0.5rem;
}

#info-sidebar h3,
#info-sidebar h4 {
    padding: 0px;
    margin: 0.75rem 0rem;
}

#info-sidebar p {
    margin: 0.75rem 0rem;
}

.control-section {
    margin-bottom: 12px;
}

.section-title {
    font-size: 1.25rem;
    font-weight: bold;
    color: #fff;
    margin-bottom: 6px;
    padding-bottom: 2px;
    border-bottom: 1px solid #555;
}

.control-group {
    margin-bottom: 6px;
}

.control-subsection {
    margin-left: 10px;
    margin-bottom: 8px;
}

.subsection-title {
    font-size: 1rem;
    color: #bbb;
    margin-bottom: 3px;
    font-weight: normal;
}

.row {
    padding: 2px 0;
}

/* ==========================================================================
   CANVAS LAYERS
   ========================================================================== */

/* Non-interactive bottom-layer canvas */
#gl {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Fabric.js wrapper */
#fabric-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
}

/* Overlay canvas */
#overlay {
    display: block;
}

/* ==========================================================================
   PERFORMANCE HUD
   ========================================================================== */

#performance-hud {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.05);
    color: #e5e5e5;
    font-size: 1rem;
    padding: 6px 12px;
    z-index: 100;
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(3px);
    display: flex;
    gap: 16px;
    ;
}

.perf-metric {
    display: flex;
    align-items: center;
    gap: 4px;
}

.perf-label {
    color: #aaa;
    font-size: 10px;
}

.perf-value {
    color: #fff;
    font-weight: bold;
}


/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

@media (max-width: 1400px) {
    #main-container {
        flex-direction: column;
        height: auto;
        gap: 10px;
    }

    #canvas-container {
        flex: none;
        width: 100%;
        max-width: 600px;
        margin: 0 auto;
    }

    #canvas-container canvas {
        width: 100%;
        height: auto;
        max-width: 600px;
        max-height: 600px;
    }

    #info-sidebar,
    #controls-sidebar {
        flex: none;
        margin-top: calc(600px - 1024px) !important;
        align-self: auto !important;
        position: relative !important;
        width: 100%;
        min-height: 0px;
    }

    #info-sidebar {
        display: none;
    }
    .control-group {
        display: flex;
        flex-wrap: wrap;
        gap: 3px;
        align-items: center;
    }

    .control-group label {
        flex: 0 0 100%;
        margin-bottom: 2px;
    }

    .control-group button {
        flex: 0 1 auto;
        min-width: 70px;
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .control-group select {
        flex: 1 1 auto;
        min-width: 120px;
    }

    .scale-control {
        min-width: 100%;
    }

    .scale-control button {
        width: 20px !important;
        height: 20px !important;
        font-size: 1rem !important;
        flex: 0 0 20px !important;
        min-width: 20px !important;
    }

    .segmented-control {
        display: grid !important;
        grid-template-columns: repeat(auto-fit, minmax(50px, 1fr));
        gap: 1px;
        width: 100%;
    }

    .mode-btn {
        font-size: 1rem;
        padding: 2px 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

}

/* Touch-friendly improvements */
@media (hover: none) and (pointer: coarse) {

    button,
    select,
    input {
        min-height: 32px;
        padding: 6px 10px;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 20px;
        height: 20px;
    }

    input[type="range"]::-moz-range-thumb {
        width: 20px;
        height: 20px;
    }
}