/* Touch-only shell: viewport space belongs to the image; original controls
   live in accessible native dialog sheets. No desktop selectors are changed. */
html.rt-touch { min-height: 0; height: 100%; height: var(--rt-touch-height, 100dvh); overflow: hidden; }
html.rt-touch body {
  position: fixed; top: var(--rt-touch-top, 0px); left: 0; right: 0;
  height: var(--rt-touch-height, 100dvh); min-height: 0; overflow: hidden;
  display: grid; grid-template-columns: minmax(0, 1fr);
  grid-template-rows: calc(48px + env(safe-area-inset-top, 0px)) 44px minmax(0, 1fr) calc(64px + env(safe-area-inset-bottom, 0px));
  overscroll-behavior: none;
}
.rt-touch .topbar {
  grid-row: 1; min-width: 0; min-height: 0; flex-wrap: nowrap; height: auto; padding: env(safe-area-inset-top, 0px) max(8px, env(safe-area-inset-right, 0px)) 0 max(10px, env(safe-area-inset-left, 0px)); gap: 10px;
}
.rt-touch .brand { flex: none; font-size: 14px; gap: 3px; }
.rt-touch .brand .dot { width: 6px; height: 6px; margin-right: 3px; }
.rt-touch .brand-mode { display: none; }
.rt-touch-context { display: flex; flex-direction: column; align-items: flex-start; justify-content: center; flex: 1; min-width: 0; height: 44px; border: 0; padding: 0 4px; background: transparent; color: var(--text); text-align: left; cursor: pointer; }
.rt-touch-case { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--text-muted); }
.rt-touch-tool { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 700; margin-top: 2px; }
.rt-touch-quick { display: flex; align-items: center; gap: 3px; flex: none; }
.rt-touch #undoBtn, .rt-touch-icon-btn { display: inline-flex; flex-direction: column; justify-content: center; align-items: center; gap: 2px; width: 44px; height: 44px; padding: 2px; font: inherit; font-size: 9px; border: 0; border-radius: 9px; color: var(--text-muted); background: transparent; cursor: pointer; }
.rt-touch #undoBtn svg, .rt-touch-icon-btn svg { width: 20px; height: 20px; }
.rt-touch .rt-touch-slice-bar { grid-row: 2; display: flex; min-width: 0; align-items: center; gap: 6px; padding: 0 max(6px, env(safe-area-inset-right, 0px)) 0 max(6px, env(safe-area-inset-left, 0px)); background: var(--surface); border-bottom: 1px solid var(--border); }
.rt-touch-planes { display: flex; gap: 1px; flex: none; }
.rt-touch .rt-touch-planes .tb { min-width: 44px; height: 44px; padding: 0 7px; font-size: 12px; border-radius: 7px; }
.rt-touch .tbslice { display: flex; gap: 6px; flex: 1; min-width: 0; height: 44px; }
.rt-touch .tbslice > span:first-child { display: none; }
.rt-touch .tbslice input[type=range] { width: 0; min-width: 44px; height: 44px; flex: 1; padding: 0; margin: 0; }
.rt-touch .slice-step { flex: 0 0 44px; width: 44px; min-width: 44px; height: 44px; padding: 8px; border-radius: 7px; }
.rt-touch #sliceVal { flex: 0 1 85px; min-width: 65px; font-size: 10px; line-height: 1.3; text-align: right; }
/* The scan's plane label retains the slice count on narrow phones. Keep
   both step buttons and a usable slider in the existing single-row strip. */
@media (max-width: 600px) { .rt-touch #sliceVal { display: none; } }
.rt-touch .workspace { grid-row: 3; display: flex; flex-direction: row; height: auto; min-height: 0; min-width: 0; overflow: hidden; }
.rt-touch .viewer { flex: 1; height: 100%; min-height: 0; min-width: 0; margin: 0; }
.rt-touch .rt-touch-empty-panel { display: none; }
.rt-touch .viewer-empty { padding: 14px; }
.rt-touch .viewer-empty .card { padding: 16px; max-width: 340px; }
.rt-touch .viewer .status-line { position: absolute; z-index: 5; bottom: 0; left: 0; right: 0; padding: 5px 9px; font-size: 10px; line-height: 1.35; background: rgba(11, 19, 28, .8); color: #d1dbe5; border: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.rt-touch .viewer .status-line.err { padding: 8px 10px; white-space: normal; max-height: min(32%, 116px); overflow-y: auto; color: #fff; background: #8d2020; pointer-events: auto; }
.rt-touch-dock { grid-row: 4; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--surface); border-top: 1px solid var(--border); padding: 3px max(4px, env(safe-area-inset-right, 0px)) calc(3px + env(safe-area-inset-bottom, 0px)) max(4px, env(safe-area-inset-left, 0px)); gap: 2px; }
.rt-touch-dock-btn { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 44px; min-height: 44px; padding: 5px 2px; gap: 3px; border: 0; border-radius: 9px; background: transparent; color: var(--text-muted); font: inherit; font-size: 10px; font-weight: 600; cursor: pointer; }
.rt-touch-dock-btn svg { width: 21px; height: 21px; }
.rt-touch-dock-btn[aria-expanded=true], .rt-touch-dock-btn:active { color: var(--accent-hover); background: var(--surface-2); }
.rt-touch-dock-btn.has-result::after { content: ''; position: absolute; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); top: 5px; right: calc(50% - 17px); }
.rt-touch :is(button,a,input,select):focus-visible { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
/* Native dialogs supply focus containment and inertness for the scan behind. */
.rt-touch-sheet { inset: auto 0 calc(var(--rt-touch-bottom, 0px) + max(8px, env(safe-area-inset-bottom, 0px))); margin: 0 auto; padding: 0; width: min(640px, calc(100% - 16px)); max-width: none; max-height: calc(var(--rt-touch-height, 100dvh) - 24px - env(safe-area-inset-top, 0px)); border: 1px solid var(--border-strong); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 18px 60px #0006; overflow: hidden; }
.rt-touch-sheet[open] { display: flex; flex-direction: column; }
.rt-touch-sheet::backdrop { background: rgba(0, 8, 17, .6); }
.rt-touch-sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 10px 18px; gap: 12px; flex: none; border-bottom: 1px solid var(--border); }
.rt-touch-sheet-header h2 { font-size: 19px; margin: 2px 0 0; letter-spacing: -.025em; }
.rt-touch-eyebrow { font-size: 10px; font-weight: 700; color: var(--accent-hover); letter-spacing: .08em; text-transform: uppercase; }
.rt-touch-sheet-scroll { overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; padding: 16px 18px 20px; min-height: 0; }
.rt-touch-section { min-width: 0; }
.rt-touch-sheet .group { margin: 0 0 18px; }
.rt-touch-sheet .group + .group { border-top: 1px solid var(--border); padding-top: 16px; }
.rt-touch-sheet h3 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .065em; color: var(--text-muted); }
.rt-touch-sheet .hint { font-size: 12px; line-height: 1.5; }
.rt-touch-sheet .btn, .rt-touch-sheet .tb { min-height: 44px; min-width: 44px; white-space: normal; justify-content: center; font-size: 13px; }
.rt-touch-sheet select, .rt-touch-sheet input:not([type=checkbox]):not([type=radio]):not([type=range]) { min-height: 44px; max-width: 100%; font-size: 16px; }
.rt-touch-sheet input[type=range] { min-width: 44px; height: 44px; margin: 0; }
.rt-touch-sheet .slider-row { min-height: 44px; }
.rt-touch-sheet .chk, .rt-touch-sheet .rad, .rt-touch-sheet .tbchk { min-height: 44px; font-size: 13px; }
.rt-touch-sheet input[type=checkbox], .rt-touch-sheet input[type=radio] { width: 20px; height: 20px; flex: 0 0 20px; }
.rt-touch-sheet .seg { gap: 7px; }
.rt-touch-sheet .toolbar { padding: 0 0 12px; border: 0; gap: 8px; background: transparent; }
.rt-touch-sheet .tbgroup { flex-wrap: wrap; gap: 6px; }
.rt-touch-sheet .tbgroup[aria-label=Tools] { display: grid; width: 100%; grid-template-columns: repeat(3, 1fr); gap: 7px; padding-bottom: 12px; }
.rt-touch-sheet .tbgroup[aria-label=Tools] .tb { background: var(--surface-2); border: 1px solid var(--border-strong); }
.rt-touch-sheet .tbgroup[aria-label=Tools] .tb.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.rt-touch-sheet .tbgroup[aria-label=Edit] { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; }
.rt-touch-sheet .tbgroup[aria-label=Edit] .tb { border: 1px solid var(--border-strong); }
.rt-touch-sheet .tbgroup[aria-label=View], .rt-touch-sheet #cycleHero { display: none; }
.rt-touch-sheet .casebar { display: grid; grid-template-columns: minmax(0, 1fr) auto; padding: 0 0 16px; background: transparent; margin-bottom: 16px; gap: 8px; }
.rt-touch-sheet .casebar label, .rt-touch-sheet #caseLoaded, .rt-touch-sheet #reloadViewerBtn { grid-column: 1 / -1; }
.rt-touch-sheet #caseSelect { min-width: 0; width: 100%; }
.rt-touch-sheet .load-state { font-size: 12px; line-height: 1.5; }
.rt-touch-sheet .fusion-select-row, .rt-touch-sheet .structure-select-row { flex-wrap: wrap; }
.rt-touch-sheet #structSelect, .rt-touch-sheet #fusionSelect { min-width: 0; }
.rt-touch-sheet #rtTouchAccount { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.rt-touch-sheet #rtTouchAccount h3, .rt-touch-sheet #userChip { width: 100%; }
.rt-touch-sheet #userChip { padding: 2px 0 8px; }
.rt-touch-sheet #submitBtn, .rt-touch-sheet #showExpertBtn { margin: 0 6px 6px 0; }
.rt-touch-status-detail { font-size: 13px; line-height: 1.5; color: var(--text-muted); margin: 0; }
.rt-touch .toast { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); max-width: calc(100vw - 24px); }
.rt-touch .modal-card, .rt-touch .fusion-dialog { max-height: calc(var(--rt-touch-height, 100dvh) - 24px); overflow-y: auto; }
.rt-touch #gate { overflow-y: auto; }
/* Focus mode keeps slice navigation and Undo. Restore is a real 44px button,
   independent of browser fullscreen support and available above the scan. */
.rt-touch.rt-touch-focus body { grid-template-rows: minmax(0, 1fr) calc(44px + env(safe-area-inset-bottom, 0px)); }
.rt-touch.rt-touch-focus .workspace { grid-row: 1; }
.rt-touch.rt-touch-focus .rt-touch-slice-bar { grid-row: 2; padding-bottom: env(safe-area-inset-bottom, 0px); }
.rt-touch.rt-touch-focus .rt-touch-dock { display: none; }
.rt-touch.rt-touch-focus .topbar { position: absolute; top: env(safe-area-inset-top, 0px); right: max(8px, env(safe-area-inset-right, 0px)); padding: 0; height: 48px; z-index: 8; border: 0; background: transparent; }
.rt-touch.rt-touch-focus .topbar > .brand, .rt-touch.rt-touch-focus .rt-touch-context { display: none; }
.rt-touch.rt-touch-focus .rt-touch-quick { padding: 2px; border-radius: 12px; background: var(--surface); box-shadow: 0 2px 12px #0004; }
.rt-touch.rt-touch-focus .viewer .status-line:not(.err) { display: none; }
/* Short landscape phones need a left rail rather than a bottom bar. */
@media (orientation: landscape) and (max-height: 540px) {
  .rt-touch:not(.rt-touch-focus) body { grid-template-columns: calc(64px + env(safe-area-inset-left, 0px)) minmax(0, 1fr); grid-template-rows: 44px 44px minmax(0, 1fr); }
  .rt-touch:not(.rt-touch-focus) .topbar { grid-column: 2; grid-row: 1; padding: 0 max(8px, env(safe-area-inset-right, 0px)) 0 10px; gap: 12px; }
  .rt-touch:not(.rt-touch-focus) .rt-touch-context { flex-direction: row; gap: 10px; align-items: center; justify-content: flex-start; }
  .rt-touch:not(.rt-touch-focus) .rt-touch-slice-bar { grid-column: 2; grid-row: 2; padding-left: 8px; }
  .rt-touch:not(.rt-touch-focus) .workspace { grid-column: 2; grid-row: 3; }
  .rt-touch:not(.rt-touch-focus) .rt-touch-dock { grid-column: 1; grid-row: 1 / 4; display: grid; grid-template-columns: 1fr; grid-template-rows: repeat(5, minmax(44px, 1fr)); padding: max(3px, env(safe-area-inset-top, 0px)) 3px max(3px, env(safe-area-inset-bottom, 0px)) max(3px, env(safe-area-inset-left, 0px)); border-top: 0; border-right: 1px solid var(--border); }
  .rt-touch .rt-touch-dock-btn { padding: 1px; gap: 1px; font-size: 9px; }
  .rt-touch .rt-touch-dock-btn svg { width: 19px; height: 19px; }
  .rt-touch-sheet { max-width: min(720px, calc(100% - 80px)); }
  .rt-touch-sheet-header { padding-top: 7px; padding-bottom: 7px; }
  .rt-touch-sheet-scroll { padding-top: 12px; }
  .rt-touch .toast { bottom: 12px; }
}

.rt-touch-sheet .tbgroup[aria-label=Tools] .tb { display: flex; align-items: center; justify-content: center; gap: 7px; }
.rt-touch-sheet .tbgroup[aria-label=Tools] .tb svg { width: 17px; height: 17px; flex: none; }
.rt-touch :is(.modal-card,.fusion-dialog,#cpModal) :is(button,input:not([type=checkbox]),select) { min-height: 44px; font-size: 16px; }
.rt-touch #cpModal { padding: 12px; }
.rt-touch #cpModal > div { max-height: calc(var(--rt-touch-height,100dvh) - 24px); overflow-y: auto; }

.rt-touch-sheet-error { flex: none; margin: 0; padding: 10px 18px; font-size: 13px; line-height: 1.45; max-height: 25vh; overflow-y: auto; background: #8d2020; color: #fff; }

/* Top-layer dialogs do not inherit the body's visual-viewport positioning. */
.rt-touch .fusion-dialog { top: calc(var(--rt-touch-top, 0px) + 12px); bottom: auto; margin: 0 auto; }
.rt-touch #uploadModal, .rt-touch #cpModal { top: var(--rt-touch-top, 0px) !important; bottom: auto !important; height: var(--rt-touch-height, 100dvh); }

/* Navigation switches reuse the original app checkboxes: no second control
   state can drift from Navigate or the core pan mode. */
.rt-touch-sheet .rt-touch-navigation { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; width: 100%; margin: 0 0 12px; }
.rt-touch-sheet .rt-touch-toggle { display: block; position: relative; min-width: 0; min-height: 88px; cursor: pointer; }
.rt-touch-sheet .rt-touch-toggle > input[type=checkbox] { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; z-index: 1; cursor: pointer; }
.rt-touch-toggle-content { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-height: 88px; height: 100%; padding: 12px 10px 10px; padding-top: 31px; border: 1px solid var(--border-strong); border-radius: 9px; background: var(--surface-2); color: var(--text); }
.rt-touch-toggle-content svg { width: 17px; height: 17px; flex: none; }
.rt-touch-toggle-title { font-size: 13px; font-weight: 650; }
.rt-touch-toggle-detail { width: 100%; color: var(--text-muted); font-size: 11px; line-height: 1.35; }
.rt-touch-toggle-visual { position: absolute; top: 9px; right: 10px; display: flex; align-items: center; gap: 5px; pointer-events: none; }
.rt-touch-toggle-state { font-size: 10px; color: var(--text-muted); }
.rt-touch-toggle-state::before { content: 'Off'; }
.rt-touch-toggle-track { width: 27px; height: 16px; padding: 2px; border-radius: 20px; background: var(--border-strong); }
.rt-touch-toggle-track::before { content: ''; display: block; width: 12px; height: 12px; border-radius: 50%; background: var(--text); }
.rt-touch-toggle > input:checked ~ .rt-touch-toggle-visual .rt-touch-toggle-track { background: var(--accent); }
.rt-touch-toggle > input:checked ~ .rt-touch-toggle-visual .rt-touch-toggle-track::before { transform: translateX(11px); background: #fff; }
.rt-touch-toggle > input:checked ~ .rt-touch-toggle-visual .rt-touch-toggle-state::before { content: 'On'; }
.rt-touch-toggle > input:checked + .rt-touch-toggle-content { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.rt-touch-toggle > input:focus-visible + .rt-touch-toggle-content { outline: 2px solid var(--accent-hover); outline-offset: 2px; }
.rt-touch-toggle > input:disabled ~ span { opacity: .45; }

.rt-touch #panToggleBtn.active { color: #fff; background: var(--accent); }
.rt-touch #panToggleBtn:disabled { opacity: .45; }
@media (max-width: 360px) { .rt-touch:not(.rt-touch-focus) .brand { font-size: 13px; gap: 3px; } }
