/* x216 UI polish. Additive, low-specificity cleanup loaded last. No colors, no layout restructuring. */

/* Base: stable text sizing, media never overflows, long words wrap */
html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
img,svg,video,canvas{max-width:100%}
:where(h1,h2,h3,h4,p,li,td,th,label,small,a){overflow-wrap:break-word}
:where(table){max-width:100%}

/* Consistent keyboard focus everywhere */
:where(a,button,input,select,textarea,summary,[role=button],[tabindex]):focus-visible{outline:2px solid currentColor;outline-offset:3px;border-radius:6px}

/* Form controls: never wider than their container, 16px on phones to stop iOS zoom */
:where(input,select,textarea){max-width:100%;min-width:0}
@media(max-width:700px){:where(input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),select,textarea){font-size:16px}}

/* Touch targets on touch devices */
@media(pointer:coarse){
  :where(button,[role=button],select,summary,input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color])){min-height:44px}
  :where(input[type=checkbox],input[type=radio]){width:22px;height:22px}
}

/* Popovers and menus: never clipped by the viewport edge */
:where([role=menu],[role=listbox],.ath30-canvas-menu){max-width:calc(100vw - 16px);overflow-wrap:anywhere}
:where([role=menu],[role=listbox]){max-height:min(70dvh,520px);overflow-y:auto;overscroll-behavior:contain}

/* Builder Studio: single-line toolbar labels, scroll instead of wrapping letter by letter */
.workspace-actions{flex-wrap:nowrap;overflow-x:auto;overflow-y:hidden;scrollbar-width:none;-webkit-overflow-scrolling:touch;min-width:0;max-width:100%}
.workspace-actions::-webkit-scrollbar{display:none}
.workspace-actions>*,.workspace-actions .quiet-btn,.workspace-actions .viewport-chip,.panel-tab,.top-right .quiet-btn,.publish-btn,.tool small{white-space:nowrap;flex:none}
.panel-tabs{overflow-x:auto;scrollbar-width:none}
.panel-tabs::-webkit-scrollbar{display:none}
.panel-tab{flex:1 0 auto;padding:0 8px}
.workspace-context{min-width:0}
.workspace-mode{min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.project-name{max-width:min(220px,40vw)}
.toast{max-width:min(88vw,420px)}
.dialog{max-width:calc(100vw - 24px)}

/* Safe areas on notched phones */
@supports(padding:max(0px)){
  .toast{bottom:max(120px,calc(env(safe-area-inset-bottom) + 96px))}
  .modal-backdrop{padding-left:max(25px,env(safe-area-inset-left));padding-right:max(25px,env(safe-area-inset-right))}
}

/* Dialogs and drawers scroll inside themselves, not the page behind */
:where(dialog,.modal-backdrop,.dialog){overscroll-behavior:contain}
:where(dialog){max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px)}

/* Agent entry panel: roomier on phones */
@media(max-width:520px){
  .agent-entry-dialog{width:calc(100vw - 16px);max-width:calc(100vw - 16px);max-height:calc(100dvh - 16px)}
  .agent-entry-actions{gap:8px}
  .agent-entry-action{flex:1 1 calc(50% - 8px);justify-content:center;text-align:center}
}

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