/* Property of Sistema THEAD. All rights reserved. */
/* Microbit Mode prototype (assets/js/microbit-sim.js): the micro:bit
   simulator panel in its three layouts, and the block that is running on
   it. Nothing here applies outside Microbit Mode: the panel only exists
   there, and the running glow only while it runs.

   The panel is fixed-position and never moves in the DOM (moving an iframe
   reloads it); microbit-sim.js sets its place and the board size
   (--mb-board-w) for the layout. */

/* No robot in Microbit Mode: no Bluetooth button, no robot chip. */
body[data-editor-mode="microbit"] .robot-actions { display: none; }

/* ONE SURFACE, THREE PLACES.
   The layout classes below choose where the panel sits and nothing else.
   Before this, moving it also changed the widget: a 3px border became none
   in split, the radius went 16 -> 24 -> 20, the title was 18px only in
   split, and the flash status inherited whatever the page gave it. One
   border, one radius, one padding, one type scale and one stacking tier
   now hold in every layout. */
.mb-sim {
    --mb-panel-border: 3px;
    --mb-panel-radius: 16px;
    --mb-panel-pad: 12px;
    --mb-panel-gap: 8px;
    position: fixed;
    z-index: 950;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--mb-panel-gap);
    padding: var(--mb-panel-pad);
    background: var(--brand-white);
    border: var(--mb-panel-border) solid var(--brand-blue);
    border-radius: var(--mb-panel-radius);
    box-shadow: 0 10px 26px rgba(3, 40, 63, 0.22);
}
/* Closed (stage / dock until the flag is pressed): off screen but loaded,
   so the flag can press the simulator's play button straight away. */
.mb-sim.mb-sim-parked {
    left: -10000px !important;
    top: 0 !important;
    visibility: hidden;
}

.mb-sim-head {
    align-self: stretch;
    display: flex;
    align-items: center;
    gap: var(--mb-panel-gap);
}
.mb-sim-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem;
    line-height: 1.2;
    font-weight: 700;
    color: var(--brand-ink);
}
.mb-sim-narrow .mb-sim-title { visibility: hidden; }
.mb-sim-btn {
    flex: none;
    width: 36px;
    height: 36px;
    border-radius: 999px !important;
    border: 2px solid var(--brand-blue);
    background: #fff;
    color: var(--brand-blue);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.mb-sim-frame {
    display: block;
    width: var(--mb-board-w, 220px);
    aspect-ratio: 191.27 / 155.77; /* the simulator's board svg */
    border: 0;
    border-radius: 10px;
    background: #f5f6f8;
}
.mb-sim-now {
    min-height: 1.3em;
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.3;
    color: var(--brand-ink);
    text-align: center;
}
/* What the board shows and what it is doing, for a screen reader. Text in the
   reading order beside the board — not a live region (TJAnnounce is the one)
   and not a control, so nothing here is focusable. Hidden from the eye with
   the same geometry as the app's announcer. */
.mb-sim-leds,
.mb-sim-state {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.mb-sim-flash:empty { display: none; }
/* The flash UI is shared with the robot's firmware guide; inside the panel
   it follows the panel's type scale instead of inheriting the page's. */
.mb-sim .tj-flash { margin: 0; gap: var(--mb-panel-gap); }
.mb-sim .tj-flash-btn { font-size: 0.95rem; }
.mb-sim .tj-flash-status { font-size: 0.95rem; line-height: 1.3; }
/* The bar and the status line appear when the first real flash starts (and
   the status line hides again while it is empty). Keep both boxes reserved
   in the panel, so starting a flash cannot grow the panel or shrink the
   board under the child's finger. One line of status is budgeted; a message
   that wraps to two lines may still use the sheet's remaining slack. */
.mb-sim .tj-flash-status:empty { display: block; visibility: hidden; }
.mb-sim .tj-flash-bar[hidden] { display: block; visibility: hidden; }

/* ---- split: a column beside the canvas (wide screens) ----
   Placement only: the surface above is the same here as everywhere else.
   The flash section is pinned to the bottom of the column so a tall column
   reads as header / board / controls / action, not a board with a void. */
.mb-sim.mb-layout-split {
    justify-content: flex-start;
}
.mb-layout-split .mb-sim-flash { margin-top: auto; }
.mb-layout-split [data-action="close"] { display: none; }

/* ---- stage: a sheet that floats over the bottom of the screen ----
   Inset from the bottom by the same 12px as its padding, so the one radius
   and the one border read all the way round instead of being clipped by
   the screen edge. The 45% budget is unchanged and lives in the JS. */
.mb-sim.mb-layout-stage {
    left: 50%;
    bottom: max(12px, var(--safe-bottom));
    width: min(calc(100vw - 24px), 480px);
    transform: translateX(-50%);
}

/* ---- dock: a small board in the canvas's bottom-right corner ---- */
.mb-sim.mb-layout-dock {
    transform: translate(-100%, -100%);
}
.mb-sim.mb-layout-dock.mb-sim-side { flex-direction: row-reverse; align-items: flex-start; }
.mb-sim-side .mb-sim-head { flex-direction: column; align-self: auto; }
.mb-sim-side .mb-sim-title { display: none; }
.mb-sim-side .mb-sim-flash { display: none; }
.mb-sim-side .mb-sim-now {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* The block running on the simulator. */
/* `>`: Blockly nests the next block inside this one's group; only this
   block's own art may glow. */
.tj-blockly-canvas .tj-running > image.tj-art {
    filter: drop-shadow(0 0 6px var(--action-green)) drop-shadow(0 0 3px var(--action-green));
}

/* The Melody block's tune picker (blocksController.js openMelodyPopup). */
.melody-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
    margin-top: 6px;
}
.melody-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 96px;
    padding: 12px 8px;
    border: 3px solid #dfe7ee;
    border-radius: 16px;
    background: #fff;
    color: var(--brand-ink, #03283f);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
/* Selected: the pale green fill says which tune; no border ring. */
.melody-option.is-selected {
    background: #effaf0;
}
.melody-glyph {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #90BF2D; /* the Melody block's green */
    color: #fff;
    font-size: 26px;
    line-height: 1;
}

/* Buttons A and B, for the keyboard and the voice (the board's own can only
   be clicked). Round, like the micro:bit's, and the same weight in every
   layout. */
.mb-sim-ab {
    display: flex;
    gap: 14px;
    justify-content: center;
}
.mb-sim-ab-btn {
    width: 44px;
    height: 44px;
    border: 3px solid #2B2A29;
    border-radius: 50%;
    background: #90BF2D;
    color: #2B2A29;
    font: inherit;
    font-size: 1.1rem;
    font-weight: 800;
    cursor: pointer;
}
.mb-sim-ab-btn:active { transform: translateY(2px); }
.mb-sim-side .mb-sim-ab { flex-direction: column; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
    .mb-sim-ab-btn:active { transform: none; }
    .mb-sim .tj-flash-bar > span { transition: none; }
}

/* Icons from the app's set (ui/tj-icons.js). */
.mb-sim-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.mb-sim-btn .tj-icon { width: 18px; height: 18px; }
