/* BUILD05 — scoped standalone integration CSS; no Host leakage. */
.g2d-standalone-page #g2d-topbar[data-g2d-drag-toolbar="off"] #toolbar-drag-handle,
.g2d-standalone-page #g2d-topbar[data-g2d-drag-toolbar="off"] #toggle-toolbar-pin,
.g2d-standalone-page #g2d-topbar[data-g2d-drag-toolbar="off"] #toggle-toolbar-orientation,
.g2d-standalone-page #g2d-topbar[data-g2d-drag-toolbar="off"] #restore-toolbar-home{display:none!important;}
.g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #g2d-text-menu-toggle,
.g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #g2d-classic-menu-bar{display:none!important;}
.g2d-standalone-page #g2d-topbar #g2d-text-menu-toggle{display:inline-flex;align-items:center;justify-content:center;gap:5px;}
.g2d-standalone-page .g2d-classic-menu-bar:not([hidden]){display:flex!important;}

/* BUILD06 — all 3 utility buttons have the same 48px hit target and legible glyphs. */
.g2d-standalone-page #g2d-topbar .g2d-top-actions :is(#toggle-fullscreen,#open-toolbar-help,#toggle-toolbar){width:48px!important;min-width:48px!important;max-width:48px!important;height:48px!important;min-height:48px!important;max-height:48px!important;padding:6px!important;}
.g2d-standalone-page #g2d-topbar .g2d-top-actions :is(#toggle-fullscreen,#open-toolbar-help,#toggle-toolbar) svg{width:32px!important;height:32px!important;max-width:32px!important;max-height:32px!important;}

/* BUILD06: while the 3D surface owns text navigation, do not duplicate 2D menu. */
.g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] :is(#g2d-text-menu-toggle,#g2d-classic-menu-bar){display:none!important;}
/* BUILD06 final specificity: former separate dropdown trigger is invisible
   in both horizontal and vertical 2D Standalone layouts. */
.g2d-standalone-page #g2d-topbar [data-toantin-tool="geometry_2d"] .g2d-toolbar-row-build01 .g2d-palette-chevron{display:none!important;width:0!important;min-width:0!important;max-width:0!important;height:0!important;min-height:0!important;border:0!important;padding:0!important;margin:0!important;}
.g2d-standalone-page #g2d-topbar [data-toantin-tool="geometry_2d"] .g2d-toolbar-row-build01 .g2d-palette-primary{border-radius:10px!important;}

/* BUILD26 mobile UX pack — scoped to Standalone, desktop unchanged.
   Goals: keep the top toolbar always visible + swipeable, collapse the vertical
   quick rails to one toggle button, and remove the duplicate right-edge tab on mobile. */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .g2d-standalone-page,
  .g2d-standalone-page .g2d-standalone-shell {
    overflow-y: visible !important;
    overscroll-behavior-y: auto;
  }

  .g2d-standalone-page #g2d-topbar,
  .g2d-standalone-page #g2d-topbar.g2d-toolbar-floating,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #g2d-topbar,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #g2d-topbar.g2d-toolbar-floating {
    position: sticky !important;
    inset: auto !important;
    left: auto !important;
    top: auto !important;
    right: auto !important;
    bottom: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    transform: none !important;
  }

  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-strip {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    width: auto !important;
    min-width: 100% !important;
    max-width: none !important;
    gap: 4px !important;
    padding: 4px !important;
  }

  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-brand-button {
    flex: 0 0 auto;
    min-width: 48px;
    width: 48px;
    min-height: 44px;
  }

  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell {
    flex: 1 1 auto !important;
    width: auto !important;
    min-width: 0 !important;
    max-width: none !important;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
    scrollbar-width: thin;
  }

  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell > #toolbar-host,
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell [data-toantin-tool="geometry_2d"].g2d-toolbar,
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell [data-toantin-tool="geometry_2d"] .g2d-toolbar-row,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #gs3d-toolbar-host,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #gs3d-toolbar-host .gs3d-toolbar,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #gs3d-toolbar-host .gs3d-tool-row {
    width: max-content !important;
    min-width: max-content !important;
    max-width: none !important;
    overflow: visible !important;
    flex-wrap: nowrap !important;
  }

  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-top-actions {
    flex: 0 0 auto !important;
    display: inline-flex !important;
    flex-wrap: nowrap !important;
    gap: 4px !important;
    margin-left: 2px;
  }

  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] :is(#toolbar-drag-handle,#toggle-toolbar-pin,#toggle-toolbar-orientation,#restore-toolbar-home,#toggle-toolbar-utilities) {
    display: none !important;
  }

  .g2d-standalone-page .g2d-right-edge-tab {
    display: none !important;
  }

  .g2d-standalone-page .g2d-mobile-rail-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    min-width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    border: 1px solid #72afe9;
    border-radius: 11px;
    background: #1662cf;
    color: #fff;
    font-size: 20px;
    font-weight: 800;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(17,63,127,.18);
  }
  .g2d-standalone-page .g2d-mobile-rail-toggle.is-open {
    background: #0f4ea9;
  }

  .g2d-standalone-page .g2d-teaching-rail[data-mobile-compact="true"],
  .g2d-standalone-page .gs3d-view-stack[data-mobile-compact="true"] {
    gap: 4px !important;
    padding: 4px !important;
    border-radius: 14px !important;
    max-width: 50px !important;
    min-width: 50px !important;
    overflow: visible !important;
  }

  .g2d-standalone-page .g2d-teaching-rail[data-mobile-compact="true"]:not([data-mobile-compact-expanded="true"]) > :not(.g2d-mobile-rail-toggle),
  .g2d-standalone-page .gs3d-view-stack[data-mobile-compact="true"]:not([data-mobile-compact-expanded="true"]) > :not(.g2d-mobile-rail-toggle) {
    display: none !important;
  }

  .g2d-standalone-page .g2d-teaching-rail[data-mobile-compact="true"] > .g2d-mobile-rail-toggle,
  .g2d-standalone-page .gs3d-view-stack[data-mobile-compact="true"] > .g2d-mobile-rail-toggle {
    display: inline-flex !important;
  }

  .g2d-standalone-page .g2d-teaching-rail[data-mobile-compact="true"][data-mobile-compact-expanded="true"],
  .g2d-standalone-page .gs3d-view-stack[data-mobile-compact="true"][data-mobile-compact-expanded="true"] {
    max-width: 52px !important;
    max-height: min(72dvh, 420px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: thin;
  }

  .g2d-standalone-page .g2d-teaching-rail[data-mobile-compact="true"][data-mobile-compact-expanded="true"] > .g2d-teaching-rail-button,
  .g2d-standalone-page .gs3d-view-stack[data-mobile-compact="true"][data-mobile-compact-expanded="true"] > .gs3d-view-btn,
  .g2d-standalone-page .gs3d-view-stack[data-mobile-compact="true"][data-mobile-compact-expanded="true"] > .gs3d-help-trigger {
    display: flex !important;
  }
}


/* BUILD27 / FB-MOBILE-B26-001/002: one swipe lane for *all* horizontal chrome.
   NO desktop rule is touched. A scrollable header clips y-overflow by design;
   geometry palettes therefore use their existing menu portals on mobile. */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .g2d-standalone-page #g2d-topbar,
  .g2d-standalone-page #g2d-topbar.g2d-toolbar-floating,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #g2d-topbar {
    box-sizing:border-box !important;
    display:block !important;
    overflow-x:auto !important;
    overflow-y:hidden !important;
    width:100% !important;
    min-width:0 !important;
    max-width:100% !important;
    touch-action:pan-x !important;
    overscroll-behavior-x:contain;
    -webkit-overflow-scrolling:touch;
    scrollbar-width:thin;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-collapse,
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-strip {
    box-sizing:border-box !important;
    width:max-content !important;
    min-width:max-content !important;
    max-width:none !important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-strip {
    flex-wrap:nowrap !important;
    gap:4px !important;
    touch-action:pan-x !important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] :is(.g2d-brand-button,#go-to-toantin-home,#g2d-text-menu-toggle,.g2d-toolbar-shell,.g2d-top-actions) {
    flex:0 0 auto !important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell {
    display:block !important;
    width:max-content !important;
    min-width:max-content !important;
    max-width:none !important;
    flex:0 0 auto !important;
    overflow:visible !important;
    scrollbar-width:none;
    touch-action:pan-x !important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell > #toolbar-host,
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell [data-toantin-tool="geometry_2d"].g2d-toolbar,
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell [data-toantin-tool="geometry_2d"] .g2d-toolbar-row,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #gs3d-toolbar-host,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #gs3d-toolbar-host .gs3d-toolbar,
  .g2d-standalone-page .g2d-standalone-shell[data-studio-mode="3d"] #gs3d-toolbar-host .gs3d-tool-row,
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-top-actions {
    width:max-content !important;
    min-width:max-content !important;
    max-width:none !important;
    overflow:visible !important;
    flex-wrap:nowrap !important;
  }
  .g2d-standalone-page #g2d-topbar .g2d-palette-primary[data-press-hold-menu="true"],
  .g2d-standalone-page #g2d-topbar .gs3d-group[aria-haspopup="true"],
  .g2d-standalone-page #g2d-topbar .gs3d-mode-command[aria-haspopup="menu"] {
    touch-action:pan-x !important;
    -webkit-touch-callout:none;
    user-select:none;
    -webkit-user-select:none;
  }
  .g2d-standalone-page #g2d-topbar .g2d-palette-primary[data-press-hold-menu="true"]::after,
  .g2d-standalone-page #g2d-topbar .gs3d-group[aria-haspopup="true"]::after {
    content:'▾';pointer-events:none;position:absolute;right:1px;bottom:0;
    font-size:10px;font-weight:850;line-height:1;color:#1654aa;
  }
  .g2d-standalone-page #g2d-topbar .g2d-palette-primary[data-press-hold-menu="true"],
  .g2d-standalone-page #g2d-topbar .gs3d-group[aria-haspopup="true"] {position:relative;}
}

/* BUILD29 — Owner: the currently effective 2D tool must be unmistakable.
   Standalone-only specificity for the prior 1px !important border-right rule. */
.g2d-standalone-page #g2d-topbar [data-toantin-tool="geometry_2d"] .g2d-toolbar-row-build01 .g2d-palette-primary[aria-pressed="true"]{
  border:3px solid #1667e8 !important;
  border-right:3px solid #1667e8 !important;
  background:#e5f0ff !important;
  box-shadow:inset 0 0 0 1px white, 0 0 0 1px rgba(22,103,232,.24);
}

/* BUILD35 mobile ☰: one geometry toolbar lane with ONE horizontal scroll owner.
   Menu palettes are portalled to body, so opening them cannot resize the lane.
   Compact and Classic labels may scroll, but never wrap into another toolbar row. */
@media (max-width: 820px), (hover:none) and (pointer:coarse) {
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] {
    overflow-x:auto!important;overflow-y:hidden!important;scrollbar-gutter:stable;
    overscroll-behavior-x:contain;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] #toolbar-collapse {
    display:block;min-width:0!important;width:max-content!important;max-width:none!important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-strip {
    display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;
    align-items:center!important;width:max-content!important;min-width:max-content!important;
    max-width:none!important;contain:layout;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-strip > * {
    flex-shrink:0!important;align-self:center!important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] .g2d-toolbar-shell {
    flex:0 0 auto!important;overflow:visible!important;width:max-content!important;max-width:none!important;
  }
  .g2d-standalone-page #g2d-topbar[data-toolbar-orientation="horizontal"] #g2d-classic-menu-bar:not([hidden]) {
    display:flex!important;flex-wrap:nowrap!important;width:max-content!important;
    max-width:none!important;white-space:nowrap;
  }
  .g2d-standalone-page :is(#g2d-text-menu-popup,.g2d-text-hover-sub):not([hidden]) {
    position:fixed!important;max-width:calc(100vw - 16px);z-index:1070;
  }
}

/* BUILD37: iOS toolbar lane. A single scrolling parent must own the *whole*
   strip, including the 2D/3D switch, Home, textual menu and geometry tools.
   The 3D workspace's historical 100%-width nested scrollers caused the mode
   switch to occupy a visual row of its own. Standalone/mobile only. */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) {
   display:block !important; width:100% !important; max-width:100% !important;
   overflow-x:auto !important; overflow-y:hidden !important;
   -webkit-overflow-scrolling:touch; touch-action:pan-x;
 }
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) .g2d-toolbar-strip {
   display:flex !important; flex-wrap:nowrap !important; flex-direction:row !important;
   align-items:center !important; width:max-content !important;
   min-width:max-content !important; max-width:none !important;
   overflow:visible !important; height:auto !important;
 }
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) #toolbar-collapse {
   display:block !important;
 }
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) .g2d-toolbar-strip > *,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) .g2d-toolbar-shell > *,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) #gs3d-toolbar-host > * {
   flex:0 0 auto !important; align-self:center !important;
 }
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) .g2d-toolbar-shell,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) .g2d-toolbar-shell > #toolbar-host,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) #gs3d-toolbar-host,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) #gs3d-toolbar-host .gs3d-toolbar,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) #gs3d-toolbar-host .gs3d-tool-row,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) [data-toantin-tool="geometry_2d"] .g2d-toolbar-row {
   display:flex !important; flex-wrap:nowrap !important; flex-direction:row !important;
   width:max-content !important; min-width:max-content !important; max-width:none !important;
   overflow:visible !important;
 }
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) .gs3d-mode-switch,
 .g2d-standalone-page #g2d-topbar:not([data-toolbar-orientation="vertical"]) #g2d-text-menu-toggle {
   flex:0 0 auto !important; align-self:center !important;
 }
}

/* GS-FB-007: the mobile flex lane must never override the native hidden state.
   Scoped to the standalone Toolbar hosts; the TOÁN TIN Host remains untouched. */
@media (max-width: 820px), (hover: none) and (pointer: coarse) {
  .g2d-standalone-page #g2d-topbar .g2d-toolbar-shell > #toolbar-host[hidden],
  .g2d-standalone-page #g2d-topbar #gs3d-toolbar-host[hidden] {
    display: none !important;
  }
}
