/* Convection simulation: page-specific styles (loaded after simulation_styles.css).
   The hint, legend and Heat / Cool switch match conduction_styles.css. */

/* The canvas is a heating/cooling tool: show a crosshair, and stop drags and
   long-presses on it from selecting page text or opening the iOS callout. */
#simulationCanvas {
    cursor: crosshair;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* "Crosshair and brush circle" switched off in the settings */
#simulationCanvas.no-brush-guides {
    cursor: default;
}

/* ---------- Docked settings panel: opens beside the canvas, which stays where it is ----------
   The square canvas leaves wide margins in the column. The shared layout puts the panel at the column's
   right edge and re-centres the canvas in what is left, which moves the canvas and leaves a gap before
   the panel. Here the panel opens in the free space right of the canvas column (canvas plus info bar),
   with the column's box running on under it; only when that space is too narrow does the column move
   left, and only as far as the panel needs. Percentages are of the area beside the page gutters. */
.simulation-area-wrapper {
    --convection-panel-gap: 1rem;
}

body.sim-panel-side:not(.sim-fullscreen-active) .sim-controls-panel.panel-open {
    margin-left: var(--convection-panel-gap);
}

body.sim-panel-side:not(.sim-fullscreen-active) .sim-controls-panel.panel-open + .simulation-main-content {
    /* The column's natural width (simulation_styles.css), the room the panel takes beside it, and how
       far the column has to move left to make that room (never more than the shared layout moves it) */
    --convection-column-w: max(calc(var(--sim-canvas-max-h) * (var(--aspect-ratio, 1 / 1)) + 2px), 26em);
    --convection-panel-room: calc(var(--sim-panel-width) + var(--convection-panel-gap));
    --convection-shift: clamp(0px, var(--convection-column-w) + 2 * var(--convection-panel-room) - 100%, var(--convection-panel-room));
    flex: 0 0 calc(100% - var(--convection-shift));
    margin-right: calc(var(--convection-shift) - max((100% - var(--convection-column-w)) / 2, var(--convection-panel-room)));
}

/* Fullscreen: the panel stays a full-height strip at the screen edge, and the canvas (as tall as the
   space above the info bar, less the column's 8px padding) keeps its place in the middle of the screen
   while there is room for it beside the panel. */
body.sim-fullscreen-active.sim-panel-side .sim-controls-panel.panel-open + .simulation-main-content {
    --convection-canvas-h: calc(100vh - var(--sim-fullscreen-info-bar-height, 56px) - 16px);
    margin-left: clamp(0px, 100% - var(--sim-panel-width) - 16px - var(--convection-canvas-h), var(--sim-panel-width));
}

@supports (height: 100dvh) {
    body.sim-fullscreen-active.sim-panel-side .sim-controls-panel.panel-open + .simulation-main-content {
        --convection-canvas-h: calc(100dvh - var(--sim-fullscreen-info-bar-height, 56px) - 16px);
    }
}

/* A closing panel fades out before giving its width back (simulation_styles.css); hold the canvas
   where it is until then. */
body.sim-panel-side .sim-controls-panel:not(.panel-open) + .simulation-main-content {
    transition: flex 0s linear 0.2s, margin 0s linear 0.2s;
}

/* ---------- First-use hint over the canvas (hidden after the first press) ---------- */
.thermal-hint {
    position: absolute;
    left: 50%;
    bottom: 0.75em;
    transform: translateX(-50%);
    margin: 0;
    padding: 0.3em 0.8em;
    width: max-content; /* left: 50% would otherwise wrap it at half the canvas width */
    max-width: calc(100% - 1.5em);
    box-sizing: border-box;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    font-size: 0.8em;
    line-height: 1.4;
    text-align: center;
    pointer-events: none;
    transition: opacity 0.4s ease-out;
    z-index: 5;
}

.thermal-hint.is-hidden {
    opacity: 0;
}

/* ---------- Info bar: readout, colour legend, Heat / Cool switch, reset ---------- */
.sim-info-bar .sim-info-actions {
    margin-left: auto;
    gap: 0.5em;
}

.thermal-legend {
    display: inline-flex;
    align-items: center;
    gap: 0.45em;
    font-size: 0.75em;
    color: var(--color-text);
    white-space: nowrap;
    margin-right: auto; /* stays beside the readout when the actions wrap below */
}

.thermal-legend > span:not(.thermal-legend-bar) {
    opacity: 0.75;
}

.thermal-legend-bar {
    display: inline-block;
    width: 5.5em;
    height: 0.6em;
    border-radius: 0.3em;
    background: linear-gradient(to right, #0000ff, #00ffff, #00ff00, #ffff00, #ff0000);
}

/* Segmented Heat / Cool switch (overrides main.css's large uppercase buttons) */
.thermal-mode {
    display: inline-flex;
    padding: 2px;
    gap: 2px;
    border-radius: 8px;
    box-shadow: inset 0 0 0 1px var(--color-border);
}

.thermal-mode button {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35em;
    height: 40px;
    min-width: 40px;
    padding: 0 0.7em;
    border-radius: 6px;
    box-shadow: none;
    background-color: transparent;
    color: var(--color-text) !important;
    font-size: 0.8em;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1;
    text-transform: none;
}

.thermal-mode button:hover {
    box-shadow: none;
    background-color: var(--color-bg-subtle);
    color: var(--color-text) !important;
}

.thermal-mode button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

.thermal-mode button .icon:before {
    line-height: 1;
}

.thermal-mode button[data-mode="heat"][aria-checked="true"] {
    background-color: #c2410c;
    color: #ffffff !important;
}

.thermal-mode button[data-mode="cool"][aria-checked="true"] {
    background-color: #1971c2;
    color: #ffffff !important;
}

/* Narrow info bars (e.g. a square canvas on a phone in landscape): icon-only Heat / Cool buttons
   (the words stay for screen readers) and a legend without its labels, so everything fits. */
.sim-info-bar {
    container-type: inline-size;
}

@container (max-width: 300px) {
    .thermal-mode button {
        padding: 0 0.6em;
    }

    .thermal-mode-label {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
    }

    .thermal-legend > span:not(.thermal-legend-bar) {
        display: none;
    }

    .thermal-legend-bar {
        width: 3em;
    }
}

/* ---------- Small screens ---------- */
@media (max-width: 480px) {
    .thermal-legend-bar {
        width: 3.5em;
    }

    .thermal-hint {
        font-size: 0.7em;
        bottom: 0.5em;
    }
}
