: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-mobile-quickbar,.pb-card-tools,.pb-card-cue,.pb-tools-panel-heading,.pb-tools-section-label,.pb-mobile-extra { display: none; }
.pb-mobile-tools-panel { display: contents; }
.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; }
}
@media (max-width: 680px), (max-width: 900px) and (max-height: 500px) {
  .app-shell { display: block; height: var(--pb-visible-height); min-height: 0; }
  .main-panel { height: var(--pb-visible-height); min-height: 0; }
  .topbar { flex: 0 0 calc(56px + env(safe-area-inset-top)); height: calc(56px + env(safe-area-inset-top)); padding: env(safe-area-inset-top) max(8px,env(safe-area-inset-right)) 0 max(8px,env(safe-area-inset-left)); 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 { display: grid; width: 44px; height: 44px; }
  .canvas-toolbar { display: block; flex: 0 0 50px; height: 50px; padding: 2px max(8px,env(safe-area-inset-right)) 2px max(8px,env(safe-area-inset-left)); overflow: visible; }
  .pb-mobile-quickbar { display: grid; grid-template-columns: repeat(6,minmax(0,1fr)); align-items: stretch; height: 46px; gap: 4px; }
  .pb-quick-button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 46px; min-height: 44px; min-width: 0; padding: 3px 0; border: 1px solid transparent; border-radius: 9px; color: var(--ui-muted,var(--muted)); background: transparent; font: 10px/1.2 var(--sans); touch-action: manipulation; }
  .pb-quick-button svg { width: 19px; height: 19px; }
  .pb-quick-button[data-mobile-drawer="add"] { color: var(--ui-accent-ink); background: var(--ui-accent-bg); }
  .pb-quick-button.active,.pb-quick-button[aria-expanded="true"] { background: var(--ui-selected); border-color: var(--ui-border); color: var(--ui-text); }
  .pb-mobile-tools-panel { display: none; position: absolute; z-index: 100; top: calc(100% + 6px); left: 8px; right: 8px; max-height: min(70dvh,calc(var(--pb-visible-height) - 122px)); overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y; padding: 12px; border: 1px solid var(--ui-border); border-radius: 20px; color: var(--ui-text); background: var(--ui-raised); box-shadow: 0 15px 45px var(--ui-shadow); }
  .canvas-toolbar.pb-tools-open .pb-mobile-tools-panel { display: block; }
  .pb-tools-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 7px; }
  .pb-tools-panel-heading strong { font: 18px/1.25 var(--serif); }
  .pb-tools-panel-heading button { min-width: 44px; min-height: 44px; border-radius: 10px; font-size: 25px; background: var(--ui-subtle); color: var(--ui-text); }
  .pb-tools-section-label { display: block; padding: 12px 4px 9px; font: 10px/1.3 var(--sans); color: var(--ui-muted); }
  .canvas-toolbar .pb-mobile-tools-panel :is(#tools,.history-tools) { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); width: 100%; margin: 0; gap: 6px; overflow: visible; touch-action: pan-y; }
  .canvas-toolbar .pb-mobile-tools-panel .tool-button,.canvas-toolbar .pb-mobile-tools-panel .history-tools #undo,.canvas-toolbar .pb-mobile-tools-panel .history-tools #redo { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 100%; min-width: 0; height: 63px; min-height: 44px; gap: 6px; padding: 7px 2px; background: var(--ui-subtle); border: 1px solid transparent; border-radius: 11px; }
  .canvas-toolbar .pb-mobile-tools-panel .tool-button.active { background: var(--ui-selected); border-color: var(--ui-border); }
  .canvas-toolbar .pb-mobile-tools-panel .tool-button svg { width: 21px; height: 21px; }
  .canvas-toolbar .pb-mobile-tools-panel .tool-button>span { display: none; }
  .canvas-toolbar .pb-mobile-tools-panel .tool-button::after { content: attr(data-mobile-label); max-width: 100%; font: 10px/1.25 var(--sans); color: var(--ui-text); white-space: normal; text-align: center; }
  .canvas-toolbar .pb-mobile-tools-panel .toolbar-divider { display: none; }
  .pb-card-tools { display: flex; position: absolute; z-index: 30; align-items: center; gap: 3px; padding: 3px; border: 1px solid var(--ui-border); border-radius: 13px; background: var(--ui-raised); color: var(--ui-text); box-shadow: 0 5px 24px var(--ui-shadow); }
  .pb-card-tools button { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; min-height: 44px; flex: 0 0 auto; padding: 8px; border-radius: 9px; touch-action: none; }
  .pb-card-tools .pb-card-move { width: auto; min-width: 110px; gap: 6px; padding: 8px 10px; background: var(--ui-accent-bg); color: var(--ui-accent-ink); font: 600 12px/1.2 var(--sans); cursor: grab; }
  .pb-card-tools .pb-card-move svg { width: 20px; height: 20px; }
  .pb-card-tools.pb-is-dragging .pb-card-move { cursor: grabbing; box-shadow: inset 0 0 0 2px var(--ui-accent-bright); }
  .pb-card-cue { display: block; position: absolute; z-index: 35; bottom: 68px; left: 12px; right: 12px; padding: 11px 14px; border: 1px solid var(--ui-border); border-radius: 13px; background: var(--ui-raised); color: var(--ui-text); font: 12px/1.5 var(--sans); pointer-events: none; box-shadow: 0 5px 24px var(--ui-shadow); }
  .node .node-controls { display: none; }
  .node.selected { outline-width: calc(2px * var(--pb-inverse-scale,1)); outline-offset: calc(5px * var(--pb-inverse-scale,1)); }
  .node.selected .node-resize { width: calc(30px * var(--pb-inverse-scale,1)); height: calc(30px * var(--pb-inverse-scale,1)); right: calc(-15px * var(--pb-inverse-scale,1)); bottom: calc(-15px * var(--pb-inverse-scale,1)); border-width: calc(2px * var(--pb-inverse-scale,1)); border-radius: calc(5px * var(--pb-inverse-scale,1)); touch-action: none; }
  .node.selected .connect-port { width: calc(26px * var(--pb-inverse-scale,1)); height: calc(26px * var(--pb-inverse-scale,1)); right: calc(-13px * var(--pb-inverse-scale,1)); border-width: calc(3px * var(--pb-inverse-scale,1)); touch-action: none; }
  .board-viewport:not(.pb-card-style-open) #style-panel:not([hidden]) { display: none; }
  .pb-keyboard-open .pb-card-tools { display: none; }
  .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 { position: fixed; top: 0; bottom: 0; left: 0; width: 224px; z-index: 100; transform: translateX(-100%); padding: 28px 20px max(20px,env(safe-area-inset-bottom)); overflow-y: auto; max-height: var(--pb-visible-height); }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .app-shell.sidebar-open::after { content: ''; position: fixed; inset: 0; background: var(--ui-scrim); z-index: 90; }
  .app-shell.sidebar-open .mobile-menu { top: calc(12px + env(safe-area-inset-top)); 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) {
  .topbar { height: calc(50px + env(safe-area-inset-top)); flex-basis: calc(50px + env(safe-area-inset-top)); }
  .topbar .eyebrow { display: none; }
  .welcome-chip,.canvas-bottom { display: none; }
}
@media (max-width: 380px) {
  .pb-header { padding: 15px 16px; gap: 10px; }
  .pb-header .pb-logo { font-size: 21px; gap: 7px; letter-spacing: -1.1px; }
  .pb-header .pb-logo i { font-size: 27px; }
  .pb-header .pb-header-actions { gap: 5px; }
  .pb-header .pb-button { padding: 8px 9px; font-size: 11px; min-height: 40px; }
}
body.presentation .pb-card-tools,body.presentation .pb-card-cue { display: none !important; }
@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; }
}
