/* --- Maxwell's demon simulation: page-specific styles (loaded after simulation_styles.css) --- */

/* Particle colours. maxwell_demon_core.js reads these, so the canvas, the readouts,
   the legend and the charts all use the same red and blue. */
:root {
    --mx-fast: #e0242b;
    --mx-slow: #1f62d6;
}
html.dark-mode {
    --mx-fast: #ff4646;
    --mx-slow: #3f8cff;
}

/* --- Canvas --- */

/* Press-and-hold must not select text, start a drag or open the long-press menu.
   The page can still scroll over the canvas in automatic mode; in manual mode the
   canvas is a hold-to-open button, so touches go to it instead of scrolling. */
#simulationCanvas {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: auto;
}
#simulationCanvas.mx-manual {
    touch-action: none;
    cursor: pointer;
}
#simulationCanvas:focus {
    outline: none;
}
#simulationCanvas:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: -2px;
}

/* Short hint shown over the bottom of the canvas (e.g. "Press and hold to open the gate"). */
.mx-canvas-hint {
    position: absolute;
    left: 50%;
    bottom: 0.75em;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 1.5em);
    box-sizing: border-box;
    padding: 0.35em 0.9em;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.62);
    color: #fff;
    font-size: 0.8em;
    line-height: 1.35;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
    z-index: 2;
}
.mx-canvas-hint.is-visible {
    opacity: 1;
}

/* --- Info bar --- */

/* Readouts, then the colour key, then the buttons. On phones the key and the
   buttons share a second row (simulation_styles.css). */
#statsBar {
    container-type: inline-size; /* lets the rules below fit the readouts to the bar's width */
}

.mx-chamber {
    display: inline-flex;
    align-items: baseline;
    gap: 0.5em;
    white-space: nowrap;
}

/* Counts sit right after their dot; the room reserved for bigger counts (--chars)
   trails them, so nothing moves as they change. */
.mx-count .sim-value {
    text-align: left;
}

/* A coloured dot in front of each count doubles as the colour key. */
.mx-fast::before,
.mx-slow::before {
    content: "";
    display: inline-block;
    width: 0.62em;
    height: 0.62em;
    margin-right: 0.3em;
    border-radius: 50%;
    vertical-align: 0.02em;
}
.mx-fast::before { background: var(--mx-fast); }
.mx-slow::before { background: var(--mx-slow); }

.mx-temp .icon {
    color: var(--color-text-subtle);
    margin-right: 0.3em;
}

/* Words next to the values: read out by screen readers, shown only when the
   colour key is folded into the readouts (narrow bars, below). */
.mx-sr,
.mx-word {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Quiet colour key after the readouts. */
.mx-legend {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    column-gap: 0.9em;
    padding: 0 0.35em;
    font-size: 0.78em;
    color: var(--color-text);
    opacity: 0.85;
    white-space: nowrap;
}
.mx-legend .icon {
    margin-right: 0.15em;
}

/* No room for the temperature note on one row with everything else (the About text explains it). */
@container (max-width: 900px) {
    .mx-legend-t {
        display: none;
    }
}
/* When the bar can't hold everything on one row, the readouts take the first row and the
   colour key shares the second with the buttons (as on phones) rather than leaving the
   buttons alone on it. */
@container (max-width: 640px) {
    #statsBar .stats-container {
        flex-basis: 100%;
    }
}
/* Phones: tighten the chamber boxes so two still share a row... */
@container (max-width: 360px) {
    #statsBar .mx-chamber {
        gap: 0.35em;
        padding-left: 0.45em;
        padding-right: 0.45em;
        font-size: 0.75em;
    }
}
/* ...and stack them when even that doesn't fit (e.g. a narrow, tall canvas on a small phone).
   The boxes then have room to say "fast" and "slow", which replaces the separate key. */
@container (max-width: 290px) {
    #statsBar .stats-container {
        grid-template-columns: minmax(0, 1fr);
    }
    #statsBar .mx-word {
        position: static;
        width: auto;
        height: auto;
        margin: 0;
        overflow: visible;
        clip: auto;
        opacity: 0.85;
    }
    #statsBar .mx-legend {
        display: none;
    }
}

/* --- About section: colour words match the particles --- */
.description-area strong.mx-fast { color: var(--mx-fast); }
.description-area strong.mx-slow { color: var(--mx-slow); }
.description-area strong.mx-fast::before,
.description-area strong.mx-slow::before {
    content: none;
}

/* --- Controls panel --- */
.mx-control-note {
    font-size: 0.78em;
    line-height: 1.45;
    margin: 0 0 0.6em 0;
    color: var(--color-text);
    opacity: 0.85;
}
