:root {
    --bg-color: #020617;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --accent-primary: #fbbf24; /* Amber - Eleganza e Scienza */
    --accent-secondary: #a78bfa; /* Soft Purple */
    --accent-tertiary: #2dd4bf; /* Emerald */
    --accent-danger: #ef4444;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --panel-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    --font-heading: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

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

body {
    background-color: var(--bg-color);
    background-image: radial-gradient(circle at 50% 50%, #0f172a 0%, #020617 100%);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* Background Animated Blobs */
.background-blobs {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: -1;
    overflow: hidden;
}

.background-blobs::after {
    content: '';
    position: absolute;
    top: -10%;
    right: -10%;
    width: 40%;
    height: 40%;
    background: radial-gradient(circle, rgba(79, 172, 254, 0.1) 0%, transparent 70%);
    filter: blur(80px);
    animation: pulse 15s infinite alternate;
}

@keyframes pulse {
    from { transform: scale(1); opacity: 0.5; }
    to { transform: scale(1.2); opacity: 0.8; }
}

.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem;
}

.app-header {
    text-align: center;
    margin-bottom: 3rem;
}

h1 {
    font-family: var(--font-heading);
    font-size: clamp(2.5rem, 5vw, 4rem);
    font-weight: 800;
    background: linear-gradient(135deg, #fff 0%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.header-badge {
    display: inline-block;
    padding: 0.4rem 1rem;
    background: rgba(251, 191, 36, 0.1);
    color: var(--accent-primary);
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 1rem;
    border: 1px solid rgba(251, 191, 36, 0.2);
}

#sub-title {
    font-size: 1.2rem;
    color: var(--text-muted);
    font-weight: 300;
    letter-spacing: 2px;
}

.key-message {
    margin-top: 1rem;
    font-style: italic;
    color: var(--accent-primary);
    opacity: 0.9;
}

.main-layout {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 2rem;
    margin-bottom: 3rem;
}

/* Glassmorphism Common */
.glass {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    box-shadow: var(--panel-shadow);
}

/* Simulation Section */
.simulation-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.canvas-wrapper {
    position: relative;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 20px;
    border: 1px solid var(--glass-border);
    overflow: hidden;
    height: 600px;
}

#galtonCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.narrative-message {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 242, 254, 0.15);
    padding: 0.5rem 1.5rem;
    border-radius: 50px;
    border: 1px solid var(--accent-primary);
    font-size: 0.9rem;
    font-weight: 600;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s, transform 0.5s;
}

.narrative-message.show {
    opacity: 1;
    transform: translateX(-50%) translateY(10px);
}

.stats-bar {
    display: flex;
    justify-content: space-around;
    padding: 1rem;
    background: var(--glass-bg);
    border-radius: 15px;
}

.stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stat-item .label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.stat-item .value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-primary);
}

/* Controls Section */
.controls-section {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.control-group h3, .toggles-group h3 {
    font-family: var(--font-heading);
    font-size: 1.1rem;
    margin-bottom: 1.2rem;
    color: #fff;
    border-left: 3px solid var(--accent-primary);
    padding-left: 10px;
}

.input-wrapper {
    margin-bottom: 1.2rem;
}

.input-wrapper label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.input-wrapper input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.range-val {
    display: block;
    text-align: right;
    font-size: 0.8rem;
    color: var(--accent-primary);
    margin-top: 2px;
}

/* Buttons */
.action-buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.8rem;
}

.btn {
    padding: 0.8rem;
    border-radius: 12px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    font-family: var(--font-body);
}

.btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.btn.primary {
    grid-column: span 2;
    background: linear-gradient(135deg, var(--accent-primary) 0%, #f59e0b 100%);
    color: #000;
}

.btn.primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(251, 191, 36, 0.3);
}

.btn.secondary {
    background: var(--glass-bg);
    color: #fff;
    border: 1px solid var(--glass-border);
}

.btn.secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.1);
}

.btn.danger {
    grid-column: span 2;
    background: transparent;
    color: var(--accent-danger);
    border: 1px solid rgba(255, 75, 43, 0.3);
}

.btn.danger:hover:not(:disabled) {
    background: rgba(255, 75, 43, 0.1);
}

/* Toggles */
.toggle-switch {
    display: flex;
    align-items: center;
    margin-bottom: 1rem;
    cursor: pointer;
}

.toggle-switch input {
    display: none;
}

.slider {
    width: 40px;
    height: 20px;
    background: #333;
    border-radius: 20px;
    position: relative;
    margin-right: 12px;
    transition: 0.3s;
}

.slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: #fff;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: 0.3s;
}

input:checked + .slider {
    background: var(--accent-secondary);
}

input:checked + .slider::before {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9rem;
}

/* Challenge Box */
.challenge-box {
    padding: 1rem;
    border-color: rgba(0, 242, 254, 0.2);
}

.challenge-box h4 {
    margin-bottom: 0.8rem;
    font-size: 0.95rem;
}

.prediction-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
    gap: 4px;
    margin-top: 10px;
}

.prediction-btn {
    aspect-ratio: 1;
    border-radius: 8px;
    border: 1px solid var(--glass-border);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.prediction-btn:hover {
    background: rgba(251, 191, 36, 0.1);
    border-color: var(--accent-primary);
    color: #fff;
    transform: translateY(-2px);
}

.prediction-btn:active {
    transform: scale(0.95);
}

.prediction-btn.selected {
    background: var(--accent-primary);
    color: #000;
    border-color: var(--accent-primary);
    box-shadow: 0 0 15px rgba(251, 191, 36, 0.4);
}

.success {
    color: #00ff88;
    background: rgba(0, 255, 136, 0.1);
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
    border: 1px solid rgba(0, 255, 136, 0.3);
}

.info {
    color: var(--accent-primary);
    background: rgba(0, 242, 254, 0.1);
    padding: 10px;
    border-radius: 8px;
    margin-top: 10px;
    border: 1px solid rgba(0, 242, 254, 0.3);
}

/* Educational Content */
.educational-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.edu-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.edu-card {
    padding: 2rem;
}

.edu-card h3 {
    font-family: var(--font-heading);
    margin-bottom: 1rem;
    color: var(--accent-primary);
}

.content-body p {
    margin-bottom: 1rem;
}

.formula {
    background: rgba(0, 0, 0, 0.3);
    padding: 1.5rem;
    border-radius: 12px;
    margin: 1rem 0;
    text-align: center;
    font-size: 1.1rem;
    border: 1px solid var(--glass-border);
}

.advanced-details {
    padding: 1rem 2rem;
    cursor: pointer;
}

.advanced-details summary {
    font-weight: 600;
    font-family: var(--font-heading);
    color: var(--accent-secondary);
}

.details-content {
    padding-top: 1.5rem;
}

/* Responsive */
/* Interactive Theory Lab Styles */
.theory-lab {
    margin-top: 3rem;
    overflow: hidden;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.theory-lab.minimized {
    max-height: 80px;
}

.lab-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1.5rem 2rem;
    background: rgba(255, 255, 255, 0.02);
}

.lab-icon {
    font-size: 2rem;
    filter: drop-shadow(0 0 10px var(--accent-primary));
}

.lab-title-box h3 {
    font-size: 1.2rem;
    color: #fff;
}

.lab-title-box p {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.lab-content {
    padding: 2rem;
    border-top: 1px solid var(--glass-border);
}

.step-explorer {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.step {
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: 15px;
    border: 1px solid transparent;
    transition: all 0.3s;
    opacity: 0.5;
}

.step.active {
    opacity: 1;
    border-color: var(--accent-primary);
    background: rgba(251, 191, 36, 0.05);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.step h4 {
    color: var(--accent-primary);
    margin-bottom: 0.8rem;
}

.mini-viz {
    margin-top: 1rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    position: relative;
}

.peg.mini {
    width: 6px;
    height: 6px;
    background: #fff;
    border-radius: 50%;
}

.arrow {
    position: absolute;
    font-size: 0.7rem;
    color: var(--text-muted);
}

.arrow.left { left: 10px; }
.arrow.right { right: 10px; }

.lab-footer {
    display: flex;
    justify-content: flex-end;
}

/* Custom Ball Colors for Elegance */
/* Handled in script.js now */

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