:root {
    --editor-vvh: 100dvh;
    --editor-vv-top: 0px;
    --editor-keyboard-inset: 0px;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body[data-editor-mobile] {
    max-width: 100%;
    overscroll-behavior-x: none;
}

body[data-editor-mobile] :is(canvas, svg, img, video, iframe) {
    max-width: 100%;
}

body[data-editor-mobile] :is(button, [role="button"], input, select, textarea) {
    max-width: 100%;
}

body[data-editor-mobile] :is(button, [role="button"], input, select, textarea):focus-visible {
    outline: 2px solid #ff9f43;
    outline-offset: 2px;
}

@media (max-width: 820px), (pointer: coarse) {
    body[data-editor-mobile] {
        width: 100%;
        overflow-x: hidden;
        -webkit-tap-highlight-color: transparent;
    }

    body[data-editor-mobile] :is(button, [role="button"], input[type="button"], input[type="submit"], select) {
        min-height: 44px;
        touch-action: manipulation;
    }

    body[data-editor-mobile] :is(input[type="text"], input[type="search"], input[type="url"], input[type="email"], input[type="tel"], input[type="password"], input[type="number"], textarea, select) {
        font-size: 16px !important;
    }

    body[data-editor-mobile] :is(input[type="checkbox"], input[type="radio"]) {
        flex: 0 0 auto;
        min-height: 20px;
        min-width: 20px;
    }

    body[data-editor-mobile] :is(.as-header-controls, .as-view-tools, .bd-tools, .bd-mobile-nav, #eg-toolbar, #qe-toolbar, .crop-tools) {
        scrollbar-width: thin;
        -webkit-overflow-scrolling: touch;
    }
}

/* Assembly */
@media (max-width: 820px) {
    body[data-editor-mobile="assembly"] .as-app {
        height: auto;
        min-height: var(--editor-vvh, 100dvh);
    }

    body[data-editor-mobile="assembly"] .as-header {
        padding: max(9px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 9px max(10px, env(safe-area-inset-left));
    }

    body[data-editor-mobile="assembly"] :is(.as-header, .as-main, .as-sidebar, .as-viewport) {
        min-width: 0;
        max-width: 100%;
    }

    body[data-editor-mobile="assembly"] .as-header-controls {
        flex-wrap: nowrap;
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        padding-block: 2px;
        scroll-snap-type: x proximity;
    }

    body[data-editor-mobile="assembly"] .as-header-controls > * {
        flex: 0 0 auto;
        scroll-snap-align: start;
    }

    body[data-editor-mobile="assembly"] .as-library {
        max-height: min(29dvh, 250px);
    }

    body[data-editor-mobile="assembly"] .as-viewport {
        height: min(58dvh, calc(var(--editor-vvh, 100dvh) - 176px));
        min-height: 320px;
    }

    body[data-editor-mobile="assembly"] .as-view-tools {
        inset-inline: 8px;
        left: auto;
        max-width: calc(100% - 16px);
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scroll-snap-type: x proximity;
        touch-action: pan-x;
    }

    body[data-editor-mobile="assembly"] .as-view-tools .as-button {
        flex: 0 0 auto;
        min-height: 44px;
        scroll-snap-align: start;
    }

    body[data-editor-mobile="assembly"] .as-view-legend {
        bottom: 8px;
        max-width: calc(100% - 20px);
        text-align: center;
        white-space: normal;
        width: max-content;
    }

    body[data-editor-mobile="assembly"] .as-field :is(input, select),
    body[data-editor-mobile="assembly"] .as-hole-fields input {
        height: 44px;
    }

    body[data-editor-mobile="assembly"] .as-footer {
        max-width: 100%;
        min-height: 44px;
        overflow-x: auto;
        padding: 7px max(10px, env(safe-area-inset-right)) max(7px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
        white-space: nowrap;
    }

    body[data-editor-mobile="assembly"].editor-keyboard-open .as-viewport {
        height: min(42dvh, 300px);
        min-height: 220px;
    }
}

@media (max-width: 430px) {
    body[data-editor-mobile="assembly"] .as-title-block { min-width: 0; }
    body[data-editor-mobile="assembly"] .as-subtitle { display: none; }
    body[data-editor-mobile="assembly"] .as-field-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body[data-editor-mobile="assembly"] .as-field.wide { grid-column: 1 / -1; }
    body[data-editor-mobile="assembly"] .as-inspector-actions { flex-wrap: wrap; }
    body[data-editor-mobile="assembly"] .as-inspector-actions .as-button { flex: 1 1 calc(50% - 6px); }
}

/* Nesting */
@media (max-width: 760px) {
    body[data-editor-mobile="nesting"] :is(.nest-shell, .sk-canvas, .nest-card, .nest-canvas-wrap) {
        min-width: 0;
        max-width: 100%;
    }

    body[data-editor-mobile="nesting"] .nest-shell {
        padding: 8px max(8px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    body[data-editor-mobile="nesting"] .nest-toolbar > :is(input, select) {
        flex: 1 1 100%;
        max-width: none !important;
        width: 100%;
    }

    body[data-editor-mobile="nesting"] .nest-toolbar > .nest-stat {
        flex: 1 1 100%;
    }

    body[data-editor-mobile="nesting"] .nest-toolbar > .ms-auto {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-inline-start: 0 !important;
        width: 100%;
    }

    body[data-editor-mobile="nesting"] .nest-toolbar > .ms-auto > :last-child {
        grid-column: 1 / -1;
    }

    body[data-editor-mobile="nesting"] .nest-toolbar .btn,
    body[data-editor-mobile="nesting"] .nest-selected-tools .btn {
        min-height: 44px;
    }

    body[data-editor-mobile="nesting"] .nest-options {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    body[data-editor-mobile="nesting"] .nest-options :is(.form-control, .form-select) {
        min-height: 44px;
    }

    body[data-editor-mobile="nesting"] .nest-options .form-check {
        align-items: center;
        display: flex;
        gap: 8px;
        min-height: 44px;
        padding-top: 0;
    }

    body[data-editor-mobile="nesting"] .nest-selected-tools.visible {
        flex-wrap: nowrap;
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        padding-block: 3px;
        touch-action: pan-x;
    }

    body[data-editor-mobile="nesting"] .nest-selected-tools > * { flex: 0 0 auto; }
    body[data-editor-mobile="nesting"] .nest-part-row { min-height: 52px; }
    body[data-editor-mobile="nesting"] #nest-canvas {
        height: min(50dvh, calc(var(--editor-vvh, 100dvh) - 230px));
        min-height: 280px;
    }
}

@media (max-width: 359px) {
    body[data-editor-mobile="nesting"] .nest-options { grid-template-columns: 1fr; }
}

/* Standalone paint */
@media (max-width: 760px) {
    body[data-editor-mobile="paint"] :is(.paint-shell, .sk-canvas, .paint-canvas-wrap) {
        min-width: 0;
        max-width: 100%;
    }

    body[data-editor-mobile="paint"] .paint-shell {
        padding: 8px max(8px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    }

    body[data-editor-mobile="paint"] .paint-toolbar {
        gap: 8px;
    }

    body[data-editor-mobile="paint"] .paint-sliders {
        flex: 1 1 125px;
        margin-inline-start: 0 !important;
        min-width: 0;
    }

    body[data-editor-mobile="paint"] .paint-sliders input[type="range"] { width: 100%; }

    body[data-editor-mobile="paint"] .paint-actions {
        display: grid !important;
        gap: 8px !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-inline-start: 0 !important;
        width: 100%;
    }

    body[data-editor-mobile="paint"] .paint-actions #paint-name,
    body[data-editor-mobile="paint"] .paint-actions #paint-save {
        grid-column: 1 / -1;
        max-width: none !important;
        width: 100%;
    }

    body[data-editor-mobile="paint"] #paint-shapes-row.visible {
        flex-wrap: nowrap;
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        padding-bottom: 3px;
        touch-action: pan-x;
    }

    body[data-editor-mobile="paint"] #paint-shapes-row > * { flex: 0 0 auto; }
    body[data-editor-mobile="paint"] #paint-canvas {
        height: min(50dvh, calc(var(--editor-vvh, 100dvh) - 220px));
        min-height: 300px;
    }
}

/* Bending */
@media (max-width: 760px) {
    body[data-editor-mobile="bending"] .bd-topbar {
        padding-top: max(7px, env(safe-area-inset-top));
    }

    body[data-editor-mobile="bending"] .bd-mobile-nav {
        top: calc(58px + env(safe-area-inset-top));
    }

    body[data-editor-mobile="bending"] .bd-mobile-nav button {
        min-height: 44px;
    }

    body[data-editor-mobile="bending"] .bd-app .bd-main > .bd-stage {
        height: calc(var(--editor-vvh, 100dvh) - 116px - env(safe-area-inset-top)) !important;
    }

    body[data-editor-mobile="bending"] .bd-rotation-row {
        min-height: 40px;
    }

    body[data-editor-mobile="bending"] .bd-check {
        min-height: 44px;
    }

    body[data-editor-mobile="bending"] .bd-footer {
        min-height: 44px;
    }
}

/* Full-height canvas tools */
@media (max-width: 760px) {
    body[data-editor-mobile="engraving"],
    body[data-editor-mobile="quick-edit"] {
        height: var(--editor-vvh, 100dvh) !important;
        min-height: var(--editor-vvh, 100dvh) !important;
        overflow: hidden;
    }

    body[data-editor-mobile="engraving"] #eg-toolbar,
    body[data-editor-mobile="quick-edit"] #qe-toolbar {
        scroll-snap-type: x proximity;
    }

    body[data-editor-mobile="engraving"] #eg-toolbar > *,
    body[data-editor-mobile="quick-edit"] #qe-toolbar > * {
        scroll-snap-align: start;
    }

    body[data-editor-mobile="engraving"] #eg-status,
    body[data-editor-mobile="quick-edit"] #qe-status {
        min-height: 44px;
    }

    body[data-editor-mobile="engraving"] #eg-selected,
    body[data-editor-mobile="quick-edit"] #qe-selected,
    body[data-editor-mobile="quick-edit"] #qe-simple-tools {
        flex: 0 0 auto;
    }

    body[data-editor-mobile="quick-edit"] .qe-size input[type="range"] {
        min-height: 44px;
    }
}

/* Coating */
@media (max-width: 520px) {
    body[data-editor-mobile="coating"] {
        padding-bottom: calc(176px + env(safe-area-inset-bottom));
    }

    body[data-editor-mobile="coating"] .ct-shell {
        padding-inline: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }

    body[data-editor-mobile="coating"] .ct-footer {
        max-height: min(172px, calc(var(--editor-vvh, 100dvh) - 12px));
        overflow-y: auto;
    }
}

/* Importers */
@media (max-width: 600px) {
    body[data-editor-mobile="dxf"] {
        max-width: 100%;
        padding: 0 max(4px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
        width: 100%;
    }

    body[data-editor-mobile="dxf"] :is(#controls, #cad-import-review, #cad-preview-shell) {
        min-width: 0;
        max-width: 100%;
    }

    body[data-editor-mobile="dxf"] .cad-review-title {
        align-items: flex-start;
        flex-direction: column;
    }

    body[data-editor-mobile="dxf"] #canvas { width: 100% !important; }
}

@media (max-width: 560px) {
    body[data-editor-mobile="svg-import"],
    body[data-editor-mobile="trace-import"] {
        padding: 0 max(4px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
    }

    body[data-editor-mobile="svg-import"] :is(#intro, .workspace, .preview-pane, .controls),
    body[data-editor-mobile="trace-import"] :is(#intro, .workspace, .preview-grid, .preview-pane, .controls) {
        min-width: 0;
        max-width: 100%;
    }

    body[data-editor-mobile="svg-import"] .zoom-tools button,
    body[data-editor-mobile="trace-import"] .zoom-tools button,
    body[data-editor-mobile="trace-import"] .recrop-btn,
    body[data-editor-mobile="trace-import"] .best-settings-btn {
        min-height: 44px;
        min-width: 44px;
    }

    body[data-editor-mobile="trace-import"] .part-picker-head {
        align-items: stretch;
        flex-direction: column;
    }

    body[data-editor-mobile="trace-import"] .part-picker-actions {
        align-items: stretch;
        flex-wrap: wrap;
    }

    body[data-editor-mobile="trace-import"] .best-settings-btn {
        flex: 1 1 100%;
    }

    body[data-editor-mobile="trace-import"] .part-card {
        min-height: 48px;
    }
}

@media (max-width: 430px) {
    body[data-editor-mobile="trace-import"] .part-columns { grid-template-columns: 1fr; }
    body[data-editor-mobile="trace-import"] .part-column + .part-column {
        border-left: 0;
        border-top: 1px solid var(--line);
    }
}

/* Parts management and its editor modals */
@media (max-width: 767.98px) {
    body[data-editor-mobile="parts"] .dashboard-mode .modal .modal-dialog,
    body[data-editor-mobile="parts"] .modal .modal-dialog {
        max-height: calc(var(--editor-vvh, 100dvh) - 8px) !important;
    }

    body[data-editor-mobile="parts"] .modal .modal-content {
        max-height: calc(var(--editor-vvh, 100dvh) - 8px) !important;
    }

    body[data-editor-mobile="parts"] .modal .modal-dialog.modal-fullscreen {
        height: var(--editor-vvh, 100dvh) !important;
        max-height: var(--editor-vvh, 100dvh) !important;
        min-height: var(--editor-vvh, 100dvh) !important;
    }

    body[data-editor-mobile="parts"] .modal :is(.btn, .btn-close, button, [role="button"]) {
        min-height: 44px;
    }

    body[data-editor-mobile="parts"] #cartRow .dropdown-card :is(.deleteButton, .card-menu) {
        height: 44px !important;
        width: 44px !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    body[data-editor-mobile] *,
    body[data-editor-mobile] *::before,
    body[data-editor-mobile] *::after {
        scroll-behavior: auto !important;
    }
}

/* Combined Sketch workspaces + standalone Part 3D ------------------------ */

@media (max-width: 760px), (pointer: coarse) {
    body:is(.engineer-mode, .artist-mode, .paint-mode, .three-d-mode)
        :is(button, [role="button"], input[type="button"], input[type="submit"], select),
    body[data-editor-mobile="part-3d"]
        :is(button, [role="button"], input[type="button"], input[type="submit"], select) {
        min-height: 44px;
        touch-action: manipulation;
    }

    body:is(.engineer-mode, .artist-mode, .paint-mode, .three-d-mode)
        :is(input[type="text"], input[type="number"], input[type="search"], textarea, select),
    body[data-editor-mobile="part-3d"]
        :is(input[type="text"], input[type="number"], input[type="search"], textarea, select) {
        font-size: 16px !important;
    }

    body:is(.engineer-mode, .artist-mode, .paint-mode, .three-d-mode)
        :is(button, input, select, textarea, [tabindex]):focus-visible,
    body[data-editor-mobile="part-3d"]
        :is(button, input, select, textarea, [tabindex]):focus-visible {
        outline: 2px solid #ff9f43;
        outline-offset: 2px;
    }
}

/* Put the workspace selector on its own row on narrow phones. This keeps
   Save, Back, and More as full-size targets instead of squeezing them. */
@media (max-width: 480px) and (orientation: portrait) {
    body.engineer-mode {
        --eng-docbar-h: calc(102px + var(--eng-safe-top));
        --cnc-workspace-top: var(--eng-docbar-h);
    }

    body.engineer-mode .eng-docbar {
        align-content: center;
        flex-wrap: wrap;
        gap: 3px 5px;
        padding-inline: calc(5px + var(--eng-safe-left)) calc(5px + var(--eng-safe-right));
    }

    body.engineer-mode .eng-brand { display: none; }
    body.engineer-mode .eng-document { flex: 1 1 40px; }
    body.engineer-mode .eng-document strong { font-size: 11px; }
    body.engineer-mode .eng-persona-switch {
        display: grid;
        flex: 0 0 100%;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        order: 20;
        width: 100%;
    }

    body.engineer-mode .eng-persona-switch button {
        height: 44px;
        justify-content: center;
        min-width: 0;
        padding-inline: 3px;
    }

    body.artist-mode {
        --art-topbar-h: calc(102px + var(--art-safe-top));
        --cnc-workspace-top: var(--art-topbar-h);
    }

    body.artist-mode .art-topbar {
        align-content: center;
        flex-wrap: wrap;
        gap: 3px 5px;
        padding-inline: max(5px, var(--art-safe-left)) max(5px, var(--art-safe-right));
    }

    body.artist-mode .art-document,
    body.artist-mode .art-fullscreen-toggle,
    body.artist-mode #artistCollaborationMount { display: none !important; }

    body.artist-mode .art-file-actions { margin-left: auto; }
    body.artist-mode .art-persona-switch {
        display: grid;
        flex: 0 0 100%;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        order: 20;
        width: 100%;
    }

    body.artist-mode .art-persona-switch button {
        height: 44px;
        justify-content: center;
        min-width: 0;
        padding-inline: 3px;
    }

    body.paint-mode {
        --paint-top-h: calc(104px + env(safe-area-inset-top, 0px));
        --paint-bottom-h: calc(158px + env(safe-area-inset-bottom, 0px));
        --cnc-workspace-top: var(--paint-top-h);
        --cnc-workspace-bottom: var(--paint-bottom-h);
    }

    body.paint-mode .paint-topbar {
        gap: 3px 6px;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-rows: 48px 46px;
        height: var(--paint-top-h);
        padding-inline: max(6px, env(safe-area-inset-left, 0px)) max(6px, env(safe-area-inset-right, 0px));
    }

    body.paint-mode .paint-brand { grid-column: 1; grid-row: 1; }
    body.paint-mode .paint-file-actions { grid-column: 3; grid-row: 1; }
    body.paint-mode .paint-persona-switch {
        display: grid;
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        justify-self: stretch;
        width: 100%;
    }

    body.paint-mode .paint-persona-switch button {
        height: 44px;
        justify-content: center;
        min-width: 0;
        padding-inline: 3px;
    }

    body.paint-mode .paint-bottom-bar {
        grid-template-rows: 36px 46px 64px;
        padding-inline: max(7px, env(safe-area-inset-left, 0px)) max(7px, env(safe-area-inset-right, 0px));
    }

    body.paint-mode .paint-history button { height: 44px; width: 44px; }
    body.paint-mode .paint-palette button,
    body.paint-mode .paint-custom-color {
        flex-basis: 30px;
        height: 30px;
        min-height: 30px;
        width: 30px;
    }
}

@media (max-width: 340px) and (orientation: portrait) {
    body.artist-mode .art-studio-toggle { display: none !important; }
    body:is(.engineer-mode, .artist-mode, .paint-mode) .editor-persona-switch button strong {
        font-size: 7px;
    }
}

/* Combined live 3D workspace. */
@media (max-width: 760px) {
    .d3-workspace {
        --d3-mobile-top-h: calc(106px + env(safe-area-inset-top, 0px));
        bottom: auto;
        height: var(--editor-vvh, 100dvh);
        left: 0;
        max-width: 100%;
        right: 0;
        top: var(--editor-vv-top, 0px);
    }

    .d3-topbar {
        display: grid;
        gap: 3px 7px;
        grid-template-columns: auto minmax(0, 1fr);
        grid-template-rows: 48px 46px;
        height: var(--d3-mobile-top-h);
        min-height: 0;
        padding: env(safe-area-inset-top, 0px) max(7px, env(safe-area-inset-right, 0px)) 5px max(7px, env(safe-area-inset-left, 0px));
    }

    .d3-brand { grid-column: 1; grid-row: 1; }
    .d3-top-actions {
        grid-column: 2;
        grid-row: 1;
        justify-content: flex-end;
        min-width: 0;
    }

    .d3-persona-switch {
        display: grid;
        grid-column: 1 / -1;
        grid-row: 2;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        margin: 0;
        order: initial;
        overflow: visible;
        width: 100%;
    }

    .d3-persona-switch button {
        height: 44px;
        justify-content: center;
        min-width: 0;
        padding-inline: 3px;
    }

    .d3-layout {
        display: grid;
        grid-template-rows: minmax(220px, 50%) minmax(0, 1fr);
        height: calc(100% - var(--d3-mobile-top-h));
        min-height: 0;
        overflow: hidden;
    }

    .d3-viewport-shell {
        height: auto;
        min-height: 0;
    }

    .d3-inspector {
        min-height: 0;
        overflow-x: hidden;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .d3-tabs button { min-height: 44px; }
    .d3-tab-panel { padding: 12px; }
    .d3-field input,
    .d3-field select,
    .d3-number { min-height: 44px; }

    .d3-view-toolbar {
        align-items: flex-start;
        flex-direction: row;
        gap: 6px;
        left: 7px;
        right: 7px;
        top: 7px;
    }

    .d3-profile-status {
        flex: 0 0 auto;
        gap: 2px;
        padding: 3px;
    }

    .d3-view-actions {
        flex: 1 1 auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
        max-width: 100%;
        min-width: 0;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
        touch-action: pan-x;
        -webkit-overflow-scrolling: touch;
    }

    .d3-view-actions > * { flex: 0 0 auto; }
    .d3-view-actions button { min-height: 44px; }
    .d3-empty { max-width: min(290px, calc(100% - 30px)); padding: 12px; }
    .d3-empty-icon { transform: scale(.8) skewY(-7deg); }

    .d3-viewport-footer {
        display: grid;
        gap: 4px;
        grid-template-columns: minmax(0, 1fr) auto;
        min-height: 50px;
        padding-inline: 8px;
    }

    .d3-viewport-footer span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .d3-viewport-footer #sketch3dTriangles { display: none; }
    .d3-viewport-footer button { min-height: 44px; }
    .d3-axis-legend { bottom: 56px; }
    .d3-bend-map-wrap { min-height: 170px; }

    body.three-d-mode.editor-keyboard-open .d3-workspace {
        --d3-mobile-top-h: calc(54px + env(safe-area-inset-top, 0px));
    }

    body.three-d-mode.editor-keyboard-open .d3-persona-switch { display: none; }
    body.three-d-mode.editor-keyboard-open .d3-layout {
        grid-template-rows: minmax(120px, 34%) minmax(0, 1fr);
    }
}

/* Standalone production Part 3D workspace. */
.mesh-mobile-nav { display: none; }

@media (max-width: 850px) {
    body[data-editor-mobile="part-3d"] {
        min-height: var(--editor-vvh, 100dvh);
        overflow-x: hidden;
        overscroll-behavior-x: none;
    }

    body[data-editor-mobile="part-3d"] .mesh-app {
        grid-template-rows: auto auto auto;
        height: auto;
        min-height: var(--editor-vvh, 100dvh);
        min-width: 0;
    }

    body[data-editor-mobile="part-3d"] .mesh-topbar {
        padding: max(9px, env(safe-area-inset-top, 0px)) max(10px, env(safe-area-inset-right, 0px)) 9px max(10px, env(safe-area-inset-left, 0px));
    }

    body[data-editor-mobile="part-3d"] .mesh-mobile-nav {
        background: rgba(15, 22, 26, .98);
        border-bottom: 1px solid var(--mesh-line);
        display: flex;
        gap: 4px;
        max-width: 100%;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        padding: 5px max(7px, env(safe-area-inset-right, 0px)) 5px max(7px, env(safe-area-inset-left, 0px));
        position: sticky;
        scrollbar-width: thin;
        top: var(--editor-vv-top, 0px);
        touch-action: pan-x;
        z-index: 32;
        -webkit-overflow-scrolling: touch;
    }

    body[data-editor-mobile="part-3d"] .mesh-mobile-nav a {
        align-items: center;
        border: 1px solid var(--mesh-line);
        border-radius: 8px;
        color: var(--mesh-muted);
        display: inline-flex;
        flex: 0 0 auto;
        font-size: 10px;
        font-weight: 700;
        justify-content: center;
        min-height: 44px;
        padding: 0 13px;
        scroll-snap-align: start;
        text-decoration: none;
    }

    body[data-editor-mobile="part-3d"] :is(.mesh-stage, .mesh-panel) { scroll-margin-top: 58px; }
    body[data-editor-mobile="part-3d"] .mesh-layout,
    body[data-editor-mobile="part-3d"] .mesh-sidebar,
    body[data-editor-mobile="part-3d"] .mesh-panel,
    body[data-editor-mobile="part-3d"] .mesh-stage { min-width: 0; max-width: 100%; }
    body[data-editor-mobile="part-3d"] .mesh-stage {
        height: min(56svh, 460px);
        min-height: 310px;
    }

    body[data-editor-mobile="part-3d"] .stage-toolbar {
        left: 8px;
        top: 8px;
    }

    body[data-editor-mobile="part-3d"] .icon-button { height: 44px; width: 44px; }
    body[data-editor-mobile="part-3d"] .stage-selection {
        left: 8px;
        max-width: calc(100% - 16px);
        right: auto;
        top: 62px;
    }

    body[data-editor-mobile="part-3d"] .stage-hint {
        bottom: 8px;
        display: block;
        max-width: calc(100% - 20px);
        text-align: center;
        white-space: normal;
        width: max-content;
    }

    body[data-editor-mobile="part-3d"] .mesh-field input,
    body[data-editor-mobile="part-3d"] .unit-field select { min-height: 44px; }
    body[data-editor-mobile="part-3d"] .component-row,
    body[data-editor-mobile="part-3d"] .toggle-row { min-height: 48px; }
    body[data-editor-mobile="part-3d"] .tool-button,
    body[data-editor-mobile="part-3d"] .mode-switch button { min-height: 44px; }
    body[data-editor-mobile="part-3d"] .mesh-sidebar {
        padding-inline: max(9px, env(safe-area-inset-left, 0px)) max(9px, env(safe-area-inset-right, 0px));
    }

    body[data-editor-mobile="part-3d"] .mesh-sidebar-right {
        padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
    }

    body[data-editor-mobile="part-3d"].editor-keyboard-open .mesh-stage {
        height: min(38svh, 300px);
        min-height: 220px;
    }
}

@media (max-width: 430px) {
    body[data-editor-mobile="part-3d"] .mesh-topbar { gap: 8px; }
    body[data-editor-mobile="part-3d"] .mesh-brand small { display: none; }
    body[data-editor-mobile="part-3d"] .mesh-brand-mark { height: 38px; width: 38px; }
    body[data-editor-mobile="part-3d"] .mesh-top-actions { gap: 5px; }
    body[data-editor-mobile="part-3d"] .mesh-top-actions .mesh-button {
        min-width: 44px;
        padding: 7px;
    }

    body[data-editor-mobile="part-3d"] .mesh-stage { min-height: 290px; }
    body[data-editor-mobile="part-3d"] .mesh-sidebar { padding: 8px; }
    body[data-editor-mobile="part-3d"] .mesh-panel { border-radius: 10px; padding: 11px; }
    body[data-editor-mobile="part-3d"] .mesh-dropzone { min-height: 150px; }
}

@media (max-width: 932px) and (max-height: 520px) and (orientation: landscape) {
    body.paint-mode {
        --paint-top-h: calc(50px + env(safe-area-inset-top, 0px));
        --paint-left-w: calc(76px + env(safe-area-inset-left, 0px));
        --paint-bottom-h: calc(68px + env(safe-area-inset-bottom, 0px));
    }

    body.paint-mode .paint-topbar { height: var(--paint-top-h); }
    body.paint-mode .paint-brand { display: none; }
    body.paint-mode .paint-toolbox {
        bottom: var(--paint-bottom-h);
        flex-direction: column;
        height: auto;
        left: env(safe-area-inset-left, 0px);
        overflow-x: hidden;
        overflow-y: auto;
        right: auto;
        top: var(--paint-top-h);
        touch-action: pan-y;
        width: 76px;
    }

    body.paint-mode .paint-tool-list,
    body.paint-mode .paint-edit-actions {
        flex-direction: column;
        height: auto;
    }

    body.paint-mode .paint-bottom-bar { left: var(--paint-left-w); }
}
