/* ===== PROFESSIONAL COMPACT THEME - Alpha-Beta Pruning Visualization ===== */

/* Import professional fonts */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ===== CSS VARIABLES ===== */
:root {
    /* Professional Colors */
    --primary: #1e40af;        /* Deep Blue */
    --primary-dark: #1e3a8a;   /* Darker Blue */
    --primary-light: #dbeafe;  /* Light Blue */
    
    --success: #059669;        /* Green for leaf nodes */
    --danger: #dc2626;         /* Red for MIN nodes */
    --warning: #d97706;        /* Orange for current */
    --secondary: #6b7280;      /* Gray */
    
    --text-dark: #1f2937;      /* Dark text */
    --text-medium: #4b5563;    /* Medium text */
    --text-light: #9ca3af;     /* Light text */
    
    --bg-white: #ffffff;       /* White background */
    --bg-gray: #f9fafb;        /* Light gray background */
    --bg-border: #e5e7eb;      /* Border color */
    
    /* Typography */
    --font-body: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    
    /* Compact spacing */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-7: 2rem;      /* 32px */
    --space-8: 3rem;      /* 48px */
    
    /* Shadows */
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

/* ===== BASE STYLES ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    font-size: 15px;
    line-height: 1.4;
    color: var(--text-dark);
    background: var(--bg-gray);
    height: 100vh;
    overflow-x: auto;
}

.container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding: var(--space-3);
    gap: var(--space-3);
}

/* ===== HEADER ===== */
header {
    background: var(--primary);
    color: var(--bg-white);
    padding: var(--space-4) var(--space-6);
    text-align: center;
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
}

header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin: 0;
}

/* ===== CONTROLS ===== */
.controls {
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-4);
    box-shadow: var(--shadow);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.control-group {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: 0; /* Remove margin between groups */
    flex-wrap: nowrap; /* Keep buttons in one row */
}

.control-btn {
    background: var(--primary);
    color: var(--bg-white);
    border: none;
    border-radius: 0.375rem;
    padding: var(--space-2) var(--space-4);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.control-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.control-btn:disabled {
    background: var(--secondary);
    opacity: 0.6;
    cursor: not-allowed;
}

.speed-control {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-left: auto;
}

.speedSlider {
    width: 80px;
    height: 4px;
    background: var(--bg-border);
    outline: none;
    -webkit-appearance: none;
    border-radius: 2px;
}

.speedSlider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.speedValue {
    font-weight: 600;
    color: var(--primary);
    min-width: 30px;
}

/* ===== STEP CONTROLS ===== */
.step-controls {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.step-counter {
    font-family: var(--font-mono);
    font-size: 0.875rem;
    font-weight: 600;
    background: var(--bg-gray);
    padding: var(--space-2) var(--space-3);
    border-radius: 0.375rem;
    border: 1px solid var(--bg-border);
}

.progress-container {
    flex: 1;
    margin: 0 var(--space-3);
}

.progress-slider {
    width: 100%;
    height: 6px;
    background: var(--bg-border);
    outline: none;
    -webkit-appearance: none;
    border-radius: 3px;
}

.progress-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-white);
}

.progress-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-light);
    margin-top: var(--space-1);
}

/* ===== SCREENSHOT CONTROLS ===== */
.screenshot-controls {
    display: none; /* Temporarily hidden - functionality preserved */
    /* display: flex; */
    align-items: center;
    gap: var(--space-2);
}

.capture-status {
    font-size: 0.875rem;
    color: var(--text-medium);
    font-style: italic;
}

/* ===== CURRENT STEP ===== */
.current-step {
    background: var(--primary-light);
    border: 1px solid var(--bg-border);
    border-left: 4px solid var(--primary);
    border-radius: 0.5rem;
    padding: var(--space-3);
    grid-column: 1; /* Align with tree column */
    grid-row: 1; /* Top row */
}

.current-step h3 {
    color: var(--primary);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: var(--space-2);
}

.current-step p {
    color: var(--text-medium);
    font-size: 0.875rem;
    margin: 0;
}

/* ===== MAIN CONTENT ===== */
.main-content {
    display: grid;
    grid-template-columns: 2fr 1fr; /* Tree gets ~67%, Algorithm gets ~33% */
    grid-template-rows: auto 1fr; /* Current step row, then content */
    gap: var(--space-4);
    min-height: 60vh; /* Ensure minimum height for visibility */
    overflow: hidden;
    flex: 1; /* Take available space */
    /* Ensure main content is visible first */
    order: 0;
}

/* ===== TREE PANEL ===== */
.tree-panel {
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-4);
    box-shadow: var(--shadow);
    overflow: auto;
    grid-column: 1;
    grid-row: 2;
}

.tree-panel h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: var(--space-4);
    text-align: center;
    border-bottom: 2px solid var(--primary);
    padding-bottom: var(--space-2);
}

/* ===== COMPACT TREE STRUCTURE ===== */
.tree-structure {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2); /* More compact gap */
    padding: var(--space-2) 0;
}

/* Tree level containers for connection lines */
.tree-level {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: var(--space-6);
    position: relative;
    width: 100%;
}

.tree-node-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1); /* Minimal gap */
    position: relative;
}

/* Tree connections now handled by CSS pseudo-elements above */

.children-container {
    display: flex;
    gap: var(--space-2); /* More compact horizontal spacing */
    margin-top: var(--space-2);
    position: relative;
}

/* CSS-based tree connections */

/* Classic tree structure - vertical line from parent downward */
.tree-node-container:not(.leaf-node)::before {
    content: '';
    position: absolute;
    top: 50px; /* Below the node */
    left: 50%;
    width: 2px;
    height: 25px; /* Line going down from parent */
    background: var(--danger); /* Red color like your drawing */
    transform: translateX(-50%);
    z-index: 1;
}

/* Horizontal line connecting all children at each level */
.children-container::before {
    content: '';
    position: absolute;
    top: -10px; /* Above the children */
    height: 2px;
    background: var(--danger); /* Red color like your drawing */
    z-index: 1;
    /* For 2 children: span from 25% to 75% (center of each child) */
    left: 25%;
    right: 25%;
}

/* Vertical lines up to each child node */
.children-container .tree-node-container::after {
    content: '';
    position: absolute;
    top: -10px; /* Connect to horizontal line */
    left: 50%;
    width: 2px;
    height: 10px; /* Short line up to each child */
    background: var(--danger); /* Red color like your drawing */
    transform: translateX(-50%);
    z-index: 2;
}

/* ===== TREE NODES ===== */
.tree-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-1);
}

.node-content {
    width: 40px; /* More compact size */
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 1.1rem; /* Increased from 0.8rem */
    font-weight: 600;
    color: var(--bg-white) !important; /* WHITE TEXT - force override */
    border: 2px solid transparent;
    transition: all 0.3s ease;
    box-shadow: var(--shadow);
    background: var(--secondary); /* Default gray background for safety */
    position: relative; /* For positioning node number */
}

/* Node ID number in top-left corner */
.node-id {
    position: absolute;
    top: -8px;
    left: -8px;
    background: var(--text-dark);
    color: var(--bg-white);
    font-size: 0.7rem;
    font-weight: 700;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--bg-white);
    z-index: 10;
}

/* Node colors with WHITE TEXT - clearly visible */
.node-content.max {
    background: linear-gradient(135deg, var(--success), #047857); /* Green gradient for MAX nodes */
    color: var(--bg-white);
    border-radius: 8px; /* Square-ish shape for MAX nodes */
}

.node-content.min {
    background: linear-gradient(135deg, var(--danger), #b91c1c); /* Red gradient for MIN nodes */
    color: var(--bg-white);
    border-radius: 50%; /* Circle shape for MIN nodes */
}

.node-content.leaf {
    background: linear-gradient(135deg, var(--success), #047857); /* Green gradient - same as MAX */
    color: var(--bg-white);
    border-radius: 8px; /* Square-ish shape - same as MAX nodes */
    /* Removed transform: rotate(45deg) - no more diamond shape */
}

/* Remove the counter-rotation for leaf text since leaves are now squares */

/* Explored vs Unexplored node states */
.node-content.explored {
    border: 3px solid var(--primary-dark); /* Thick border for explored nodes */
    box-shadow: 0 0 8px rgba(59, 130, 246, 0.3), var(--shadow); /* Blue glow */
}

.node-content.unexplored {
    border: 2px dashed var(--text-light); /* Dashed border for unexplored nodes */
    opacity: 0.7; /* Slightly faded */
}

.node-content.current {
    border-color: var(--warning) !important;
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.2), var(--shadow);
    transform: scale(1.1);
}

.node-content.evaluated {
    opacity: 0.8;
}

.node-content.pruned {
    background: var(--secondary);
    opacity: 0.6;
}

.node-content.pruned::after {
    content: '✕';
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: var(--bg-white);
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
}

.node-bounds {
    font-family: var(--font-mono);
    font-size: 0.9rem; /* Increased from 0.7rem */
    color: var(--text-dark);
    background: var(--bg-white);
    padding: var(--space-1) var(--space-2);
    border-radius: 0.25rem;
    border: 1px solid var(--bg-border);
    text-align: center;
    min-width: 60px;
    box-shadow: var(--shadow);
}

/* ===== ALGORITHM PANEL ===== */
.algorithm-panel {
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-4);
    box-shadow: var(--shadow);
    overflow: auto;
    grid-column: 2;
    grid-row: 1 / 3; /* Span both rows to align with current step */
}

.algorithm-panel h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: var(--space-4);
    text-align: center;
    border-bottom: 2px solid var(--primary);
    padding-bottom: var(--space-2);
}

/* ===== PSEUDOCODE ===== */
.pseudocode {
    background: var(--bg-gray);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-3);
    font-family: var(--font-mono);
    font-size: 0.875rem; /* Larger font */
    line-height: 1.4;
    color: var(--text-dark);
    overflow-x: auto;
    white-space: nowrap;
}

.code-line {
    padding: var(--space-1) var(--space-2);
    border-radius: 0.25rem;
    transition: all 0.2s ease;
    margin-bottom: 1px;
}

.code-line.highlighted {
    background: var(--primary-light);
    border-left: 3px solid var(--primary);
    color: var(--primary-dark);
    font-weight: 600;
}

.code-line.highlighted::before {
    content: '▶ ';
    color: var(--primary);
    font-weight: bold;
}

.blank-line {
    height: 1em;
    line-height: 1;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }
    
    .container {
        height: auto;
        min-height: 100vh;
    }
}

@media (max-width: 768px) {
    .controls {
        flex-direction: column;
        align-items: stretch;
        gap: var(--space-2);
    }
    
    .control-group {
        justify-content: center;
    }
    
    .speed-control {
        margin-left: 0;
    }
    
    .progress-container {
        margin: 0;
    }
    
    .node-content {
        width: 40px;
        height: 40px;
        font-size: 1rem; /* Increased from 0.75rem for mobile */
    }
    
    .pseudocode {
        font-size: 0.75rem;
    }
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.node-content.current {
    animation: pulse 2s infinite;
}

/* ===== FOCUS STYLES ===== */
.control-btn:focus,
.speedSlider:focus,
.progress-slider:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ===== ADVERTISEMENT STYLES ===== */
.ad-banner {
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-3);
    box-shadow: var(--shadow);
    text-align: center;
    margin: var(--space-2) 0;
}

.ad-footer {
    margin-top: var(--space-3);
    /* Footer ad comes after educational content */
    order: 2;
}

.ad-placeholder {
    background: var(--bg-gray);
    border: 2px dashed var(--bg-border);
    border-radius: 0.375rem;
    padding: var(--space-4);
    color: var(--text-light);
    font-size: 0.875rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 90px;
}

.ad-placeholder p {
    margin: 0 0 var(--space-1) 0;
    font-weight: 500;
}

.ad-placeholder small {
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Responsive ad adjustments */
@media (max-width: 1200px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .ad-banner {
        padding: var(--space-2);
        margin: var(--space-1) 0;
    }
    
    .ad-placeholder {
        min-height: 60px;
        padding: var(--space-2);
    }
    
    .ad-placeholder p {
        font-size: 0.75rem;
    }
    
    .ad-placeholder small {
        font-size: 0.625rem;
    }
}

/* ===== EDUCATIONAL CONTENT STYLES ===== */
.educational-content {
    margin-top: var(--space-6);
    padding: var(--space-4);
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    /* Educational content comes right after main content */
    order: 1;
}

.content-section {
    margin-bottom: var(--space-6);
}

.content-section:last-child {
    margin-bottom: 0;
}

.content-section h3 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: var(--space-4);
    text-align: center;
    border-bottom: 2px solid var(--primary);
    padding-bottom: var(--space-2);
}

.content-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: var(--space-4);
}

.content-card {
    background: var(--bg-gray);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-4);
    transition: all 0.3s ease;
}

.content-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--primary);
}

.content-card h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: var(--space-3);
    border-bottom: 1px solid var(--bg-border);
    padding-bottom: var(--space-2);
}

.content-card p {
    color: var(--text-medium);
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: var(--space-3);
}

.content-card ul, .content-card ol {
    color: var(--text-medium);
    font-size: 0.875rem;
    line-height: 1.6;
    margin-bottom: var(--space-3);
    padding-left: var(--space-4);
}

.content-card li {
    margin-bottom: var(--space-1);
}

.highlight-box {
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: 0.375rem;
    padding: var(--space-3);
    margin-top: var(--space-3);
    font-size: 0.875rem;
    color: var(--primary-dark);
}

.complexity-table {
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.375rem;
    overflow: hidden;
    margin-top: var(--space-3);
}

.complexity-row {
    display: flex;
    justify-content: space-between;
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--bg-border);
    font-size: 0.875rem;
}

.complexity-row:last-child {
    border-bottom: none;
}

.complexity-row:first-child {
    background: var(--primary-light);
    font-weight: 600;
    color: var(--primary-dark);
}

/* Responsive educational content */
@media (max-width: 768px) {
    .educational-content {
        padding: var(--space-3);
        margin-top: var(--space-4);
    }
    
    .content-grid {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }
    
    .content-card {
        padding: var(--space-3);
    }
    
    .content-section h3 {
        font-size: 1.25rem;
    }
}

/* ===== COMMERCIAL ADVERTISEMENT STYLES ===== */
.commercial-ads {
    margin-top: var(--space-6);
    padding: var(--space-4);
    background: var(--bg-white);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    /* Add significant spacing to push ads below the fold */
    margin-bottom: var(--space-8);
    /* Commercial ads come last */
    order: 3;
}

.ad-section {
    margin-bottom: var(--space-6);
}

.ad-section:last-child {
    margin-bottom: 0;
}

.ad-section h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: var(--space-4);
    text-align: center;
    border-bottom: 2px solid var(--primary);
    padding-bottom: var(--space-2);
}

.ad-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-4);
}

.ad-card {
    background: var(--bg-gray);
    border: 1px solid var(--bg-border);
    border-radius: 0.5rem;
    padding: var(--space-4);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.ad-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: var(--primary);
}

.ad-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--space-3);
}

.ad-badge {
    background: var(--primary);
    color: var(--bg-white);
    font-size: 0.75rem;
    font-weight: 500;
    padding: var(--space-1) var(--space-2);
    border-radius: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ad-card h4 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
    flex: 1;
    margin-left: var(--space-2);
}

.ad-card p {
    color: var(--text-medium);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-bottom: var(--space-3);
}

.ad-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto;
}

.ad-price {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--success);
}

.ad-btn {
    background: var(--primary);
    color: var(--bg-white);
    text-decoration: none;
    padding: var(--space-2) var(--space-4);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
}

.ad-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

/* Responsive commercial ads */
@media (max-width: 768px) {
    .commercial-ads {
        padding: var(--space-3);
        margin-top: var(--space-4);
    }
    
    .ad-grid {
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }
    
    .ad-card {
        padding: var(--space-3);
    }
    
    .ad-card-header {
        flex-direction: column;
        gap: var(--space-2);
    }
    
    .ad-card h4 {
        margin-left: 0;
    }
    
    .ad-card-footer {
        flex-direction: column;
        gap: var(--space-2);
        align-items: stretch;
    }
    
    .ad-btn {
        text-align: center;
        justify-content: center;
    }
}