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

:root {
    --bg-color: #F5F5F0;
    /* Papier/Ecru */
    --text-color: #000000;
    /* Noir Pur */
    --accent-blue: #0044CC;
    /* Bleu Plan */
    --accent-red: #CC0000;
    /* Rouge Alerte */
    --grid-line: 1px solid #000000;
    --font-mono: 'Courier New', Courier, monospace;
    --font-sans: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-sans);
    line-height: 1.5;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* App-like feel */
}

/* HEADER */
.main-header {
    border-bottom: var(--grid-line);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: var(--bg-color);
    z-index: 10;
}

h1 {
    font-family: var(--font-mono);
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.subtitle {
    font-weight: 400;
    opacity: 0.7;
    display: none;
    /* Hidden on small mobile */
}

@media (min-width: 600px) {
    .subtitle {
        display: inline;
    }
}

.meta-info {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    text-align: right;
}

.meta-info span {
    display: block;
}

/* LAYOUT */
.grid-container {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
    height: 100%;
    overflow-y: auto;
}

@media (min-width: 900px) {
    .grid-container {
        grid-template-columns: 2fr 1fr;
        /* Visualizer takes 2/3 */
        grid-template-rows: 1fr auto;
        overflow: hidden;
    }
}

/* PANELS */
.panel {
    border-bottom: var(--grid-line);
    padding: 1rem;
    position: relative;
}

@media (min-width: 900px) {
    .visualizer-panel {
        grid-row: 1 / -1;
        grid-column: 1 / 2;
        border-right: var(--grid-line);
        border-bottom: none;
        display: flex;
        flex-direction: column;
    }

    .controls-panel {
        grid-row: 1 / 2;
        grid-column: 2 / 3;
        overflow-y: auto;
    }

    .theory-panel {
        grid-row: 2 / 3;
        grid-column: 2 / 3;
        border-top: var(--grid-line);
        /* Explicit border if needed */
    }
}

.panel-title {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    text-transform: uppercase;
    margin-bottom: 1rem;
    border-bottom: 1px dotted #000;
    padding-bottom: 0.2rem;
    display: inline-block;
}

/* VISUALIZER */
.canvas-container {
    position: relative;
    flex-grow: 1;
    min-height: 300px;
    /* Mobile minimum */
    background-image:
        linear-gradient(rgba(0, 0, 0, 0.05) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 0, 0, 0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    border: 1px solid #000;
    margin-bottom: 1rem;
    display: flex;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
}

/* Energy Profile within Visualizer */
.energy-profile {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 60px;
    border-left: 1px dashed #000;
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 0;
}

.energy-bar {
    width: 30px;
    height: 4px;
    background: #000;
    margin: 2px 0;
    transition: transform 0.3s ease;
}

.energy-label {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    position: absolute;
}

.energy-label.top {
    top: 10px;
}

.energy-label.bottom {
    bottom: 10px;
}

.energy-gap-indicator {
    height: 50px;
    /* Dynamic */
    border-left: 1px solid #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    margin: 5px 0;
}

/* LEGEND */
.legend {
    display: flex;
    gap: 1rem;
    font-size: 0.8rem;
    font-family: var(--font-mono);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.swatch {
    width: 12px;
    height: 12px;
    border: 1px solid #000;
}

.swatch.positive {
    background-color: var(--accent-blue);
}

.swatch.negative {
    background-color: var(--accent-red);
}

.swatch.node {
    background: repeating-linear-gradient(45deg, #ccc, #ccc 2px, #fff 2px, #fff 4px);
}

/* CONTROLS */
.control-group {
    margin-bottom: 1.5rem;
}

label {
    display: block;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    margin-bottom: 0.4rem;
    font-weight: 700;
}

select,
input[type="range"] {
    width: 100%;
    display: block;
}

select {
    padding: 0.5rem;
    border: 1px solid #000;
    background: #fff;
    border-radius: 0;
    font-family: var(--font-mono);
    cursor: pointer;
    appearance: none;
    /* Custom arrow ideally, but simple for now */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1em;
}

/* Custom Range Slider */
input[type=range] {
    -webkit-appearance: none;
    background: transparent;
}

input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 16px;
    width: 16px;
    background: #000;
    cursor: pointer;
    margin-top: -6px;
    border-radius: 50%;
}

input[type=range]::-webkit-slider-runnable-track {
    width: 100%;
    height: 4px;
    cursor: pointer;
    background: #ccc;
    border: 1px solid #000;
}

.value-display {
    text-align: right;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    margin-top: 0.2rem;
}

/* Switch */
.switch-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #fff;
    border: 1px solid #000;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 3px;
    bottom: 3px;
    background-color: #000;
    transition: .4s;
}

input:checked+.slider {
    background-color: #ccc;
}

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

/* MONITOR */
.monitor {
    background: #fff;
    border: 1px solid #000;
    padding: 0.8rem;
    font-family: var(--font-mono);
    margin-top: 2rem;
    box-shadow: 4px 4px 0px #000;
}

.monitor h3 {
    font-size: 0.75rem;
    border-bottom: 1px solid #eee;
    margin-bottom: 0.5rem;
    color: #666;
}

.data-value {
    font-weight: 700;
    color: var(--accent-blue);
}

.console-output {
    font-size: 0.8rem;
    color: #333;
    margin-top: 0.5rem;
    min-height: 1.2em;
}

/* THEORY */
.theory-panel details {
    cursor: pointer;
}

.theory-panel summary {
    font-weight: bold;
    font-family: var(--font-mono);
    margin-bottom: 0.5rem;
}

.theory-content {
    font-size: 0.9rem;
    padding-left: 1rem;
    border-left: 2px solid #ccc;
}

.formula-box {
    background: #fff;
    border: 1px dashed #000;
    padding: 0.5rem;
    margin: 1rem 0;
    font-family: var(--font-mono);
    text-align: center;
    font-size: 0.85rem;
    overflow-x: auto;
}

.theory-content p {
    margin-bottom: 0.8rem;
}

.principles-list {
    list-style-type: none;
    margin-bottom: 1rem;
}

.principles-list li {
    margin-bottom: 0.5rem;
    padding-left: 10px;
    position: relative;
}

.principles-list li::before {
    content: "■";
    position: absolute;
    left: -5px;
    font-size: 0.6em;
    top: 5px;
}