:root {
  --inc-safe-top: max(6px, env(safe-area-inset-top));
  --inc-safe-right: max(6px, env(safe-area-inset-right));
  --inc-safe-bottom: max(6px, env(safe-area-inset-bottom));
  --inc-safe-left: max(6px, env(safe-area-inset-left));
}

html, body, #app { min-width: 0; min-height: 0; }
body.incoprea-android { touch-action: none; -webkit-user-select: none; user-select: none; }
body.incoprea-android input,
body.incoprea-android textarea { -webkit-user-select: text; user-select: text; }

/* Native WebViews are always touch-first, even on devices that report a fine pointer. */
body.incoprea-android .edge-dock { width: 52px; }
body.incoprea-android .hud-stack { grid-template-columns: 52px minmax(0, 1fr); }
body.incoprea-android .left-panel.tools-right .hud-stack { grid-template-columns: minmax(0, 1fr) 52px; }
body.incoprea-android .edge-dock .icon-button,
body.incoprea-android .view-chip .icon-button,
body.incoprea-android .mobile-move-controls .icon-button,
body.incoprea-android .mobile-elevation-controls .icon-button,
body.incoprea-android .mobile-exit-control,
body.incoprea-android .mobile-flight-control,
body.incoprea-android .mobile-top-controls button,
body.incoprea-android .inspector-close-button.icon-button,
body.incoprea-android .inspector-grip {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
}
body.incoprea-android .tool-button,
body.incoprea-android .object-button,
body.incoprea-android .creation-menu-button,
body.incoprea-android .mini-button,
body.incoprea-android .script-tab,
body.incoprea-android select,
body.incoprea-android input[type="button"],
body.incoprea-android input[type="submit"] { min-height: 44px; }

.incoprea-studio-bar,
.incoprea-mobile-guide,
.incoprea-touch-hint { display: none; }

body.incoprea-touch-shell .incoprea-studio-bar {
  position: fixed;
  z-index: 8;
  top: var(--inc-safe-top);
  left: 50%;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 4px;
  transform: translateX(-50%);
  color: #eef4f4;
  background: linear-gradient(180deg, #13191de8, #0e1215d9);
  border: 1px solid #7f9aa577;
  border-radius: 10px;
  box-shadow: 0 10px 28px #0005, inset 0 1px #d7f7ff0d;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  pointer-events: auto;
}
body.incoprea-touch-shell .incoprea-studio-identity {
  display: grid;
  grid-template-columns: auto auto;
  align-items: baseline;
  gap: 6px;
  padding: 0 5px 0 7px;
  white-space: nowrap;
}
body.incoprea-touch-shell .incoprea-studio-identity b { color: #f5f8f8; font-size: 11px; letter-spacing: .08em; }
body.incoprea-touch-shell .incoprea-studio-identity span { color: #9bb1ba; font-size: 8px; letter-spacing: .15em; }
body.incoprea-touch-shell .incoprea-studio-actions { display: flex; align-items: center; gap: 3px; }
body.incoprea-touch-shell .incoprea-studio-actions button,
body.incoprea-touch-shell .incoprea-guide-close,
body.incoprea-touch-shell .incoprea-touch-hint button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 34px;
  color: #e9f1f2;
  background: #202a2f;
  border: 1px solid #667b84;
  border-radius: 7px;
  font: 800 11px/1 system-ui, sans-serif;
}
body.incoprea-touch-shell .incoprea-shell-save { gap: 5px; padding: 0 9px; color: #c5eef2; letter-spacing: .08em; }
body.incoprea-touch-shell .incoprea-shell-save span { color: #78d3dd; font-size: 13px; }
body.incoprea-touch-shell .incoprea-shell-save.saving { opacity: .62; }
body.incoprea-touch-shell .incoprea-shell-save.saved { color: #d8f5d0; border-color: #84bd77; background: #1c3224; }
body.incoprea-touch-shell .incoprea-shell-help { font-size: 15px; }

body.incoprea-touch-shell .incoprea-mobile-guide {
  position: fixed;
  z-index: 9;
  top: calc(var(--inc-safe-top) + 50px);
  left: 50%;
  display: block;
  width: min(460px, calc(100vw - var(--inc-safe-left) - var(--inc-safe-right) - 20px));
  max-height: calc(100dvh - var(--inc-safe-top) - var(--inc-safe-bottom) - 62px);
  padding: 10px;
  transform: translateX(-50%);
  overflow: auto;
  color: #e8eff0;
  background: linear-gradient(150deg, #101619f2, #11191ceb);
  border: 1px solid #86a2ad88;
  border-radius: 12px;
  box-shadow: 0 18px 55px #000a;
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
body.incoprea-touch-shell .incoprea-mobile-guide[hidden] { display: none; }
body.incoprea-touch-shell .incoprea-guide-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 9px; }
body.incoprea-touch-shell .incoprea-guide-heading div { display: grid; gap: 3px; }
body.incoprea-touch-shell .incoprea-guide-heading b { color: #ccecf0; font-size: 11px; letter-spacing: .16em; }
body.incoprea-touch-shell .incoprea-guide-heading span { color: #9eafb5; font-size: 10px; }
body.incoprea-touch-shell .incoprea-guide-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; }
body.incoprea-touch-shell .incoprea-guide-grid > button {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: center;
  gap: 5px;
  min-height: 48px;
  padding: 5px 7px;
  text-align: left;
  color: #eff5f5;
  background: #20282ccc;
  border: 1px solid #3f5058;
  border-radius: 8px;
}
body.incoprea-touch-shell .incoprea-guide-grid > button.active { border-color: #76c6d0; background: #17343b; }
body.incoprea-touch-shell .incoprea-guide-grid > button > b { color: #7dd3dc; font-size: 17px; text-align: center; }
body.incoprea-touch-shell .incoprea-guide-grid > button > span { display: grid; gap: 2px; font: 800 9px/1 system-ui, sans-serif; letter-spacing: .06em; }
body.incoprea-touch-shell .incoprea-guide-grid small { color: #94a6ad; font: 500 8px/1.1 system-ui, sans-serif; letter-spacing: 0; }
body.incoprea-touch-shell .incoprea-guide-gestures { display: flex; justify-content: space-between; gap: 8px; margin-top: 9px; color: #a9b8bd; font: 600 9px/1.2 system-ui, sans-serif; }
body.incoprea-touch-shell .incoprea-guide-gestures span { display: flex; align-items: center; gap: 5px; }
body.incoprea-touch-shell .incoprea-guide-gestures i { display: grid; place-items: center; width: 17px; height: 17px; color: #101618; background: #83ced7; border-radius: 50%; font-style: normal; font-weight: 900; }

body.incoprea-touch-shell .incoprea-touch-hint {
  position: fixed;
  z-index: 6;
  left: 50%;
  bottom: var(--inc-safe-bottom);
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 3px 3px 3px 11px;
  transform: translateX(-50%);
  color: #b9c7cb;
  background: #11171bdb;
  border: 1px solid #70899377;
  border-radius: 9px;
  box-shadow: 0 8px 24px #0006;
  font: 600 9px/1.2 system-ui, sans-serif;
  white-space: nowrap;
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}
body.incoprea-touch-shell .incoprea-touch-hint[hidden] { display: none; }
body.incoprea-touch-shell .incoprea-touch-hint b { color: #d9edef; letter-spacing: .05em; }
body.incoprea-touch-shell .incoprea-touch-hint button { min-width: 30px; min-height: 30px; background: transparent; border-color: transparent; color: #8fa2a9; font-size: 15px; }

@media (pointer: coarse), (max-width: 720px) {
  .edge-dock { width: 52px; }
  .hud-stack { grid-template-columns: 52px minmax(0, 1fr); }
  .left-panel.tools-right .hud-stack { grid-template-columns: minmax(0, 1fr) 52px; }
  .edge-dock .icon-button,
  .view-chip .icon-button,
  .mobile-move-controls .icon-button,
  .mobile-elevation-controls .icon-button,
  .mobile-exit-control,
  .mobile-flight-control,
  .mobile-top-controls button,
  .inspector-close-button.icon-button,
  .inspector-grip {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  .tool-button,
  .object-button,
  .creation-menu-button,
  .mini-button,
  .script-tab,
  select,
  input[type="button"],
  input[type="submit"] { min-height: 44px; }
  .view-chip,
  .popover-header,
  .camera-control-header { min-height: 48px; }
  .mobile-move-controls { grid-template-columns: repeat(3, 44px); grid-auto-rows: 44px; }
  .mobile-elevation-controls { grid-auto-rows: 44px; }
  .hud-popover { max-height: min(68dvh, 440px); }
}

@media (orientation: landscape) and (max-height: 480px) {
  .left-panel { top: var(--inc-safe-top); left: var(--inc-safe-left); }
  .left-panel.tools-right { right: var(--inc-safe-right); left: auto; }
  .right-panel { right: var(--inc-safe-right); bottom: var(--inc-safe-bottom); }
  .hud-popover { max-height: calc(100dvh - var(--inc-safe-top) - var(--inc-safe-bottom)); }
  .selection-stack > .panel-section { max-height: calc(100dvh - 64px); }
  .toast { bottom: var(--inc-safe-bottom); }
  body.incoprea-touch-shell .toast { bottom: calc(var(--inc-safe-bottom) + 42px); }
  body.incoprea-touch-shell .incoprea-mobile-guide { width: min(520px, calc(100vw - 154px)); }
  body.incoprea-touch-shell .incoprea-guide-grid > button { grid-template-columns: 24px minmax(0,1fr); }
}

@media (orientation: portrait) and (pointer: coarse),
       (orientation: portrait) and (max-width: 720px) {
  body.incoprea-touch-shell .incoprea-studio-bar { top: calc(var(--inc-safe-top) + 52px); }
  body.incoprea-touch-shell .incoprea-studio-identity span { display: none; }
  body.incoprea-touch-shell .left-panel,
  body.incoprea-android .left-panel {
    top: var(--inc-safe-top);
    left: var(--inc-safe-left);
    width: auto;
  }
  body.incoprea-touch-shell .left-panel.tools-right,
  body.incoprea-android .left-panel.tools-right { right: auto; left: var(--inc-safe-left); }
  body.incoprea-touch-shell .hud-stack,
  body.incoprea-android .hud-stack,
  body.incoprea-touch-shell .left-panel.tools-right .hud-stack,
  body.incoprea-android .left-panel.tools-right .hud-stack { display: block; }
  body.incoprea-touch-shell .edge-dock,
  body.incoprea-android .edge-dock {
    display: grid;
    grid-template-columns: repeat(4, 44px);
    width: auto;
    padding: 4px;
  }
  body.incoprea-touch-shell .hud-popover,
  body.incoprea-android .hud-popover {
    position: fixed;
    top: calc(var(--inc-safe-top) + 104px);
    left: var(--inc-safe-left);
    width: calc(100vw - var(--inc-safe-left) - var(--inc-safe-right));
    max-height: min(48dvh, 430px);
  }
  body.incoprea-touch-shell .incoprea-mobile-guide { top: calc(var(--inc-safe-top) + 102px); width: calc(100vw - var(--inc-safe-left) - var(--inc-safe-right)); }
  body.incoprea-touch-shell .incoprea-guide-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  body.incoprea-touch-shell .incoprea-guide-gestures { display: grid; grid-template-columns: 1fr 1fr; }
  body.incoprea-touch-shell .incoprea-touch-hint { bottom: calc(var(--inc-safe-bottom) + 96px); max-width: calc(100vw - 24px); white-space: normal; }
  body.incoprea-touch-shell .toast { bottom: calc(var(--inc-safe-bottom) + 142px); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
