/* Phones, laid out the way the big apps do it (ChatGPT and Claude are the reference): one slim header with the
   menu, the logo or the chat's title and one action; a drawer that holds everything else; a compact box;
   answers that use the full width; sheets that rise from the bottom. Wide screens are unchanged.
   Loaded last on the app's pages (home and its chats, My worlds, Pricing). */

/* only phones show these (side.js and tabbar.js add them) */
.side-top,.side-pages,.side-extra,.nav-new,.tabbar,.feed{display:none}

/* ---------- tablets and phones: the drawer is the whole menu ---------- */
@media (max-width:900px){
  a,button,summary{-webkit-tap-highlight-color:transparent}
  .nav{padding-top:env(safe-area-inset-top)}
  .side-in{gap:6px;padding-left:10px;padding-right:10px}
  .side-list{overscroll-behavior:contain}
  .side-top{display:flex;align-items:center;justify-content:space-between;height:44px;padding:0 0 0 8px}
  .side-top .brand .wm{font-size:22px;letter-spacing:-1.1px}
  .side-close{width:42px;height:42px;margin-right:-4px;border:0;border-radius:12px;display:grid;place-items:center;background:transparent;color:var(--muted);cursor:pointer}
  .side-close:hover,.side-close:active{background:var(--hover);color:var(--ink)}
  .side-close svg{width:20px;height:20px}
  .side-new{height:46px;margin-top:6px;border-radius:14px;font-size:15px;gap:12px}
  .side-new svg{width:19px;height:19px}
  .side-pages{display:grid;gap:2px;padding:6px 0 10px;border-bottom:1px solid var(--line)}
  .side-pages a,.side-theme,.side-discord{display:flex;align-items:center;gap:12px;height:44px;padding:0 12px;border:0;border-radius:12px;background:transparent;
    color:var(--ink);font:500 15px/1 var(--font);text-decoration:none;text-align:left;cursor:pointer;transition:background .15s}
  .side-pages a:hover,.side-theme:hover,.side-discord:hover,.side-pages a:active,.side-theme:active,.side-discord:active{background:var(--hover)}
  .side-pages a[aria-current="page"]{background:var(--chip);font-weight:600}
  .side-pages svg,.side-theme svg,.side-discord svg{flex:none;width:19px;height:19px;color:var(--muted)}
  .side-pages a[aria-current="page"] svg{color:var(--ink)}
  .side-discord svg{width:18px;height:18px}
  .side-group{margin:16px 12px 4px;font-size:12.5px}
  .side-group:first-child{margin-top:12px}
  .side-item{height:44px;border-radius:12px}
  .side-item a{line-height:44px;font-size:15px}
  .side-more{top:8px}
  .side-extra{display:grid;gap:2px;padding:8px 0 4px;border-top:1px solid var(--line)}
  .side.signed-in .side-foot{padding-top:4px;box-shadow:none}
  .side-me{height:56px;padding:0 8px}
  .me-av{width:34px;height:34px;font-size:14px}
  .me-name{font-size:15px}
  .side-account{margin-top:4px}
  .side-signin{height:42px;font-size:14.5px;border-radius:12px}
  .side-item input{font-size:16px}
}

/* ---------- phones ---------- */
@media (max-width:640px){
  /* the header: the menu, then the logo (or in a chat, its title), then one action */
  .nav-in{height:56px;padding:0 12px;gap:8px}
  .nav .theme-switch,.nav .icon-link{display:none}
  .side-toggle{width:42px;height:42px;margin-left:-8px;border-radius:12px;color:var(--ink)}
  .side-toggle svg{width:21px;height:21px}
  .brand .wm{font-size:21px;letter-spacing:-1px}
  .nav .g-btn{height:36px;padding:0 13px 0 11px;gap:8px;font-size:14px}
  .nav .g-btn .g-logo{width:16px;height:16px}
  .nav-new{display:grid;place-items:center;width:42px;height:42px;margin-right:-8px;border:0;border-radius:12px;background:transparent;color:var(--ink);cursor:pointer}
  .nav-new:active{background:var(--hover)}
  .nav-new svg{width:21px;height:21px}
  body:not(.in-chat) .nav-new{display:none}
  body.in-chat #signin{display:none!important}
  body.in-chat .nav-left .brand{visibility:hidden}
  body.in-chat .chat-bar{position:fixed;top:env(safe-area-inset-top);left:52px;right:56px;z-index:51;height:56px;padding:0;background:none;pointer-events:none}
  body.in-chat .chat-bar>*{pointer-events:auto}
  body.in-chat .chat-bar::after{display:none}
  .chat-title{font-size:16px;font-weight:600}
  .live-pill{margin-left:8px}

  /* home: the question, then a compact box with the photo button and a round send button, as in the apps */
  .top-in{padding:40px 16px 30px;gap:24px}
  .top h1{font-size:33px;line-height:1.1;letter-spacing:-1.2px}
  .ask:not(.in-chat){grid-template-columns:auto minmax(0,1fr) auto;gap:8px 10px;padding:10px 10px 10px 12px;border-radius:26px}
  .ask:not(.in-chat) .ask-text{grid-column:1 / -1}
  .ask:not(.in-chat) textarea{min-height:54px;padding:6px 4px 0;font-size:17px}
  .ask-add{width:40px;height:40px;border-radius:50%}
  .ask-add svg{width:19px;height:19px}
  .ask:not(.in-chat) .ask-go{grid-column:3;grid-row:2;width:40px;height:40px;padding:0;border-radius:50%}
  .ask .go-label{display:none}
  .ask:not(.in-chat) .ask-go svg,.ask:not(.in-chat) .ask-go:hover svg{width:18px;height:18px;transform:rotate(-90deg)}

  /* home fills the screen: the question and the box take the middle, the worlds sit just above the bar */
  body:not(.in-chat) .main:has(> .top){display:flex;flex-direction:column;min-height:calc(100dvh - 56px - env(safe-area-inset-top))}
  body:not(.in-chat) .main:has(> .top)>.top{flex:1;display:grid;align-content:center}
  /* the worlds: a swipe of cards; the name and its button under each */
  .gallery{padding:0 16px 18px}
  .gallery-head{min-height:0;margin-bottom:14px}
  .shelf-title{font-size:17px;font-weight:800;letter-spacing:-.2px}
  .grid{grid-auto-columns:80%;gap:12px;margin:-12px -16px -30px;padding:12px 16px 30px;scroll-padding-inline:16px}
  .tpl{gap:10px}
  .tpl-card{border-radius:20px}
  /* worlds: small portrait cards, about two and a half to a screen */
  .grid.has-world{grid-auto-columns:128px;gap:10px}
  .grid:empty:not(.loaded){min-height:284px}
  .tpl.world{gap:8px}
  .tpl.world .tpl-card{border-radius:16px}
  .tpl.world .tpl-meta b{font-size:14.5px}
  .tpl.world .tpl-meta .pc-btn{font-size:12.5px}
  /* no website footer in an app: its links live in Profile (tabbar.js) */
  .site-foot{display:none}
  .sheet-legal{display:flex;justify-content:center;flex-wrap:wrap;gap:6px 18px;margin-top:18px}
  .sheet-legal a{color:var(--muted);font-size:13px;text-decoration:none}
  .sheet-legal a:active{color:var(--ink)}

  /* a chat: answers use the whole width; the box is one slim line until it grows */
  .thread{padding:8px 16px 20px;gap:24px}
  .turn{gap:0}
  .turn.ai .ai-av{display:none}
  .ai-body{gap:12px}
  .said{max-width:85%;padding:10px 15px;border-radius:20px 20px 6px 20px;font-size:15.5px}
  .ai-text{font-size:15.5px;line-height:1.55}
  .world{gap:12px}
  .wf,.world-frame,.world-shot{border-radius:16px}
  .wf-track{gap:8px}
  .wf-step{gap:6px;font-size:11.5px}
  .world-acts{display:grid;grid-template-columns:1fr 1fr;width:100%;gap:8px}
  .world-acts .pc-btn{justify-content:center;height:46px;border-radius:14px;font-size:15px}
  .world-info .need-chip{height:36px;font-size:13.5px}
  .composer{padding:6px 12px calc(10px + env(safe-area-inset-bottom));background:linear-gradient(transparent,var(--bg) 16px)}
  .ask.in-chat{grid-template-columns:auto minmax(0,1fr) auto;align-items:end;gap:6px;padding:6px;border-radius:26px}
  .ask.in-chat .ask-text{grid-column:1 / 3;grid-row:1;align-self:center;padding-left:10px}
  .ask.in-chat textarea{min-height:24px;max-height:140px;padding:9px 4px 8px;font-size:16px;line-height:1.4}
  .ask.in-chat .ask-add{grid-column:1;grid-row:1}
  .ask.in-chat .ask-go{grid-column:3;grid-row:1;width:40px;height:40px}
  .ask .ai-low{padding-top:8px}
  /* the questions: a compact card above the box, scrolling inside if it's long */
  .qs{display:flex;flex-direction:column;max-height:min(52vh,430px);margin:0 0 8px;border-radius:20px}
  .qs-head{flex:none;padding:6px 8px 6px 16px}
  .qs-body{min-height:0;overflow-y:auto;overscroll-behavior:contain;padding:12px 8px 2px}
  .qs-q{margin:0 8px 8px;font-size:15.5px}
  .qs-opt{min-height:50px}
  .qs-own input{height:40px;font-size:16px}
  .qs-foot{flex:none;padding:6px 10px 10px}
  .pop-row input{font-size:16px}
  .toast{bottom:calc(92px + env(safe-area-inset-bottom))}

  /* sheets rise from the bottom, with a handle, and their buttons stack full width */
  .sheet,.sheet.wide,.ai-usage-sheet{width:100%;max-width:none;max-height:calc(100dvh - 48px);margin:auto 0 0;overflow-y:auto;
    padding:10px 20px calc(18px + env(safe-area-inset-bottom));border:0;border-radius:24px 24px 0 0;box-shadow:0 -24px 60px -24px rgba(0,0,0,.5)}
  .sheet[open],.ai-usage-sheet[open]{animation:sheet-up .42s cubic-bezier(.32,.72,0,1) both}
  .sheet::before,.ai-usage-sheet::before{content:"";display:block;width:36px;height:5px;margin:0 auto 18px;border-radius:3px;background:var(--line-strong)}
  .sheet h2{font-size:20px}
  .sheet p{margin-bottom:18px}
  .sheet-btns{flex-direction:column-reverse;gap:8px}
  .sheet-btns button,.sheet-btns .sheet-link,.sheet-btns .g-btn{width:100%;height:50px;justify-content:center;border-radius:14px;font-size:15.5px}
  .sheet-btns .ghost-danger{margin-right:0}
  .link-box{margin:0 0 16px}
  .link-box input{height:48px;font-size:16px}
  .link-box button{height:48px;padding:0 18px}

  /* My worlds and Pricing: phone margins */
  .dash-in{padding:20px 16px 80px}
  .dash-head{padding-bottom:16px}
  .dash-head .cta-btn{height:40px;padding:0 16px;font-size:14.5px}
  .inv-grid{gap:22px 12px;margin-top:20px}
  .pr-hero{padding:40px 16px 28px}
  .pr-hero h1{font-size:38px}
  .plans{padding-inline:16px}
  .faq{padding:64px 16px 72px}
  .faq summary{padding:18px 2px;font-size:16px}
  .cx{padding:0 16px;margin-bottom:56px}
  .cx-in{border-radius:28px}
}
@keyframes sheet-up{from{transform:translateY(100%)}to{transform:none}}

/* ---------- phones: the bar along the bottom, as on Astrocade (tabbar.js) ---------- */
@media (max-width:640px){
  .tabbar{--tab-bg:var(--bg);position:fixed;left:0;right:0;bottom:0;z-index:85;display:grid;grid-template-columns:repeat(5,minmax(0,1fr));align-items:center;
    height:calc(64px + env(safe-area-inset-bottom));padding:0 4px env(safe-area-inset-bottom);background:var(--tab-bg);box-shadow:0 -1px 0 var(--line)}
  body.in-chat .tabbar{display:none}
  /* with Profile in the bar, the header doesn't need its own sign-in button, as on Astrocade */
  body.has-tabbar .nav #signin{display:none!important}
  body.has-tabbar:not(.in-chat) .main{padding-bottom:calc(64px + env(safe-area-inset-bottom))}
  body.has-tabbar:not(.in-chat) .toast{bottom:calc(80px + env(safe-area-inset-bottom))}
  .tab{display:grid;justify-items:center;align-content:center;gap:4px;height:64px;padding:0;border:0;background:none;color:var(--muted);
    font:600 11.5px/1 var(--font);letter-spacing:.01em;text-decoration:none;cursor:pointer;-webkit-tap-highlight-color:transparent;transition:color .2s}
  .tab-ico{position:relative;width:24px;height:24px;transition:transform .15s}
  .tab-ico svg{position:absolute;inset:0;width:24px;height:24px;transition:opacity .2s}
  .tab-ico svg+svg{opacity:0}
  .tab[aria-current="page"]{color:var(--ink)}
  .tab[aria-current="page"] .tab-ico svg:first-child{opacity:0}
  .tab[aria-current="page"] .tab-ico svg+svg{opacity:1}
  .tab:active .tab-ico{transform:scale(.88)}
  .tab-label{white-space:nowrap}
  .tab-play{justify-items:center}
  .tab-disc{position:relative;width:48px;height:48px;border-radius:15px;display:grid;place-items:center;background:var(--ink);color:var(--tab-bg);
    box-shadow:0 8px 20px -8px rgba(0,0,0,.45);transition:transform .15s}
  .tab-play:active .tab-disc{transform:scale(.92)}
  .tab-disc svg{position:absolute;width:24px;height:24px;transition:opacity .2s,transform .3s cubic-bezier(.2,.8,.2,1)}
  .tab-disc .tab-mark{width:auto;height:22px;margin-left:1px}
  .tab-disc svg+svg{opacity:0;transform:translateY(-6px)}
  /* signed in, Profile is your initial */
  .tab-face{position:absolute;inset:1px;border-radius:50%;display:none;place-items:center;background:var(--btn-bg);color:var(--btn-fg);font:700 11.5px/1 var(--font)}
  .tab.has-face .tab-face{display:grid}
  .tab.has-face .tab-ico svg{opacity:0!important}
  body.feed-open .tab-disc svg:first-child{opacity:0;transform:scale(.6)}
  body.feed-open .tab-disc svg+svg{opacity:1;transform:none}
  /* over the feed the bar goes dark with it */
  body.feed-open .tabbar{--tab-bg:#0C0E12;--ink:#F3F4F6;--muted:rgba(243,244,246,.55);box-shadow:none}
  /* the account rises above the bar, full width */
  .account-menu.up{left:8px!important;right:8px!important;width:auto!important;bottom:calc(72px + env(safe-area-inset-bottom))!important;border-radius:18px}
  body:not(.has-tabbar) .account-menu.up,body.in-chat .account-menu.up{bottom:calc(12px + env(safe-area-inset-bottom))!important}

  /* Play: the live worlds, one to a screen, swiped up and down */
  .feed{position:fixed;inset:0;z-index:84;display:block;background:#0C0E12;color:#F3F4F6;opacity:0;visibility:hidden;transition:opacity .25s,visibility 0s .25s}
  body.feed-open .feed{opacity:1;visibility:visible;transition:opacity .25s}
  body.feed-open{overflow:hidden}
  .feed-list{position:absolute;inset:0 0 calc(64px + env(safe-area-inset-bottom));overflow-y:auto;scroll-snap-type:y mandatory;overscroll-behavior:contain;scrollbar-width:none}
  .feed-list::-webkit-scrollbar{display:none}
  .feed-item{height:100%;scroll-snap-align:start;scroll-snap-stop:always;display:grid;grid-template-rows:minmax(0,1fr) auto;justify-items:center;align-items:center;gap:16px;
    padding:calc(60px + env(safe-area-inset-top)) 16px 14px}
  .feed-card{position:relative;display:block;width:min(100%,calc((100dvh - 64px - 270px) * .8));aspect-ratio:4/5;border-radius:22px;overflow:hidden;background:#16141D;
    box-shadow:0 0 0 1px rgba(255,255,255,.06),0 30px 60px -30px rgba(0,0,0,.9)}
  .feed-card img,.feed-card video{position:absolute;inset:0;width:100%;height:100%;object-fit:cover;display:block}
  .feed-card video{opacity:0;transition:opacity .35s}
  .feed-card video.on{opacity:1}
  .feed-card .world-badge{position:absolute;top:12px;left:12px;z-index:1;display:inline-flex;align-items:center;gap:6px;height:26px;padding:0 10px;border-radius:999px;
    background:rgba(20,24,20,.52);-webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px);color:#fff;font:600 11.5px/1 var(--font)}
  .feed-card .world-badge i{width:7px;height:7px;border-radius:50%;background:#7BD88F;box-shadow:0 0 0 3px rgba(123,216,143,.22)}
  .feed-info{width:min(100%,520px);display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:12px}
  .feed-who{display:grid;gap:3px;min-width:0}
  .feed-who b{font-size:18px;font-weight:650;letter-spacing:-.2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .feed-who span{font-size:13.5px;color:rgba(243,244,246,.6)}
  .feed-share{width:44px;height:44px;border:0;border-radius:50%;display:grid;place-items:center;background:rgba(255,255,255,.1);color:#F3F4F6;cursor:pointer;transition:background .2s}
  .feed-share svg{width:19px;height:19px}
  .feed-share.done{background:#3FA34D}
  .feed-enter{grid-column:1 / -1;display:grid;place-items:center;height:50px;border-radius:14px;background:#F3F4F6;color:#111;font:600 15.5px/1 var(--font);text-decoration:none}
  .feed-enter:active{transform:scale(.98)}
  .feed-x{position:absolute;top:calc(10px + env(safe-area-inset-top));right:12px;width:42px;height:42px;border:0;border-radius:50%;display:grid;place-items:center;
    background:rgba(255,255,255,.1);color:#F3F4F6;cursor:pointer}
  .feed-x svg{width:20px;height:20px}
}
@media (max-width:640px) and (prefers-reduced-motion: reduce){
  .feed,.tab-disc svg,.tab-ico svg{transition:none}
}

@media (max-width:640px) and (prefers-reduced-motion: reduce){
  .sheet[open],.ai-usage-sheet[open]{animation:none}
}
