/*
 * MICRO:BIT MODE, COMPACT LAYOUT — a proposal waiting for Dora's OK
 * (18 Nov 2026: "we are wasting a lot of space on the microbit mode UI ...
 * the logo inside the notch, the microbit being inside an awkward vertical
 * container, the single settings button on the left side"; and "you also
 * need to find a layout that will work on mobile too").
 *
 * Only with body[data-mb-layout="compact"], which editor-bootstrap.js sets in
 * micro:bit mode when ?layout=compact asked for it (remembered per device;
 * ?layout=classic turns it off). Robot and story mode never see these rules,
 * and the classic layout stays the default until Dora approves.
 *
 * One rule everywhere: the logo is a small home link in a corner, never over
 * the canvas; the gear joins the other round buttons; the board is shown in
 * whatever shape the screen affords, in a card no taller than what is in it.
 */

/* ---- Wide screens (desktop, landscape tablets) ------------------------
   Dora, 18 Nov: the board's box on the LEFT, the logo above it (as big as
   fits within the box's width), the round buttons on the left too; the
   canvas takes everything to the right.

   Left column (the header's grid column, --mb-col-w wide): the logo, then
   the board's card (placed by microbit-sim.js). Right: the usual rail of
   round buttons, the gear on top. The tray runs the full width. */
body[data-mb-layout="compact"].screen-desktop.screen-landscape.sandbox-mode {
    --mb-col-w: clamp(280px, 30vw, 420px);
    grid-template-columns:
        calc(var(--mb-col-w) + var(--safe-left))
        1fr
        calc(var(--navbar-size) + var(--safe-right));
}

body[data-mb-layout="compact"].screen-desktop.screen-landscape.sandbox-mode .top-bar {
    width: calc(var(--mb-col-w) + var(--safe-left));
    padding: 12px;
    padding-top: calc(12px + var(--safe-top));
    padding-left: calc(12px + var(--safe-left));
    justify-content: flex-start;
    align-items: stretch;
}

/* The logo: not the notch; as wide as the board's card, above it. */
body[data-mb-layout="compact"].screen-desktop.screen-landscape .top-bar > .logo {
    position: static;
    transform: none;
    width: 100% !important;
    max-width: none !important;
    height: auto !important;
    background: none;
    border-radius: 0;
    overflow: visible;
}

body[data-mb-layout="compact"].screen-desktop.screen-landscape .top-bar > .logo img {
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: 22vh;
    object-fit: contain;
}

/* The round buttons stay where they always are: the right rail (Dora,
   18 Nov). The gear, which had the whole left column to itself, tops it. */
body[data-mb-layout="compact"].screen-desktop.screen-landscape .top-bar .settings {
    position: fixed;
    top: var(--desktop-landscape-main-margin);
    right: calc((var(--navbar-size) - 80px) / 2 + var(--safe-right));
    z-index: 130;
}

/* The tray: from the left edge to the rail, under both columns, so more
   blocks fit (under the canvas alone it cut the last ones off). Start-
   aligned: centring an overflowing row hides its first blocks. The left
   column's card is sized to end above it (microbit-sim.js). */
body[data-mb-layout="compact"].screen-desktop.screen-landscape.sandbox-mode .sandbox-palette {
    left: calc(12px + var(--safe-left));
    right: calc(var(--navbar-size) + var(--safe-right));
}

/* The board's card: the canvas's twin. Same corners, no border, its
   bottom on the canvas's bottom (height set by microbit-sim.js); the flash
   button keeps to the bottom so any slack sits above it, not under it. */
body[data-mb-layout="compact"] .mb-sim.mb-layout-split {
    --mb-panel-radius: 20px;
    --mb-panel-border: 0px;
    box-shadow: none;
}

/* ---- Upright screens (phones, portrait tablets) -------------------------
   Row 1: a small logo on the left, the gear on the right.
   Row 2: the board ("strip", placed by microbit-sim.js), always in view.
   Then the tray, the canvas (smaller, by Dora's choice), and ONE row of the
   four round buttons (the gear left that grid, so no hole in it). */
@media (orientation: portrait) {
    body[data-mb-layout="compact"].sandbox-mode {
        --sandbox-portrait-logo-height: 44px;
        --sandbox-portrait-header-height: calc(
            var(--sandbox-portrait-header-padding-top) +
            var(--sandbox-portrait-logo-height) +
            var(--sandbox-portrait-header-gap) +
            var(--mb-strip-h, 0px) +
            var(--sandbox-portrait-header-gap) +
            var(--sandbox-portrait-palette-slot-height) +
            var(--sandbox-portrait-header-padding-bottom)
        );
        --sandbox-portrait-header-height-collapsed: calc(
            var(--sandbox-portrait-header-padding-top) +
            var(--sandbox-portrait-logo-height) +
            var(--sandbox-portrait-header-gap) +
            var(--mb-strip-h, 0px) +
            var(--sandbox-portrait-header-padding-bottom)
        );
        --sandbox-portrait-palette-gap: 16px;
    }

    body[data-mb-layout="compact"].sandbox-mode .top-bar > .logo {
        width: auto;
        align-self: flex-start;
        margin: 0 0 calc(var(--mb-strip-h, 0px) + var(--sandbox-portrait-header-gap));
    }

    body[data-mb-layout="compact"].sandbox-mode .top-bar > .logo img {
        width: auto;
        height: 100%;
    }

    /* The gear, top right, in the logo's row. */
    body[data-mb-layout="compact"].sandbox-mode .sandbox-control-grid .settings {
        position: fixed;
        top: var(--sandbox-portrait-header-padding-top);
        right: calc(12px + var(--safe-right));
        width: var(--sandbox-portrait-logo-height);
        height: var(--sandbox-portrait-logo-height);
        z-index: 30;
    }

    body[data-mb-layout="compact"].sandbox-mode .sandbox-control-grid .settings a {
        width: 100%;
        height: 100%;
    }

    /* One row of four: undo, trash, camera, run. */
    body[data-mb-layout="compact"].sandbox-mode .sandbox-control-grid {
        --sandbox-control-size: min(72px, calc((100vw - 24px - 3 * 12px) / 4));
        grid-template-columns: repeat(4, var(--sandbox-control-size));
    }

    body[data-mb-layout="compact"].sandbox-mode .sandbox-control-grid .bluetooth {
        display: none;
    }
}

/* The strip itself: the same panel surface, never closed (it IS the board). */
.mb-sim.mb-layout-strip { height: auto; }
.mb-layout-strip [data-action="close"] { display: none; }

/* A wide strip (portrait tablets): the board on the left, its controls on
   the right, so the row stays short. */
.mb-sim.mb-layout-strip.mb-strip-wide {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    grid-auto-rows: auto;
    align-items: center;
    justify-items: stretch;
    column-gap: 16px;
}
.mb-strip-wide .mb-sim-frame {
    grid-column: 1;
    grid-row: 1 / span 4;
}
.mb-strip-wide > :not(.mb-sim-frame) {
    grid-column: 2;
}

/* A narrow strip (phones): the board as large as the row allows, A and B
   either side of "Pasarlo a mi micro:bit" in one row (A left, B right, as on
   the board), so the board gets the height the A/B row used to take. */
.mb-sim.mb-layout-strip:not(.mb-strip-wide) {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "head head head"
        "frame frame frame"
        "a flash b"
        "now now now";
    align-items: center;
    column-gap: var(--mb-panel-gap);
}
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-head { grid-area: head; }
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-frame { grid-area: frame; justify-self: center; }
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-ab { display: contents; }
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-ab-btn:first-child { grid-area: a; }
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-ab-btn:last-child { grid-area: b; }
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-flash { grid-area: flash; }
.mb-layout-strip:not(.mb-strip-wide) .mb-sim-now { grid-area: now; }

/* The canvas is short here: its zoom buttons go in a row along its top
   right, beside the voice button, instead of a column that stood out over
   the tray (and not top left, where the program starts). */
@media (orientation: portrait) {
    body[data-mb-layout="compact"].sandbox-mode #canvas-zoom-controls {
        top: 8px;
        bottom: auto;
        left: auto;
        right: 60px;
        width: auto;
        height: auto;
        flex-direction: row;
    }
}
