/* Phone layout. Loaded last; everything here applies at 760px and below.
   A slim header at the top, a bottom tab bar within thumb reach, iPhone
   safe areas, 16px inputs (no zoom on focus) and pages reflowed for one hand. */
.mobile-tabbar,.mobile-sheet{display:none}
@media(max-width:760px){
  :root{--tabbar-h:62px;--mobile-header-h:54px;--safe-top:env(safe-area-inset-top,0px);--safe-bottom:env(safe-area-inset-bottom,0px)}
  html{-webkit-text-size-adjust:100%;text-size-adjust:100%}
  body{-webkit-tap-highlight-color:transparent}
  html.mobile-sheet-open,html.mobile-sheet-open body{overflow:hidden}

  /* Header: page name on the left, notifications and account on the right. */
  .sidebar{display:none!important}
  .topbar{position:fixed!important;inset:0 0 auto 0!important;z-index:1500;height:auto!important;min-height:0!important;padding:calc(var(--safe-top) + 7px) 14px 7px!important;display:flex!important;align-items:center;justify-content:space-between;gap:10px;background:rgb(var(--bg-rgb)/.84)!important;backdrop-filter:blur(18px) saturate(140%);-webkit-backdrop-filter:blur(18px) saturate(140%);border-bottom:1px solid rgb(var(--accent-rgb)/.13)!important;pointer-events:auto!important}
  .topbar>div:first-child{display:flex!important;visibility:visible!important;align-items:center;gap:8px;min-width:0;max-width:none!important}
  .topbar #page-label{font-size:11px!important;font-weight:800;letter-spacing:1.3px!important;color:var(--text)!important;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .topbar .topbar-right{margin:0!important;padding:0!important;border:0!important;background:none!important;backdrop-filter:none!important;display:flex!important;align-items:center;gap:8px!important;width:auto!important;flex-shrink:0}
  .topbar .device-status,.topbar .preview-tag{display:none!important}
  .notification-bell{width:38px;height:38px}

  /* The desktop layout reserves room above the content for the floating dock. */
  .content-shell{padding-top:0!important}
  main{padding:calc(var(--mobile-header-h) + var(--safe-top) + 16px) 16px 22px!important;min-height:calc(100dvh - 120px)}
  .page-footer{padding:18px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 18px)!important;flex-wrap:wrap}

  /* Bottom tab bar. */
  .mobile-tabbar{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));position:fixed;left:0;right:0;bottom:0;z-index:1800;padding:5px max(6px,env(safe-area-inset-left)) calc(5px + var(--safe-bottom)) max(6px,env(safe-area-inset-right));background:rgb(var(--bg-rgb)/.9);backdrop-filter:blur(22px) saturate(150%);-webkit-backdrop-filter:blur(22px) saturate(150%);border-top:1px solid rgb(var(--accent-rgb)/.15)}
  .mobile-tabbar a,.mobile-tabbar button{display:flex!important;flex-direction:column;align-items:center;justify-content:center;gap:2px!important;width:auto!important;min-height:52px!important;height:auto!important;padding:0!important;border:0;border-radius:14px;background:none!important;box-shadow:none!important;color:var(--muted);font-family:inherit;font-size:10.5px!important;font-weight:600;line-height:1.2;letter-spacing:0;text-decoration:none;touch-action:manipulation;translate:none!important;scale:none!important}
  /* The desktop dock hides link text; the tab bar always shows its labels. */
  .mobile-tabbar a>span,.mobile-tabbar button>span{display:block!important}
  .mobile-tab-icon{display:grid!important;place-items:center;width:48px;height:28px;border-radius:999px;transition:background .18s,color .18s}
  .mobile-tab-icon svg{width:22px;height:22px}
  .mobile-tabbar .is-active{color:var(--accent)}
  .mobile-tabbar .is-active .mobile-tab-icon{background:rgb(var(--accent-rgb)/.2)}
  .mobile-tabbar a:active .mobile-tab-icon,.mobile-tabbar button:active .mobile-tab-icon{background:rgb(var(--accent-rgb)/.28)}

  /* "More" sheet. */
  .mobile-sheet{display:block;position:fixed;inset:0;z-index:1700}
  .mobile-sheet[hidden]{display:none}
  .mobile-sheet-backdrop{position:absolute;inset:0;width:100%;border:0;background:rgb(0 0 0/.55);backdrop-filter:blur(2px)}
  .mobile-sheet-panel{position:absolute;left:0;right:0;bottom:0;padding:10px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 14px);border-radius:24px 24px 0 0;border-top:1px solid rgb(var(--accent-rgb)/.25);background:rgb(var(--bg-rgb)/.98);box-shadow:0 -18px 50px rgb(0 0 0/.5);animation:mobile-sheet-up .22s ease-out}
  .mobile-sheet-handle{display:block;width:40px;height:4px;margin:0 auto 14px;border-radius:99px;background:rgb(var(--accent-rgb)/.35)}
  .mobile-sheet-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}
  .mobile-sheet-item{display:flex;flex-direction:column;align-items:center;gap:7px;padding:14px 6px;border:1px solid rgb(var(--accent-rgb)/.12);border-radius:16px;background:rgb(var(--accent-rgb)/.05);color:var(--text);font-size:12px;font-weight:600;text-align:center;text-decoration:none}
  .mobile-sheet-item[aria-current=page]{border-color:rgb(var(--accent-rgb)/.45);color:var(--accent)}
  .mobile-sheet-icon{display:grid;place-items:center;width:40px;height:40px;border-radius:13px;background:rgb(var(--accent-rgb)/.14);color:var(--accent)}
  .mobile-sheet-icon svg{width:21px;height:21px}
  @keyframes mobile-sheet-up{from{transform:translateY(30px);opacity:.4}to{transform:none;opacity:1}}

  /* Floating things clear the tab bar. */
  .toast{bottom:calc(var(--tabbar-h) + var(--safe-bottom) + 12px)!important}
  .notification-popups{bottom:calc(var(--tabbar-h) + var(--safe-bottom) + 12px)!important;left:12px!important;right:12px!important}
  .notification-panel{position:fixed!important;top:calc(var(--mobile-header-h) + var(--safe-top) + 6px)!important;left:10px!important;right:10px!important;width:auto!important;max-height:calc(100dvh - var(--mobile-header-h) - var(--tabbar-h) - var(--safe-top) - var(--safe-bottom) - 24px)!important}

  /* Centered buttons: labels sit in the middle of every button, and buttons
     that stand on their own line span the width and center. */
  :is(.community-button,.profile-button,.social-button,.appearance-reset,.appearance-save,.admin-tab,.notification-link):not([hidden]){display:inline-flex!important;align-items:center;justify-content:center!important;text-align:center!important}
  :is(.page-intro,.community-panel,.profile-panel,.social-panel,.settings-panel,.community-actions,.social-actions,.community-room-tools,.community-room-forms form,.appearance-heading,.custom-theme-save,.admin-room-heading)>:is(a,button):is(.community-button,.profile-button,.social-button,.appearance-reset,.appearance-save){width:100%!important;max-width:none!important;margin-left:0!important;margin-right:0!important}
  .community-actions,.social-actions{display:flex!important;flex-direction:column!important;align-items:stretch!important;gap:10px!important}
  .community-room-forms>summary,.community-room-tools>.community-fineprint{text-align:center}
  .profile-page-links,.social-tabs,.admin-tabs{justify-content:safe center!important}
  .appearance-heading{flex-direction:column;align-items:stretch!important;gap:12px}
  .community-intro>.community-button{align-self:stretch}
  /* Home quick links, link rows and leaderboard periods sit in the middle. */
  .quick-links>button{justify-content:center!important;text-align:center!important}
  /* Icons sit centered above their word, like the tab bar. */
  :is(.quick-links>button,.secondary-button:has(>svg),.private-call-button:not(.private-call-control),.community-room-button):not([hidden]){display:inline-flex!important;flex-direction:column!important;align-items:center!important;justify-content:center!important;gap:6px!important;text-align:center!important}
  :is(.quick-links>button,.secondary-button:has(>svg),.private-call-button:not(.private-call-control),.community-room-button)>:is(svg,.quick-icon,.community-room-symbol){order:-1;margin:0!important;flex-shrink:0}
  .quick-links>button{height:auto!important;min-height:86px;padding:14px 8px!important}
  .quick-links>button>svg.icon{display:none!important}
  .library-page>.load-more.secondary-button:not([hidden]),.empty-state>.secondary-button:not([hidden]){display:flex!important;width:100%;max-width:none}
  .community-room-button{padding:9px 14px!important;gap:3px!important;line-height:1.3!important}
  .community-room-symbol{font-size:18px!important;line-height:1}
  .community-discovery-links,.profile-periods{justify-content:center!important;flex-wrap:wrap}
  .community-widget-heading{align-items:center!important;text-align:center}
  /* Forms laid out in a column: their buttons fill the width. */
  .profile-editor-actions{align-items:stretch!important}
  :is(.profile-search-form,.profile-edit-form,.profile-editor-actions,.community-form)>:is(a,button){align-self:stretch!important;width:100%!important;max-width:none!important;justify-content:center!important;text-align:center!important}
  /* Text and a button on one line: the button drops below, full width. */
  :is(.community-composer>div,.social-send-row,.settings-row:has(>button),.profile-person-row){flex-wrap:wrap!important;justify-content:center!important;gap:10px!important}
  :is(.community-composer>div,.social-send-row,.settings-row,.profile-person-row)>:is(button,a.profile-button){flex:1 1 100%!important;width:100%!important;justify-content:center!important;text-align:center!important}
  :is(.community-composer>div,.social-send-row)>span{flex:1 1 100%;text-align:center}
  .settings-row:has(>button)>div{flex:1 1 100%;text-align:center}
  .profile-person-row>.profile-identity{flex:1 1 100%;justify-content:center}
  .profile-person-row>a.profile-button{margin-left:0!important;margin-right:0!important}
  /* Room chips and the invite code. */
  .community-room-list{justify-content:safe center}
  #community-room-invite:not(:empty){justify-content:center!important;text-align:center;padding:12px 14px!important}

  /* Calls: everything centered; in-call controls are round buttons with the
     label underneath, like a phone call. */
  .private-call-panel{padding:16px!important}
  :is(.private-call-status,.private-call-hint,.private-call-privacy,.private-call-error){text-align:center}
  .private-call-actions{justify-content:center!important;gap:10px!important}
  .private-call-actions>.private-call-button:not(.private-call-control){flex:1 1 0!important;max-width:220px;min-height:46px!important}
  .private-call-actions:has(>.private-call-control:not([hidden])){display:grid!important;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr);gap:8px!important;max-width:360px;margin-left:auto;margin-right:auto}
  .private-call-control{flex-direction:column!important;gap:7px!important;min-height:0!important;padding:0!important;border:0!important;background:none!important;box-shadow:none!important;font-size:11px!important;line-height:1.25!important;transform:none!important}
  .private-call-control svg{box-sizing:content-box;width:22px!important;height:22px!important;padding:16px;border-radius:50%;border:1px solid rgb(var(--accent-rgb)/.28);background:rgb(var(--accent-rgb)/.1);transition:background .15s}
  .private-call-control[aria-pressed=true] svg{background:var(--accent);border-color:var(--accent);color:var(--accent-ink)}
  .private-call-control.private-call-leave{color:var(--text)!important}
  .private-call-control.private-call-leave svg{background:#e5484d;border-color:#e5484d;color:#fff}
  .private-call-grid{display:flex!important;flex-wrap:wrap;justify-content:center;gap:8px!important}
  .private-call-grid[hidden]{display:none!important}
  .private-call-tile{flex:1 1 calc(50% - 8px);max-width:calc(50% - 4px)}
  .private-call-tile:only-child{flex-basis:100%;max-width:260px}
  .private-call-caption{align-items:center!important;text-align:center}

  /* The floating call widget becomes a bar above the tab bar, and steps aside
     while the call's own room is on screen. */
  html[data-call-room-open] .call-dock{display:none!important}
  .call-dock{left:10px!important;right:10px!important;top:auto!important;bottom:calc(var(--tabbar-h) + var(--safe-bottom) + 8px)!important;width:auto!important;max-height:none!important;border-radius:20px!important;z-index:1790!important}
  .call-dock-top{padding:6px 8px 4px!important;border-bottom:0!important}
  .call-dock-grip{font-size:12px!important;font-weight:700}
  .call-dock-return{font-size:12px!important;color:var(--accent)!important}
  .call-dock-minimize{display:none!important}
  .call-dock .private-call-panel{padding:4px 12px 12px!important}
  .call-dock .private-call-status{display:none}
  .call-dock .private-call-grid:not(:has(.private-call-hear:not([hidden]))){display:none!important}
  .call-dock .private-call-actions{max-width:none;margin-top:2px!important}
  .call-dock .private-call-error:not([hidden]){margin:0 0 6px;text-align:center}
  .call-dock .private-call-control svg{padding:11px;width:18px!important;height:18px!important}
  .call-dock .private-call-control{font-size:10px!important}
  /* With a call widget showing, toasts and pop-ups sit above it. */
  body:has(.call-dock:not([hidden])) :is(.toast,.notification-popups){bottom:calc(var(--tabbar-h) + var(--safe-bottom) + 112px)!important}
  html[data-call-room-open] body :is(.toast,.notification-popups){bottom:calc(var(--tabbar-h) + var(--safe-bottom) + 12px)!important}

  /* Incoming call fills the phone screen; answer buttons sit low, in thumb reach. */
  .incoming-call{padding:0}
  .incoming-call-card{width:100%;height:100%;max-width:none;border:0;border-radius:0;padding:calc(var(--safe-top) + 32px) 24px calc(var(--safe-bottom) + 44px);background:radial-gradient(ellipse at 50% 28%,rgb(var(--accent-rgb)/.24),rgb(var(--bg-rgb)/.98) 62%)}
  .incoming-call-pulse{margin-top:auto;width:112px;height:112px}
  .incoming-call-avatar{width:112px;height:112px;font-size:38px}
  .incoming-call-name{font-size:32px}
  .incoming-call-actions{margin-top:auto;gap:56px}
  .incoming-call-circle{width:72px;height:72px}

  /* No zoom-on-focus in iOS Safari; comfortable touch targets. */
  input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=color]),textarea,select{font-size:16px!important}
  button,.community-button,.profile-button{min-height:40px}

  /* Calmer, tighter page headings. */
  .page-intro{margin-bottom:18px!important;gap:12px!important}
  .page-intro h1{font-size:clamp(28px,8.4vw,36px)!important;letter-spacing:-1px!important;line-height:1.08!important;margin:6px 0!important}
  .page-intro p{font-size:13px!important;line-height:1.6!important}
  .community-intro,.admin-intro{flex-direction:column;align-items:flex-start!important}

  /* Games: two big cards per row. */
  .game-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important}

  /* Browser: the page heading gives way to the frame. */
  .browser-page{padding-top:0!important}
  .browser-heading{display:none!important}
  .browser-window{border-radius:14px!important}
  .browser-frame{height:calc(100dvh - var(--mobile-header-h) - var(--tabbar-h) - var(--safe-top) - var(--safe-bottom) - 120px)!important;min-height:320px!important}

  /* Playing a game: it fills the screen; the game toolbar (Back to games,
     Reload, Fullscreen) stays at the top and the tab bar steps aside. */
  body[data-view=browser][data-player=game] .topbar,body[data-view=browser][data-player=game] .page-footer,body[data-view=browser][data-player=game] .mobile-tabbar,body[data-view=browser][data-player=game] .notification-popups{display:none!important}
  body[data-view=browser][data-player=game] main{padding:0!important;min-height:0!important}
  body[data-view=browser][data-player=game] .browser-window{position:fixed!important;inset:0!important;z-index:1450;display:flex!important;flex-direction:column;border:0!important;border-radius:0!important;padding:var(--safe-top) 0 var(--safe-bottom);background:#000}
  body[data-view=browser][data-player=game] .browser-toolbar{flex-shrink:0;padding:6px 8px!important}
  body[data-view=browser][data-player=game] .browser-frame{flex:1;height:auto!important;min-height:0!important}
  body[data-view=browser][data-player=game] :is(.browser-footnote,.browser-welcome){display:none!important}

  /* Chat comes first on the community page; activity follows below. */
  .community-page{display:flex;flex-direction:column}
  .community-page>.community-intro{order:0}
  .community-page>.community-chat-layout{order:1;margin-top:0}
  .community-page>#community-stat-cards{order:2;margin-top:18px}
  .community-page>.community-owners-slot{order:3}
  .community-page>.community-peak-panel{order:4}
  .community-intro p{display:none}
  .community-chat-layout{display:flex!important;flex-direction:column;align-items:stretch!important;gap:12px!important}
  .community-rooms,.community-chat{width:auto!important;max-width:none!important}
  .community-rooms{padding:12px!important}
  .community-page>.community-intro{margin-top:0!important}
  .community-rooms .community-panel-heading{margin-bottom:8px}
  .community-room-list{display:flex!important;flex-direction:row!important;gap:8px;overflow-x:auto;padding-bottom:4px;scrollbar-width:none}
  .community-room-list::-webkit-scrollbar{display:none}
  .community-room-button{flex:0 0 auto;width:auto!important;white-space:nowrap}
  .community-chat{padding:0!important}
  .community-chat-heading{padding:14px 14px 10px!important}
  .community-chat-log{height:min(58dvh,calc(100dvh - 330px))!important;min-height:280px!important;padding:12px 14px!important}
  .community-composer{padding:12px 14px 0!important}
  .community-chat-notice,.community-typing{padding-left:14px!important;padding-right:14px!important}
  .community-chat-footnote{padding:0 14px 14px}
  .community-stats{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important}

  /* Messages, people and profiles. */
  .profile-page-links{display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;gap:8px;overflow-x:auto;scrollbar-width:none}
  .profile-page-links::-webkit-scrollbar{display:none}
  .profile-page-links a{flex:0 0 auto;white-space:nowrap;width:auto!important}
  .social-tabs{display:flex;overflow-x:auto;scrollbar-width:none;flex-wrap:nowrap!important}
  .social-tabs button{flex:0 0 auto;white-space:nowrap}

  /* Settings: two themes per row; owner tables scroll sideways. */
  .theme-grid{grid-template-columns:repeat(2,minmax(0,1fr))!important;gap:10px!important}
  .admin-tabs{overflow-x:auto}
  .admin-table td{padding:9px 8px}
}
/* Phones have no mouse cursor to style. */
@media(hover:none) and (pointer:coarse){.cursor-panel{display:none!important}}
@media(max-width:760px) and (prefers-reduced-motion:reduce){.mobile-sheet-panel{animation:none}}
html.reduce-motion .mobile-sheet-panel{animation:none}
