/* MABNI 3.8 Visual QA + Classroom Flow Stabilization
   Final layer loaded after page/app CSS. Keep this boring and strong. */
:root{--mabni-footer-h:58px;--mabni-focus-ring:0 0 0 4px rgba(0,108,255,.18)}
*{scrollbar-width:thin}html,body{max-width:100%;overflow-x:hidden}body{padding-bottom:var(--mabni-footer-h)}
button,a,input,select,textarea{touch-action:manipulation}button:focus-visible,a:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible{outline:3px solid rgba(0,108,255,.45);outline-offset:3px;box-shadow:var(--mabni-focus-ring)}
img,svg,canvas,iframe{max-width:100%}.hidden[hidden]{display:none!important}

/* Homepage stabilization */
.home-shell{align-items:flex-start!important;padding-bottom:calc(var(--mabni-footer-h) + 16px)!important}.home-card{margin-inline:auto}.main-grid,.utility-grid{align-items:stretch}.home-btn-card{min-width:0}.home-btn-card strong,.home-btn-card p{overflow-wrap:anywhere}.home-btn-card a,.home-btn-card button{align-self:flex-start;min-height:42px;display:inline-flex;align-items:center;justify-content:center}.utility-grid-section{margin-top:18px!important}.mabni-seo-content-v32{margin-bottom:12px!important}.sticky-footer{position:fixed!important;left:0;right:0;bottom:0;z-index:999!important;min-height:var(--mabni-footer-h);background:rgba(255,255,255,.96)!important;color:#475569!important}.sticky-footer nav{max-width:100%;overflow-x:auto;padding-bottom:2px}.sticky-footer a,.sticky-footer button{white-space:nowrap}.teacher-server-dialog::backdrop,.teacher-login-dialog::backdrop{background:rgba(15,23,42,.55)}.teacher-server-card,.teacher-login-card{max-height:min(88vh,760px);overflow:auto}.support-method p,.support-block p{overflow-wrap:anywhere}

/* Coding studio: responsive and classroom-safe */
.topbar{position:sticky!important;top:0;z-index:100;min-height:64px}.level-strip{overscroll-behavior-x:contain}.level-chip,.mp-level-bubble{flex:0 0 auto}.game-shell{min-width:0}.visualization{overflow:hidden}.workspace-concept-brand strong,.workspace-concept-brand span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.run-dock button,.event-game-pad button{min-width:0}.event-game-pad{display:grid}.event-game-pad.hidden{display:none!important}.event-game-pad:not(.hidden){display:grid!important}.event-pad-actions{display:flex!important;justify-content:center!important;gap:8px!important;grid-column:1/-1}.event-stop{background:#ef4444!important;color:#fff!important;border:0!important}.event-game-score{grid-column:1/-1}.feedback{max-width:100%;overflow-wrap:anywhere}.level-objective-dialog .level-objective-card{max-height:min(88vh,760px);overflow:auto}.level-objective-dialog .objective-blocks{display:flex;flex-wrap:wrap;gap:8px}.mabni-embedded-lab-overlay{position:fixed!important;inset:0!important;z-index:1000!important;background:#061020!important;display:grid!important;grid-template-rows:auto 1fr!important}.mabni-embedded-lab-overlay iframe{width:100%!important;height:100%!important;border:0!important;background:#fff!important}.mabni-embedded-lab-head{min-width:0}.mabni-embedded-lab-head strong,.mabni-embedded-lab-head span{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:70vw;display:block}

/* Dark mode: final catch-all for Coding Studio only. */
html[data-mabni-theme="dark"] body{background:#07101f!important;color:#f3f8ff!important}
html[data-mabni-theme="dark"] :where(.topbar,.game-shell,.left-panel,.right-panel,.mission-bar,.learning-focus-card,.visualization,.workspace-head,#blocklyArea,.dialog-card,.student-login-panel,.online-class-panel,.local-student-panel,.local-name-card,.class-code-card,.class-student-card,.saved-user,.lesson-card-panel,.mp-course-btn,.mp-world-card,.mp-course-hero,.event-game-pad,.level-objective-card,.mabni-embedded-lab-head,.custom-preview,.choice,.movement-option,.movement-editor,.settings-menu){background:#101a2e!important;color:#f3f8ff!important;border-color:rgba(174,190,215,.30)!important;box-shadow:0 16px 42px rgba(0,0,0,.42)!important}
html[data-mabni-theme="dark"] :where(.visualization,#blocklyArea,#blocklyDiv,.blocklyWorkspace){background:#08111f!important;color:#f3f8ff!important}
html[data-mabni-theme="dark"] :where(h1,h2,h3,h4,h5,h6,strong,label,.mp-course-copy strong,.mp-world-copy h3,.workspace-concept-brand strong,.dialog-head h2,.panel-title-row strong){color:#f3f8ff!important}
html[data-mabni-theme="dark"] :where(p,small,span,em,.muted,.lead,.workspace-note,.saved-empty,.class-login-message,.mp-course-copy em,.mp-world-copy p,.dialog-card p,.dialog-card small,.mission-copy,.goal-pill span){color:#b7c6dc!important}
html[data-mabni-theme="dark"] :where(input,textarea,select){background:#0b1425!important;color:#f3f8ff!important;border-color:rgba(174,190,215,.30)!important;-webkit-text-fill-color:#f3f8ff!important}
html[data-mabni-theme="dark"] :where(input::placeholder,textarea::placeholder){color:#8fa3c3!important;-webkit-text-fill-color:#8fa3c3!important}
html[data-mabni-theme="dark"] :where(button.secondary,.secondary,button:not(.primary):not(.big-run):not(.event-stop):not(.level-chip):not(.mp-level-bubble)){background:#15243e!important;color:#f3f8ff!important;border-color:rgba(174,190,215,.30)!important}
html[data-mabni-theme="dark"] :where(.primary,.big-run){background:linear-gradient(135deg,#a78bfa,#38e8ff)!important;color:#07101f!important;border-color:transparent!important}
html[data-mabni-theme="dark"] .blocklyToolboxDiv{background:#0b1425!important;color:#f3f8ff!important}html[data-mabni-theme="dark"] .blocklyFlyoutBackground{fill:#101a2e!important}html[data-mabni-theme="dark"] .blocklyText{fill:#f8fbff!important}.blocklyHtmlInput{color:#10213d!important}html[data-mabni-theme="dark"] .blocklyHtmlInput{background:#0b1425!important;color:#f8fbff!important}

/* Event games */
body.event-page-v38 .top{position:sticky;top:0;z-index:40}.stageTools .btn,.top nav .btn{min-height:40px}.stageTools{gap:8px!important}.stageTools #newBtn,.stageTools #runAgainBtn{background:#16a34a!important;color:#fff!important;border-color:#16a34a!important}.stageTools #stopBtn,.stageTools #stopInlineBtn{background:#ef4444!important;color:#fff!important;border-color:#ef4444!important}.helperBubble{pointer-events:none}.stageTag{display:none!important}.event-objective-card{max-height:min(88vh,760px);overflow:auto}.levelbar{overflow-x:auto;scrollbar-width:thin}.levelbtn{flex:0 0 auto}.arena,.world{overflow:hidden}

/* Hardware Lab: smoother touch/mouse behavior */
body.hardware-v38{overscroll-behavior:none}.board{touch-action:none}.trayDragImg,.partImageHandle{touch-action:none!important;cursor:grab!important}.trayDragImg:active,.partImageHandle:active{cursor:grabbing!important}.partCard{width:120px!important;min-height:92px!important;display:grid!important;place-items:center!important;padding:8px!important}.partCard img.partImageHandle{width:86px!important;height:70px!important;object-fit:contain!important}.partCard.is-lit{filter:drop-shadow(0 0 16px rgba(250,204,21,.75))}.trayItem{min-height:92px!important}.trayItem img{width:70px!important;height:54px!important;object-fit:contain}.conceptBoxes{display:grid;grid-template-columns:repeat(auto-fit,minmax(160px,1fr));gap:8px}.helpBox p{display:none}.mission p{font-size:13px!important;line-height:1.35!important}.robotSpeech p{display:none}.terminal{touch-action:none!important}.legend{gap:6px!important}.legend span{white-space:nowrap}.resultText{max-height:4.3em;overflow:hidden}

/* Teacher dashboard broadly: tables/cards fit smaller screens */
.teacher-dashboard,.dashboard-shell,.teacher-shell{max-width:100%;overflow-x:hidden}.teacher-dashboard table,.dashboard-shell table,.teacher-shell table{display:block;max-width:100%;overflow-x:auto;white-space:nowrap}.td-card,.dash-card,.progress-card,.report-card,.live-card{min-width:0;overflow-wrap:anywhere}.control-grid,.report-grid,.progress-grid,.teacher-grid{grid-template-columns:repeat(auto-fit,minmax(min(260px,100%),1fr))!important}

@media(max-width:1180px){.topbar{min-height:auto}.game-shell{min-height:auto}.workspace-meta{display:none!important}.home-card{width:min(100%,calc(100vw - 16px))!important}.main-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}.utility-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important}.layout{height:auto!important}.blockly{min-height:480px!important}}
@media(max-width:820px){:root{--mabni-footer-h:86px}body{padding-bottom:var(--mabni-footer-h)}.home-shell{padding-bottom:calc(var(--mabni-footer-h) + 14px)!important}.sticky-footer{display:grid!important;grid-template-columns:1fr!important;text-align:center;gap:6px!important}.sticky-footer nav{justify-content:center}.topbar{grid-template-columns:auto 1fr!important}.game-shell{display:block!important}.left-panel,.right-panel{margin-bottom:10px}.visualization{height:360px!important}.right-panel{min-height:560px!important}#blocklyArea{height:520px!important;min-height:520px!important}.run-dock{grid-template-columns:repeat(2,minmax(0,1fr))!important}.layout{grid-template-columns:1fr!important}.arena,.world{height:420px!important}.blockly{height:540px!important}.conceptBoxes{display:none}.panelGrid{grid-template-columns:1fr!important}.boardShell{min-height:500px!important}.trayGrid{grid-template-columns:repeat(auto-fit,minmax(82px,1fr))!important}.partCard{width:108px!important}.terminal{width:28px!important;height:28px!important}.mabni-embedded-lab-head{display:grid!important;grid-template-columns:1fr!important;gap:8px!important}.mabni-embedded-lab-head strong,.mabni-embedded-lab-head span{max-width:100%}}
@media(max-width:560px){:root{--mabni-footer-h:96px}.main-grid,.utility-grid{grid-template-columns:1fr!important}.brand-lock strong{font-size:24px!important}.trust-row{display:none!important}.lead{font-size:14px!important}.home-btn-card{min-height:126px!important}.topbar{padding:8px!important}.user-area{gap:5px!important}.user-chip-btn{max-width:120px}.visualization{height:330px!important}.run-dock button{font-size:12px!important;padding:8px!important}.mission-goals{display:none!important}#blocklyArea{height:460px!important;min-height:460px!important}.stageTools .btn,.top nav .btn{font-size:12px!important;padding:8px 10px!important}.arena,.world{height:360px!important}.blockly{height:500px!important}.boardShell{min-height:460px!important}.sticky-footer{font-size:12px!important}.sticky-footer a,.sticky-footer button{padding:7px 9px!important}}


/* MABNI 3.8.1 targeted visual repair */
.theme-toggle-clean.theme-toggle-icon-only{min-width:44px!important;width:44px!important;height:42px!important;padding:0!important;border-radius:999px!important}.theme-toggle-clean .contrast-label{display:none!important}.theme-glyph{font-size:20px;line-height:1}
/* Light mode Blockly/toolbox must stay light. */
html:not([data-mabni-theme="dark"]) :where(#blocklyArea,#blocklyDiv,.blocklyWorkspace){background:#f7fbff!important;color:#10213d!important}
html:not([data-mabni-theme="dark"]) .blocklyMainBackground{fill:#f7fbff!important;stroke:#bee3f8!important}
html:not([data-mabni-theme="dark"]) .blocklyToolboxDiv{background:linear-gradient(180deg,#f8fbff,#eef6ff)!important;color:#173b5f!important;border-right:1px solid #c7dcf1!important;box-shadow:inset -1px 0 0 #c7dcf1!important}
html:not([data-mabni-theme="dark"]) .blocklyTreeLabel{color:#173b5f!important}.blocklyFlyoutBackground{fill:#f8fbff!important;fill-opacity:.98!important}
/* Dark mode topbar should be truly dark. */
html[data-mabni-theme="dark"] .topbar{background:linear-gradient(180deg,#050816,#0a1224)!important;color:#f8fbff!important;border-color:#243a5c!important;box-shadow:0 16px 38px rgba(0,0,0,.5)!important}
html[data-mabni-theme="dark"] .topbar :where(strong,span,button){color:inherit}
/* Stable readable level chips in both modes. */
.level-chip,.mp-level-bubble{background:linear-gradient(180deg,#fff8dc,#ffe8a3)!important;color:#10213d!important;border:2px solid #facc15!important;box-shadow:0 8px 18px rgba(15,23,42,.10)!important}
.level-chip.active,.mp-level-bubble.active{background:linear-gradient(135deg,#0b5cff,#5aa4ff)!important;color:#fff!important;border-color:#0b5cff!important}
.level-chip.done,.mp-level-bubble.done{background:linear-gradient(135deg,#fff1a8,#facc15)!important;color:#10213d!important;border-color:#eab308!important}
html[data-mabni-theme="dark"] .level-strip{background:#0b1425!important;border-color:#243a5c!important}
/* Red close/cancel buttons in dialogs, readable in every mode. */
#signinCancel,#avatarDialog button[value="cancel"],#lessonDialog button[value="cancel"],#teacherDialog button[value="cancel"],dialog button[value="cancel"],.dialog-card .secondary[value="cancel"],.dialog-card button[id$="Close"]{background:#ef4444!important;color:#fff!important;border:0!important;box-shadow:0 10px 20px rgba(239,68,68,.22)!important}
#objectiveClose{background:#ef4444!important;color:#fff!important;border:0!important}
/* Event pages: force Start/Stop strip visible inside embedded games. */
.stageQuickActions{display:flex!important;visibility:visible!important;opacity:1!important;align-items:center!important;justify-content:center!important;gap:10px!important;padding:10px 12px!important;background:linear-gradient(180deg,#ecfdf5,#ffffff)!important;border-bottom:1px solid #bbf7d0!important}.stageQuickActions .eventStartBig{display:inline-flex!important;background:#16a34a!important;color:#fff!important;min-width:128px!important}.stageQuickActions .eventStopBig{display:inline-flex!important;background:#ef4444!important;color:#fff!important;min-width:128px!important}.controls #runAgainBtn{display:inline-flex!important;background:#16a34a!important;color:#fff!important}.controls #stopInlineBtn{display:inline-flex!important;background:#ef4444!important;color:#fff!important}
/* Hardware tray whole block is clickable. */
.trayItem{cursor:pointer!important}.trayItem *{pointer-events:none!important}.trayItem:focus-visible{outline:4px solid rgba(11,92,255,.30)!important;outline-offset:3px!important}
