/* Renewables series: standalone-simulation shell. Cream page, canvas above
   the controls (portrait) or to their left (landscape); the explainer sits
   under the controls in the same column, so the sliders stay in view and the
   canvas keeps the full height.
   Palette values are the house "Honey & ink" tokens copied as literals; this
   file imports no site CSS so the sim stays self-contained. The same shell is
   used by every sim in Renewables/, so keep the copies in step. */
@import url('https://fonts.googleapis.com/css2?family=Source+Sans+3:wght@400;600;700&display=swap');

/* ── Reset & base ────────────────────────────────────────────── */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Source Sans 3', Arial, sans-serif;
    background-color: #fffaea;
    color: #34302a;
}

/* ── Outer container ─────────────────────────────────────────── */
#simulation-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
}

/* ── Canvas area ─────────────────────────────────────────────── */
#canvas-container {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
}

#canvas-container canvas {
    display: block;
    /* p5 writes inline width/height styles on the element, so !important is
       required to win. height: auto preserves the aspect ratio while max-width
       downscales; height fitting belongs in windowResized(). */
    max-width: 100% !important;
    height: auto !important;
}

/* ── Controls panel ──────────────────────────────────────────── */
#controls-container {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 14px;
    background-color: #f8f5ec;
    border-top: 1px solid #ded5bf;
    flex-shrink: 0;
    max-height: 42vh;   /* portrait: the canvas keeps the larger share */
    overflow-y: auto;
}

/* Children must never shrink below their content when the column scrolls */
#controls-container > * { flex-shrink: 0; }

/* ── Explainer text ──────────────────────────────────────────── */
#explainer {
    padding: 4px 12px;
    background-color: #faf0cd;
    border: 1px solid #ded5bf;
    border-left: 4px solid #f2c419;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.45;
}

#explainer summary {
    cursor: pointer;
    font-weight: 700;
    font-size: 15px;
    padding: 4px 0;
    color: #8c690d;
}

#explainer summary:focus-visible {
    outline: 3px solid #a87f10;
    outline-offset: 2px;
}

#explainer-body {
    padding-bottom: 6px;
}

#explainer-body p { margin: 4px 0; }

#explainer-body .try-title { font-weight: 700; margin-top: 8px; }

#explainer-body ul {
    margin: 2px 0 0 0;
    padding-left: 20px;
}

#explainer-body li { margin: 3px 0; }

.controls-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px 14px;
}

.group-label {
    font-size: 13px;
    font-weight: 700;
    color: #34302a;
    margin-top: 2px;
}

/* ── Mode / preset buttons ───────────────────────────────────── */
.mode-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.mode-btn {
    flex: 1 1 60px;
    padding: 6px 8px;
    font-size: 12px;
    font-weight: bold;
    font-family: 'Source Sans 3', Arial, sans-serif;
    line-height: 1.3;
    text-align: center;
    color: #34302a;
    border: 2px solid #cfc5ab;
    border-radius: 4px;
    background-color: #f0ece1;
    cursor: pointer;
    transition: background-color 0.2s, border-color 0.2s;
}

/* PeltonOptimum: four long preset labels, so two buttons per row */
#preset-row .mode-btn { flex: 1 1 calc(50% - 3px); }

.mode-btn:hover  { background-color: #f7df8b; border-color: #f2c419; }
.mode-btn.active { background-color: #f2c419; border-color: #a87f10; color: #34302a; }

/* ── Slider control items ────────────────────────────────────── */
.control-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.control-item label {
    font-size: 13px;
    font-weight: bold;
    color: #34302a;
}

.slider {
    width: 100%;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: #e6dfd0;
    outline: none;
    border-radius: 3px;
    margin: 6px 0;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    background: #4f9143;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #3c6e26;
}

.slider::-moz-range-thumb {
    width: 22px;
    height: 22px;
    background: #4f9143;
    cursor: pointer;
    border-radius: 50%;
    border: 2px solid #3c6e26;
}

.slider-value {
    font-family: monospace;
    font-size: 12px;
    color: #5d5749;
}

/* ── Action buttons ──────────────────────────────────────────── */
#action-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.action-btn {
    flex: 1 1 80px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: bold;
    font-family: 'Source Sans 3', Arial, sans-serif;
    color: #34302a;
    border: 2px solid #a87f10;
    border-radius: 4px;
    background-color: #f2c419;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s, box-shadow 0.2s;
}

.action-btn.secondary {
    background-color: #f0ece1;
    border-color: #cfc5ab;
}

.action-btn.secondary[aria-pressed="true"] {
    background-color: #f7df8b;
    border-color: #a87f10;
}

.action-btn:hover {
    background-color: #d9a414;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(0,0,0,0.2);
}

.action-btn.secondary:hover { background-color: #f7df8b; }

.action-btn:active { transform: translateY(0); box-shadow: none; }

/* Keyboard focus is always visible: a thick gold-brown ring on every control. */
.action-btn:focus-visible,
.mode-btn:focus-visible {
    outline: 3px solid #a87f10;
    outline-offset: 2px;
}

.slider:focus-visible {
    outline: 3px solid #a87f10;
    outline-offset: 4px;
}

.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px #f7df8b; }
.slider:focus-visible::-moz-range-thumb     { box-shadow: 0 0 0 3px #f7df8b; }

.hint {
    margin: 0;
    font-size: 11px;
    color: #5d5749;
}

/* ── Landscape: side-by-side ─────────────────────────────────── */
@media (orientation: landscape) and (min-width: 700px) {
    #simulation-container { flex-direction: row; }

    #controls-container {
        width: 310px;
        max-height: none;
        flex-shrink: 0;
        border-top: none;
        border-left: 1px solid #ded5bf;
        overflow-y: auto;
    }
}

/* ── Phones: one slider column, roomier thumbs ───────────────── */
@media (max-width: 480px) {
    .controls-grid { grid-template-columns: 1fr; }
    #explainer { font-size: 13px; }
}

@media (max-width: 768px) {
    .slider::-webkit-slider-thumb { width: 28px; height: 28px; }
    .slider::-moz-range-thumb     { width: 28px; height: 28px; }
}
