/* RoamBunny PWA phase 2: phone "native app" feel. Loaded last. Every rule is scoped to touch devices (pointer:coarse) or <=640px, so desktop is unchanged. */
:root{--rb-sat:env(safe-area-inset-top,0px);--rb-sab:env(safe-area-inset-bottom,0px);--rb-sal:env(safe-area-inset-left,0px);--rb-sar:env(safe-area-inset-right,0px)}

/* 1) full-screen: notch / rounded corners / home indicator (landscape side insets; top handled in the header block) */
@media (pointer:coarse){
  html{background-color:#FBF8F1;-webkit-text-size-adjust:100%;text-size-adjust:100%;-webkit-tap-highlight-color:rgba(64,85,56,.14);touch-action:manipulation}
  body{padding-left:var(--rb-sal);padding-right:var(--rb-sar)}
}

/* 2) less "web page": no bounce-white, no double-tap zoom, UI chrome not selectable (body copy stays selectable) */
@media (pointer:coarse),(max-width:640px){
  html,body{overscroll-behavior-y:contain}
  a,button,input,select,textarea,summary,label,[role=button],.btn{touch-action:manipulation}
  header.top,header.top *,.btn,button,summary,[role=button],.story-dots,.story-dots *,.foot-links a,body>.social-row,body>.social-row *,.rb-offline{-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
  header.top input,header.top textarea{-webkit-user-select:text;user-select:text}
}
@media (pointer:coarse){
  button,.btn,select,summary,[role=button],input[type=submit],input[type=button],input[type=search],input[type=text],input[type=email],input[type=password],input[type=tel],input[type=number]{min-height:44px}
  .btn,.foot-links a,.top .nav a,.nav-account a{display:inline-flex;align-items:center;min-height:44px;box-sizing:border-box}
  .btn{justify-content:center}
  button:not(.dest-pin),[role=button]{min-width:44px}
  .dest-pin.pin-muted::after{content:"";position:absolute;inset:-7px}
  .btn,button,.top .nav a,.foot-links a,.mobile-nav-toggle,summary,[role=button]{transition:transform .08s ease,filter .08s ease}
  .btn:active,button:not(:disabled):not(.dest-pin):active,.top .nav a:active,.foot-links a:active,.mobile-nav-toggle:active,summary:active,[role=button]:active{transform:scale(.97);filter:brightness(.93)}
}
@media (pointer:coarse) and (prefers-reduced-motion:reduce){
  .btn:active,button:not(:disabled):not(.dest-pin):active,.top .nav a:active,.foot-links a:active,.mobile-nav-toggle:active,summary:active,[role=button]:active{transform:none}
}

/* 3) scrolling: momentum scroll containers, header that tucks away while reading */
@media (pointer:coarse),(max-width:640px){
  .story-scroll,.story-content,.story-screen .hero,.top .nav.mobile-open,.search-results,.member-dialog{-webkit-overflow-scrolling:touch}
  .top .nav.mobile-open,.search-results,.member-dialog{overscroll-behavior:contain}
}
@media (max-width:640px){
  header.top,.home-story header.top{height:calc(56px + var(--rb-sat))!important;min-height:calc(56px + var(--rb-sat))!important;max-height:calc(56px + var(--rb-sat))!important;padding:calc(4px + var(--rb-sat)) calc(8px + var(--rb-sar)) 4px calc(8px + var(--rb-sal))!important}
  .top .nav.mobile-open,.home-story header.top .nav.mobile-open{top:100%}
  body{overflow-x:clip;overflow-y:visible}
  body:not(.home-story) header.top{position:sticky!important;top:0;z-index:100;background-color:#FBF8F1;transition:transform .24s cubic-bezier(.2,.7,.2,1)}
  body:not(.home-story) header.top.rb-hide{transform:translateY(-100%)}
}
@media (prefers-reduced-motion:reduce){body:not(.home-story) header.top{transition:none}}

/* 4) first-screen skeleton: cream + placeholder blocks until the page script has run (JS adds html.rb-ready; CSS fail-safe after 5s) */
@media (max-width:640px){
  body::before,body::after{content:"";position:fixed;inset:0;pointer-events:none;opacity:1;transition:opacity .25s ease,visibility 0s}
  body::before{z-index:2147483000;background-color:#FBF8F1;background-repeat:no-repeat;
    background-image:radial-gradient(circle,#E9E3D2 0 70%,transparent 72%),linear-gradient(#E9E3D2,#E9E3D2),linear-gradient(#E9E3D2,#E9E3D2),linear-gradient(#E4DECB,#E4DECB),linear-gradient(#EFEADB,#EFEADB),linear-gradient(#EFEADB,#EFEADB),linear-gradient(#EFEADB,#EFEADB),linear-gradient(#EFEADB,#EFEADB),linear-gradient(#E3EBDC,#E3EBDC);
    background-position:10px calc(var(--rb-sat) + 10px),56px calc(var(--rb-sat) + 19px),calc(100% - 8px) calc(var(--rb-sat) + 6px),0 calc(var(--rb-sat) + 56px),14% 34%,22% calc(34% + 40px),10% calc(34% + 92px),10% calc(34% + 116px),5% calc(34% + 160px);
    background-size:36px 36px,124px 18px,44px 44px,100% 1px,72% 26px,56% 26px,80% 14px,64% 14px,90% 50px}
  body::before{animation:rb-skel-failsafe .3s ease 5s forwards}
  body::after{z-index:2147483001;background:linear-gradient(100deg,transparent 30%,rgba(255,255,255,.55) 50%,transparent 70%) 0 0/200% 100% no-repeat;animation:rb-skel-sweep 1.4s linear infinite,rb-skel-failsafe .3s ease 5s forwards}
  html.rb-ready body::before,html.rb-ready body::after{opacity:0;visibility:hidden;transition:opacity .25s ease,visibility 0s .25s}
}
@keyframes rb-skel-sweep{from{background-position:200% 0}to{background-position:-100% 0}}
@keyframes rb-skel-failsafe{to{opacity:0;visibility:hidden}}
@media (prefers-reduced-motion:reduce){body::after{display:none}}

/* 6) offline hint: slim pill, no dialog, never blocks taps */
.rb-offline{position:fixed;z-index:9990;inset-inline-start:max(12px,var(--rb-sal));bottom:calc(var(--social-bar-height,0px) + 10px);box-sizing:border-box;max-width:min(360px,calc(100vw - 112px));padding:8px 14px;border-radius:999px;background:#3c3a33;color:#fff8ec;font:600 13px/1.35 system-ui,-apple-system,"Segoe UI",sans-serif;box-shadow:0 4px 14px rgba(40,36,30,.28);pointer-events:none;opacity:0;visibility:hidden;transform:translateY(8px);transition:opacity .2s ease,transform .2s ease,visibility 0s .2s}
.rb-offline.on{opacity:1;visibility:visible;transform:none;transition:opacity .2s ease,transform .2s ease}
@media (prefers-reduced-motion:reduce){.rb-offline{transition:none}}

/* 7) bottom tab bar: installed-app mode only (pwa-mobile.js sets html.standalone from display-mode standalone|fullscreen|minimal-ui, or iOS navigator.standalone) and phones only (<=560px). The JS also injects the markup and sets html.rb-has-tabbar; in a normal browser tab none of these classes exist, so nothing here applies. z-index: social bar 40 < tab bar 60 < header 100 < chat 9997+. */
.rb-tabbar,html:not(.standalone) .rb-tabbar{display:none}
@media (max-width:560px){
  html.standalone.rb-has-tabbar{--rb-tab-h:60px;--rb-tab-total:calc(var(--rb-tab-h) + var(--rb-sab));--social-bar-height:60px}
  html.standalone.rb-has-tabbar body{padding-bottom:var(--rb-tab-total)}
  html.standalone.rb-has-tabbar body:not(.home-story):has(>.social-row){padding-bottom:calc(var(--rb-tab-total) + var(--social-bar-height))}
  html.standalone.rb-has-tabbar body:not(.home-story)>.social-row{bottom:var(--rb-tab-total)}
  html.standalone.rb-has-tabbar body #rb-chat-toggle{bottom:calc(var(--rb-tab-total) + 12px)}
  html.standalone.rb-has-tabbar body #rb-chat-bubble{bottom:calc(var(--rb-tab-total) + 102px)}
  html.standalone.rb-has-tabbar body:has(>.social-row) #rb-chat-toggle{bottom:calc(var(--rb-tab-total) + var(--social-bar-height) + 8px)}
  html.standalone.rb-has-tabbar body:has(>.social-row) #rb-chat-bubble{bottom:calc(var(--rb-tab-total) + var(--social-bar-height) + 98px)}
  html.standalone.rb-has-tabbar #reward-sync-status{bottom:calc(var(--rb-tab-total) + 88px)!important;left:12px!important;max-width:calc(100vw - 24px)!important}
  html.standalone.rb-has-tabbar #reward-toast{bottom:calc(var(--rb-tab-total) + 88px)!important;right:12px!important}
  html.standalone.rb-has-tabbar body:has(>.social-row) #reward-sync-status,html.standalone.rb-has-tabbar body:has(>.social-row) #reward-toast{bottom:calc(var(--rb-tab-total) + var(--social-bar-height) + 88px)!important}
  html.standalone.rb-has-tabbar .rb-offline{bottom:calc(var(--rb-tab-total) + var(--social-bar-height) + 10px)}

  html.standalone.rb-has-tabbar .rb-tabbar{display:flex;position:fixed;inset-inline:0;bottom:0;z-index:60;box-sizing:border-box;height:var(--rb-tab-total);padding:0 var(--rb-sar) var(--rb-sab) var(--rb-sal);background:#FBF8F1;border-top:1px solid #d9d3bf;box-shadow:0 -3px 12px rgba(40,36,30,.07);-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}
  .rb-tabbar a{position:relative;flex:1 1 0;min-width:0;min-height:48px;box-sizing:border-box;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;padding:6px 2px 4px;color:#5b6755;text-decoration:none;-webkit-tap-highlight-color:transparent;transition:background-color .08s ease}
  .rb-tabbar a:active{background-color:rgba(64,85,56,.14)}
  .rb-tabbar a:focus-visible{outline:3px solid #4468ab;outline-offset:-3px}
  .rb-tabbar svg{display:block;flex:none;width:24px;height:24px;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round}
  .rb-tabbar span{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font:600 11px/1.2 system-ui,-apple-system,"Segoe UI",sans-serif}
  .rb-tabbar a[aria-current=page]{color:#405538}
  .rb-tabbar a[aria-current=page] svg{stroke-width:2.2}
  .rb-tabbar a[aria-current=page] span{font-weight:750}
  .rb-tabbar a[aria-current=page]::before{content:"";position:absolute;top:0;left:50%;width:28px;height:3px;margin-left:-14px;border-radius:0 0 3px 3px;background:#405538}
  html.rb-kbd .rb-tabbar{display:none}

  /* the four tabs replace these header links; hamburger keeps Manage, Forum, About, search and language */
  html.standalone.rb-has-tabbar .top .nav>a.rb-dup,
  html.standalone.rb-has-tabbar .top .nav-account>a{display:none!important}
}
@media print{.rb-tabbar{display:none!important}}
