:root { --pb-visible-height: 100dvh; }
html { overscroll-behavior: none; }
body { overscroll-behavior: none; }
.board-viewport.mobile-navigating { cursor: grabbing; }
.board-viewport.mobile-navigating :is(.node,.resident-actor,.board-group) { user-select: none; }
.pb-touch-hint { display: none; }
.pb-install-guide { width: min(440px,calc(100vw - 32px)); max-height: calc(100dvh - 40px); overflow: auto; padding: 30px; border: 1px solid #ffffff1c; border-radius: 24px; background: #1e2733; color: #f4f1e8; box-shadow: 0 24px 100px #0005; font-family: var(--sans,system-ui,sans-serif); }
.pb-install-guide::backdrop { background: #081017a6; backdrop-filter: blur(6px); }
.pb-install-guide h2 { font: 400 30px/1.25 Georgia,serif; margin: 0 0 16px; }
.pb-install-guide p,.pb-install-guide li { color: #bac6d0; font-size: 14px; line-height: 1.7; }
.pb-install-guide ol { padding-left: 24px; }
.pb-install-guide li { padding: 5px 0 5px 5px; }
.pb-install-close { width: 100%; min-height: 46px; padding: 12px 18px; margin-top: 14px; background: #d5e79f; color: #263823; border-radius: 12px; font-size: 15px; font-weight: 650; }
@media (pointer: coarse) {
  .icon-button,.tool-button,.zoom-controls button { min-width: 44px; min-height: 44px; }
  .node button,.drawing-toolbar button { min-height: 36px; min-width: 36px; }
  .magnet-favorite { opacity: 1; min-width: 32px; min-height: 32px; background: #ffffff12; }
  .magnet-option { padding-top: 15px; }
  .board-item { min-height: 46px; }
  :is(.studio-panel,.residents-panel,.background-picker,.magnet-picker,.dropdown-menu,.context-menu) button { min-height: 38px; }
  :is(.studio-panel,.residents-panel,.background-picker,.magnet-picker) input:not([type=checkbox]):not([type=radio]):not([type=color]):not([type=range]),.search-panel input,.pb-input { font-size: 16px; }
  .node-resize,.group-resize { width: 30px; height: 30px; }
  .pb-touch-hint { display: block; position: absolute; left: 14px; bottom: 12px; font: 10px/1.4 var(--sans); color: var(--overlay-ink,#a3ad94); pointer-events: none; max-width: calc(100% - 190px); opacity: .85; }
  .pb-keyboard-open .pb-touch-hint { display: none; }
}
@media (max-width: 680px) {
  .app-shell { height: var(--pb-visible-height); min-height: 0; }
  .main-panel { height: var(--pb-visible-height); min-height: 0; }
  .topbar { flex: 0 0 66px; height: 66px; padding: 0 8px; gap: 4px; }
  .topbar .board-heading { min-width: 50px; }
  .board-title { font-size: 20px; }
  .topbar .eyebrow { font-size: 7px; letter-spacing: .8px; }
  .header-actions { gap: 1px; }
  .header-actions .export-button { min-width: 40px; min-height: 42px; padding: 8px; }
  .header-actions #present-button { display: none; }
  .mobile-menu { width: 44px; height: 44px; }
  .canvas-toolbar { display: grid; grid-template-columns: minmax(0,1fr); grid-template-rows: 44px 44px; flex: 0 0 104px; height: 104px; padding: 6px 8px; gap: 4px; }
  .canvas-toolbar #tools,.canvas-toolbar .history-tools { width: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; margin: 0; gap: 3px; touch-action: pan-x; }
  .canvas-toolbar .history-tools::-webkit-scrollbar { display: none; }
  .canvas-toolbar .history-tools { justify-content: space-between; }
  .canvas-toolbar .history-tools #undo,.canvas-toolbar .history-tools #redo { display: inline-flex; }
  .canvas-toolbar .tool-button { width: 44px; min-width: 44px; height: 44px; flex: 0 0 44px; padding: 10px; }
  .canvas-toolbar .tool-button svg { width: 20px; height: 20px; }
  .canvas-toolbar .toolbar-divider { height: 22px; margin: 0 3px; }
  .canvas-toolbar :is(#studio-panel,#residents-panel,#background-picker,#magnet-picker) { position: fixed; top: auto; left: 8px; right: 8px; bottom: max(8px,env(safe-area-inset-bottom)); width: auto; max-width: none; max-height: min(70dvh,calc(var(--pb-visible-height) - 75px)); overflow-y: auto; padding: 18px; border-radius: 22px; overscroll-behavior: contain; touch-action: pan-y; }
  .canvas-toolbar #magnet-picker { display: flex; overflow: hidden; max-height: min(78dvh,calc(var(--pb-visible-height) - 75px)); gap: 9px; }
  .magnet-categories { grid-template-columns: repeat(3,minmax(0,1fr)); max-height: 170px; overflow-y: auto; }
  .magnet-categories button { min-height: 38px; font-size: 10px; }
  .magnet-grid { grid-template-columns: repeat(4,minmax(0,1fr)); max-height: 240px; min-height: 90px; }
  .magnet-option { height: 90px; }
  .magnet-label { font-size: 9px; }
  .magnet-search input { font-size: 16px; }
  .appearance-tabs button,.studio-tabs button { min-height: 40px; }
  .floating-style,.connection-panel { bottom: max(70px,env(safe-area-inset-bottom)); max-height: calc(var(--pb-visible-height) - 130px); overflow-y: auto; right: 8px; max-width: calc(100vw - 16px); }
  .dropdown-menu button,.context-menu button { min-height: 44px; font-size: 12px; }
  .zoom-controls { right: 8px; bottom: max(10px,env(safe-area-inset-bottom)); padding: 3px; }
  .zoom-controls button { width: 36px; min-width: 36px; height: 40px; min-height: 40px; }
  .zoom-controls .zoom-value { width: 48px; }
  .canvas-bottom { bottom: 44px; left: 12px; }
  .welcome-chip { max-width: calc(100% - 24px); left: 12px; top: 12px; font-size: 10px; }
  .search-panel { top: 8px; left: 8px; right: 8px; width: auto; max-width: none; }
  .search-panel input { font-size: 16px; min-width: 0; }
  .toast-stack { bottom: max(68px,env(safe-area-inset-bottom)); }
  .sidebar { padding-bottom: max(20px,env(safe-area-inset-bottom)); overflow-y: auto; max-height: var(--pb-visible-height); }
  .app-shell.sidebar-open .mobile-menu { top: 12px; left: 230px; width: 44px; height: 44px; background: var(--white); }
  .sidebar .tip-card { display: none; }
  .sidebar-bottom { padding-top: 12px; }
  .story-hud { bottom: max(14px,env(safe-area-inset-bottom)); gap: 6px; }
  .story-buttons button { min-width: 34px; min-height: 38px; }
  .story-progress { max-width: 100px; min-width: 60px; }
  .pb-keyboard-open .welcome-chip,.pb-keyboard-open .canvas-bottom { display: none; }
  .pb-install-guide { padding: 24px; }
}
@media (max-height: 500px) and (max-width: 900px) {
  .app-shell { min-height: 0; height: var(--pb-visible-height); }
  .main-panel { height: var(--pb-visible-height); }
  .sidebar { overflow-y: auto; max-height: var(--pb-visible-height); }
  .topbar { height: 52px; flex-basis: 52px; }
  .canvas-toolbar { display: flex; height: 52px; flex-basis: 52px; padding: 4px 8px; }
  .canvas-toolbar #tools { flex: 1; }
  .canvas-toolbar .history-tools { width: auto; flex: 0 0 auto; }
  .canvas-toolbar .history-tools #undo,.canvas-toolbar .history-tools #redo { display: none; }
  .welcome-chip,.canvas-bottom { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .resident-actor,.resident-svg,.resident-actor *,.resident-particle { animation: none !important; transition: none !important; }
  .pb-install-guide::backdrop { backdrop-filter: none; }
}
