/* =============================================================================
   NirtsCAD — Mobile layout
   Every rule below is scoped to html.is-mobile (phone layout) or html.is-touch
   (coarse pointer). Those classes are set by the inline script in index.html
   <head> and are NEVER present on a desktop browser, so desktop is unaffected.
   ============================================================================= */

/* Mobile-only elements are hidden everywhere unless the layout is mobile. */
.mobile-only,
.touch-desktop-only {
    display: none !important;
}

html.is-mobile .mobile-only {
    display: revert !important;
}

html.is-touch:not(.is-mobile) .touch-desktop-only {
    display: block !important;
}

/* Desktop-only elements are hidden when mobile layout is active. */
html.is-mobile .desktop-only {
    display: none !important;
}

/* Tablets (touch + desktop layout): menus also open on tap (mobile.js toggles .is-open). */
html.is-touch:not(.is-mobile) .menu-bar .menu-item.dropdown.is-open>.dropdown-content,
html.is-touch:not(.is-mobile) .menu-bar .dropdown-submenu-item.is-open>.dropdown-submenu {
    display: block;
}

/* =============================================================================
   1. Shell / viewport
   ============================================================================= */
html.is-mobile {
    --m-topbar-h: 48px;
    --m-safe-top: env(safe-area-inset-top, 0px);
    --m-safe-bottom: env(safe-area-inset-bottom, 0px);
    --m-safe-left: env(safe-area-inset-left, 0px);
    --m-safe-right: env(safe-area-inset-right, 0px);
    --m-surface: rgba(14, 15, 19, 0.96);
    --m-surface-2: rgba(28, 30, 36, 0.98);
    --m-hair: rgba(255, 255, 255, 0.08);
    /* app.js syncs this to the menu-bar height; on mobile the bar is a drawer, so pin it to the top bar. */
    --app-menu-offset: calc(var(--m-topbar-h) + var(--m-safe-top)) !important;
    height: 100%;
    overscroll-behavior: none;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html.is-mobile body {
    height: 100vh;
    height: 100dvh;
    /* --kb-inset is set by mobile.js from visualViewport (iOS); 0 on Android (resizes-content). */
    padding-bottom: var(--kb-inset, 0px);
    padding-left: var(--m-safe-left);
    padding-right: var(--m-safe-right);
    overscroll-behavior: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

html.is-mobile .app-container {
    min-height: 0;
}

html.is-mobile .canvas-wrapper {
    border-radius: 0;
    border: none;
    box-shadow: none;
    overflow: hidden;
}

html.is-touch #webgl-canvas {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Precision reticle for touch aim and pick */
#mobile-pick-reticle {
    position: fixed;
    width: 44px;
    height: 44px;
    margin-left: -22px;
    margin-top: -22px;
    border-radius: 50%;
    border: 2px solid #00ffff;
    background: rgba(0, 255, 255, 0.12);
    box-shadow: 0 0 10px rgba(0, 255, 255, 0.6), inset 0 0 4px rgba(0, 255, 255, 0.4);
    pointer-events: none;
    z-index: 9999;
    display: none;
    opacity: 0;
    transition: opacity 0.08s ease;
}
#mobile-pick-reticle::before {
    content: '';
    position: absolute;
    left: 4px;
    right: 4px;
    top: 50%;
    height: 1.5px;
    background: #00ffff;
    transform: translateY(-50%);
}
#mobile-pick-reticle::after {
    content: '';
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 50%;
    width: 1.5px;
    background: #00ffff;
    transform: translateX(-50%);
}
#mobile-pick-reticle.show {
    display: block;
    opacity: 1;
}

/* =============================================================================
   2. Top bar
   ============================================================================= */
html.is-mobile #mobile-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--m-topbar-h) + var(--m-safe-top));
    padding: var(--m-safe-top) calc(6px + var(--m-safe-right)) 0 calc(6px + var(--m-safe-left));
    box-sizing: border-box;
    display: flex !important;
    align-items: center;
    gap: 2px;
    z-index: 1001;
    background: linear-gradient(180deg, rgba(20, 22, 18, 0.98), rgba(12, 13, 15, 0.96));
    border-bottom: 1px solid rgba(212, 168, 42, 0.22);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

html.is-mobile body.nirts-auth-gate #mobile-topbar,
html.is-mobile body.nirts-auth-gate #mobile-drawer-backdrop {
    display: none !important;
}

html.is-mobile .mobile-icon-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    display: inline-grid;
    place-items: center;
    padding: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

html.is-mobile .mobile-icon-btn:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.94);
}

/* Pen (freehand) toggle: dot shows the current width; ▾ opens the thickness popover */
html.is-mobile .mobile-pen-group {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
}

html.is-mobile .mobile-pen-btn {
    position: relative;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

html.is-mobile .mobile-pen-btn.is-on,
html.is-mobile .mobile-pen-eraser-btn.is-on {
    color: var(--brand-ink, #14160f);
    background: var(--brand-gold-fill, #d4a82a);
}

html.is-mobile .mobile-pen-eraser-btn[hidden] {
    display: none;
}

html.is-mobile .mobile-pen-eraser-btn {
    margin-left: 2px;
}

html.is-mobile .mobile-pen-dot {
    position: absolute;
    right: 5px;
    bottom: 5px;
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: currentColor;
    transform: translate(50%, 50%);
    pointer-events: none;
}

html.is-mobile .mobile-pen-caret {
    flex: 0 0 auto;
    width: 18px;
    height: 40px;
    padding: 0;
    margin-left: -2px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1;
    cursor: pointer;
}

#mobile-pen-popover {
    display: none;
    position: fixed;
    z-index: 1100;
    width: 248px;
    padding: 12px 12px 10px;
    border-radius: 16px;
    background: linear-gradient(145deg, rgba(34, 38, 30, 0.98), rgba(20, 22, 18, 0.98));
    border: 1px solid rgba(212, 168, 42, 0.45);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
    color: var(--text-primary);
    box-sizing: border-box;
}

#mobile-pen-popover.show {
    display: block;
    animation: mobileBannerIn 0.18s ease;
}

#mobile-pen-popover .mpp-title {
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--brand-gold-bright, #f0c74a);
    margin-bottom: 8px;
}

#mobile-pen-popover .mpp-presets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 10px;
}

#mobile-pen-popover .mpp-preset {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 2px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
    cursor: pointer;
}

#mobile-pen-popover .mpp-preset.is-current {
    border-color: rgba(212, 168, 42, 0.85);
    background: rgba(212, 168, 42, 0.16);
}

#mobile-pen-popover .mpp-dot-box {
    display: grid;
    place-items: center;
    width: 24px;
    height: 24px;
}

#mobile-pen-popover .mpp-dot {
    display: block;
    border-radius: 50%;
    background: currentColor;
}

#mobile-pen-popover .mpp-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
}

#mobile-pen-popover .mpp-slider {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

#mobile-pen-popover .mpp-slider input[type="range"] {
    flex: 1 1 auto;
    min-width: 0;
    accent-color: var(--brand-gold, #d4a82a);
}

#mobile-pen-popover .mpp-val {
    flex: 0 0 auto;
    min-width: 42px;
    text-align: right;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

html.is-mobile .mobile-ai-btn {
    width: 36px;
    height: 32px;
    margin-left: 4px;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.06em;
    color: var(--brand-gold);
    background: var(--brand-olive);
    border: 1.5px solid var(--brand-gold);
    border-radius: 8px 12px 8px 8px;
}

html.is-mobile .mobile-doc-title {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0 6px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--brand-gold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Floating AI button is replaced by the top-bar button on phones. */
html.is-mobile #chat-toggle-btn {
    display: none !important;
}

/* =============================================================================
   3. Menu → off-canvas drawer (same nav.menu-bar DOM, restyled)
   ============================================================================= */
html.is-mobile #mobile-drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1009;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    display: block !important;
}

html.is-mobile.mobile-drawer-open #mobile-drawer-backdrop {
    opacity: 1;
    pointer-events: auto;
}

html.is-mobile .menu-bar {
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 340px);
    min-height: 0;
    height: 100%;
    padding: calc(12px + var(--m-safe-top)) 0 calc(16px + var(--m-safe-bottom)) var(--m-safe-left);
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    align-content: stretch;
    gap: 0;
    z-index: 1010;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
    background: var(--m-surface);
    border: none;
    border-right: 1px solid rgba(212, 168, 42, 0.25);
    box-shadow: 8px 0 32px rgba(0, 0, 0, 0.55);
    transform: translateX(-105%);
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.25s;
    visibility: hidden;
}

html.is-mobile.mobile-drawer-open .menu-bar {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.25s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s;
}

html.is-mobile .menu-bar>.menu-item {
    border-bottom: 1px solid var(--m-hair);
}

html.is-mobile .menu-bar .menu-item.dropdown:hover {
    z-index: auto;
}

html.is-mobile .menu-bar .menu-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 0 18px;
    font-size: 1rem;
    color: var(--text-primary);
}

html.is-mobile .menu-bar .menu-item.dropdown>.menu-trigger::after {
    content: '';
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    opacity: 0.5;
    transition: transform 0.2s ease;
}

html.is-mobile .menu-bar .menu-item.dropdown.is-open>.menu-trigger::after {
    transform: rotate(-135deg);
}

html.is-mobile .menu-bar .menu-item.dropdown.is-open>.menu-trigger {
    color: var(--accent-color);
}

/* Locked menus keep their lock indicator instead of the chevron. */
html.is-mobile #cadmax-menu-item.cadmax-locked .menu-trigger::after,
html.is-mobile #isyddhi-menu-item.hydraulics-locked .menu-trigger::after {
    content: ' 🔒';
    width: auto;
    height: auto;
    border: none;
    transform: none;
    opacity: 1;
}

html.is-mobile #cadmax-menu-item {
    display: block;
    max-width: none;
}

html.is-mobile #cadmax-menu-item .document-path-label {
    display: none;
}

/* Dropdowns become inline accordions; :hover no longer opens them. */
html.is-mobile .menu-bar .dropdown-content,
html.is-mobile .menu-bar .dropdown:hover .dropdown-content {
    display: none;
    position: static;
    min-width: 0;
    margin: 0;
    padding: 4px 0 8px;
    border: none;
    border-radius: 0;
    background: rgba(255, 255, 255, 0.025);
    box-shadow: none;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

html.is-mobile .menu-bar .menu-item.dropdown.is-open>.dropdown-content {
    display: block !important;
}

html.is-mobile .menu-bar .dropdown-content a,
html.is-mobile .menu-bar .dropdown-submenu a {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 0 18px 0 30px;
    font-size: 0.95rem;
}

html.is-mobile .menu-bar .dropdown-content a.mobile-only {
    display: flex !important;
}

html.is-mobile .menu-bar .dropdown-content a:active,
html.is-mobile .menu-bar .submenu-trigger:active {
    background: rgba(0, 229, 255, 0.12);
}

html.is-mobile .menu-bar .submenu-trigger {
    min-height: 44px;
    padding: 0 18px 0 30px;
    font-size: 0.95rem;
    cursor: pointer;
}

html.is-mobile .menu-bar .submenu-chevron {
    transition: transform 0.2s ease;
}

html.is-mobile .menu-bar .dropdown-submenu-item.is-open>.submenu-trigger {
    color: var(--accent-color);
}

html.is-mobile .menu-bar .dropdown-submenu-item.is-open>.submenu-trigger .submenu-chevron {
    transform: rotate(90deg);
}

html.is-mobile .menu-bar .dropdown-submenu,
html.is-mobile .menu-bar .dropdown-submenu-item:hover .dropdown-submenu {
    display: none;
    position: static;
    margin: 0;
    min-width: 0;
    max-height: none;
    padding: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

html.is-mobile .menu-bar .dropdown-submenu-item.is-open>.dropdown-submenu {
    display: block !important;
}

html.is-mobile .menu-bar .dropdown-submenu a {
    padding-left: 44px;
    font-size: 0.9rem;
}

html.is-mobile .menu-bar .isyddhi-type-menu {
    max-height: none;
    overflow: visible;
}

/* User menu → drawer footer */
html.is-mobile .menu-bar #user-menu {
    order: 999;
    margin: auto 0 0;
    padding: 16px 18px 12px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    border-top: 1px solid var(--m-hair);
}

html.is-mobile .menu-bar #user-email-display {
    flex: 1 1 100%;
    max-width: none;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

html.is-mobile .menu-bar #plan-badge {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 10px;
    box-sizing: border-box;
    border-radius: 8px;
    font-size: 11px;
    vertical-align: middle;
}

html.is-mobile .menu-bar .user-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    min-height: 36px;
    box-sizing: border-box;
    padding: 0 12px;
    border-radius: 8px;
    font-size: 13px;
    vertical-align: middle;
}

html.is-mobile .menu-bar #upgrade-btn.upgrade-btn {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    height: 36px !important;
    min-height: 36px !important;
    padding: 0 14px !important;
    border-radius: 8px !important;
    font-size: 13px !important;
    line-height: normal !important;
    vertical-align: middle !important;
}

html.is-mobile .menu-bar #settings-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 8px;
    font-size: 15px;
    vertical-align: middle;
}

html.is-mobile .menu-bar .user-menu-power-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 8px;
    vertical-align: middle;
}

/* =============================================================================
   4. Status bar — compact mobile pane (stays intact from ~320px to wide phones)
      Row 1: [coord value ........] [zoom] [color ▾][■] [▲/▼]
      Row 2: extra-instruction line (coord-msg placeholder)
      Row 3: U: [unit ▾]   G: [☑][B ▾]   L: name [Manage]
      Collapsed  → Row 1 only (Row 2 also appears while a prompt is active).
      Expanded   → Rows 1–3; the pane grows upward, arrow flips to point down.
   ============================================================================= */
html.is-mobile {
    /* Scales with viewport width, clamped so narrow phones (S22 Ultra ≈ 384px,
       Galaxy Fold ≈ 320px) shrink gracefully and wide phones don't balloon. */
    --sb-font: clamp(0.60rem, 2.7vw, 0.74rem);
    --sb-ctl-h: 22px;
    --sb-gap: clamp(4px, 1.6vw, 10px);
    --sb-zoom-w: clamp(40px, 12vw, 58px);
    --sb-aci-w: clamp(46px, 13vw, 64px);
    --sb-unit-w: clamp(50px, 14vw, 62px);
}

/* Hide verbose / unused labels; show compact U: G: L: labels only. */
html.is-mobile #document-path-wrapper,
html.is-mobile .bg-label-mobile,
html.is-mobile .bg-label-desktop,
html.is-mobile .coord-label-desktop,
html.is-mobile .coord-label-mobile,
html.is-mobile .zoom-label-desktop,
html.is-mobile .zoom-label-mobile,
html.is-mobile .color-label-desktop,
html.is-mobile .color-label-mobile,
html.is-mobile .unit-label-desktop,
html.is-mobile .layer-label-desktop,
html.is-mobile .grid-label-desktop {
    display: none !important;
}

html.is-mobile .single-line-bar .unit-label-mobile,
html.is-mobile .single-line-bar .grid-label-mobile,
html.is-mobile .single-line-bar .layer-label-mobile {
    display: inline !important;
    font-size: var(--sb-font) !important;
    font-weight: 700 !important;
    letter-spacing: 0 !important;
    color: var(--text-secondary) !important;
    margin: 0 !important;
    flex: 0 0 auto;
}

html.is-mobile .ui-overlay {
    margin-top: 0 !important;
    padding: 0 !important;
}

/* ---------- Pane container ---------- */
html.is-mobile .single-line-bar {
    display: flex !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 3px var(--sb-gap) !important;
    padding: 4px calc(4px + var(--m-safe-right)) 4px calc(8px + var(--m-safe-left)) !important;
    box-sizing: border-box !important;
    width: 100% !important;
    max-width: 100% !important;
    min-height: 30px !important;
    overflow: hidden !important;
    background: linear-gradient(180deg, rgba(18, 20, 27, 0.97), rgba(12, 13, 18, 0.97));
    border-top: 1px solid rgba(0, 229, 255, 0.18);
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
}

/* Reset all boxes; nothing is allowed to force horizontal overflow. */
html.is-mobile .single-line-bar > .coordinate-box,
html.is-mobile .single-line-bar > .color-box-horizontal,
html.is-mobile .single-line-bar > .zoom-box,
html.is-mobile .single-line-bar > .unit-box,
html.is-mobile .single-line-bar > .grid-toggle-label,
html.is-mobile .single-line-bar > .bg-select-box,
html.is-mobile .single-line-bar > .layer-box {
    display: inline-flex !important;
    align-items: center !important;
    box-sizing: border-box !important;
    width: auto !important;
    min-width: 0 !important;
    height: var(--sb-ctl-h) !important;
    padding: 0 !important;
    margin: 0 !important;
}

html.is-mobile .single-line-bar select {
    height: var(--sb-ctl-h) !important;
    font-size: var(--sb-font) !important;
    line-height: 1 !important;
    border-radius: 5px !important;
    padding: 0 2px 0 4px !important;
    color: var(--text-primary) !important;
    background-color: rgba(255, 255, 255, 0.06) !important;
    border: 1px solid rgba(255, 255, 255, 0.12) !important;
    box-sizing: border-box !important;
    flex-shrink: 0 !important;
}

html.is-mobile .single-line-bar .ui-button {
    height: var(--sb-ctl-h) !important;
    font-size: var(--sb-font) !important;
    padding: 0 7px !important;
    border-radius: 5px !important;
}

/* ---------- Row 1 ---------- */
/* Coord: takes all remaining width; fits "X: 9999.999, Y: 9999.999, Z: 9999.999"
   on typical phones and ellipsizes cleanly on the narrowest ones. */
html.is-mobile .single-line-bar > .coordinate-box {
    order: 1 !important;
    flex: 1 1 0 !important;
    justify-content: flex-start !important;
    overflow: hidden !important;
}

/* Left-aligned so "X:" starts on the same left edge as "U:" in row 3. */
html.is-mobile .single-line-bar #coord-val {
    display: block !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    text-align: left !important;
    font-size: var(--sb-font) !important;
    font-family: 'JetBrains Mono', 'Courier New', monospace !important;
    font-variant-numeric: tabular-nums !important;
    letter-spacing: -0.3px !important;
    color: var(--accent-color) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Zoom: fixed slot, right-aligned so the number doesn't jitter. */
html.is-mobile .single-line-bar > .zoom-box {
    order: 2 !important;
    flex: 0 0 var(--sb-zoom-w) !important;
    width: var(--sb-zoom-w) !important;
    justify-content: flex-end !important;
    overflow: hidden !important;
}

html.is-mobile .single-line-bar #zoom-level {
    display: block !important;
    max-width: 100% !important;
    font-size: var(--sb-font) !important;
    font-family: 'JetBrains Mono', 'Courier New', monospace !important;
    font-variant-numeric: tabular-nums !important;
    color: var(--text-primary) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Color: ACI combo + swatch, right-aligned and hugging the chevron. */
html.is-mobile .single-line-bar > .color-box-horizontal {
    order: 3 !important;
    flex: 0 0 auto !important;
    gap: 3px !important;
    justify-content: flex-end !important;
    margin-right: calc(-1 * var(--sb-gap) + 2px) !important;
}

html.is-mobile .single-line-bar #aci-select {
    width: var(--sb-aci-w) !important;
    min-width: 0 !important;
    max-width: var(--sb-aci-w) !important;
}

html.is-mobile .single-line-bar #line-color {
    width: 20px !important;
    height: 20px !important;
    padding: 0 !important;
    border-radius: 4px !important;
    flex-shrink: 0 !important;
}

/* Toggle arrow: chevron points UP (open upward); flips DOWN when expanded. */
html.is-mobile #mobile-status-more {
    order: 4 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 0 0 26px !important;
    width: 26px !important;
    min-width: 26px !important;
    max-width: 26px !important;
    height: 26px !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    border-radius: 6px !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    color: var(--accent-color) !important;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.12s ease;
}

html.is-mobile #mobile-status-more svg {
    display: block;
    width: 16px !important;
    height: 16px !important;
    stroke: var(--accent-color) !important;
    stroke-width: 2.8px !important;
}

html.is-mobile #mobile-status-more .mobile-status-arrow {
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
    transform: rotate(0deg);
}

html.is-mobile.mobile-status-expanded #mobile-status-more .mobile-status-arrow {
    transform: rotate(180deg);
}

html.is-mobile #mobile-status-more:active {
    background: rgba(0, 229, 255, 0.12) !important;
    transform: scale(0.9);
}

/* ---------- Row breaks ---------- */
html.is-mobile #mobile-status-break-1,
html.is-mobile #mobile-status-break-2 {
    flex: 0 0 100% !important;
    width: 100% !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
}

html.is-mobile #mobile-status-break-1 { order: 10 !important; }
html.is-mobile #mobile-status-break-2 { order: 20 !important; }

/* ---------- Row 2: extra-instruction placeholder ---------- */
html.is-mobile #coord-msg {
    order: 11 !important;
    position: static !important;
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 16px !important;
    line-height: 16px !important;
    margin: 0 !important;
    padding: 0 0 0 1px !important;
    box-sizing: border-box !important;
    font-size: var(--sb-font) !important;
    font-family: 'JetBrains Mono', 'Courier New', monospace !important;
    color: var(--text-secondary) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

/* Empty placeholder keeps its height and shows a faint hairline. */
html.is-mobile #coord-msg:empty {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.06), transparent) center / 100% 1px no-repeat;
}

/* ---------- Row 3: U: unit  G: grid/bg  L: layer ---------- */
html.is-mobile .single-line-bar > .unit-box {
    order: 21 !important;
    flex: 0 0 auto !important;
    gap: 3px !important;
}

html.is-mobile .single-line-bar #unit-selector {
    width: var(--sb-unit-w) !important;
    min-width: 0 !important;
    max-width: var(--sb-unit-w) !important;
}

html.is-mobile .single-line-bar > .grid-toggle-label {
    order: 22 !important;
    flex: 0 0 auto !important;
    gap: 3px !important;
    color: var(--text-primary);
    cursor: pointer;
}

html.is-mobile .single-line-bar .grid-toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0 !important;
    accent-color: var(--accent-color);
    cursor: pointer;
}

html.is-mobile .single-line-bar > .bg-select-box {
    order: 23 !important;
    flex: 0 0 auto !important;
    margin-left: calc(-1 * var(--sb-gap) + 3px) !important;
}

html.is-mobile .single-line-bar #bg-select {
    width: 36px !important;
    min-width: 0 !important;
    max-width: 36px !important;
    font-weight: 600 !important;
}

/* Layer: name (max 15 chars + "…", trimmed in mobile.js) with Manage right beside it. */
html.is-mobile .single-line-bar > .layer-box {
    order: 24 !important;
    flex: 0 1 auto !important;
    justify-content: flex-start !important;
    gap: 4px !important;
    overflow: hidden !important;
}

html.is-mobile .single-line-bar #current-layer-name {
    display: block !important;
    flex: 0 1 auto !important;
    min-width: 0 !important;
    max-width: none !important;
    font-size: var(--sb-font) !important;
    font-weight: 600 !important;
    color: var(--accent-color) !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
}

html.is-mobile .single-line-bar #layer-manager-btn {
    flex: 0 0 auto !important;
    margin: 0 !important;
    font-weight: 600 !important;
}

/* ---------- Visibility per state ---------- */
/* Row 2: shown when expanded (as placeholder) or whenever a prompt is active. */
html.is-mobile:not(.has-coord-msg):not(.mobile-status-expanded) #mobile-status-break-1,
html.is-mobile:not(.has-coord-msg):not(.mobile-status-expanded) #coord-msg {
    display: none !important;
}

html.is-mobile.has-coord-msg #mobile-status-break-1,
html.is-mobile.mobile-status-expanded #mobile-status-break-1,
html.is-mobile.has-coord-msg #coord-msg,
html.is-mobile.mobile-status-expanded #coord-msg {
    display: block !important;
}

/* Row 3: expanded only. */
html.is-mobile:not(.mobile-status-expanded) #mobile-status-break-2,
html.is-mobile:not(.mobile-status-expanded) .single-line-bar > .unit-box,
html.is-mobile:not(.mobile-status-expanded) .single-line-bar > .grid-toggle-label,
html.is-mobile:not(.mobile-status-expanded) .single-line-bar > .bg-select-box,
html.is-mobile:not(.mobile-status-expanded) .single-line-bar > .layer-box {
    display: none !important;
}

html.is-mobile.mobile-status-expanded #mobile-status-break-2 {
    display: block !important;
}

/* Very narrow phones (≤ 340px, e.g. Galaxy Fold cover screen). */
@media (max-width: 340px) {
    html.is-mobile {
        --sb-ctl-h: 20px;
        --sb-aci-w: 44px;
        --sb-unit-w: 48px;
    }
    html.is-mobile .single-line-bar #line-color {
        width: 16px !important;
        height: 16px !important;
    }
    html.is-mobile .single-line-bar #layer-manager-btn {
        padding: 0 5px !important;
    }
}

/* Command bar toggle buttons: pure cyan arrows without border */
html.is-mobile .mobile-cmd-toggle-btn {
    margin-left: auto;
    margin-right: 0 !important;
    min-width: 24px !important;
    max-width: 24px !important;
    width: 24px !important;
    height: 24px !important;
    padding: 0 !important;
    border-radius: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none !important;
    color: var(--accent-color) !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    flex: 0 0 24px !important;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

html.is-mobile .mobile-cmd-toggle-btn svg {
    display: block;
    width: 16px;
    height: 16px;
    stroke: var(--accent-color) !important;
    stroke-width: 2.8px !important;
}

html.is-mobile .mobile-cmd-toggle-btn:active {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    transform: scale(0.88);
    opacity: 0.75;
}

/* =============================================================================
   5. Command bar — docked at the bottom, expandable & collapsible
   ============================================================================= */
html.is-mobile .command-box {
    margin-top: 0 !important;
    padding: 4px calc(8px + var(--m-safe-right)) calc(6px + var(--m-safe-bottom)) calc(8px + var(--m-safe-left)) !important;
    width: 100% !important;
    max-width: none !important;
    box-sizing: border-box !important;
    gap: 4px !important;
    border-radius: 0 !important;
    border-left: none !important;
    border-right: none !important;
    border-bottom: none !important;
    background: var(--m-surface);
    transition: padding 0.15s ease;
}

/* Fully collapsed command line: minimal black pane with cyan prompt text & up arrow */
html.is-mobile #mobile-cmd-collapsed-bar {
    display: none !important;
}

html.is-mobile.mobile-cmd-collapsed .command-box {
    padding: 0 !important;
    background: transparent !important;
    border: none !important;
}

html.is-mobile.mobile-cmd-collapsed #mobile-cmd-collapsed-bar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    height: 30px !important;
    padding: 0 calc(8px + var(--m-safe-right)) calc(var(--m-safe-bottom) * 0.5) calc(8px + var(--m-safe-left)) !important;
    box-sizing: border-box !important;
    background: #0c0d12;
    border-top: 1px solid rgba(0, 229, 255, 0.3);
    border-left: none !important;
    border-right: none !important;
    cursor: pointer;
}

html.is-mobile.mobile-cmd-collapsed .mobile-cmd-collapsed-prompt {
    color: var(--accent-color);
    font-family: monospace;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.2px;
}

html.is-mobile.mobile-cmd-collapsed #command-history,
html.is-mobile.mobile-cmd-collapsed .mobile-cmd-input-row,
html.is-mobile.mobile-cmd-collapsed #command-input-area,
html.is-mobile.mobile-cmd-collapsed #mobile-num-row,
html.is-mobile.mobile-cmd-collapsed #mobile-quick-keys {
    display: none !important;
}

/* Keyboard open: home-indicator inset is covered by the keyboard. */
html.is-mobile.mobile-kb-open .command-box {
    padding-bottom: 4px;
}

/* Messaging/History area: 2 lines high as requested */
html.is-mobile .command-history {
    font-size: 0.75rem;
    line-height: 1.35;
    max-height: calc(0.75rem * 1.35 * 2 + 4px);
    overflow-y: auto;
    cursor: pointer;
    transition: max-height 0.2s ease;
    padding: 2px 4px;
}

html.is-mobile.mobile-history-expanded .command-history {
    max-height: calc(0.75rem * 1.35 * 6 + 6px);
}

html.is-mobile .mobile-cmd-input-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    gap: 6px !important;
    width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
}

html.is-mobile #mobile-cmd-collapse-btn {
    flex: 0 0 24px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

html.is-mobile .command-input-area {
    display: flex;
    flex: 1 1 auto;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 6px;
    min-height: 28px;
    padding: 3px 8px 3px 10px;
    box-sizing: border-box;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--m-hair);
}

html.is-mobile .command-input-area:focus-within {
    border-color: rgba(0, 229, 255, 0.5);
    box-shadow: 0 0 0 2px rgba(0, 229, 255, 0.12);
}

html.is-mobile #command-prompt-text {
    flex: 0 1 auto;
    white-space: normal;
    word-break: break-word;
    font-size: 0.8rem;
    font-family: monospace;
    color: var(--accent-color);
    line-height: 1.35;
}

html.is-mobile #command-input-field {
    flex: 1 1 80px;
    min-width: 60px;
    height: 22px;
    min-height: 22px;
    line-height: 22px;
    padding: 0;
    margin: 0;
    resize: none !important;
    overflow-y: hidden;
}

/* 16px prevents iOS Safari from zooming the page when the input is focused. */
html.is-mobile #command-input-field,
html.is-mobile .modal-content input,
html.is-mobile .modal-content select,
html.is-mobile .modal-content textarea,
html.is-mobile #chat-input {
    font-size: 16px !important;
}

/* Numeric keypad row (NUM button toggle): completely removed when toggled off */
html.is-mobile #mobile-num-row {
    display: none !important;
    flex-wrap: nowrap !important;
    gap: 3px;
    width: 100%;
    box-sizing: border-box;
    padding: 2px 0;
    overflow-x: auto !important;
    overflow-y: hidden !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
html.is-mobile.mobile-num-open #mobile-num-row,
html.is-mobile #mobile-num-row.is-open {
    display: flex !important;
}
html.is-mobile.mobile-kb-open #mobile-num-row {
    display: none !important;
}
html.is-mobile #mobile-num-row::-webkit-scrollbar { display: none; }

html.is-mobile .mqk-num-key {
    flex: 1 0 auto !important;
    min-width: 26px !important;
    height: 32px;
    padding: 0 3px;
    border-radius: 6px;
    border: 1px solid var(--m-hair);
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
    font-family: monospace;
    font-size: 0.92rem;
    font-weight: 600;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    white-space: nowrap !important;
}
html.is-mobile .mqk-num-key:active {
    background: rgba(0, 229, 255, 0.25);
    border-color: var(--accent-color);
}
html.is-mobile .mqk-num-del {
    background: rgba(255, 75, 75, 0.15);
    border-color: rgba(255, 75, 75, 0.35);
    color: #ff8585;
}

html.is-mobile .mqk.mqk-num-toggle {
    font-weight: 700;
    font-size: 0.76rem;
    color: var(--text-secondary);
    background: rgba(18, 20, 26, 0.95);
    border: 1px solid var(--m-hair);
    letter-spacing: 0.5px;
}
html.is-mobile .mqk.mqk-num-toggle.is-on {
    background: rgba(0, 229, 255, 0.22) !important;
    border-color: var(--accent-color) !important;
    color: #00e5ff !important;
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.35) !important;
}
html.is-mobile .mqk.mqk-num-toggle:disabled,
html.is-mobile.mobile-kb-open #mqk-num {
    opacity: 0.3 !important;
    pointer-events: none !important;
    cursor: default !important;
    border-color: rgba(255, 255, 255, 0.1) !important;
    color: var(--text-secondary) !important;
    box-shadow: none !important;
    background: transparent !important;
}
html.is-mobile.mobile-kb-open #mobile-num-row {
    display: none !important;
}
html.is-mobile .mqk.mqk-kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    color: var(--text-primary);
}
html.is-mobile .mqk.mqk-kbd svg {
    display: block;
    opacity: 0.85;
}

html.is-mobile #mobile-quick-keys {
    display: flex !important;
    gap: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-top: 2px;
    width: 100%;
}

html.is-mobile #mobile-quick-keys::-webkit-scrollbar {
    display: none;
}

html.is-mobile .mqk {
    flex: 0 0 auto;
    min-width: 42px;
    height: 38px;
    padding: 0 12px;
    border-radius: 9px;
    border: 1px solid var(--m-hair);
    background: var(--m-surface-2);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', 'Courier New', monospace;
    font-size: 0.9rem;
    -webkit-user-select: none;
    user-select: none;
    transition: background 0.12s ease, transform 0.08s ease;
}

html.is-mobile .mqk:active {
    background: rgba(0, 229, 255, 0.18);
    transform: scale(0.95);
}

html.is-mobile .mqk-primary {
    color: var(--brand-ink);
    background: var(--brand-gold-fill);
    border-color: transparent;
    font-weight: 700;
}

html.is-mobile .mqk-enter {
    min-width: 52px;
    height: 38px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

html.is-mobile .mqk-enter-icon {
    display: block;
    width: 36px;
    height: 24px;
}

html.is-mobile .mqk-space {
    min-width: 72px;
    height: 38px;
    padding: 0 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

html.is-mobile .mqk-space-icon {
    display: block;
    width: 52px;
    height: 16px;
}

html.is-mobile .mqk.is-on {
    color: var(--accent-color);
    border-color: rgba(0, 229, 255, 0.5);
}

html.is-mobile .mqk.mqk-kbd.is-on,
html.is-mobile.mobile-kb-open #mqk-kbd {
    background: rgba(0, 229, 255, 0.22);
    border-color: var(--accent-color);
    color: #ffffff;
    box-shadow: 0 0 8px rgba(0, 229, 255, 0.35);
}

/* ---- Quick keys: core 9 keys always fit the screen width ----
   kbd · NUM · Esc · Enter · Space · , · . · @ · ⌫  share 100% of the row
   (Enter/Space weighted 1.4×); Ortho/Snap follow and are reached by swiping. */
html.is-mobile {
    --mqk-gap: clamp(3px, 1.1vw, 6px);
    --mqk-h: clamp(32px, 9vw, 38px);
    /* 7 normal keys + 2 × 1.4 wide keys = 9.8 units, 8 gaps between 9 keys */
    --mqk-unit: calc((100% - 8 * var(--mqk-gap)) / 9.8);
}

html.is-mobile #mobile-quick-keys {
    gap: var(--mqk-gap);
    box-sizing: border-box;
}

html.is-mobile #mobile-quick-keys > .mqk {
    flex: 0 0 var(--mqk-unit);
    width: var(--mqk-unit);
    min-width: 0;
    height: var(--mqk-h);
    padding: 0;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: clamp(0.7rem, 3.4vw, 0.9rem);
    border-radius: clamp(7px, 2vw, 9px);
}

html.is-mobile #mobile-quick-keys > .mqk-enter,
html.is-mobile #mobile-quick-keys > .mqk-space {
    flex-basis: calc(var(--mqk-unit) * 1.4);
    width: calc(var(--mqk-unit) * 1.4);
}

html.is-mobile #mobile-quick-keys > .mqk.mqk-num-toggle {
    font-size: clamp(0.6rem, 2.8vw, 0.76rem);
    letter-spacing: 0;
}

html.is-mobile #mobile-quick-keys .mqk-enter-icon {
    width: 70%;
    max-width: 36px;
    height: auto;
    max-height: 24px;
}

html.is-mobile #mobile-quick-keys .mqk-space-icon {
    width: 72%;
    max-width: 52px;
    height: auto;
    max-height: 16px;
}

html.is-mobile #mobile-quick-keys .mqk-kbd svg {
    width: clamp(15px, 4.6vw, 18px);
    height: clamp(15px, 4.6vw, 18px);
}

/* Ortho / Snap sit past the right edge (swipe the row to reach them). */
html.is-mobile #mobile-quick-keys > .mqk[data-mqk="F8"],
html.is-mobile #mobile-quick-keys > .mqk[data-mqk="F3"] {
    flex: 0 0 auto;
    width: auto;
    padding: 0 10px;
}

/* =============================================================================
   6. Modals, panels, popups → full-screen sheets
   ============================================================================= */
html.is-mobile .modal-overlay,
html.is-mobile .modal {
    align-items: stretch;
    justify-content: stretch;
    height: 100%;
    height: 100dvh;
}

html.is-mobile .modal-overlay .modal-content,
html.is-mobile .modal .modal-content {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100%;
    margin: 0;
    box-sizing: border-box;
    border-radius: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: calc(14px + var(--m-safe-top)) calc(16px + var(--m-safe-right)) calc(16px + var(--m-safe-bottom)) calc(16px + var(--m-safe-left));
}

html.is-mobile .modal-overlay .modal-footer {
    position: sticky;
    bottom: calc(-16px - var(--m-safe-bottom));
    padding: 10px 0;
    background: inherit;
}

html.is-mobile .modal-content .ui-button,
html.is-mobile .modal-header button {
    min-height: 40px;
    min-width: 40px;
}

html.is-mobile #layer-modal .modal-footer .ui-button,
html.is-mobile #layer-modal #add-layer-modal-btn,
html.is-mobile #layer-modal #confirm-add-layer-btn,
html.is-mobile #layer-modal #cancel-add-layer-btn {
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    min-width: unset !important;
    padding: 0 12px !important;
    font-size: 0.75rem !important;
    line-height: 26px !important;
    box-sizing: border-box !important;
}

html.is-mobile #layer-modal #new-layer-name-input {
    height: 28px !important;
    min-height: 28px !important;
    max-height: 28px !important;
    padding: 0 8px !important;
    font-size: 0.78rem !important;
    box-sizing: border-box !important;
}

html.is-mobile .chat-panel {
    width: 100vw;
    right: -100vw;
    height: 100%;
    height: 100dvh;
    padding-top: var(--m-safe-top);
    padding-bottom: calc(var(--m-safe-bottom) + var(--kb-inset, 0px));
    box-sizing: border-box;
}

html.is-mobile .chat-panel.open {
    right: 0;
}

html.is-mobile .plan-side-panel {
    box-sizing: border-box;
    width: calc(100vw - 24px);
    right: -100vw;
    top: calc(var(--m-topbar-h) + var(--m-safe-top) + 8px);
}

html.is-mobile .plan-side-panel.open {
    right: 0;
}

html.is-mobile #cadmax-panel {
    width: 100vw;
    height: calc(100dvh - var(--app-menu-offset));
}

html.is-mobile #cadmax-blazor-root .cadmax-wasm-modal-overlay,
html.is-mobile .isyddhi-js-modal-overlay {
    padding: 0;
}

html.is-mobile #cadmax-blazor-root .cadmax-wasm-modal,
html.is-mobile .isyddhi-js-modal {
    width: 100%;
    max-height: 100dvh;
    height: 100%;
    border-radius: 0;
}

html.is-mobile .isyddhi-js-modal-body label {
    grid-template-columns: 1fr;
}

html.is-mobile .entity-props-popup {
    max-width: calc(100vw - 16px);
}

/* Splash screen */
html.is-mobile #splash-screen {
    height: 100dvh;
    padding: 16px;
    box-sizing: border-box;
    overflow-y: auto;
}

html.is-mobile .splash-container {
    padding: 1.5rem 1.1rem;
}

html.is-mobile .splash-container h1 {
    font-size: 2rem;
}

/* =============================================================================
   7. Install banner (PWA)
   ============================================================================= */
#mobile-install-banner {
    display: none;
}

html.is-mobile #mobile-install-banner.show {
    position: fixed;
    left: calc(10px + var(--m-safe-left));
    right: calc(10px + var(--m-safe-right));
    top: calc(var(--m-topbar-h) + var(--m-safe-top) + 10px);
    z-index: 1005;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 12px 12px 14px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(61, 74, 44, 0.97), rgba(26, 28, 22, 0.97));
    border: 1px solid rgba(212, 168, 42, 0.45);
    box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
    color: var(--text-primary);
    animation: mobileBannerIn 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

html.is-mobile #mobile-install-banner img {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    flex: 0 0 auto;
}

html.is-mobile #mobile-install-banner .mib-text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.85rem;
    line-height: 1.35;
}

html.is-mobile #mobile-install-banner .mib-text strong {
    display: block;
    color: var(--brand-gold-bright);
    font-size: 0.95rem;
}

html.is-mobile #mobile-install-banner button {
    flex: 0 0 auto;
    min-height: 36px;
    border-radius: 9px;
    border: none;
    font-weight: 700;
    cursor: pointer;
}

html.is-mobile #mobile-install-banner .mib-install {
    padding: 0 14px;
    color: var(--brand-ink);
    background: var(--brand-gold-fill);
}

html.is-mobile #mobile-install-banner .mib-close {
    width: 32px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

@keyframes mobileBannerIn {
    from {
        opacity: 0;
        transform: translateY(-12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Live window / crossing box while a long-press drag is in progress. */
#mobile-sel-rect {
    display: none;
    position: fixed;
    z-index: 1002;
    box-sizing: border-box;
    pointer-events: none;
    border: 1.5px dashed rgba(102, 230, 140, 0.95);
    background: rgba(102, 230, 140, 0.14);
}

#mobile-sel-rect.show {
    display: block;
}

#mobile-sel-rect.is-crossing {
    border-color: rgba(102, 178, 255, 0.95);
    background: rgba(102, 178, 255, 0.14);
}

/* Precision-pick reticle (touch-and-hold) */
#mobile-pick-reticle {
    display: none;
}

html.is-touch #mobile-pick-reticle.show {
    display: block;
    position: fixed;
    width: 44px;
    height: 44px;
    margin: -22px 0 0 -22px;
    border-radius: 50%;
    border: 2px solid rgba(0, 229, 255, 0.85);
    box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.5), 0 0 14px rgba(0, 229, 255, 0.4);
    pointer-events: none;
    z-index: 950;
}

html.is-touch #mobile-pick-reticle.show::before,
html.is-touch #mobile-pick-reticle.show::after {
    content: '';
    position: absolute;
    background: rgba(0, 229, 255, 0.9);
    left: 50%;
    top: 50%;
}

html.is-touch #mobile-pick-reticle.show::before {
    width: 2px;
    height: 12px;
    margin: -6px 0 0 -1px;
}

html.is-touch #mobile-pick-reticle.show::after {
    width: 12px;
    height: 2px;
    margin: -1px 0 0 -6px;
}

/* iOS Install Guide Modal */
#mobile-ios-install-guide {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
}

#mobile-ios-install-guide.show {
    display: grid;
    place-items: center;
    padding: 16px;
}

#mobile-ios-install-guide .mig-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.72);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

#mobile-ios-install-guide .mig-card {
    position: relative;
    max-width: 360px;
    width: 100%;
    padding: 20px;
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(34, 38, 30, 0.98), rgba(20, 22, 18, 0.98));
    border: 1px solid rgba(212, 168, 42, 0.45);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.75);
    color: var(--text-primary);
    box-sizing: border-box;
    animation: mobileBannerIn 0.25s ease;
}

#mobile-ios-install-guide .mig-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

#mobile-ios-install-guide .mig-header img {
    border-radius: 8px;
    flex: 0 0 auto;
}

#mobile-ios-install-guide .mig-header strong {
    display: block;
    font-size: 1.05rem;
    color: var(--brand-gold-bright);
}

#mobile-ios-install-guide .mig-header span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#mobile-ios-install-guide .mig-close {
    margin-left: auto;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px;
}

#mobile-ios-install-guide .mig-steps {
    margin: 0 0 20px 0;
    padding-left: 20px;
    font-size: 0.9rem;
    line-height: 1.6;
}

#mobile-ios-install-guide .mig-steps li {
    margin-bottom: 10px;
}

#mobile-ios-install-guide .mig-steps strong {
    color: #fff;
}

#mobile-ios-install-guide .mig-icon {
    display: inline-block;
    padding: 0 4px;
    background: rgba(255, 255, 255, 0.14);
    border-radius: 4px;
    font-family: monospace;
}

#mobile-ios-install-guide .mig-btn {
    width: 100%;
    height: 40px;
    border-radius: 10px;
    background: var(--brand-gold-fill);
    color: var(--brand-ink);
    border: none;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
}
