/* ========================================
   3D Z-Plane Explorer - Premium Dark Theme
   ======================================== */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2235;
    --bg-card: #151d2e;
    --border-color: #2a3a52;
    --border-glow: #3b82f6;
    --text-primary: #e8ecf4;
    --text-secondary: #8899b4;
    --text-muted: #556b8a;
    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-amber: #f59e0b;
    --accent-purple: #8b5cf6;
    --zero-color: #06b6d4;
    --pole-color: #ef4444;
    --unit-circle: rgba(99, 140, 200, 0.25);
    --grid-color: rgba(99, 140, 200, 0.08);
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.5);
}

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

html,
body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    /* dynamic viewport height for mobile */
}

/* ---- Header ---- */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 20px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
    min-width: 0;
}

#app-header h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
}

#app-header .subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.back-btn {
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}

.back-btn:hover,
.back-btn:active {
    border-color: var(--accent-blue);
    color: var(--text-primary);
    background: rgba(59, 130, 246, 0.1);
}

/* ---- Main layout ---- */
#main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 0;
}

#left-pane {
    width: 380px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

#right-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-primary);
}

/* ---- Pane headers ---- */
.pane-header {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

.pane-header.sub-header {
    border-top: 1px solid var(--border-color);
}

.pane-header h2 {
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
}

/* ---- Surface controls ---- */
#surface-controls {
    display: flex;
    gap: 16px;
    margin-top: 8px;
    flex-wrap: wrap;
    align-items: center;
}

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

.control-group label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.scale-btn {
    padding: 4px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.scale-btn:hover {
    border-color: var(--accent-cyan);
    color: var(--text-primary);
}

.scale-btn.active {
    border-color: var(--accent-cyan);
    background: rgba(6, 182, 212, 0.15);
    color: var(--accent-cyan);
    box-shadow: 0 0 6px rgba(6, 182, 212, 0.15);
}

.slider-group {
    flex: 1;
    min-width: 140px;
}

#gain-slider {
    flex: 1;
    min-width: 80px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--border-color);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    touch-action: none;
}

#gain-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 6px rgba(6, 182, 212, 0.3);
    cursor: pointer;
}

#gain-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--accent-cyan);
    border: 2px solid var(--bg-card);
    box-shadow: 0 0 6px rgba(6, 182, 212, 0.3);
    cursor: pointer;
}

#gain-readout {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--accent-cyan);
    min-width: 50px;
    text-align: right;
}

/* ---- Toolbar ---- */
#toolbar {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.tool-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.tool-btn:hover,
.tool-btn:active {
    border-color: var(--accent-blue);
    color: var(--text-primary);
    background: rgba(59, 130, 246, 0.08);
}

.tool-btn.active {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-blue);
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.2);
}

.tool-btn.danger:hover,
.tool-btn.danger:active {
    border-color: var(--accent-red);
    color: var(--accent-red);
    background: rgba(239, 68, 68, 0.08);
}

.tool-icon {
    font-size: 14px;
    line-height: 1;
}

.tool-label {
    font-weight: 500;
}

.toolbar-divider {
    width: 1px;
    height: 28px;
    background: var(--border-color);
    margin: 0 4px;
    align-self: center;
}

/* ---- Z-Plane canvas ---- */
#zplane-container {
    flex: 1;
    position: relative;
    min-height: 300px;
    touch-action: none;
    /* prevent browser gestures on canvas */
}

#zplane-canvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

#zplane-info {
    padding: 6px 16px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    flex-shrink: 0;
}

/* ---- Three.js container ---- */
#three-container {
    flex: 1;
    min-height: 380px;
    position: relative;
    background: radial-gradient(ellipse at center, #0f172a 0%, #070b14 100%);
    touch-action: none;
    /* OrbitControls handles touch */
}

#three-container canvas {
    display: block;
    touch-action: none;
}

/* ---- Frequency response ---- */
#freqresp-container {
    height: 180px;
    min-height: 150px;
    position: relative;
    background: var(--bg-secondary);
}

#freqresp-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ---- H(z) display ---- */
#hz-display {
    padding: 16px 20px;
    text-align: center;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow-x: auto;
}

#hz-display .katex {
    font-size: 1.2em;
    color: var(--text-primary);
}

/* ---- Scrollbar styling ---- */
#right-pane::-webkit-scrollbar {
    width: 6px;
}

#right-pane::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

#right-pane::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

#right-pane::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===========================================
   Responsive: Tablet (≤ 900px)
   =========================================== */
@media (max-width: 900px) {
    #main-content {
        flex-direction: column;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #left-pane {
        width: 100%;
        min-width: unset;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
    }

    #right-pane {
        overflow-y: visible;
        flex-shrink: 0;
    }

    #zplane-container {
        min-height: 320px;
        height: 45vw;
        max-height: 400px;
    }

    #three-container {
        min-height: 320px;
        height: 50vw;
        max-height: 420px;
    }

    #freqresp-container {
        height: 180px;
    }

    /* Larger touch targets for tablet */
    .tool-btn {
        padding: 8px 14px;
        font-size: 13px;
    }

    .scale-btn {
        padding: 6px 12px;
        font-size: 12px;
    }

    #app-header .subtitle {
        display: none;
    }
}

/* ===========================================
   Responsive: Phone (≤ 600px)
   =========================================== */
@media (max-width: 600px) {
    #app-header {
        padding: 8px 12px;
    }

    #app-header h1 {
        font-size: 15px;
    }

    .back-btn {
        padding: 6px 10px;
        font-size: 12px;
    }

    .pane-header {
        padding: 8px 12px;
    }

    .pane-header h2 {
        font-size: 11px;
    }

    #toolbar {
        gap: 3px;
    }

    .tool-btn {
        padding: 8px 10px;
        font-size: 11px;
        gap: 3px;
    }

    .tool-label {
        display: none;
        /* icons only on phone */
    }

    .tool-icon {
        font-size: 16px;
    }

    .toolbar-divider {
        height: 24px;
    }

    #zplane-container {
        min-height: 280px;
        height: 70vw;
        max-height: 360px;
    }

    #three-container {
        min-height: 280px;
        height: 70vw;
        max-height: 380px;
    }

    #freqresp-container {
        height: 160px;
        min-height: 130px;
    }

    #surface-controls {
        gap: 10px;
    }

    .slider-group {
        min-width: 100px;
    }

    #hz-display {
        padding: 12px 10px;
    }

    #hz-display .katex {
        font-size: 1em;
    }

    #zplane-info {
        padding: 4px 12px;
        font-size: 11px;
    }
}