/* ===== DESIGN TOKENS ===== */
:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --bg-elevated: #212d45;
    --border: #2a3655;
    --border-glow: rgba(99, 179, 237, 0.25);

    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --accent: #63b3ed;
    --accent-bright: #90cdf4;
    --accent-dim: #2b6cb0;
    --accent-green: #68d391;
    --accent-orange: #f6ad55;
    --accent-pink: #f687b3;
    --accent-red: #fc8181;

    --gradient-accent: linear-gradient(135deg, #63b3ed, #7c3aed);
    --gradient-card: linear-gradient(180deg, #1a2235 0%, #151d30 100%);

    --radius: 12px;
    --radius-sm: 8px;

    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 20px rgba(99, 179, 237, 0.15);

    --transition: 0.2s ease;
}

/* ===== RESET & BASE ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* ===== HEADER ===== */
#app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
}

#app-header h1 {
    font-size: 1.15rem;
    font-weight: 700;
    background: var(--gradient-accent);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

#back-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 44px;
}

#back-btn:hover {
    background: var(--bg-card);
    color: var(--text-primary);
    border-color: var(--accent);
    box-shadow: var(--shadow-glow);
}

/* ===== MAIN LAYOUT ===== */
#app-main {
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    max-width: 1600px;
    margin: 0 auto;
    overflow: hidden;
}

/* ===== CONTROL PANEL ===== */
#controls {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    box-shadow: var(--shadow-sm);
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.label-math {
    font-family: var(--font-mono);
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 500;
    text-transform: none;
    letter-spacing: normal;
}

.slider-value {
    margin-left: auto;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-bright);
    font-weight: 500;
    background: rgba(99, 179, 237, 0.1);
    padding: 2px 10px;
    border-radius: 20px;
    letter-spacing: normal;
    text-transform: none;
}

/* ===== TOGGLE BUTTONS ===== */
.toggle-container {
    display: flex;
    gap: 4px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 4px;
    border: 1px solid var(--border);
}

.toggle-btn {
    flex: 1;
    padding: 12px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 48px;
    touch-action: manipulation;
}

.toggle-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
}

.toggle-btn.active {
    background: var(--bg-elevated);
    color: var(--accent-bright);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

/* ===== SLIDERS (Touch-friendly) ===== */
.slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    outline: none;
    border: 1px solid var(--border);
    cursor: pointer;
    touch-action: none;
    padding: 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-card);
    box-shadow: 0 0 10px rgba(99, 179, 237, 0.4), var(--shadow-sm);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.slider::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 0 16px rgba(99, 179, 237, 0.6), var(--shadow-md);
}

.slider::-webkit-slider-thumb:active {
    transform: scale(1.25);
    box-shadow: 0 0 24px rgba(99, 179, 237, 0.7);
}

.slider::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    border: 3px solid var(--bg-card);
    box-shadow: 0 0 10px rgba(99, 179, 237, 0.4), var(--shadow-sm);
    cursor: pointer;
}

.slider::-moz-range-track {
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    border: 1px solid var(--border);
}

/* ===== INFO BOX ===== */
#info-box {
    background: rgba(99, 179, 237, 0.06);
    border: 1px solid rgba(99, 179, 237, 0.15);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    text-align: center;
}

#info-type {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent-bright);
}

#info-detail {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
    font-family: var(--font-mono);
}

/* ===== TAB BAR ===== */
#tab-bar {
    display: flex;
    gap: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px;
    margin-bottom: 4px;
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 48px;
    touch-action: manipulation;
    white-space: nowrap;
}

.tab-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.03);
}

.tab-btn.active {
    background: var(--gradient-accent);
    color: #fff;
    box-shadow: 0 2px 12px rgba(99, 179, 237, 0.3);
}

.tab-btn svg {
    flex-shrink: 0;
}

/* ===== PLOT CONTAINERS ===== */
#plot-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    overflow: hidden;
}

.plot-container {
    display: none;
    flex: 1;
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
    min-height: 350px;
    min-width: 0;
    box-shadow: var(--shadow-sm);
}

.plot-container.active {
    display: flex;
}

.plot-container canvas {
    width: 100%;
    height: 100%;
    display: block;
    min-width: 0;
}

/* ===== TRANSFER FUNCTION DISPLAY ===== */
#tf-display {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

#tf-display .tf-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

#tf-display .tf-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

#tf-toggle-btn {
    padding: 4px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: var(--font-main);
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    min-height: 30px;
}

#tf-toggle-btn:hover {
    color: var(--text-secondary);
    border-color: var(--accent);
}

#tf-content {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}

#tf-content::-webkit-scrollbar {
    height: 4px;
}

#tf-content::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.tf-fraction {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    vertical-align: middle;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-primary);
    padding: 0 4px;
}

.tf-fraction .tf-num,
.tf-fraction .tf-den {
    padding: 4px 8px;
    white-space: nowrap;
}

.tf-fraction .tf-line {
    width: 100%;
    height: 1px;
    background: var(--accent);
    margin: 2px 0;
}

.tf-label {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--accent-bright);
    vertical-align: middle;
    margin-right: 6px;
}

.tf-eq {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-muted);
    vertical-align: middle;
    margin: 0 6px;
}

/* ===== DESKTOP LAYOUT ===== */
@media (min-width: 900px) {
    #app-main {
        flex-direction: row;
        height: calc(100dvh - 60px);
        padding: 20px;
        gap: 20px;
    }

    #controls {
        width: 320px;
        flex-shrink: 0;
        overflow-y: auto;
    }

    #plot-area {
        flex: 1;
        min-width: 0;
    }

    .plot-container {
        min-height: 0;
    }
}

@media (min-width: 1200px) {
    #controls {
        width: 360px;
    }

    #app-header h1 {
        font-size: 1.3rem;
    }
}

/* ===== SMALL SCREENS ===== */
@media (max-width: 480px) {
    #app-header {
        padding: 10px 16px;
    }

    #app-header h1 {
        font-size: 1rem;
    }

    #back-btn {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    #app-main {
        padding: 10px;
        gap: 10px;
    }

    #controls {
        padding: 14px;
        gap: 14px;
    }

    .tab-btn {
        font-size: 0.75rem;
        padding: 10px 8px;
    }

    .tab-btn svg {
        display: none;
    }

    .plot-container {
        min-height: 300px;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.plot-container.active {
    animation: fadeIn 0.25s ease;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 6px;
}

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

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

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