/* ReSurge Academy phone shell. Owned by package F. Every rule sits inside the media query below, so nothing here can reach a
   desktop (plan 7.2 rule 2). Animate transform, opacity and colour only. Opaque bars, no blur, no glass. */
@media (max-width: 1023.98px) {

  /* ---------- touch ---------- */
  html { -webkit-tap-highlight-color: transparent; }
  a, button, input, select, textarea, summary, label, [role="button"], [data-press] { touch-action: manipulation; }
  #topbar, #tabbar, .btn, .tabbar__item, .topbtn, .bar__back, .seg__opt, .chip, .menu__item {
    -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  }
  /* an installed app on Android has no browser pull to refresh of its own once ours takes over (JA.ui.ptr) */
  html.is-standalone { overscroll-behavior-y: contain; }

  /* ---------- press (JA.press toggles is-pressed) ---------- */
  .btn { transition: transform var(--t-snappy) var(--spring), background-color var(--dur-1) var(--ease-out), color var(--dur-1) var(--ease-out); }
  .btn.is-pressed { transform: scale(var(--press-scale)); transition-duration: var(--t-press), var(--dur-1), var(--dur-1); transition-timing-function: var(--ease-out); }
  [data-press="card"] { transition: transform var(--t-snappy) var(--spring); }
  [data-press="card"].is-pressed { transform: scale(var(--press-scale-card)); transition-duration: var(--t-press); transition-timing-function: var(--ease-out); }
  .topbtn, .bar__back { transition: transform var(--t-snappy) var(--spring), background-color 300ms var(--ease-out); }
  .topbtn.is-pressed, .bar__back.is-pressed, [data-press="icon"].is-pressed { transform: scale(var(--press-scale-icon)); background-color: var(--press-bg); transition-duration: var(--t-press), 60ms; transition-timing-function: var(--ease-out); }
  [data-press="row"], .learn-ladder__row, .quiz-option { transition: background-color 300ms var(--ease-out); }
  [data-press="row"].is-pressed, .learn-ladder__row.is-pressed, .quiz-option.is-pressed { background-color: var(--press-bg); transition-duration: 0s; }
  .tabbar__ico { transition: transform var(--t-bounce) var(--spring-bounce); }
  .tabbar__item.is-pressed .tabbar__ico { transform: scale(0.86); transition: transform var(--t-press) var(--ease-out); }
  .btn:disabled.is-pressed, .btn[aria-disabled="true"].is-pressed { transform: none; }

  /* ---------- the top bar: 44px, opaque, a hairline once the large title has passed under it ---------- */
  #topbar { border-bottom: 0; background: var(--bar-bg); padding-top: var(--safe-t); position: sticky; }
  #topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px; background: var(--line); opacity: 0; transition: opacity var(--t-fade) var(--ease-out); pointer-events: none; }
  #topbar[data-collapsed]::after { opacity: 1; }
  .bar { height: var(--topbar-h); position: relative; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 0 max(var(--sp-2), var(--safe-r)) 0 max(var(--sp-2), var(--safe-l)); }
  .bar__lead { display: flex; align-items: center; justify-self: start; min-width: 0; }
  .bar__trail { display: flex; align-items: center; justify-self: end; }
  .bar__title {
    max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center;
    font-size: var(--fs-17); font-weight: var(--fw-semi); color: var(--ink);
    opacity: 0; transform: translateY(6px); transition: opacity var(--t-fade) var(--ease-out), transform var(--t-fade) var(--ease-out);
  }
  #topbar[data-collapsed] .bar__title { opacity: 1; transform: none; }
  .bar__back {
    display: inline-flex; align-items: center; min-width: var(--tap); min-height: var(--tap); padding: 0 var(--sp-2) 0 var(--sp-1);
    border-radius: var(--r-3); color: var(--brand-ink); font-size: var(--fs-17); text-decoration: none; gap: 2px;
  }
  .bar__back--close { color: var(--ink); justify-content: center; padding: 0; }
  .bar__backlabel { max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bar--root .logo { min-height: var(--tap); min-width: var(--tap); }
  .bar--root .logo__img { height: 26px; }
  .bar .topbtn { width: var(--tap); height: var(--tap); }
  .topbar__streak { display: none; }
  /* a touch target is at least 44px, small buttons included */
  .btn--sm { min-height: var(--tap); }

  /* ---------- the tab bar: five tabs, 52px plus the safe area ---------- */
  #tabbar { background: var(--surface); border-top: 1px solid var(--line); padding: 0 var(--safe-r) var(--safe-b) var(--safe-l); }
  .tabbar { height: var(--tabbar-h); }
  .tabbar__item { gap: 1px; font-size: 11px; font-weight: var(--fw-semi); color: var(--ink-3); -webkit-touch-callout: none; }
  .tabbar__ico { position: relative; display: inline-flex; }
  .tabbar__ico .icon { width: 24px; height: 24px; }
  .tabbar__ico .badge { position: absolute; top: -4px; left: 14px; }
  .tabbar__item[aria-current="page"]::before { display: none; }
  .tabbar__item[aria-current="page"] { color: var(--brand-ink); }
  .tabbar__item[aria-current="page"] .icon { stroke-width: 2.25; }
  html.kb-open #tabbar { display: none; }
  html.kb-open #view { padding-bottom: var(--sp-4); }

  @media (max-width: 767.98px) { #view { padding-left: max(var(--sp-4), var(--safe-l)); padding-right: max(var(--sp-4), var(--safe-r)); } }
  /* the tab bar clears the page's last line */
  #view { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--sp-8)); }
  body[data-chrome="focus"] #view { padding-bottom: calc(var(--safe-b) + var(--sp-8)); }

  /* ---------- the large title ---------- */
  .page-head { border-bottom: 0; padding-bottom: var(--sp-2); margin-bottom: var(--sp-4); }
  .page-head::after { display: none; }
  .page-head h1 { font-size: var(--lt-size); line-height: 1.1; margin: var(--sp-1) 0 var(--sp-2); }
  /* the lede stays everywhere it carries copy (billing). Learn drops it, per plan 4.2. */
  #view[data-view="learn"] .page-head__lede { display: none; }

  /* ---------- toasts: one at a time, clear of the bar underneath ---------- */
  #toasts { bottom: calc(var(--safe-b) + 12px); }
  body:not([data-chrome="focus"]):not([data-chrome="bare"]) #toasts { bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); }
  html.kb-open #toasts { bottom: calc(var(--kb) + 12px) !important; }
  .toast { opacity: 0; translate: 0 16px; transition: opacity var(--t-snappy) var(--spring), translate var(--t-snappy) var(--spring); }
  .toast.is-open { opacity: 1; translate: 0 0; }

  /* ---------- the Chapters | Guidelines control ---------- */
  .learn-seg { margin: 0 0 var(--sp-4); }
  .learn-seg .seg__opt { text-decoration: none; min-height: 40px; }
  .rungs { display: inline-flex; align-items: center; gap: var(--sp-1); }

  /* ---------- a screen that does not scroll the document: the Tutor, the note editor (2.12) ---------- */
  html.is-fixed-screen, html.is-fixed-screen body { overflow: hidden; height: 100%; }
  html.is-fixed-screen #app {
    position: fixed; top: 0; left: 0; right: 0; height: var(--vvh); min-height: 0;
    transform: translateY(var(--vv-top)); display: flex; flex-direction: column;
  }
  html.is-fixed-screen #topbar { flex: none; }
  html.is-fixed-screen #offline { flex: none; }
  html.is-fixed-screen #view { flex: 1; min-height: 0; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
  html.is-fixed-screen #view > * { max-width: none; flex: 1; min-height: 0; }
  html.is-fixed-screen #tabbar { position: static; flex: none; }

  /* ---------- view transitions (JA.motion.transition, step 2). The bars stay still while the content moves. ---------- */
  #topbar { view-transition-name: topbar; }
  #tabbar { view-transition-name: tabbar; }
  ::view-transition-group(topbar), ::view-transition-group(tabbar) { animation-duration: 0s; }
  @media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  }

  /* push and pop: the content slides, the bars stay. Only transform and opacity move. */
  @keyframes vt-push-in  { from { transform: translateX(100%); } to { transform: translateX(0); } }
  @keyframes vt-push-out { from { transform: translateX(0); opacity: 1; } to { transform: translateX(-28%); opacity: 0.6; } }
  @keyframes vt-pop-in   { from { transform: translateX(-28%); opacity: 0.6; } to { transform: translateX(0); opacity: 1; } }
  @keyframes vt-pop-out  { from { transform: translateX(0); } to { transform: translateX(100%); } }
  ::view-transition-old(root), ::view-transition-new(root) { mix-blend-mode: normal; animation-duration: 540ms; animation-timing-function: var(--spring); animation-fill-mode: both; }
  html[data-vt="push"]::view-transition-old(root) { animation-name: vt-push-out; }
  html[data-vt="push"]::view-transition-new(root) { animation-name: vt-push-in; z-index: 2; }
  html[data-vt="pop"]::view-transition-old(root) { animation-name: vt-pop-out; z-index: 2; }
  html[data-vt="pop"]::view-transition-new(root) { animation-name: vt-pop-in; }
  ::view-transition-group(hero-rung) { animation-duration: 540ms; animation-timing-function: var(--spring); }

  /* ---------- toasts: leave, and follow a swipe down ---------- */
  .toast { touch-action: pan-x; }
  .toast.is-leaving { opacity: 0; translate: 0 8px; transition: opacity 200ms ease-in, translate 200ms ease-in; }
  .toast.is-dragging { transition: none; }

  /* ---------- pull to refresh (installed app only, JA.ui.ptr) ---------- */
  html.is-android { overscroll-behavior-y: contain; }
  .ptr { position: fixed; left: 50%; top: calc(var(--safe-t) + var(--topbar-h) + 8px); z-index: var(--z-bar); width: 28px; height: 28px; margin-left: -14px; opacity: 0; pointer-events: none; will-change: transform, opacity; color: var(--brand); }
  .ptr svg { width: 28px; height: 28px; display: block; }
  .ptr__bond { opacity: 0; }
  .ptr.is-armed .ptr__bond { opacity: 1; transition: opacity 120ms var(--ease-out); }
  .ptr.is-busy .ptr__bond { animation: ptr-pulse 900ms ease-in-out infinite; opacity: 1; }
  @keyframes ptr-pulse { 0%, 100% { opacity: 0.4; } 50% { opacity: 1; } }
  .ptr.is-leaving { opacity: 0; transition: opacity 200ms ease-in; }

  /* ---------- install steps (iOS) ---------- */
  .install-row { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-4); background: var(--surface); margin: var(--sp-4) 0; }
  .install-row__text { display: flex; flex-direction: column; gap: var(--sp-1); }
  .install-row__text span { color: var(--ink-2); font-size: var(--fs-14); }
  .install-row__acts { display: flex; gap: var(--sp-2); }
  .install-steps { margin: 0 0 var(--sp-3); padding-left: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-2); }

  /* ---------- sheets below 768px: a bottom sheet with detents and a drag zone ---------- */
  @media (max-width: 767.98px) {
    .sheet--phone { left: 0; right: 0; bottom: var(--kb); top: auto; width: auto; max-height: none; border-radius: var(--sheet-r) var(--sheet-r) 0 0; box-shadow: var(--sh-sheet); translate: none; transition: none; background: var(--surface); padding-bottom: 0; }
    .sheet--phone.is-dragging { will-change: transform; }
    .sheet--phone .sheet__body { overscroll-behavior: contain; padding-bottom: var(--sp-6); }
    .sheet__grab { height: 44px; flex: none; display: flex; align-items: center; justify-content: center; touch-action: none; cursor: grab; margin-bottom: -20px; }
    .sheet__grab span { display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--ink-4); margin-top: -12px; }
    .sheet--phone .sheet__head { padding-top: var(--sp-3); }
    .sheet-scrim.is-dragging { transition: none; }
    .sheet--menu .sheet__head { display: none; }
    .sheet--menu .sheet__body { padding: var(--sp-2) var(--sp-3) var(--sp-3); }
    .sheet--menu .menu { display: flex; flex-direction: column; min-width: 0; box-shadow: none; border: 0; background: transparent; padding: 0; }
    .sheet--menu .menu__item { min-height: 52px; }
    .sheet--menu .menu__item--cancel { margin-top: var(--sp-2); justify-content: center; font-weight: 600; border-top: 1px solid var(--line); }
  }
}
