/* mobile-fill: phone fixes for the Match Room and the Atlas. Add-on only, loaded last.
   Every rule lives in the phone query: width up to 820px, or a phone turned sideways (short and not wide).
   Desktop is untouched. js/mobile-fill.js adds attributes, a few helper classes and the landscape copy of the room's own
   820px rules; ?classic=1 turns both files off. */

/* ---- loading line: shows from the first paint, goes the moment room.js draws anything into #stage ---- */
@media (max-width:820px),(orientation:landscape) and (max-height:500px) and (max-width:950px){
  #stage:empty::before{content:"Loading the room…";display:block;padding:28px 16px;color:var(--text-muted);font:500 14px var(--font-body)}
  #stage:empty{min-height:80px}
}

@media (max-width:820px),(orientation:landscape) and (max-height:500px) and (max-width:950px){
  :root{--topbar-h:52px;--text-muted:#979797;--mfx-sab:env(safe-area-inset-bottom,0px)}
  html{-webkit-text-size-adjust:100%}

  /* ---------- 13. fields never under 16px, so iPhones do not zoom on focus ---------- */
  input:not(.gf-game *),textarea:not(.gf-game *),select:not(.gf-game *),.code-in,.frm input,.frm select,.composer input,.h-modal-card input{font-size:16px!important}

  /* ---------- 16. touch behaviour and contrast ---------- */
  button:not(.gf-game *),[role=button]:not(.gf-game *),a:not(.gf-game *),select:not(.gf-game *),summary:not(.gf-game *),label:not(.gf-game *),input[type=checkbox]:not(.gf-game *),input[type=radio]:not(.gf-game *),.react,.tcard,.lb-row{touch-action:manipulation}
  .chans,.roster{touch-action:pan-y;padding-bottom:calc(12px + var(--mfx-sab))}
  /* the rent sheet (rally.css) is a bottom sheet on phones: keep its last row off the home indicator */
  .rl-sheet{padding-bottom:var(--mfx-sab)}

  /* ---------- 11 + 12. top bar: one row on both pages ---------- */
  .topbar{height:52px;flex-wrap:nowrap;padding:0 8px;gap:6px;align-items:center;overflow:visible}
  .topbar .nav-btn{order:1;width:44px;height:44px}
  .topbar .logo{order:2;flex:none;padding:0}
  .topbar .tabs{order:3;margin:0;flex:none;padding:3px;gap:8px}
  .topbar .tab{min-height:40px;padding:0 12px;position:relative}
  .topbar .tab::before{content:"";position:absolute;inset:-4px -4px}
  .topbar .spin-cd{order:4;flex:1 1 0;min-width:0;margin:0;min-height:44px;justify-content:center;overflow:hidden;padding:0 8px;white-space:nowrap}
  .topbar .who{order:5;flex:none;margin-left:auto;gap:8px}
  .topbar .mem-btn{order:6}
  /* ---- the one-row bar is pinned, so no other stylesheet can wrap it or push a child off screen.
     Other builds add their own line-break tricks to the bar (a 100%-wide ::before or ::after item, row-gap, order, flex-basis:100%,
     auto margins). Pinned here with !important: the bar is a nowrap row; no pseudo-element of the bar takes part in layout;
     the bar's children have no vertical margins, a basis of auto (except the spin chip), fixed order and no auto margins (except Account, which sits right). ---- */
  .topbar{display:flex!important;flex-direction:row!important;flex-wrap:nowrap!important;row-gap:0!important;column-gap:6px!important;justify-content:flex-start!important;align-items:center!important}
  .topbar::before,.topbar::after{content:none!important;display:none!important;flex:none!important;width:0!important;height:0!important;margin:0!important;padding:0!important;border:0!important}
  .topbar>*{flex-basis:auto!important;margin-top:0!important;margin-bottom:0!important;max-width:100%}
  .topbar>.nav-btn,.topbar>.logo,.topbar>.tabs,.topbar>.mem-btn{flex:0 0 auto!important;margin-left:0!important;margin-right:0!important}
  .topbar>.nav-btn{order:1!important}.topbar>.logo{order:2!important}.topbar>.tabs{order:3!important}
  .topbar>.spin-cd{order:4!important;flex:1 1 0!important;min-width:0!important;margin:0!important}
  .topbar>.who{order:5!important;flex:0 0 auto!important;margin-left:auto!important;margin-right:0!important}
  .topbar>.mem-btn{order:6!important}
  .topbar .who button.primary,.topbar .who button.acct{min-height:44px;padding:0 14px}
  .topbar .who .bolts{display:inline-block;font-size:0;color:var(--text)}
  .topbar .who .bolts::before{content:attr(data-short);font-size:13px}
  .topbar .who .bolts:not([data-short]){display:none}
  /* narrow phones: the wordmark becomes the small mark; only the OTHER page shows, as a link chip with an arrow; the spin chip shows only when a spin is ready */
  @media (max-width:600px){
    .topbar .logo img{display:none}
    .topbar .logo{width:40px;height:40px;background:url(../img/harlolabs-mark.png?v=20261203lg1) center/32px 32px no-repeat;border-radius:6px}
    .topbar .tab.on{display:none}
    .topbar .tabs{padding:0;border:0;background:none}
    .topbar .tab:not(.on){border:1px solid var(--line-strong);background:var(--surface-2);color:var(--text);white-space:nowrap}
    .topbar .tab:not(.on)::before{content:"";position:absolute;inset:-4px -4px}
    .topbar .tab:not(.on)::after{content:" \203A";position:static;inset:auto;margin-left:5px;font-size:15px;line-height:1;color:var(--text-muted)}
    .topbar .spin-cd{display:none}
    .topbar .who button.primary,.topbar .who button.acct{padding:0 10px}
    .topbar{padding:0 6px;gap:6px}
  }
  @media (max-width:360px){
    .topbar .logo{display:none}
    .topbar .tab{padding:0 10px}
    .topbar .who button.primary,.topbar .who button.acct{padding:0 8px}
  }
  /* a lone tab chip is not a strip */
  .topbar .tabs.mfx-one{display:none}

  /* ---------- 10. stage header: long titles wrap to two lines, then an ellipsis ---------- */
  .stage-head{min-height:52px;height:auto;padding:6px 12px;gap:8px;min-width:0}
  .stage-head h1{flex:1 1 auto;min-width:0;white-space:normal;overflow-wrap:anywhere;display:-webkit-box;-webkit-box-orient:vertical;-webkit-line-clamp:2;overflow:hidden;line-height:1.25}
  .stage-head .topic{flex:0 1 auto;min-width:0;max-width:46%}
  .stage-head:has(.back){flex-wrap:wrap}
  .stage-head:has(.back) .topic{flex:1 0 100%;max-width:none;order:9;white-space:normal}
  .stage-head .ic,.stage-head .back,.stage-head .chal-coin,.stage-head .chal-tag{flex:none}
  .stage-head .back,.chal-head .back{position:relative;min-width:36px;min-height:36px}
  .stage-head .back::after,.chal-head .back::after{content:"";position:absolute;inset:-6px}

  /* ---------- 4. chat composer: photo button is an icon, the input gets the room ---------- */
  .composer{padding:8px 10px calc(8px + var(--mfx-sab));gap:8px}
  .composer input:not([type=file]){height:44px;min-width:0}
  .composer button{min-height:44px}
  .composer button[type=submit]{min-width:56px}
  .composer .attach-btn{position:relative;flex:none;width:44px;min-width:44px;padding:0;font-size:0;line-height:0;color:var(--text)}
  .composer .attach-btn::before{content:"";position:absolute;left:50%;top:50%;width:20px;height:14px;margin:-6px 0 0 -10px;border:2px solid currentColor;border-radius:3px;box-sizing:border-box}
  .composer .attach-btn::after{content:"";position:absolute;left:50%;top:50%;width:6px;height:6px;margin:-2px 0 0 -3px;border:2px solid currentColor;border-radius:50%;box-sizing:content-box;width:4px;height:4px;margin:-3px 0 0 -4px}

  /* ---------- 5. message tools sit on their own line, long links wrap ---------- */
  .msg .body,.msg .body a,.msg .line,.msg .name{overflow-wrap:anywhere}
  .msg .body a{word-break:normal}
  .msg:not(.block){grid-template-rows:auto}
  /* tools are hidden until the message is tapped (class set by the add-on) or a tool has keyboard focus; hidden = out of the flow but still focusable */
  .msg:not(.block) .msg-tools{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip-path:inset(50%);opacity:0;pointer-events:none;top:auto;right:auto}
  .msg.mfx-t .msg-tools,.msg:not(.block) .msg-tools:focus-within{position:static;grid-column:2;display:flex;flex-wrap:wrap;justify-content:flex-start;gap:8px;width:auto;height:auto;margin:12px 0 2px;overflow:visible;clip-path:none;opacity:1;pointer-events:auto}
  .msg .msg-tools .react-add{position:relative;min-width:44px;min-height:44px;padding:0 10px;border:1px solid var(--line-strong);background:var(--surface-2);color:var(--text);line-height:1;opacity:1}
  .msg .line{padding-right:0}
  .msg .body{padding-right:0}
  .msg.block .react-add.mod{position:absolute}
  .reacts{gap:8px}
  .react{position:relative;min-height:32px}
  .react::after{content:"";position:absolute;inset:-7px -4px}

  /* ---------- 3. the @ picker: a full-width list right above the composer ---------- */
  .mf-pick{overflow-y:auto!important;left:8px!important;right:8px!important;width:auto!important;top:auto!important;bottom:var(--mfx-cb,72px)!important;max-height:min(300px,var(--mfx-mh,calc(100dvh - 160px)))!important;padding:6px}
  .mf-row{min-height:48px;padding:6px 10px}
  .mf-name{overflow:visible;text-overflow:clip;white-space:normal;overflow-wrap:anywhere;font-size:16px}
  .mf-rate,.mf-where{font-size:12px}
  .mf-tag{position:relative}
  .mf-tag::after{content:"";position:absolute;inset:-13px -6px}
  .msg-tools .mf-at-btn{min-width:44px;min-height:44px}

  /* ---------- 15. leaderboards: the whole row is the tap target ---------- */
  .lb-row{position:relative;min-height:44px}
  .lb-row .lnk{position:static;font-size:13px}
  .lb-row .lnk::after{content:"";position:absolute;inset:0}

  /* ---------- 1. Bolts store: a card with its form or code box open takes the whole row and clips nothing ---------- */
  .sto-card.mfx-open{grid-column:1/-1;overflow:visible}
  .sto-card.mfx-open .sto-img{aspect-ratio:auto;height:96px}
  .sto-card.mfx-open .sto-body{min-width:0}
  .sto-card.mfx-open .sto-form,.sto-card.mfx-open .codebox{min-width:0;max-width:100%}
  .sto-card.mfx-open .err:empty{display:none}
  .sto-card.mfx-open .sc-row{display:flex;flex-wrap:wrap;gap:8px}
  .sto-card.mfx-open .sc-row .btn{flex:1 1 120px;min-height:48px}
  .sto-card.mfx-open .codebox .row{flex-wrap:wrap}
  .sto-card.mfx-open .codebox .row .btn{min-height:48px}
  .sto-card.mfx-open input,.sto-card.mfx-open select{min-height:44px}
  .sto-card.mfx-open .grid2{grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:8px}
  /* redeem form: a placeholder never reads as a typed value */
  .sto-card.mfx-open input::placeholder,.sto-card.mfx-open textarea::placeholder{color:var(--text-muted,#979797);opacity:1;font-style:italic}

  /* ---------- 16. checkboxes and other small things ---------- */
  input[type=checkbox]:not(.gf-game *),input[type=radio]:not(.gf-game *){flex:none;width:24px;height:24px;margin:0}
  .switch{min-height:44px;padding:8px 0}
  .chans button,.row{min-height:44px}
  .acct-tabs{gap:8px}.acct-tabs button{min-height:44px}
  .tcard{margin-bottom:10px}

  /* ---------- 18. sheets and drawers keep clear of the home bar ---------- */
  #panel{padding-bottom:var(--mfx-sab)}
  .rr-join{padding-bottom:calc(var(--sp-4) + var(--mfx-sab))}
  .h-modal{padding:12px 12px calc(12px + var(--mfx-sab))}
  .h-modal-card{max-height:calc(100dvh - 24px);overflow:auto}

  /* ---------- 11. keyboard up, or a very short screen: the bar gets out of the way ---------- */
  html.mfx-kb{--topbar-h:0px}
  html.mfx-kb .topbar{display:none!important}
  html.mfx-kb .stage-head{min-height:36px;padding-top:2px;padding-bottom:2px}
  html.mfx-kb .stage-head .topic{display:none}
  html.mfx-kb body{height:var(--mfx-vh,100dvh)}
  html.mfx-kb .stage form.form:focus-within{position:sticky;bottom:0;z-index:5;background:var(--surface-1,#101010);padding:8px 0 calc(8px + var(--mfx-sab));margin:0}
  html.mfx-kb .stage form.form:focus-within textarea{min-height:64px;max-height:30vh}
  @media (max-height:300px){html.mfx-kb .stage form.form:focus-within{display:flex;align-items:flex-end;gap:8px;padding:6px 0}html.mfx-kb .stage form.form:focus-within textarea{flex:1 1 0;min-width:0;min-height:44px;height:44px;max-height:44px}html.mfx-kb .stage form.form:focus-within .err:empty{display:none}html.mfx-kb .stage form.form:focus-within .btn{min-height:44px}}
}

/* ---------- 2. short screens (phone sideways): compact bar, header and composer ---------- */
@media (max-height:500px) and (max-width:950px),(max-width:820px) and (max-height:500px){
  :root{--topbar-h:44px}
  .topbar{height:44px}
  .topbar .nav-btn{width:40px;height:40px}
  .topbar .tab{min-height:32px}
  .topbar .who button.primary,.topbar .who button.acct{min-height:36px}
  .topbar .spin-cd{min-height:36px}
  .stage-head{min-height:50px;padding-top:7px;padding-bottom:7px}
  .composer{padding-top:6px;padding-bottom:calc(6px + var(--mfx-sab))}
  .composer input:not([type=file]),.composer button{height:40px;min-height:40px}
  .composer .attach-btn{width:40px;min-width:40px}
}
