/* Mobile shell layout: canvas-first + in-place bottom sheet (no DOM moves) */

html.mobile-layout .app-shell {
  display: grid !important;
  grid-template-columns: 1fr !important;
  grid-template-rows: var(--m-top-h) 1fr !important;
  grid-template-areas:
    "toolbar"
    "viewer" !important;
  height: 100dvh !important;
  width: 100% !important;
  overflow: hidden !important;
}

html.mobile-layout .toolbar {
  grid-area: toolbar;
  position: relative;
  z-index: 30;
  height: var(--m-top-h) !important;
  min-height: var(--m-top-h) !important;
  padding:
    env(safe-area-inset-top, 0px)
    max(12px, env(safe-area-inset-right, 0px))
    0
    max(12px, env(safe-area-inset-left, 0px)) !important;
  align-items: flex-end !important;
  background: var(--m-chrome-bg) !important;
  backdrop-filter: var(--m-blur);
  -webkit-backdrop-filter: var(--m-blur);
  border-bottom: 1px solid var(--m-hairline) !important;
  gap: 8px !important;
}

html.mobile-layout .toolbar .brand {
  font-size: 15px;
  line-height: 44px;
}

html.mobile-layout .toolbar > *:not(.brand):not(.spacer):not(.language-select):not(#mobile-lang-toggle) {
  display: none !important;
}

html.mobile-layout .toolbar .language-select {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  pointer-events: none !important;
  margin: 0 !important;
}

html.mobile-layout .viewer {
  grid-area: viewer !important;
  min-height: 0 !important;
  padding-bottom: calc(var(--m-sheet-offset, var(--m-peek-h)) + 4px);
  transition: padding-bottom 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

html.mobile-layout.sheet-dragging .viewer {
  transition: none;
}

/* Keep panel in React tree; restyle as fixed bottom sheet */
html.mobile-layout .app-shell > .panel {
  position: fixed !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  top: auto !important;
  z-index: 40 !important;
  width: 100% !important;
  height: var(--m-sheet-offset, var(--m-peek-h)) !important;
  max-height: var(--m-full-h) !important;
  margin: 0 !important;
  grid-area: unset !important;
  display: flex !important;
  flex-direction: column !important;
  background: var(--m-sheet-bg) !important;
  backdrop-filter: var(--m-blur);
  -webkit-backdrop-filter: var(--m-blur);
  border: 0 !important;
  border-top: 1px solid var(--m-hairline) !important;
  border-radius: var(--m-radius-sheet) var(--m-radius-sheet) 0 0 !important;
  box-shadow: var(--m-shadow);
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  padding:
    52px
    max(8px, env(safe-area-inset-right, 0px))
    calc(12px + env(safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-left, 0px)) !important;
  transition: height 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  touch-action: pan-y;
}

html.mobile-layout.sheet-dragging .app-shell > .panel {
  transition: none;
}

html.mobile-layout .app-shell > .panel .section {
  padding: 14px 12px;
}

html.mobile-layout .app-shell > .panel .section h3 {
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0.02em;
  margin-bottom: 10px;
}

html.mobile-layout .app-shell > .panel .row {
  grid-template-columns: 88px 1fr;
  gap: 10px;
  margin-bottom: 10px;
  min-height: var(--m-touch);
}

html.mobile-layout .app-shell > .panel button,
html.mobile-layout .app-shell > .panel input,
html.mobile-layout .app-shell > .panel select {
  min-height: 40px;
  font-size: 15px;
  border-radius: 12px;
  padding: 8px 12px;
}

html.mobile-layout .rotation-slider-bar {
  width: min(420px, calc(100vw - 32px)) !important;
}

html.mobile-layout .rotation-fix-overlay {
  padding-bottom: calc(var(--m-sheet-offset, var(--m-peek-h)) + 12px);
}

html.mobile-layout .placeholder {
  pointer-events: auto;
  padding-bottom: calc(var(--m-sheet-offset, var(--m-peek-h)) * 0.35);
}

html.mobile-layout .placeholder .hint {
  font-size: 14px;
}

html.mobile-layout.sheet-full .viewer::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.28);
  pointer-events: none;
  z-index: 2;
}

/* ---- Injected chrome ---- */

#mobile-root {
  display: none;
}

html.mobile-layout #mobile-root {
  display: block;
}

#mobile-lang-toggle {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-2);
  color: var(--text-0);
  border-radius: 999px;
  min-height: 36px;
  min-width: 64px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  touch-action: manipulation;
}

#mobile-sheet-chrome {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--m-sheet-offset, var(--m-peek-h)) - 52px);
  z-index: 45;
  height: 52px;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  pointer-events: none;
  transition: bottom 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

html.mobile-layout.sheet-dragging #mobile-sheet-chrome {
  transition: none;
}

#mobile-sheet-handle {
  pointer-events: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 22px;
  cursor: grab;
  touch-action: none;
}

#mobile-sheet-handle::before {
  content: "";
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.28);
}

#mobile-sheet-tabs {
  pointer-events: auto;
  display: flex;
  gap: 4px;
  padding: 0 12px 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  touch-action: manipulation;
}

#mobile-sheet-tabs::-webkit-scrollbar {
  display: none;
}

#mobile-sheet-tabs button {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: rgba(17, 20, 24, 0.65);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  touch-action: manipulation;
}

#mobile-sheet-tabs button.active {
  background: rgba(96, 165, 250, 0.2);
  border-color: rgba(96, 165, 250, 0.4);
  color: var(--text-0);
}

#mobile-fab-stack {
  position: fixed;
  right: max(14px, env(safe-area-inset-right, 0px));
  bottom: calc(var(--m-sheet-offset, var(--m-peek-h)) + 14px);
  z-index: 46;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: bottom 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

html.mobile-layout.sheet-dragging #mobile-fab-stack {
  transition: none;
}

#mobile-fab-stack button {
  width: var(--m-fab-size);
  height: var(--m-fab-size);
  border-radius: var(--m-radius-fab);
  border: 1px solid var(--m-hairline);
  background: var(--m-chrome-bg);
  backdrop-filter: var(--m-blur);
  -webkit-backdrop-filter: var(--m-blur);
  color: var(--text-0);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.02em;
  touch-action: manipulation;
  padding: 0;
}

#mobile-fab-stack button .fab-icon {
  font-size: 18px;
  line-height: 1;
}

#mobile-fab-stack button.primary {
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  border-color: transparent;
  color: #fff;
}

#mobile-fab-stack button:disabled {
  opacity: 0.4;
}

#mobile-upload-sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

#mobile-upload-sheet.open {
  display: flex;
}

#mobile-upload-sheet .mobile-upload-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

#mobile-upload-sheet .mobile-upload-panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  background: var(--m-sheet-bg, rgba(17, 20, 24, 0.94));
  backdrop-filter: var(--m-blur, saturate(160%) blur(20px));
  -webkit-backdrop-filter: var(--m-blur, saturate(160%) blur(20px));
  border: 1px solid var(--m-hairline, rgba(255, 255, 255, 0.08));
  border-bottom: 0;
  border-radius: var(--m-radius-sheet, 22px) var(--m-radius-sheet, 22px) 0 0;
  box-shadow: var(--m-shadow, 0 -8px 32px rgba(0, 0, 0, 0.45));
  padding: 10px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  color: var(--text-0, #e8eef4);
}

#mobile-upload-sheet .mobile-upload-grab {
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  margin: 2px auto 12px;
}

#mobile-upload-sheet .mobile-upload-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  min-height: 28px;
}

#mobile-upload-sheet .mobile-upload-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  flex: 1;
}

#mobile-upload-sheet .mobile-upload-back {
  border: 0;
  background: transparent;
  color: #60a5fa;
  font-size: 0.92rem;
  font-weight: 600;
  padding: 6px 4px;
  min-height: 40px;
  touch-action: manipulation;
}

#mobile-upload-sheet .mobile-upload-back[hidden] {
  display: none !important;
}

#mobile-upload-sheet .mobile-upload-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

#mobile-upload-sheet .mobile-upload-option {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--m-hairline, rgba(255, 255, 255, 0.08));
  background: rgba(255, 255, 255, 0.04);
  color: inherit;
  font-size: 0.98rem;
  font-weight: 600;
  text-align: left;
  touch-action: manipulation;
}

#mobile-upload-sheet .mobile-upload-option:active {
  background: rgba(96, 165, 250, 0.16);
  border-color: rgba(96, 165, 250, 0.35);
}

#mobile-upload-sheet .mobile-upload-option .opt-icon {
  width: 28px;
  text-align: center;
  font-size: 1.1rem;
  opacity: 0.9;
}

#mobile-upload-sheet .mobile-upload-cancel {
  width: 100%;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid var(--m-hairline, rgba(255, 255, 255, 0.08));
  background: transparent;
  color: #9aabbc;
  font-size: 0.95rem;
  font-weight: 600;
  touch-action: manipulation;
}

html.mobile-layout #oodles-toast {
  bottom: auto !important;
  top: calc(var(--m-top-h) + 12px) !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
}

html.mobile-layout #oodles-unit-modal {
  align-items: flex-end !important;
  padding: 0 !important;
  background: rgba(0, 0, 0, 0.5) !important;
}

html.mobile-layout #oodles-unit-modal .panel {
  display: block !important;
  position: relative !important;
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
  border-radius: 22px 22px 0 0 !important;
  padding: 20px 18px calc(18px + env(safe-area-inset-bottom, 0px)) !important;
  border: 1px solid #2c3a48 !important;
  inset: auto !important;
}

html.mobile-layout #oodles-unit-modal select,
html.mobile-layout #oodles-unit-modal button {
  min-height: 44px;
  font-size: 15px;
  border-radius: 12px;
}

html.mobile-layout .confirm-overlay {
  align-items: flex-end;
  padding: 0;
}

html.mobile-layout .confirm-dialog {
  width: 100%;
  max-width: 100%;
  border-radius: 22px 22px 0 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}

#mobile-ar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100000;
  background: #000;
  flex-direction: column;
}

#mobile-ar-overlay.open {
  display: flex;
}

#mobile-ar-overlay header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding:
    calc(10px + env(safe-area-inset-top, 0px))
    max(14px, env(safe-area-inset-right, 0px))
    10px
    max(14px, env(safe-area-inset-left, 0px));
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
}

#mobile-ar-overlay header button {
  min-height: 40px;
  min-width: 72px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  font-weight: 600;
}

#mobile-ar-overlay model-viewer {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  background: #111;
}

#mobile-ar-message {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  max-width: min(90vw, 360px);
  padding: 16px 18px;
  border-radius: 14px;
  background: rgba(26, 34, 44, 0.95);
  color: #e8eef4;
  text-align: center;
  line-height: 1.45;
  display: none;
}

#mobile-ar-message.show {
  display: block;
}

#mobile-blocking,
#mobile-boot-splash {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99990;
  background: rgba(0, 0, 0, 0.55);
  align-items: center;
  justify-content: center;
  padding: 24px;
}

html.mobile-layout #mobile-boot-splash:not(.done) {
  display: flex;
  background: #0b0d10;
  z-index: 100001;
}

#mobile-blocking.open {
  display: flex;
}

#mobile-blocking .card,
#mobile-boot-splash .card {
  width: min(360px, 100%);
  padding: 22px 18px;
  border-radius: 16px;
  background: var(--bg-1, #111418);
  border: 1px solid var(--border, #262d36);
  color: var(--text-0, #e6e9ee);
  text-align: center;
}

#mobile-blocking .spinner,
#mobile-boot-splash .spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent, #60a5fa);
  border-radius: 50%;
  animation: mobile-spin 0.8s linear infinite;
}

@keyframes mobile-spin {
  to {
    transform: rotate(360deg);
  }
}
