/* Milo & Poppy Maths Toolkit v2 — drawing and text on one canvas-style surface. */
.mp-workings{box-sizing:border-box;width:100%;margin:12px auto;padding:12px;background:#f4f9ff;border:2px solid #457ab9;border-radius:16px;color:#182b43;min-width:0}
.mp-workings>summary{cursor:pointer;font-weight:700;font-size:1.08rem;padding:8px}
.mp-workings-body{width:100%;box-sizing:border-box}
.mp-tools{display:flex;flex-wrap:wrap;gap:8px;margin:10px 0}
.mp-tools button{min-height:44px;padding:8px 11px;border:2px solid #477cba;border-radius:9px;background:white;color:#163c6d;cursor:pointer}
.mp-tools button[aria-pressed="true"]{background:#d8eafd;border-color:#174f91;font-weight:bold}
.mp-tools button:focus-visible,.mp-text-item:focus-visible{outline:3px solid #f1a340;outline-offset:2px}
.mp-tip{font-size:.85rem;margin:8px 0;color:#405673}
.mp-stage{position:relative;width:100%;aspect-ratio:760 / 340;background:#fff;border:2px solid #a7c2de;border-radius:9px;overflow:hidden;box-sizing:border-box}
.mp-stage canvas{position:absolute;inset:0;width:100%;height:100%;touch-action:none;cursor:crosshair}
.mp-text-layer{position:absolute;inset:0;pointer-events:none}
.mp-text-item{position:absolute;box-sizing:border-box;width:31%;min-width:74px;height:23%;min-height:38px;resize:both;overflow:auto;padding:3px 5px;background:rgba(255,255,255,.82);border:1px dashed #6794c5;border-radius:3px;color:#172334;font:500 clamp(12px,1.5vw,19px)/1.3 Arial,sans-serif;pointer-events:auto}
/* Layout: question full width; answers left, workings right when expanded. */
@media (min-width:751px){
  #question-screen:not(.hidden):has(.mp-workings[open]){display:grid;grid-template-columns:minmax(200px,40%) minmax(0,60%);gap:14px;align-items:start}
  #question-screen:has(.mp-workings[open]) #question-text{grid-column:1/-1;grid-row:1;margin:8px auto 12px}
  #question-screen:has(.mp-workings[open]) #answers{grid-column:1;grid-row:2;display:grid;grid-template-columns:1fr;gap:10px;width:100%}
  #question-screen:has(.mp-workings[open]) .mp-workings{grid-column:2;grid-row:2;margin:0;max-height:65vh;overflow-y:auto}
}
#question-screen.hidden{display:none!important}
@media(max-width:750px){.mp-tools button{flex:1 1 auto} .mp-stage{aspect-ratio:760 / 460}}

/* ==========================================
   MILO & POPPY — WORKINGS AREA SIZING
========================================== */

#question-screen .workings-area[open] {
    height: auto !important;
    min-height:  0 !important;
    max-height: none !important;
    overflow: visible !important;
    box-sizing: border-box;
}

/* Let the container grow naturally */
#question-screen .workings-area[open] .workings-content {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
    box-sizing: border-box;
}

/* Keep the drawing area inside its parent */
#question-screen .workings-area[open] .workings-canvas-container {
    position: relative;
    width: 100%;
    height: min(48vh, 440px);
    min-height: 260px;
    flex: none;
    box-sizing: border-box;
}

/* Canvas fills only the defined workspace */
#question-screen .workings-area[open] #workings-canvas {
    display: block;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
}

/* ==========================================
   MILO & POPPY — MOBILE ANSWER GRID
========================================== */

@media (max-width: 750px) {

    /* Display four answers in a 2 x 2 grid */
    #question-screen #answers,
    #question-screen:has(.mp-workings[open]) #answers {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
        width: 100%;
    }

    /* Keep buttons readable and touch-friendly */
    #question-screen #answers .answer-button {
        width: 100%;
        min-width: 0;
        min-height: 64px;
        padding: 12px 6px;
        font-size: clamp(1rem, 4vw, 1.25rem);
        box-sizing: border-box;
        overflow-wrap: anywhere;
    }

}