/* ============================================================================
 *  BrainBrick — mobile styles  (PHASE 2 · STEP 1b)
 *  ----------------------------------------------------------------------------
 *  < 1024px only (desktop untouched):
 *   - Fill the WHOLE viewport (desktop's framed/centered container left white
 *     gaps on the right/bottom).
 *   - Canvas fills the screen; code panel is a slide-up sheet (toggle button).
 *   - Toolbox scrolls so every category (… SD Card) is reachable.
 *  ROLLBACK: re-upload the neutralized mobile.css + mobile-shell.js.
 * ========================================================================== */

/* Stop mobile browsers from auto-inflating text — otherwise the phone enlarges
   Blockly's SVG labels past the widths Blockly measured, misaligning them. */
html, body { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

@media (max-width: 1023px) {
  /* ---- Full-bleed: kill the centered/framed gaps -------------------------- */
  html,
  body {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden !important;
  }
  body { display: block !important; }
  .cContainer {
    width: 100vw !important;
    height: 100vh !important;
    margin: 0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* ---- Mobile top bar (hamburger · BrainBrick · Run) ---------------------- */
  #bbMobileBar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    height: 52px;
    padding: 0 8px;
    background: #1b1f26;
    color: #fff;
    /* Never clip: the middle items scroll horizontally; ☰ and ▶ stay pinned. */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #bbMobileBar::-webkit-scrollbar { display: none; }
  /* Keep the menu button always visible on the left and Run always on the right. */
  #bbMobileBar #bbBurger {
    position: sticky; left: 0; z-index: 3;
    background: #1b1f26;
    box-shadow: 6px 0 8px -4px rgba(0,0,0,.5);
  }
  #bbMobileBar #bbMobileRun {
    position: sticky; right: 0; z-index: 3;
    box-shadow: -6px 0 8px -4px rgba(0,0,0,.5);
  }
  /* Icon-only on the bar: hide the Examples / Learn / Pinout text labels here
     (they still show in the ☰ drawer). Saves the width that caused the overflow. */
  #bbMobileBar .bb-bar-iconbtn span { display: none !important; }
  #bbBurger,
  #bbMobileRun {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 22px;
    line-height: 1;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 8px;
  }
  #bbMobileRun { background: #22c55e; font-size: 18px; }
  #bbMobileTitle { flex: 1; font-weight: 700; font-size: 16px; }

  /* Project-name textbox + Serial + Store, in the bar */
  #bbMobileBar #projectNameInput.bb-mobile-proj {
    flex: 1 1 auto;
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    border-radius: 8px;
    border: 1px solid #3a4048;
    background: #0f141a;
    color: #fff;
    font-size: 14px;
  }
  #bbMobileBar #bbSerialMonitorBtn,
  #bbMobileBar #bbStoreIcon,
  #bbMobileBar #bbConnectBtn {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    margin: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 18px;
    text-decoration: none;
  }
  #bbMobileBar #bbSerialMonitorBtn img { height: 22px; width: auto; display: block; }

  /* Robot-code box in the bar (compact; hide its "Robot code" label) */
  #bbMobileBar #bbDeviceCodeWrap {
    flex: 0 0 auto;
    margin: 0;
    display: flex;
    align-items: center;
  }
  #bbMobileBar #bbDeviceCodeWrap label { display: none !important; }
  #bbMobileBar #bbDeviceCodeBox {
    width: 92px;
    height: 34px;
    padding: 0 8px;
    border-radius: 8px;
    border: 1px solid #3a4048;
    background: #0f141a;
    color: #fff;
    font-size: 13px;
  }

  /* Undo / Redo icon buttons in the bar (icon only, left of the project name) */
  #bbMobileBar .bb-bar-iconbtn {
    flex: 0 0 auto;
    width: 34px;
    height: 40px;
    margin: 0;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    text-decoration: none;
  }
  #bbMobileBar .bb-bar-iconbtn .bb-lbl { display: none !important; }
  #bbMobileBar .bb-bar-iconbtn i,
  #bbMobileBar .bb-bar-iconbtn svg {
    width: 20px;
    height: 20px;
    font-size: 18px;
  }

  /* ---- Menu drawer (holds the original desktop toolbar) ------------------- */
  #bbDrawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 84%;
    max-width: 360px;
    background: #262b31;
    z-index: 10001;
    transform: translateX(100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.4);
  }
  body.bb-drawer-open #bbDrawer { transform: translateX(0); }
  #bbDrawerBackdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }
  body.bb-drawer-open #bbDrawerBackdrop { opacity: 1; pointer-events: auto; }

  /* The original toolbar, FORCED into a tidy vertical list of rows. The desktop
     toolbar stacks icon-over-label with absolute positioning, which overlaps in
     a narrow drawer — so we reset everything to static block + flex rows. */
  #bbDrawer .cm-e-menu { display: block !important; padding: 6px 0 14px !important; }
  #bbDrawer .bb-accent,
  #bbDrawer .bb-spacer,
  #bbDrawer .bb-logo { display: none !important; }

  /* Flatten all grouping wrappers to plain blocks. */
  #bbDrawer .bb-tier1,
  #bbDrawer .bb-tier2,
  #bbDrawer .bb-group,
  #bbDrawer .bb-right-group,
  #bbDrawer .d-flex,
  #bbDrawer ul.cCtrlBtn,
  #bbDrawer ul.cCtrlBtn > li,
  #bbDrawer li {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    background: transparent !important;
    position: static !important;
    list-style: none !important;
  }

  /* Every clickable item -> a clean icon + label row. */
  #bbDrawer a {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 14px !important;
    padding: 13px 18px !important;
    width: 100% !important;
    height: auto !important;
    position: static !important;
    color: #e2e8f0 !important;
    text-decoration: none !important;
    border-bottom: 1px solid #353b42 !important;
    box-sizing: border-box !important;
  }
  #bbDrawer a i,
  #bbDrawer a svg,
  #bbDrawer a img {
    position: static !important;
    flex: 0 0 22px !important;
    width: 22px !important;
    height: 22px !important;
    margin: 0 !important;
    font-size: 19px !important;
  }
  #bbDrawer .bb-lbl {
    position: static !important;
    display: inline !important;
    margin: 0 !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    opacity: 1 !important;
    color: #e2e8f0 !important;
  }

  /* Board switch + version get their own rows. (position:relative is REQUIRED —
     the sliding knob is absolutely positioned inside it.) */
  #bbDrawer .bb-board-switch {
    display: inline-flex !important;
    margin: 14px 18px !important;
    position: relative !important;
  }
  #bbDrawer .bb-gear {
    font-size: 20px;
    width: 22px;
    flex: 0 0 22px;
    text-align: center;
  }
  #bbDrawer #appVersion {
    display: block !important;
    padding: 8px 18px !important;
    color: #94a3b8 !important;
    border-bottom: 1px solid #353b42 !important;
  }

  /* ---- Drawer polish: header, hover/press, icon accent ------------------- */
  #bbDrawerHeader {
    display: flex; align-items: center; gap: 12px;
    padding: 15px 16px; background: #1b1f26;
    border-bottom: 1px solid #353b42;
    position: sticky; top: 0; z-index: 3;
  }
  #bbDrawerHeader img { width: 30px; height: 30px; border-radius: 8px; }
  #bbDrawerHeader .bb-dh-name { font-weight: 800; font-size: 17px; color: #fff; letter-spacing: .2px; }
  #bbDrawerHeader .bb-dh-close {
    margin-left: auto; background: transparent; border: 0; color: #93a3b8;
    font-size: 26px; line-height: 1; width: 38px; height: 38px; cursor: pointer; border-radius: 9px;
  }
  #bbDrawerHeader .bb-dh-close:active { background: #2f353d; color: #fff; }
  #bbDrawer a { transition: background .12s ease; }
  #bbDrawer a:hover, #bbDrawer a:active { background: #2f353d !important; }
  #bbDrawer a i, #bbDrawer a .bb-gear { color: #37c26b !important; }   /* brand-green icons */
  #bbDrawer #bbInstallApp i { color: #2d7ff9 !important; }             /* install = blue */
  #bbDrawer a .bb-lbl { font-weight: 600 !important; }
  #bbDrawer #bbCompileSetup { background: #20262d !important; }
  #bbDrawer #bbCompileSetup .bb-lbl small { color: #93a3b8 !important; font-weight: 400 !important; }
  #bbDrawer #bbDrawerList > a:last-child { border-bottom: 0 !important; }

  /* ---- Canvas fills the available height ---------------------------------- */
  .codeArea {
    display: flex !important;
    flex-direction: column !important;
  }
  .bb-canvas-col {
    flex: 1 1 auto !important;
    width: 100% !important;
    min-height: 0 !important;
  }
  .workspace,
  #blocklyDiv,
  .blocklySvg {
    width: 100% !important;
    height: 100% !important;
  }

  /* ---- Toolbox scrolls (reach every category, incl. SD Card) -------------- */
  .blocklyToolboxDiv {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Toolbar rows scroll sideways so the right-hand items (Robot code,
     Serial, Store) are reachable instead of clipped on narrow screens. ------- */
  .cm-e-menu { overflow: visible !important; }
  .bb-tier1,
  .bb-tier2 {
    overflow-x: auto !important;
    overflow-y: hidden !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
  }

  /* ---- Code panel = bottom sheet ------------------------------------------ */
  #divider { display: none !important; }
  .generated {
    position: fixed !important;
    left: 0; right: 0; bottom: 0;
    width: 100% !important;
    height: 72vh !important;
    transform: translateY(100%);
    transition: transform 0.25s ease;
    z-index: 9000;
    background: #1e1e1e;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.35);
    overflow: auto;
  }
  body.bb-code-open .generated { transform: translateY(0); }

  /* ---- Floating "Code" toggle button -------------------------------------- */
  #bbCodeFab {
    position: fixed;
    right: 14px;
    bottom: 14px;
    z-index: 9001;
    height: 48px;
    padding: 0 18px;
    border: 0;
    border-radius: 24px;
    background: #2a9d8f;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  }
}

/* ---- Force landscape: "rotate" overlay when a phone is held in portrait --- */
#bbRotateOverlay { display: none; }
@media (max-width: 1023px) and (orientation: portrait) {
  body > *:not(#bbRotateOverlay) { display: none !important; }
  #bbRotateOverlay {
    display: flex !important;
    position: fixed;
    inset: 0;
    z-index: 100000;
    background: #1b1f26;
    color: #fff;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  }
  #bbRotateOverlay svg { width: 68px; height: 68px; margin-bottom: 18px; opacity: 0.95; transform-origin: 50% 50%; animation: bbRotateHint 2.4s ease-in-out infinite; }
  @keyframes bbRotateHint { 0%,16% { transform: rotate(0deg); } 42%,66% { transform: rotate(-90deg); } 90%,100% { transform: rotate(0deg); } }
  @media (prefers-reduced-motion: reduce) { #bbRotateOverlay svg { animation: none; } }
  #bbRotateOverlay p { margin: 4px 0; font-size: 18px; font-weight: 700; }
  #bbRotateOverlay .sub { font-size: 14px; font-weight: 400; opacity: 0.75; }
}
@media (orientation: landscape), (min-width: 1024px) {
  #bbRotateOverlay { display: none !important; }
}

