/* TF-0002 — Phone accessibility / support FABs were covering studio-card
   labels, the gift bar, and the create-sheet billing row.
   Round 4 (Claude UNSURE v3): keep compact wrap padding clear of a notch
   without double-counting the gift bar. Round 3: raise the a11y panel,
   keep a compact landscape prompt, scope home parking by data-tf-view,
   park off-header, honor body.tf-typing. Additive last-loading layer. Remove this file and its
   <link> in index.html to undo. UI/CSS only. */

/* A1: the widget panel must paint above create (10060) and billing (10080).
   a11y.js already sets 2147483000; this last layer restates it so a later
   sheet cannot cover the open panel. Focus trap / aria-modal would be JS. */
html.tf2 .tfa11y-panel{
  z-index:2147483000;
}

/* Shared vertical inset used when the gift bar is on or a notch is present.
   B1: max() so a published --tf-gift-h:0px cannot drop the button under the notch. */
html.tf2{
  --tf-0002-top:max(var(--tf-gift-h, 0px), env(safe-area-inset-top, 0px));
  /* N1: compact wrap padding adds the top inset only when the gift bar is
     off. When it is on, #tf2home already starts at --tf-gift-h, which
     includes the gift bar's own safe-area padding — do not double-count. */
  --tf-0002-wrap-safe:env(safe-area-inset-top, 0px);
}
html.tf-gift-on{
  --tf-0002-wrap-safe:0px;
}

/* ---------- Phone width: dock gutters + overlay parking ---------- */
@media (max-width:767px){

  /* A3: scope home parking by the real home view (data-tf-view="home"),
     not only html.tf2home-on, so a stale tf2home-on class cannot beat
     chat / music / voice parking. A11y gutters also stay off html.tf2c-on
     so a11y.js's 164px Generate clearance is left alone. */
  html.tf2:not(.tf2bill-on) body[data-tf-view="home"] .tf2-dock,
  html.tf2 body[data-tf-view="gallery"] .tf2-dock{
    width:auto;
    inset-inline:auto;
    left:58px;
    right:58px;
  }
  html.tf2:not(.tf2c-on):not(.tf2bill-on) body[data-tf-view="home"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="gallery"] ~ .tfa11y-btn{
    top:auto;
    left:8px;
    bottom:calc(max(18px, env(safe-area-inset-bottom,0px)) + 12px);
  }
  html.tf2:not(.tf2bill-on) body[data-tf-view="home"] .tf-help-fab,
  html.tf2 body[data-tf-view="gallery"] .tf-help-fab{
    right:6px;
    bottom:calc(max(18px, env(safe-area-inset-bottom,0px)) + 8px);
  }
  html.tf2:not(.tf2bill-on) body[data-tf-view="home"] .tf-help-menu,
  html.tf2 body[data-tf-view="gallery"] .tf-help-menu{
    right:6px;
    bottom:calc(max(18px, env(safe-area-inset-bottom,0px)) + 76px);
  }

  html.tf-gift-on #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 8px)}
  html.tf-gift-on #tf2home .top{margin-bottom:8px}
  html.tf-gift-on #tf2home .sec{margin-top:8px}
  html.tf2 #tf2home .wrap{padding-bottom:calc(176px + env(safe-area-inset-bottom,0px))}
  html.tf2 #tf2home{scroll-padding-bottom:calc(96px + env(safe-area-inset-bottom,0px))}

  /* A3/A4: on chat and the other composer views, lift a11y the same way
     a11y.js lifts it in the image studio (164px), instead of pinning it
     to the top-left where it can cover header controls. These selectors
     key off data-tf-view, so they never fight the home-gutter rule. */
  html.tf2 body[data-tf-view="chat"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="music"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="voice"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="tryon"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="pricing"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="songvideo"] ~ .tfa11y-btn{
    top:auto;
    left:8px;
    bottom:calc(164px + env(safe-area-inset-bottom,0px));
    z-index:10100;
  }
}

/* Overlay parking is needed on any short phone, including landscape
   models whose CSS width exceeds 767 (e.g. 844×390). */
@media (max-width:767px), (pointer:coarse) and (orientation:landscape) and (max-height:500px) and (max-width:1099px){

  html.tf2:has(#tf2ov) .tf-help-fab,
  html.tf2:has(#tf2ov) .tf-help-menu,
  html.tf2:has(body > .tf2b-second) .tf-help-fab,
  html.tf2:has(body > .tf2b-second) .tf-help-menu,
  html.tf2:has(body > #tf2bill) .tf-help-fab,
  html.tf2:has(body > #tf2bill) .tf-help-menu{
    display:none !important;
  }

  /* Profile has its own Accessibility row. Hide the FAB only while that
     sheet is up and billing is not also open. Nodes are remove()d on close. */
  html.tf2:has(body > .tf2b-second):not(:has(body > #tf2bill)) .tfa11y-btn{
    display:none !important;
  }

  /* Create hub: a 52px band under the gift/notch, a11y at inline-start,
     close (.tf2-x) stays at inline-end. No display:!important — A5. */
  html.tf2:has(#tf2ov) .tf2-sheet{
    max-height:calc(100vh - var(--tf-0002-top) - 52px);
    max-height:calc(100dvh - var(--tf-0002-top) - 52px);
  }
  html.tf2:has(#tf2ov):not(:has(body > #tf2bill)) .tfa11y-btn{
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:10100;
    top:calc(var(--tf-0002-top) + 4px);
    bottom:auto;
    left:auto;
    right:auto;
    inset-inline-start:8px;
    inset-inline-end:auto;
    width:44px;
    height:44px;
    min-width:44px;
    min-height:44px;
    border-radius:12px;
    line-height:1;
    transform:none;
  }

  /* Billing: B4 uses only :has(body > #tf2bill) (close() also drops .tf2bill-on).
     Park a11y in the header's inline-end slot, opposite Back. */
  html.tf2:has(body > #tf2bill) .tfa11y-btn{
    display:flex;
    align-items:center;
    justify-content:center;
    z-index:10100;
    top:calc(var(--tf-0002-top) + 8px);
    bottom:auto;
    left:auto;
    right:auto;
    inset-inline-end:8px;
    inset-inline-start:auto;
    width:44px;
    height:44px;
    min-width:44px;
    min-height:44px;
    border-radius:12px;
    line-height:1;
    transform:none;
  }
  /* B2: the billing header is already a flex sibling of .tf2b-scroll (not
     inside the scroller). Keep it above scrolling content and reserve the
     inline-end slot for the parked ♿ button. */
  html.tf2 #tf2bill.tfpage .tfp-head{
    position:sticky;
    top:0;
    z-index:2;
    padding-inline-end:56px;
    background:#0b0b14;
  }
}

/* A5: hide a11y while the keyboard is up. :has(#tf2ov)/#tf2bill parking no
   longer uses display:!important, so this !important hide wins. The :has
   forms are listed so the hide also wins if a future park rule adds it back. */
@media (pointer:coarse){
  html.tf2 body.tf-typing ~ .tfa11y-btn,
  html.tf2:has(#tf2ov) body.tf-typing ~ .tfa11y-btn,
  html.tf2:has(body > #tf2bill) body.tf-typing ~ .tfa11y-btn{
    display:none !important;
  }
}

/* Mid compact: short phone viewports. 12px+ text. A 390×844 iPhone
   in-browser (~664px tall) lands here, not in the tiny-phone tier. */
@media (max-width:767px) and (max-height:850px){
  html.tf2 #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 10px)}
  html.tf2 #tf2home .top{margin-bottom:8px}
  html.tf2 #tf2home .hi{font-size:.85rem}
  html.tf2 #tf2home h1{font-size:1.55rem;line-height:1.08;margin:2px 0 8px}
  html.tf2 #tf2home .prompt{padding:10px 12px}
  html.tf2 #tf2home .sec{margin:10px 2px 8px}
  html.tf2 #tf2home .dcard{height:max(118px, 4.5em);min-height:118px}
  html.tf-gift-on #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 8px)}
  html.tf-gift-on #tf2home .top{margin-bottom:6px}
  html.tf-gift-on #tf2home .sec{margin-top:8px}
}

/* Short normal-width phones (390×664 class). 96px cards, 12px labels. */
@media (min-width:361px) and (max-width:767px) and (max-height:700px){
  html.tf2 #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 4px)}
  html.tf2 #tf2home .top{margin-bottom:2px}
  html.tf2 #tf2home .hi{font-size:.8rem;margin:0}
  html.tf2 #tf2home h1{font-size:1.2rem;line-height:1.05;margin:0 0 2px}
  html.tf2 #tf2home .tf2-herosub{margin:0 0 2px;font-size:12px;line-height:1.2}
  html.tf2 #tf2home .prompt{padding:6px 8px}
  html.tf2 #tf2home .sec{margin:4px 2px 4px}
  html.tf2 #tf2home .grid{gap:8px}
  html.tf2 #tf2home .dcard{height:max(96px, 4.5em);min-height:96px}
  html.tf2 #tf2home .dcard .nm{bottom:6px}
  html.tf2 #tf2home .dcard .nm b{font-size:.9rem}
  html.tf2 #tf2home .dcard .nm s{font-size:12px}
  html.tf-gift-on #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 4px)}
  html.tf-gift-on #tf2home .top{margin-bottom:2px}
  html.tf-gift-on #tf2home .sec{margin-top:4px}
}

/* Tiny-phone tier: WIDTH-GATED so 390-wide devices never get it. 12px min. */
@media (max-width:360px) and (max-height:700px){
  html.tf2 #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 4px)}
  html.tf2 #tf2home .top{margin-bottom:2px}
  html.tf2 #tf2home .hi{font-size:.75rem;margin:0}
  html.tf2 #tf2home h1{font-size:1.15rem;line-height:1.05;margin:0 0 2px}
  html.tf2 #tf2home .tf2-herosub{margin:0 0 4px;font-size:12px;line-height:1.25}
  html.tf2 #tf2home .prompt{padding:6px 8px}
  html.tf2 #tf2home .sec{margin:4px 2px 4px}
  html.tf2 #tf2home .grid{gap:8px}
  html.tf2 #tf2home .dcard{height:max(88px, 4.5em);min-height:88px}
  html.tf2 #tf2home .dcard .nm{bottom:6px}
  html.tf2 #tf2home .dcard .nm b{font-size:.85rem}
  html.tf2 #tf2home .dcard .nm s{font-size:12px}
  html.tf-gift-on #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 4px)}
  html.tf-gift-on #tf2home .top{margin-bottom:2px}
}

/* 320-wide gutters: 54+58 so 44/52px FABs sit outside the dock (208px / 4). */
@media (max-width:360px){
  html.tf2:not(.tf2bill-on) body[data-tf-view="home"] .tf2-dock{
    left:54px;
    right:58px;
  }
  html.tf2:not(.tf2c-on):not(.tf2bill-on) body[data-tf-view="home"] ~ .tfa11y-btn,
  html.tf2 body[data-tf-view="gallery"] ~ .tfa11y-btn{left:6px}
  html.tf2:not(.tf2bill-on) body[data-tf-view="home"] .tf-help-fab,
  html.tf2 body[data-tf-view="gallery"] .tf-help-fab{right:4px}
  html.tf2:not(.tf2bill-on) body[data-tf-view="home"] .tf-help-menu,
  html.tf2 body[data-tf-view="gallery"] .tf-help-menu{right:4px}
}

/* Ultra-short 320×568 class. 360×640 is taller than 600px and is not in this
   query. The prompt stays visible. */
@media (max-width:360px) and (max-height:600px){
  html.tf2 #tf2home .hi,
  html.tf2 #tf2home .tf2-herosub{display:none}
  html.tf2 #tf2home h1{font-size:1.05rem;line-height:1.05;margin:0 0 2px}
  html.tf2 #tf2home .prompt{padding:4px 8px}
  html.tf2 #tf2home .grid{gap:6px}
  html.tf2 #tf2home .dcard{height:max(84px, 4.5em);min-height:84px}
  html.tf2 #tf2home .dcard .nm b{font-size:.85rem}
  html.tf2 #tf2home .dcard .nm s{font-size:12px}
}

/* A2: landscape compact on real touch phones only (pointer:coarse), so a
   desktop 1280×720 viewport at 200% zoom (640×360, pointer:fine) is not
   caught. The home prompt stays visible (compact, not display:none), including
   a keyboard-resized 390×374 viewport. */
@media (pointer:coarse) and (orientation:landscape) and (max-height:500px) and (max-width:1099px){
  html.tf2 #tf2home .wrap{padding-top:calc(var(--tf-0002-wrap-safe) + 2px);padding-bottom:calc(120px + env(safe-area-inset-bottom,0px))}
  html.tf2 #tf2home .top{margin-bottom:0}
  html.tf2 #tf2home .hi,
  html.tf2 #tf2home .tf2-herosub,
  html.tf2 #tf2home .sec{display:none}
  html.tf2 #tf2home h1{font-size:1rem;line-height:1.05;margin:0 0 2px}
  html.tf2 #tf2home .prompt{display:flex;padding:2px 8px;margin:0 0 2px}
  html.tf2 #tf2home .grid{grid-template-columns:repeat(3,minmax(0,1fr));gap:6px}
  html.tf2 #tf2home .dcard,
  html.tf2 #tf2home .dcard.wide{height:max(62px, 3.2em);min-height:62px;grid-column:auto}
  html.tf2 #tf2home .dcard .nm{bottom:6px}
  html.tf2 #tf2home .dcard .nm b{font-size:.8rem}
  html.tf2 #tf2home .dcard .nm s{font-size:12px}
}
