:root {
    --bg: #f8fafc;
    --text: #0f172a;
    --muted: #475569;
    --border: #e5e7eb;
    --card: #ffffff;
    --shadow: 0 6px 20px rgba(15,23,42,0.06);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --success: #22c55e;
    --success-bg: #dcfce7;
    --warning: #f59e0b;
    --warning-bg: #fff7ed;
    --error: #ef4444;
    --error-bg: #fee2e2;
}

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

html, body { height: 100%; }

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

.container { max-width: 1400px; margin: 24px auto; padding: 0 16px; }

header { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
header h1 { font-size: 24px; letter-spacing: 0.2px; margin: 0; }
header .description { 
    color: var(--muted); 
    line-height: 1.45;
    max-width: 900px;
}
header .description a { 
    color: var(--accent); 
    text-decoration: none; 
}
header .description a:hover { 
    text-decoration: underline; 
}
header .description strong { 
    color: var(--text); 
}
header .description .highlight { 
    color: var(--success); 
    font-weight: 600; 
}

.distribution-chart {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-top: 12px;
}
.distribution-chart h4 {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.dist-bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
    font-size: 0.7rem;
}
.dist-bar-row .dist-label {
    width: 80px;
    text-align: right;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.dist-bar-row .dist-bar-bg {
    flex: 1;
    height: 14px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
}
.dist-bar-row .dist-bar-high {
    height: 100%;
    background: var(--success);
}
.dist-bar-row .dist-bar-low {
    height: 100%;
    background: var(--error);
}
.dist-bar-row .dist-count {
    width: 50px;
    color: var(--muted);
}

.main-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0;
}

.main-tab {
    padding: 12px 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}

.main-tab:hover { color: var(--text); }
.main-tab.active {
    background: var(--card);
    color: var(--accent);
    border-color: var(--border);
    border-bottom: 2px solid var(--card);
    position: relative;
    z-index: 1;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-content {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0 14px 14px 14px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.algo-grid {
    display: grid;
    grid-template-columns: 280px 1fr 280px;
    gap: 20px;
}

@media (max-width: 1100px) {
    .algo-grid { grid-template-columns: 1fr; }
}

.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.card h3 {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.control-group { margin-bottom: 14px; }
.control-group:last-child { margin-bottom: 0; }
.control-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 4px;
}
.control-group .val {
    float: right;
    color: var(--accent);
    font-weight: 600;
}

input[type="range"] {
    width: 100%;
    height: 5px;
    border-radius: 3px;
    background: var(--border);
    appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: 2px solid var(--card);
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

select {
    width: 100%;
    padding: 8px 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.85rem;
}

.checkbox-list { display: flex; flex-direction: column; gap: 6px; }
.checkbox-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--muted);
}
.checkbox-item input { accent-color: var(--accent); }

button.primary {
    width: 100%;
    padding: 10px 16px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    margin-top: 12px;
}
button.primary:hover { background: var(--accent-hover); }

.sidebar-col {
    min-width: 0;
    overflow: hidden;
}

.metrics-row {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 16px;
}

.metric {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 10px 8px;
    border-radius: 12px;
    text-align: center;
}

.metric .value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
}

.metric .label {
    display: block;
    font-size: 0.65rem;
    color: var(--muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.metric.accent {
    background: var(--warning-bg);
    border-color: #fed7aa;
}
.metric.accent .value {
    color: #b45309;
}

.tree-container {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    min-height: 350px;
    overflow: hidden;
    position: relative;
}

.tree-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.tree-header h3 { margin: 0; }

.zoom-controls { display: flex; gap: 6px; align-items: center; }
.zoom-controls button {
    padding: 4px 10px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    cursor: pointer;
    font-size: 0.8rem;
}
.zoom-controls button:hover {
    border-color: var(--accent);
    color: var(--accent);
}
.zoom-controls .zoom-level {
    font-size: 0.7rem;
    color: var(--muted);
    min-width: 40px;
    text-align: center;
}

.tree-viewport {
    width: 100%;
    height: 400px;
    overflow: hidden;
    cursor: grab;
    position: relative;
    border-radius: 12px;
    background: var(--card);
    border: 1px solid var(--border);
}
.tree-viewport:active { cursor: grabbing; }
.tree-viewport-inner {
    transform-origin: 0 0;
    position: absolute;
}

#tree-svg, #manual-tree-svg { min-height: 280px; }

.tree-node rect {
    fill: var(--card);
    stroke: var(--border);
    stroke-width: 1.5px;
    rx: 6;
}
.tree-node:hover rect { stroke: var(--accent); }
.tree-node.leaf.positive rect { 
    fill: var(--success-bg);
    stroke: var(--success); 
    stroke-width: 2px; 
}
.tree-node.leaf.negative rect { 
    fill: var(--error-bg);
    stroke: var(--error); 
    stroke-width: 2px; 
}
.tree-node text { fill: var(--text); font-size: 10px; }
.tree-node text.sub { fill: var(--muted); font-size: 9px; }
.tree-link { fill: none; stroke: var(--border); stroke-width: 1.5px; }

.legend {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--muted);
}
.legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
}
.legend-dot.pos { background: var(--success); }
.legend-dot.neg { background: var(--error); }

.importance-bars { margin-top: 8px; }
.imp-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}
.imp-row .fname {
    width: 90px;
    font-size: 0.75rem;
    color: var(--muted);
    text-align: right;
    flex-shrink: 0;
}
.imp-row .bar-bg {
    flex: 1;
    height: 16px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.imp-row .bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--success));
    border-radius: 4px;
}
.imp-row .pct {
    width: 40px;
    font-size: 0.75rem;
    color: var(--text);
    font-weight: 600;
}

.manual-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
}

@media (max-width: 900px) {
    .manual-grid { grid-template-columns: 1fr; }
}

.manual-builder { 
    background: var(--bg); 
    border: 1px solid var(--border);
    border-radius: 12px; 
    padding: 16px; 
}

.node-editor {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    border-left: 3px solid var(--accent);
}

.node-editor.leaf-node { border-left-color: var(--success); }
.node-editor.highlighted { 
    border-left-color: var(--warning); 
    border-left-width: 4px;
    background: var(--warning-bg);
}
.node-editor.highlighted > h4 { color: var(--warning); }

.node-editor h4 {
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 8px;
}

.tree-node { cursor: pointer; }
.tree-node.selected rect { stroke: var(--warning) !important; stroke-width: 3px !important; }

.node-row {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.node-row select, .node-row input {
    flex: 1;
    padding: 6px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.8rem;
}

.node-children {
    margin-left: 20px;
    padding-left: 12px;
    border-left: 1px dashed var(--border);
}

.add-node-btn {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--muted);
    padding: 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    width: 100%;
    margin-top: 8px;
}
.add-node-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: transparent;
}

.remove-btn {
    background: transparent;
    border: none;
    color: var(--error);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px 6px;
}

.manual-results {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.info-text {
    color: var(--muted);
    font-size: 0.85rem;
    text-align: center;
    padding: 40px 20px;
}

header .dataset-info {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 4px;
}
header .dataset-info span {
    color: var(--accent);
    font-weight: 500;
}

.legend .branch-hint {
    color: var(--muted);
    font-size: 0.75rem;
    margin-left: auto;
    opacity: 0.8;
}

/* Educational Section */
.education-section {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
    margin-top: 24px;
    box-shadow: var(--shadow);
}

.education-section h2 {
    font-size: 1.3rem;
    margin-bottom: 12px;
    color: var(--text);
}

.education-section .intro {
    color: var(--muted);
    margin-bottom: 20px;
    font-size: 0.9rem;
    line-height: 1.7;
}

.criteria-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
    margin-bottom: 24px;
}

.criterion-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    border-left: 3px solid var(--accent);
}

.criterion-card h3 {
    font-size: 1rem;
    color: var(--accent);
    margin-bottom: 10px;
}

.criterion-card p {
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 12px;
}

.criterion-card .formula {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    overflow-x: auto;
    font-size: 0.95rem;
}

.criterion-card .example {
    background: var(--warning-bg);
    border: 1px solid #fed7aa;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--muted);
    margin: 12px 0;
    border-left: 3px solid var(--warning);
}

.criterion-card .properties {
    font-size: 0.8rem;
    color: var(--muted);
    padding-left: 20px;
    margin-top: 12px;
}

.criterion-card .properties li {
    margin-bottom: 6px;
}

.comparison-section {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 20px;
}

.comparison-section h3 {
    font-size: 1rem;
    color: var(--text);
    margin-bottom: 12px;
}

.comparison-section p {
    font-size: 0.85rem;
    color: var(--muted);
    line-height: 1.6;
    margin-bottom: 10px;
}

.comparison-section ul {
    font-size: 0.85rem;
    color: var(--muted);
    padding-left: 24px;
    margin-bottom: 16px;
}

.comparison-section ul li {
    margin-bottom: 6px;
}

.comparison-section .formula {
    background: var(--card);
    border: 1px solid var(--border);
    padding: 12px 16px;
    border-radius: 8px;
    margin: 12px 0;
    overflow-x: auto;
}

/* Footer / Tagline */
.footer {
    text-align: center;
    padding: 24px 16px;
    margin-top: 24px;
    color: var(--muted);
    font-size: 0.85rem;
}

/* Hide elements when needed */
.hidden { display: none !important; }
