/* --- Buoyancy simulation page styles (loaded after simulation_styles.css) --- */

.buoyancy-sim {
    --buoy-btn: 34px;                                   /* tool button size */
    --buoy-cols: 4;                                     /* buttons per row in the tool column */
    /* tool column beside the canvas: buttons, 3px gaps, padding and border */
    --buoy-side-w: calc(var(--buoy-cols) * (var(--buoy-btn) + 3px) + 11px);
    --buoy-side-gap: 8px;
}

/* (main.css raises the page's font size on wide screens: the buttons grow with it, so "Draw" and
   "Drop" still fit) */
@media (pointer: coarse), (min-width: 1681px) {
    .buoyancy-sim {
        --buoy-btn: 40px;
    }
}

/* ---------- Drawing toolbar ----------
   Portrait / narrow: under the tank, [Draw | Drop] size undo clear / materials tools / hint.
   Landscape: a column of tools beside the tank (see the media query further down), so the tank
   keeps the full height of the screen. */
.buoy-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-top: 0.5em;
    padding: 5px 6px;
    box-sizing: border-box;
    background-color: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: var(--sim-radius, 6px);
    font-size: 0.85em;
    line-height: 1.3;
}

.buoy-group {
    display: flex;
    align-items: center;
    gap: 3px;
}

.buoy-toolbar button {
    -webkit-appearance: none;
    appearance: none;
    height: var(--buoy-btn);
    min-width: var(--buoy-btn);
    padding: 0;
    margin: 0;
    line-height: 1;
    font-size: 0.95em;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: none;
    color: var(--color-text) !important;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px var(--color-border);
    background-color: var(--color-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45em;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

@media (hover: hover) {
    .buoy-toolbar button:hover {
        box-shadow: inset 0 0 0 1px var(--color-accent);
    }
}

.buoy-toolbar button.is-active {
    box-shadow: inset 0 0 0 2px var(--color-accent);
    background-color: var(--color-bg-button-active-overlay);
}

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

.buoy-toolbar .icon:before {
    line-height: 1;
}

/* Draw / Drop: a segmented switch that shows which mode is on */
.buoy-mode {
    display: flex;
    flex: 0 0 auto;
    order: 1;
    border-radius: 4px;
    box-shadow: inset 0 0 0 1px var(--color-border);
}

.buoy-toolbar .buoy-mode-btn {
    flex: 1 1 0;
    padding: 0 0.85em;
    box-shadow: none;
    background-color: transparent;
}

.buoy-toolbar .buoy-mode-btn:first-child {
    border-radius: 4px 0 0 4px;
}

.buoy-toolbar .buoy-mode-btn:last-child {
    border-radius: 0 4px 4px 0;
}

.buoy-toolbar .buoy-mode-btn[aria-pressed="true"] {
    background-color: var(--color-accent);
    color: #ffffff !important;
    box-shadow: none;
}

@media (hover: hover) {
    .buoy-toolbar .buoy-mode-btn[aria-pressed="true"]:hover {
        background-color: var(--color-accent-active);
        box-shadow: none;
    }
}

/* Material swatches and drawing tools: dimmed while the object is being simulated (picking one
   goes back to drawing). Only the swatches and icons dim, and only so far that they keep 3:1;
   the size's text stays at full contrast. */
.buoy-mats { order: 5; }
.buoy-tools { order: 6; }
.buoy-size { order: 2; }
.buoy-edit { order: 3; margin-left: auto; }
.buoy-break { order: 4; flex-basis: 100%; height: 0; }

.buoy-toolbar.is-sim .buoy-mats,
.buoy-toolbar.is-sim .buoy-tools {
    opacity: 0.72;
}

@media (hover: hover) {
    .buoy-toolbar.is-sim .buoy-mats:hover,
    .buoy-toolbar.is-sim .buoy-tools:hover {
        opacity: 1;
    }
}

/* nothing to undo */
.buoy-toolbar #undoBtn[aria-disabled="true"] {
    opacity: 0.45;
    cursor: default;
}

@media (hover: hover) {
    .buoy-toolbar #undoBtn[aria-disabled="true"]:hover {
        box-shadow: inset 0 0 0 1px var(--color-border);
    }
}

.buoy-toolbar .buoy-mat {
    padding: 4px;
}

.buoy-toolbar .buoy-mat.is-active {
    box-shadow: inset 0 0 0 2px var(--color-accent), inset 0 0 0 4px var(--color-bg);
}

.buoy-swatch {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 3px;
    border: 1px solid rgba(0, 0, 0, 0.45);
    box-sizing: border-box;
}

.buoy-size {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    margin: 0;
    font-size: 0;                /* the visible label is the select's own "3 cm"; it has an aria-label */
}

.buoy-toolbar select {
    -webkit-appearance: none;
    appearance: none;
    width: auto;
    height: var(--buoy-btn);
    margin: 0;
    padding: 0 1.9em 0 0.6em;
    font-size: 0.8rem;
    font-weight: 400;
    line-height: normal;
    color: var(--color-text);
    background-color: var(--color-bg);
    background-position: calc(100% - 0.55em) center;
    background-size: 0.85em;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    box-shadow: none;
    cursor: pointer;
}

.buoy-toolbar select:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 1px var(--color-accent);
}

.buoy-hint {
    order: 7;
    flex: 1 1 100%;
    min-width: 0;
    margin: 0;
    padding: 0 0.15em;
    font-size: 0.95em;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.buoy-hint strong {
    font-weight: 700;
}

/* Phones: materials and tools each fill a row */
@media (max-width: 480px) {
    .buoy-mats,
    .buoy-tools {
        flex: 1 1 100%;
    }

    .buoy-toolbar .buoy-mats button,
    .buoy-toolbar .buoy-tools button {
        flex: 1 1 0;
        min-width: 0;
        max-width: 52px;
    }

    .buoy-mats,
    .buoy-tools {
        justify-content: space-between;
    }

    /* two fixed lines, so a longer hint never changes the toolbar's height */
    .buoy-hint {
        white-space: normal;
        height: 2.7em;
        display: -webkit-box;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
        line-clamp: 2;
    }
}

/* ---------- Landscape: tools in a column beside the tank ----------
   The column has a fixed width, so the display container is made that much wider than the
   canvas (which the shared layout sizes from the screen height). */
@media (orientation: landscape) and (min-width: 640px) {
    .buoyancy-sim .simulation-display-container {
        display: grid;
        grid-template-columns: var(--buoy-side-w) minmax(0, 1fr);
        grid-template-areas: "tools canvas" "info info";
        column-gap: var(--buoy-side-gap);
        width: min(100%, calc(var(--sim-canvas-max-h) * (var(--aspect-ratio, 16 / 10)) + 2px + var(--buoy-side-w) + var(--buoy-side-gap)));
    }

    .buoyancy-sim .sim-canvas-wrapper {
        grid-area: canvas;
        min-width: 0;
    }

    .buoyancy-sim .sim-info-bar {
        grid-area: info;
    }

    /* As tall as the canvas beside it, never taller; if the tools need more room they scroll,
       with soft shadows at the edges that show there is more. */
    .buoy-toolbar {
        grid-area: tools;
        display: grid;
        grid-template-columns: repeat(var(--buoy-cols), minmax(0, 1fr));
        align-content: start;
        gap: 8px 3px;
        margin-top: 0;
        min-height: 0;
        contain: size;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        scrollbar-width: thin;
        background:
            linear-gradient(var(--color-bg-alt) 40%, transparent) center top / 100% 22px no-repeat local,
            linear-gradient(transparent, var(--color-bg-alt) 60%) center bottom / 100% 22px no-repeat local,
            radial-gradient(farthest-side at 50% 0, rgba(128, 128, 128, 0.55), transparent) center top / 100% 9px no-repeat scroll,
            radial-gradient(farthest-side at 50% 100%, rgba(128, 128, 128, 0.55), transparent) center bottom / 100% 9px no-repeat scroll;
        background-color: var(--color-bg-alt);
    }

    .buoy-mode,
    .buoy-mats,
    .buoy-tools,
    .buoy-hint {
        grid-column: 1 / -1;
    }

    .buoy-mats,
    .buoy-tools {
        display: grid;
        grid-template-columns: repeat(var(--buoy-cols), minmax(0, 1fr));
        gap: 3px;
    }

    .buoy-toolbar .buoy-mats button,
    .buoy-toolbar .buoy-tools button {
        min-width: 0;
        width: 100%;
    }

    .buoy-toolbar .buoy-mode-btn {
        min-width: 0;
        padding: 0 0.4em;
        gap: 0.35em;
    }

    .buoy-size {
        order: 7;
        grid-column: 1 / span 2;
    }

    .buoy-size select {
        width: 100%;
    }

    .buoy-edit {
        order: 8;
        grid-column: 3 / span 2;
        margin-left: 0;
    }

    .buoy-edit button {
        flex: 1 1 0;
        min-width: 0;
    }

    .buoy-break {
        display: none;
    }

    .buoy-hint {
        order: 9;
        white-space: normal;
        font-size: 0.9em;
        line-height: 1.4;
        padding: 2px 2px 0;
        overflow: hidden;
    }

    .buoy-hint strong {
        display: block;
    }

    /* Phones held sideways: no room for the hint beside the tools */
    @media (max-height: 540px) {
        .buoy-hint {
            display: none;
        }

        /* ...and with the settings docked beside the tank too, a two-wide column leaves the tank
           more width (it scrolls if it is taller than the tank) */
        body.sim-panel-side.sim-panel-active .buoyancy-sim {
            --buoy-cols: 2;
        }

        body.sim-panel-side.sim-panel-active .buoy-mode {
            flex-direction: column;
        }

        body.sim-panel-side.sim-panel-active .buoy-toolbar .buoy-mode-btn {
            flex: 0 0 auto;
        }

        body.sim-panel-side.sim-panel-active .buoy-toolbar .buoy-mode-btn:first-child {
            border-radius: 4px 4px 0 0;
        }

        body.sim-panel-side.sim-panel-active .buoy-toolbar .buoy-mode-btn:last-child {
            border-radius: 0 0 4px 4px;
        }

        body.sim-panel-side.sim-panel-active .buoy-size,
        body.sim-panel-side.sim-panel-active .buoy-edit {
            grid-column: 1 / -1;
        }
    }

    /* Fullscreen: the grid fills the space above the fixed info bar */
    body.sim-fullscreen-active .buoyancy-sim .simulation-display-container {
        display: grid;
        grid-template-rows: minmax(0, 1fr);
        grid-template-areas: "tools canvas";
        width: 100%;
    }

    body.sim-fullscreen-active .buoyancy-sim .sim-canvas-wrapper {
        height: 100%;
    }

}

/* ---------- Controls panel ---------- */
.buoy-key {
    display: inline-block;
    width: 0.9em;
    height: 0.9em;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.4);
    flex: 0 0 auto;
}

/* the arrows' colours: deeper in the light theme, where they sit on a white halo (buoyancy_core.js) */
.buoy-key-weight { background: #d32f2f; }
.buoy-key-buoyancy { background: #0b8a55; }
.buoy-key-drag { background: #b26a00; }
.buoy-key-contact { background: #7e47d1; }
html.dark-mode .buoy-key-weight { background: #ff5f5f; }
html.dark-mode .buoy-key-buoyancy { background: #2fe39b; }
html.dark-mode .buoy-key-drag { background: #ffc53d; }
html.dark-mode .buoy-key-contact { background: #c58cff; }

/* the net force is drawn dashed, so its key is a dashed line (as in the key on the canvas) */
.buoy-key.buoy-key-net {
    height: 3px;
    border: 0;
    border-radius: 0;
    background: repeating-linear-gradient(90deg, #1d2329 0 4px, transparent 4px 7px);
}

html.dark-mode .buoy-key.buoy-key-net {
    background: repeating-linear-gradient(90deg, #ffffff 0 4px, transparent 4px 7px);
}

/* one-line notes under a control (as on the other simulation pages) */
.sim-controls-content .buoy-note {
    margin: -0.35em 0 0 0;
    font-size: 0.8em;
    line-height: 1.35;
    opacity: 0.85;
}

.sim-controls-content .buoy-arrow-chips + .buoy-note {
    margin-top: 0.4em;
}

.buoy-gravity-name {
    opacity: 0.75;
    font-weight: 400;
}
