/* Phones and small tablets, plus the "lite" graphics tiers. Loaded last so it wins over the desktop rules.
   Phone layout: floating orb, a bottom tab bar (Home / Today / Projects / Chat / Menu), big touch targets, no hover-only controls. */

html{-webkit-text-size-adjust:100%}
*{-webkit-tap-highlight-color:transparent}
button,.icon,.btn,select,summary{touch-action:manipulation}

/* ---------- lite graphics: no blur filters, no glow animation (they are what makes a phone hot) ---------- */
body.lite .panel,body.lite #composer,body.lite #talkBtn,body.lite #kbBtn,body.lite #gearBtn,body.lite .sc,body.lite #tip,body.lite #ideas,body.lite #tabbar{backdrop-filter:none!important;-webkit-backdrop-filter:none!important}
body.lite #talkBtn.on{animation:none;box-shadow:0 0 0 3px rgba(var(--st-rgb),.5)}
body.lite .avatar *,body.lite .avatar{animation:none!important}
body.lite #ideasSvg .float,body.lite #ideasSvg .halo{animation:none}
body.lite #foot .bar i{filter:none}
body.saver *{transition-duration:.01s!important}

/* tab bar only exists on phones */
#tabbar{display:none}

@media (max-width:700px),(pointer:coarse) and (max-width:900px){
  body{font-size:16px}
  /* ----- bottom tab bar ----- */
  #tabbar{display:flex;position:fixed;left:0;right:0;bottom:0;z-index:9;height:calc(58px + env(safe-area-inset-bottom));padding:0 4px env(safe-area-inset-bottom);background:rgba(6,12,34,.96);border-top:1px solid rgba(var(--st-rgb),.28)}
  #tabbar button{flex:1;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;border:0;background:none;color:#8da2cf;font:600 10.5px/1 "Segoe UI",system-ui,sans-serif;letter-spacing:.8px;text-transform:uppercase;cursor:pointer;min-width:0;position:relative}
  #tabbar button svg{width:22px;height:22px;stroke:currentColor;fill:none;stroke-width:1.7;stroke-linecap:round;stroke-linejoin:round}
  #tabbar button.active{color:var(--st)}
  #tabbar button.active::before{content:"";position:absolute;top:0;left:30%;right:30%;height:2px;border-radius:2px;background:var(--st);box-shadow:0 0 10px rgba(var(--st-rgb),.8)}

  /* ----- top: name on the left, ear / speaker / diagram on the right ----- */
  body.view-home #topbar,body.view-proj #topbar{top:max(8px,env(safe-area-inset-top));right:8px;gap:4px;align-items:center}
  body.view-home #views button:not(#ideasBtn),body.view-proj #views button:not(#ideasBtn),body.view-chat #views button:not(#ideasBtn){display:none}
  body.view-home #topbar .icon,body.view-proj #topbar .icon{display:none}
  body.view-home #earBtn,body.view-home #ttsBtn,body.view-proj #earBtn,body.view-proj #ttsBtn,body.view-home #bell,body.view-proj #bell{display:inline-flex!important;align-items:center;justify-content:center;width:42px;height:42px;padding:0;border-radius:50%;border:1px solid rgba(var(--st-rgb),.3);background:rgba(8,16,44,.7)}
  body.view-home #bell,body.view-proj #bell{display:none!important}
  body.hud #topbar #earBtn,body.hud #topbar #ttsBtn{color:#e6ebff;opacity:1}
  body.hud #topbar #earBtn[aria-pressed=true],body.hud #topbar #ttsBtn[aria-pressed=true]{background:var(--st);color:#07101f}
  body #views #ideasBtn{padding:0 16px;height:42px;font-size:12px;letter-spacing:1px;border-radius:21px;border:1px solid rgba(var(--st-rgb),.5);background:rgba(8,16,44,.7);color:var(--st)}
  body #views #ideasBtn.active{background:var(--st);color:#07101f}
  body.view-home .brand{top:max(14px,calc(env(safe-area-inset-top) + 6px));left:14px}
  body.view-home .brand b{font-size:17px;letter-spacing:5px}
  body.view-home #stageInfo{top:max(54px,calc(env(safe-area-inset-top) + 46px));left:14px;width:calc(100vw - 28px)}
  #stageInfo #stage-caption small{display:block;margin:4px 0 0;font-size:12px}
  #subtitle{font-size:15px;max-height:28vh}
  body.view-home #legend{display:none!important}
  #stats,#stageClock{display:none!important}
  #foot{display:none!important}
  /* orb sits in the visual centre between the caption and the buttons */
  body.view-home #orbWrap,body.view-proj #orbWrap{bottom:calc(58px + env(safe-area-inset-bottom))}

  /* ----- buttons above the tab bar ----- */
  #talkBtn,#kbBtn{bottom:calc(74px + env(safe-area-inset-bottom))!important}
  #talkBtn{width:68px;height:68px;transform:translateX(-72px)!important}
  #kbBtn{width:50px;height:50px;transform:translateX(8px)!important;left:50%!important}
  body.view-proj #talkBtn{left:16px!important;transform:none!important}
  body.view-proj #kbBtn{left:96px!important;transform:none!important}
  #gearBtn{display:none!important}
  #heardLine{bottom:calc(158px + env(safe-area-inset-bottom));font-size:18px;max-width:88vw}
  body.view-home #jobs,body.view-proj #jobs{left:10px;right:10px;width:auto;bottom:calc(150px + env(safe-area-inset-bottom));max-height:34vh;overflow-y:auto}
  body.view-home.typing #composer,body.view-proj.typing #composer{left:8px;right:8px;width:auto;transform:none;bottom:calc(66px + env(safe-area-inset-bottom))}
  body.typing #tabbar{display:flex}

  /* ----- Today page: the side panels become a full screen list ----- */
  body.view-today #app{position:absolute;inset:0;overflow-y:auto;z-index:1}
  body.view-today #hudL{display:flex!important;position:static;width:100%;flex:none;padding:calc(max(14px,env(safe-area-inset-top)) + 8px) 12px calc(80px + env(safe-area-inset-bottom));gap:12px}
  body.view-today #hudR,body.view-today main,body.view-today #orbWrap,body.view-today #stageInfo,body.view-today #talkBtn,body.view-today #kbBtn,body.view-today #topbar,body.view-today .brand{display:none!important}
  body.view-today #hudL .panel:nth-child(2){order:-1}
  body.view-today #hudL .panel.grow{flex:none}
  body.view-today #todayList{max-height:none;min-height:60px}
  body.view-today #telemetry{max-height:40vh}
  body.view-today .panel{font-size:14px}

  /* ----- Transcript ----- */
  body.view-chat #app{padding-bottom:calc(58px + env(safe-area-inset-bottom))}
  body.view-chat header#topbar{position:sticky;top:0;z-index:7;padding-top:max(8px,env(safe-area-inset-top));background:rgba(6,12,34,.96)}
  body.view-chat #menu{display:inline-flex}
  body.view-chat .brand{display:block}
  body.view-chat #orbWrap{height:clamp(84px,13vh,120px)}
  body.view-chat #gearBtn{display:none!important}
  #messages{padding:10px 10px 6px}
  .msg{max-width:94%;font-size:16px}
  #composer{padding:8px 8px 10px;gap:4px;align-items:center}
  #composer .icon{width:42px;height:42px;padding:0;display:inline-flex;align-items:center;justify-content:center}
  #composer #liveBtn{display:none}
  #input{font-size:16px;line-height:22px;min-height:42px;max-height:120px;padding:10px 14px;border-radius:21px;overflow-y:auto;scrollbar-width:none}
  #input::-webkit-scrollbar{display:none}
  #input::placeholder{text-transform:none;letter-spacing:0}
  body.view-chat .brand span{display:none}
  body.view-chat .brand b{font-size:17px;letter-spacing:5px}
  body.view-chat #topbar #views,body.view-chat #topbar #objective,body.view-chat #topbar #clock,body.view-chat #topbar #chipsTop{display:none}
  body.view-chat #topbar{gap:4px}
  body.view-chat #topbar .spacer{flex:1;display:block}
  .icon{min-width:40px;min-height:40px}
  .btn{min-height:42px}
  .job .btn{min-height:40px;padding:6px 16px}

  /* ----- menu sheet (chats, memory, devices, more) ----- */
  body.hud #side{position:fixed;inset:0;left:0;top:0;bottom:0;right:0;width:100%;z-index:30;background:#070b22!important;padding:calc(max(10px,env(safe-area-inset-top)) + 4px) 12px calc(12px + env(safe-area-inset-bottom));box-shadow:none}
  #app:has(#side:not(.closed)){z-index:40!important}
  body.hud #side.closed{display:none}
  #side .tabs button{padding:12px 6px;font-size:15px}
  .item{padding:12px 10px}
  #sideSettings{display:inline-flex!important}

  /* ----- settings becomes a bottom sheet ----- */
  #settingsPanel{left:8px!important;right:8px!important;width:auto!important;bottom:calc(66px + env(safe-area-inset-bottom))!important;max-height:72dvh!important}
  #settingsPanel select,#settingsPanel input{font-size:16px}

  /* ----- projects: a plain scrolling page, one panel under another ----- */
  body.view-proj #stageInfo,body.view-proj #orbWrap,body.view-proj #talkBtn,body.view-proj #kbBtn,body.view-proj #topbar #earBtn,body.view-proj #topbar #ttsBtn,body.view-proj #stats,body.view-proj .brand{display:none!important}
  body.view-proj #app{z-index:2}
  body.view-proj #board{display:block;position:absolute;inset:0;overflow-y:auto;overflow-x:hidden;pointer-events:auto;padding:calc(max(10px,env(safe-area-inset-top)) + 8px) 12px calc(86px + env(safe-area-inset-bottom));-webkit-overflow-scrolling:touch}
  body.view-proj #boardHead{position:static!important;transform:none!important;display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:8px;margin:0 0 10px;padding:0}
  body.view-proj #projSel{font-size:22px;max-width:100%;width:100%;text-align:center;padding:4px 0}
  body.view-proj #boardHead select,body.view-proj #boardHead .set{min-height:40px;font-size:14px}
  body.view-proj #projReset{display:none}
  body.view-proj #boardGrid{position:static;inset:auto;display:flex;flex-direction:column;gap:12px;pointer-events:auto}
  body.view-proj #boardGrid .bp{position:relative;left:auto;top:auto;width:auto;height:auto;min-height:190px;max-height:55vh;margin:0}
  body.view-proj .bp textarea{min-height:150px}
  body.view-proj #boardLinks{display:none}
  /* ----- diagram: full screen, scrolls sideways so the text stays readable ----- */
  #ideas{left:0;top:0;transform:none;width:100vw;height:calc(100dvh - 58px - env(safe-area-inset-bottom));border-radius:0;z-index:25;overflow:auto;animation:none}
  #ideas header{position:sticky;left:0;top:0;z-index:2;padding-top:max(10px,env(safe-area-inset-top));background:rgba(4,10,30,.96)}
  #ideas{background:#050b22}
  #ideasSvg{flex:none;width:max(100%,var(--minw,820px));height:auto}
  body.ideas-open #talkBtn,body.ideas-open #kbBtn{display:none!important}
  #ideasKey{display:none}
  body.ideas-open #topbar{visibility:hidden}

  #tip{display:none!important}   /* no hover on a touch screen */
  #toast{top:calc(env(safe-area-inset-top) + 56px)}
  dialog{max-width:calc(100vw - 24px)}
}

/* very small phones */
@media (max-width:360px){#tabbar button{font-size:9.5px;letter-spacing:.4px}body.view-home .brand b{font-size:15px;letter-spacing:4px}}
/* landscape phones: keep the buttons clear of the orb */
@media (max-height:480px) and (orientation:landscape){#talkBtn,#kbBtn{bottom:calc(66px + env(safe-area-inset-bottom))!important}#stageInfo{width:42vw!important}#heardLine{bottom:calc(120px + env(safe-area-inset-bottom))}}
/* wide screens: the side panels stop above the XP line and the settings button */
@media (min-width:1051px){body.view-home .hudcol{padding-bottom:96px!important}}
