/* 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;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

html.mobile-layout .toolbar .brand .brand-icon {
  width: 22px;
  height: 22px;
  object-fit: contain;
  border-radius: 4px;
}

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(6px, env(safe-area-inset-right, 0px))
    calc(8px + env(safe-area-inset-bottom, 0px))
    max(6px, 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: 8px 10px 6px;
}

html.mobile-layout .app-shell > .panel .section + .section {
  padding-top: 4px;
  border-top: 1px solid rgba(0, 0, 0, 0.06);
}

html.mobile-layout .app-shell > .panel .section h3 {
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0.02em;
  margin: 0 0 4px;
  line-height: 1.2;
}

html.mobile-layout .app-shell > .panel .row {
  grid-template-columns: 76px 1fr;
  gap: 6px 8px;
  margin-bottom: 4px;
  min-height: 32px;
  align-items: center;
  line-height: 1.25;
}

html.mobile-layout .app-shell > .panel .row label {
  line-height: 1.25;
  margin: 0;
}

html.mobile-layout .app-shell > .panel button,
html.mobile-layout .app-shell > .panel input,
html.mobile-layout .app-shell > .panel select {
  min-height: 34px;
  font-size: 14px;
  border-radius: 10px;
  padding: 5px 10px;
  line-height: 1.2;
}

html.mobile-layout .rotation-slider-bar {
  width: min(420px, calc(100vw - 32px)) !important;
}

html.mobile-layout .rotation-action-bar {
  width: min(420px, calc(100vw - 32px));
  justify-content: center;
}

html.mobile-layout .rotation-fix-overlay {
  padding-bottom: calc(var(--m-sheet-offset, var(--m-peek-h)) + 12px);
  z-index: 6;
}

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);
  background: var(--m-sheet-bg, rgba(255, 255, 255, 0.94));
  backdrop-filter: var(--m-blur, saturate(160%) blur(20px));
  -webkit-backdrop-filter: var(--m-blur, saturate(160%) blur(20px));
  border-bottom: 1px solid var(--m-hairline, rgba(0, 0, 0, 0.08));
  border-radius: var(--m-radius-sheet, 22px) var(--m-radius-sheet, 22px) 0 0;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55) inset;
}

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(0, 0, 0, 0.18);
}

#mobile-sheet-tabs-row {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px 6px 12px;
  min-height: 30px;
}

#mobile-sheet-tabs {
  flex: 1 1 auto;
  display: flex;
  gap: 4px;
  min-width: 0;
  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(0, 0, 0, 0.05);
  color: var(--text-1);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  touch-action: manipulation;
}

#mobile-sheet-tabs button.active {
  background: rgba(217, 69, 64, 0.14);
  border-color: rgba(217, 69, 64, 0.4);
  color: var(--text-0);
}

#mobile-sheet-toggle {
  flex: 0 0 auto;
  width: 36px;
  height: 32px;
  padding: 0;
  border-radius: 10px;
  border: 1px solid var(--m-hairline, rgba(0, 0, 0, 0.08));
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-0, #1f1f1f);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

#mobile-sheet-toggle:active {
  background: rgba(217, 69, 64, 0.12);
  border-color: rgba(217, 69, 64, 0.35);
}

#mobile-sheet-toggle .sheet-toggle-icon {
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
}

#mobile-sheet-toggle.expanded {
  color: var(--accent-strong, #d94540);
  border-color: rgba(217, 69, 64, 0.35);
}

#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.12);
  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, #e85a54, #d94540);
  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(255, 255, 255, 0.96));
  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: #d94540;
  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(217, 69, 64, 0.12);
  border-color: rgba(217, 69, 64, 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: #8a8a8a;
  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: #f3f3f3;
  flex-direction: column;
  color: var(--text-0, #1f1f1f);
}

#mobile-ar-overlay.open {
  display: flex;
}

#mobile-ar-overlay header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  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(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--border, #e6e6e6);
  color: var(--text-0, #1f1f1f);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

#mobile-ar-overlay header strong {
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}

#mobile-ar-overlay header strong::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 2px;
  background: var(--accent-strong, #d94540);
  transform: translateY(-1px) rotate(45deg);
  vertical-align: middle;
}

#mobile-ar-overlay header button {
  min-height: 40px;
  min-width: 72px;
  border-radius: 999px;
  border: 1px solid var(--accent-strong, #d94540);
  background: var(--accent-strong, #d94540);
  color: #fff;
  font-weight: 650;
  font-size: 0.9rem;
}

#mobile-ar-overlay header button:hover {
  background: var(--accent, #e85a54);
  border-color: var(--accent, #e85a54);
}

#mobile-ar-overlay model-viewer {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  background: #f0f0f0;
}

#mobile-ar-launch {
  position: absolute;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  z-index: 2;
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--accent-strong, #d94540);
  color: #fff;
  font-weight: 700;
  font-size: 1rem;
  box-shadow: 0 8px 24px rgba(217, 69, 64, 0.35);
}

#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: #ffffff;
  color: var(--text-0, #1f1f1f);
  border: 1px solid var(--border, #e6e6e6);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  text-align: center;
  line-height: 1.45;
  font-size: 0.92rem;
  display: none;
}

#mobile-ar-message.show {
  display: block;
}

#mobile-blocking,
#mobile-boot-splash {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100010;
  background: rgba(243, 243, 243, 0.72);
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

html.mobile-layout #mobile-boot-splash:not(.done) {
  display: flex;
  background: #f3f3f3;
  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, #ffffff);
  border: 1px solid var(--border, #e6e6e6);
  color: var(--text-0, #1f1f1f);
  text-align: center;
}

#mobile-blocking .spinner,
#mobile-boot-splash .spinner {
  width: 28px;
  height: 28px;
  margin: 0 auto 12px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--accent-strong, #d94540);
  border-radius: 50%;
  animation: mobile-spin 0.8s linear infinite;
}

@keyframes mobile-spin {
  to {
    transform: rotate(360deg);
  }
}

/* —— Desktop toolbar: upload dropdown + AR —— */
html:not(.mobile-layout) .desktop-native-upload-hidden {
  display: none !important;
}

html:not(.mobile-layout) #desktop-upload-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  z-index: 90;
}

html:not(.mobile-layout) #desktop-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

html:not(.mobile-layout) #desktop-upload-btn .desktop-upload-caret {
  font-size: 10px;
  opacity: 0.75;
  line-height: 1;
}

html:not(.mobile-layout) #desktop-upload-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 100;
  min-width: 220px;
  padding: 6px;
  border-radius: 10px;
  border: 1px solid var(--border, #e6e6e6);
  background: var(--bg-1, #fff);
  box-shadow: var(--shadow-panel, 0 8px 24px rgba(0, 0, 0, 0.12));
  display: flex;
  flex-direction: column;
  gap: 2px;
}

html:not(.mobile-layout) #desktop-upload-menu[hidden] {
  display: none !important;
}

html:not(.mobile-layout) #desktop-upload-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-0, #1f1f1f);
  font-weight: 600;
  cursor: pointer;
}

html:not(.mobile-layout) #desktop-upload-menu button:hover {
  background: rgba(217, 69, 64, 0.1);
  border-color: transparent;
}

html:not(.mobile-layout) #desktop-upload-menu .opt-icon {
  width: 18px;
  text-align: center;
  opacity: 0.85;
  flex: 0 0 auto;
}

html:not(.mobile-layout) #desktop-upload-menu .desktop-upload-menu-sep {
  height: 1px;
  margin: 4px 6px;
  background: var(--border, #e6e6e6);
}

html:not(.mobile-layout) #desktop-toolbar-ar {
  margin-left: 2px;
}

html:not(.mobile-layout) #desktop-toolbar-ar:disabled {
  opacity: 0.45;
}

html:not(.mobile-layout) #mobile-ar-overlay {
  z-index: 100010;
}

html:not(.mobile-layout) #mobile-blocking {
  z-index: 100020;
}

#glb-app-toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 100100;
  display: none;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--bg-1, #fff);
  color: var(--text-0, #1f1f1f);
  border: 1px solid var(--border, #e6e6e6);
  font-family: var(--font-sans, "Segoe UI", "Noto Sans TC", sans-serif);
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-width: min(90vw, 420px);
}

#glb-app-toast.show {
  display: block;
}

#glb-app-toast.error {
  border-color: #d94540;
  color: #c73732;
}

html.mobile-layout #glb-app-toast {
  bottom: auto;
  top: calc(var(--m-top-h, 48px) + 12px);
}

