/**
 * Phone / tablet app shell for public pages (< 1024px).
 *
 * Opt in from a page:
 *   {% block body_class %}app-shell app-shell--tabs{% endblock %}   tab page
 *   {% block body_class %}app-shell app-shell--push{% endblock %}   detail page
 * Add `app-shell--has-action` when the page has its own bottom action bar
 * (the tab bar then gives way to it).
 *
 * Contrast: custom.css paints span/p/li gray and every <a> rose, both with
 * !important, so every text rule here sets color and -webkit-text-fill-color
 * with !important. Labels use <b> instead of <span>. See docs/UI_GUARDRAILS.md.
 */

.app-bar,
.app-tabbar {
  display: none;
}

@media (max-width: 1023.98px) {
  body.app-shell {
    --app-ink: #1c1917;
    --app-ink-2: #57534e;
    --app-rose: #9f1239;
    --app-rose-soft: #ffe4e6;
    --app-surface: rgba(255, 250, 251, 0.9);
    --app-line: rgba(159, 18, 57, 0.1);
    --app-bar-h: 56px;
    --app-tab-h: 58px;
    --app-safe-top: env(safe-area-inset-top, 0px);
    --app-safe-bottom: env(safe-area-inset-bottom, 0px);
    --app-ease: cubic-bezier(0.22, 1, 0.36, 1);

    padding-top: calc(var(--app-bar-h) + var(--app-safe-top));
    padding-bottom: calc(var(--app-tab-h) + var(--app-safe-bottom));
    /* `hidden` makes body a scroll box and breaks every position: sticky
       inside it; `clip` trims the same overflow without that. */
    overflow-x: clip !important;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    touch-action: manipulation;
    scroll-padding-top: calc(var(--app-bar-h) + var(--app-safe-top) + 8px);
  }

  html:has(body.app-shell) {
    scroll-padding-top: calc(56px + env(safe-area-inset-top, 0px) + 8px);
  }

  body.app-shell.app-shell--has-action {
    padding-bottom: calc(76px + var(--app-safe-bottom));
  }

  /* The tall glass header, its menu hint and the old floating buttons give
     way to the app bar and tab bar. */
  body.app-shell > header.hero-bodhi,
  body.app-shell .bm-top-fab,
  body.app-shell .floating-nav-buttons,
  body.app-shell #nav-menu-hint,
  body.app-shell .home-edge-nav,
  body.app-shell .home-edge-nav-summon {
    display: none !important;
  }

  body.app-shell .env-banner {
    bottom: calc(var(--app-tab-h) + var(--app-safe-bottom) + 8px) !important;
    left: 8px !important;
    pointer-events: none;
    opacity: 0.85;
  }

  body.app-shell #siteFooter {
    padding-bottom: 4px;
  }

  /* ---------- Top app bar ---------- */
  body.app-shell .app-bar {
    color: var(--app-ink);
    -webkit-text-fill-color: var(--app-ink);
    display: block;
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1100;
    padding-top: var(--app-safe-top);
    background: var(--app-surface);
    -webkit-backdrop-filter: saturate(1.8) blur(18px);
    backdrop-filter: saturate(1.8) blur(18px);
    border-bottom: 1px solid transparent;
    transition: border-color 200ms var(--app-ease), box-shadow 200ms var(--app-ease);
    view-transition-name: app-bar;
  }

  body.app-shell .app-bar.is-scrolled {
    border-bottom-color: var(--app-line);
    box-shadow: 0 6px 18px rgba(28, 25, 23, 0.06);
  }

  .app-bar__inner {
    height: var(--app-bar-h);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    gap: 4px;
    padding-left: max(6px, env(safe-area-inset-left, 0px));
    padding-right: max(6px, env(safe-area-inset-right, 0px));
  }

  .app-bar__lead {
    justify-self: start;
    display: flex;
    align-items: center;
    min-width: 0;
  }

  .app-bar__trail {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 2px;
  }

  body.app-shell .app-bar__icon-btn {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--app-ink) !important;
    -webkit-text-fill-color: var(--app-ink) !important;
    transition: background-color 150ms var(--app-ease), transform 150ms var(--app-ease);
  }

  body.app-shell .app-bar__icon-btn[hidden] {
    display: none;
  }

  body.app-shell .app-bar__icon-btn:active {
    background: rgba(159, 18, 57, 0.08);
    transform: scale(0.94);
  }

  body.app-shell .app-bar__icon-btn:focus-visible {
    outline: 2px solid var(--app-rose);
    outline-offset: 1px;
  }

  .app-bar__icon-btn svg {
    width: 22px;
    height: 22px;
  }

  body.app-shell a.app-bar__brand,
  body.app-shell a.app-bar__brand:hover {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    min-height: 44px;
    text-decoration: none !important;
    color: var(--app-ink) !important;
    -webkit-text-fill-color: var(--app-ink) !important;
  }

  .app-bar__logo {
    height: 32px;
    width: 32px;
    object-fit: cover;
    border-radius: 999px;
    box-shadow: 0 0 0 1px var(--app-line);
  }

  .app-bar__logo--rectangle {
    width: auto;
    max-width: 96px;
    border-radius: 6px;
    object-fit: contain;
    box-shadow: none;
  }

  body.app-shell .app-bar__title {
    max-width: 58vw;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 17px;
    font-weight: 650;
    letter-spacing: 0.01em;
    color: var(--app-ink) !important;
    -webkit-text-fill-color: var(--app-ink) !important;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity 180ms var(--app-ease), transform 180ms var(--app-ease);
  }

  /* Tab pages: brand on the left; the page title fades in once the page's own
     large heading has scrolled away. */
  body.app-shell--tabs .app-bar__back {
    display: none;
  }

  body.app-shell--tabs .app-bar.is-scrolled .app-bar__title {
    opacity: 1;
    transform: none;
  }

  /* Push pages: back button, title always on. */
  body.app-shell--push .app-bar__brand {
    display: none !important;
  }

  body.app-shell--push .app-bar__title {
    opacity: 1;
    transform: none;
  }

  /* ---------- Bottom tab bar ---------- */
  body.app-shell .app-tabbar {
    color: var(--app-ink);
    -webkit-text-fill-color: var(--app-ink);
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    position: fixed;
    inset: auto 0 0 0;
    z-index: 1100;
    height: calc(var(--app-tab-h) + var(--app-safe-bottom));
    padding: 4px max(4px, env(safe-area-inset-left, 0px)) var(--app-safe-bottom) max(4px, env(safe-area-inset-right, 0px));
    background: var(--app-surface);
    -webkit-backdrop-filter: saturate(1.8) blur(18px);
    backdrop-filter: saturate(1.8) blur(18px);
    border-top: 1px solid var(--app-line);
    transition: transform 220ms var(--app-ease);
    view-transition-name: app-tabbar;
  }

  body.app-shell--has-action .app-tabbar,
  body.app-shell.app-kb-open .app-tabbar {
    transform: translateY(110%);
    pointer-events: none;
  }

  body.app-shell a.app-tab,
  body.app-shell a.app-tab:hover,
  body.app-shell a.app-tab:focus {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 48px;
    border-radius: 12px;
    text-decoration: none !important;
    color: var(--app-ink-2) !important;
    -webkit-text-fill-color: var(--app-ink-2) !important;
    font-weight: 500;
  }

  body.app-shell .app-tab .app-tab__icon {
    width: 52px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    color: var(--app-ink-2) !important;
    -webkit-text-fill-color: var(--app-ink-2) !important;
    line-height: 1;
    transition: background-color 200ms var(--app-ease), transform 200ms var(--app-ease);
  }

  .app-tab__icon svg {
    width: 22px;
    height: 22px;
  }

  body.app-shell .app-tab .app-tab__label {
    font-size: 11px;
    line-height: 1.2;
    font-weight: 600;
    letter-spacing: 0.04em;
    color: var(--app-ink-2) !important;
    -webkit-text-fill-color: var(--app-ink-2) !important;
  }

  body.app-shell a.app-tab.is-active,
  body.app-shell a.app-tab.is-active .app-tab__label,
  body.app-shell a.app-tab.is-active .app-tab__icon {
    color: var(--app-rose) !important;
    -webkit-text-fill-color: var(--app-rose) !important;
  }

  body.app-shell a.app-tab.is-active .app-tab__icon {
    background: var(--app-rose-soft);
    color: var(--app-rose) !important;
    -webkit-text-fill-color: var(--app-rose) !important;
  }

  body.app-shell a.app-tab:active .app-tab__icon {
    transform: scale(0.9);
  }

  body.app-shell a.app-tab:focus-visible {
    outline: 2px solid var(--app-rose);
    outline-offset: -2px;
  }

  /* ---------- Touch feel shared by public pages ---------- */
  body.app-shell :is(a, button, [role="button"], summary) {
    -webkit-tap-highlight-color: transparent;
  }

  body.app-shell :is(
    .event-card, .home-hero__cta, .home-hero__next, .home-hero-toc-item,
    .filter-pill, .ed-btn, .detail-cta-float-btn, .blog-card, .past-event-card
  ) {
    transition: transform 140ms var(--app-ease), box-shadow 140ms var(--app-ease);
  }

  body.app-shell :is(
    .event-card, .home-hero__next, .home-hero-toc-item,
    .filter-pill, .ed-btn, .blog-card, .past-event-card
  ):active {
    transform: scale(0.975);
  }

  /* Toasts sit above the tab bar instead of mid-screen. */
  body.app-shell .toast-container {
    top: auto !important;
    bottom: calc(var(--app-tab-h) + var(--app-safe-bottom) + 12px) !important;
    transform: translateX(-50%) !important;
    width: calc(100vw - 24px);
  }

  body.app-shell .toast-container .toast {
    min-width: 0;
    padding: 0.875rem 1rem;
    border-radius: 14px;
  }
}

/* Soft cross-page transition: the bars hold still, the page fades. */
@media (max-width: 1023.98px) and (prefers-reduced-motion: no-preference) {
  @view-transition {
    navigation: auto;
  }

  ::view-transition-old(root) {
    animation: app-vt-out 160ms cubic-bezier(0.4, 0, 1, 1) both;
  }

  ::view-transition-new(root) {
    animation: app-vt-in 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  @keyframes app-vt-out {
    to { opacity: 0; }
  }

  @keyframes app-vt-in {
    from { opacity: 0; transform: translateY(6px); }
  }

  /* Types are set in base.html (pagereveal). push: a detail page slides in
     from the right over the one before; pop: it slides back out; tab: a
     quick cross-fade, as when switching tabs in a native app. */
  html:active-view-transition-type(push)::view-transition-old(root) {
    animation: app-vt-push-old 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  html:active-view-transition-type(push)::view-transition-new(root) {
    animation: app-vt-push-new 240ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  html:active-view-transition-type(pop)::view-transition-old(root) {
    z-index: 1;
    animation: app-vt-pop-old 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  html:active-view-transition-type(pop)::view-transition-new(root) {
    animation: app-vt-pop-new 220ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  html:active-view-transition-type(tab)::view-transition-old(root) {
    animation: app-vt-out 100ms linear both;
  }

  html:active-view-transition-type(tab)::view-transition-new(root) {
    animation: app-vt-fade-in 140ms linear both;
  }

  @keyframes app-vt-push-old {
    to { transform: translateX(-24%); opacity: 0.7; }
  }

  @keyframes app-vt-push-new {
    from { transform: translateX(100%); }
  }

  @keyframes app-vt-pop-old {
    to { transform: translateX(100%); }
  }

  @keyframes app-vt-pop-new {
    from { transform: translateX(-24%); opacity: 0.7; }
  }

  @keyframes app-vt-fade-in {
    from { opacity: 0; }
  }
}

@media (max-width: 1023.98px) {
  /* A page with its own action bar hands the app-tabbar transition name to
     that bar; two elements with one name would cancel the transition. */
  body.app-shell--has-action .app-tabbar {
    view-transition-name: none;
  }

  /* ---------- Chrome that should feel like an app, not a web page ---------- */
  body.app-shell :is(.app-bar, .app-tabbar, .app-install, .app-ptr,
    .detail-cta-float, .home-page-toc) {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }

  body.app-shell :is(.app-bar, .app-tabbar) img {
    -webkit-user-drag: none;
  }

  /* The installed app: no rubber-band glow past the top on Android. */
  html:has(body.app-standalone) {
    overscroll-behavior-y: none;
  }

  /* ---------- Pull to refresh (installed app, see app-shell.js) ---------- */
  body.app-shell .app-ptr {
    position: fixed;
    top: calc(var(--app-bar-h) + var(--app-safe-top) - 36px);
    left: 50%;
    z-index: 1090;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #ffffff;
    color: var(--app-ink-2);
    -webkit-text-fill-color: var(--app-ink-2);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08), 0 6px 18px rgba(28, 25, 23, 0.08);
    opacity: 0;
    transform: translate(-50%, 0);
    pointer-events: none;
  }

  body.app-shell .app-ptr.is-settling {
    transition: transform 200ms var(--app-ease), opacity 200ms var(--app-ease);
  }

  body.app-shell .app-ptr.is-armed,
  body.app-shell .app-ptr.is-loading {
    color: var(--app-rose);
    -webkit-text-fill-color: var(--app-rose);
  }

  body.app-shell .app-ptr.is-loading svg {
    animation: app-ptr-spin 700ms linear infinite;
  }

  @keyframes app-ptr-spin {
    to { transform: rotate(360deg); }
  }

  /* ---------- Add to home screen card (see app-shell.js) ---------- */
  body.app-shell .app-install {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(var(--app-tab-h) + var(--app-safe-bottom) + 10px);
    z-index: 1120;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px 12px 12px;
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid var(--app-line);
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 10px 28px rgba(28, 25, 23, 0.12);
    color: var(--app-ink);
    -webkit-text-fill-color: var(--app-ink);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 220ms var(--app-ease), transform 220ms var(--app-ease);
  }

  body.app-shell .app-install.is-open {
    opacity: 1;
    transform: none;
  }

  body.app-shell.app-kb-open .app-install {
    display: none;
  }

  body.app-shell .app-install__icon {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    border-radius: 12px;
  }

  body.app-shell .app-install__text {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  body.app-shell .app-install__title {
    font-size: 16px;
    line-height: 1.4;
    font-weight: 700;
    color: var(--app-ink) !important;
    -webkit-text-fill-color: var(--app-ink) !important;
  }

  body.app-shell .app-install__body {
    font-size: 14px;
    line-height: 1.55;
    color: var(--app-ink-2) !important;
    -webkit-text-fill-color: var(--app-ink-2) !important;
  }

  body.app-shell .app-install__glyph {
    display: inline-flex;
    vertical-align: -3px;
    color: #0369a1 !important;
    -webkit-text-fill-color: #0369a1 !important;
  }

  body.app-shell button.app-install__cta {
    flex: 0 0 auto;
    min-width: 64px;
    height: 44px;
    padding: 0 16px;
    border: 0;
    border-radius: 12px;
    background: #be123c !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.06em;
  }

  body.app-shell button.app-install__cta:active {
    background: #9f1239 !important;
    transform: scale(0.97);
  }

  body.app-shell button.app-install__close {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--app-ink-2) !important;
    -webkit-text-fill-color: var(--app-ink-2) !important;
  }

  body.app-shell button.app-install__close:active {
    background: rgba(28, 25, 23, 0.06);
  }

  body.app-shell :is(.app-install__cta, .app-install__close):focus-visible {
    outline: 2px solid var(--app-rose);
    outline-offset: 2px;
  }
}

@media (max-width: 1023.98px) and (prefers-reduced-motion: reduce) {
  body.app-shell .app-install,
  body.app-shell .app-ptr.is-settling {
    transition: none;
  }

  body.app-shell .app-ptr.is-loading svg {
    animation-duration: 1.6s;
  }
}

/* ======================================================================
   Page tweaks under the app shell (phone / tablet only)
   ====================================================================== */
@media (max-width: 1023.98px) {
  /* Breadcrumbs repeat what the app bar and tab bar already say. */
  body.app-shell .events-list-breadcrumb,
  body.app-shell .blog-breadcrumb,
  body.app-shell .past-events-breadcrumb,
  body.app-shell--push .event-detail-premium > .breadcrumb-nav,
  body.app-shell--push nav[aria-label="Breadcrumb"],
  body.app-shell--push .album-header .album-back-link,
  body.app-shell--push .album-header > nav:not(:has(> :not(.album-back-link))) {
    display: none !important;
  }

  /* ---------- Homepage: section chips as one swipeable row ---------- */
  body.app-shell .home-page-toc {
    color: var(--app-ink);
    -webkit-text-fill-color: var(--app-ink);
    top: calc(var(--app-bar-h) + var(--app-safe-top));
    padding: 8px 0;
    background: rgba(255, 250, 251, 0.92);
    -webkit-backdrop-filter: saturate(1.6) blur(14px);
    backdrop-filter: saturate(1.6) blur(14px);
    border-bottom: 1px solid var(--app-line);
    box-shadow: none;
  }

  body.app-shell .home-page-toc.is-quiet {
    opacity: 1;
    visibility: visible;
    transform: none;
    pointer-events: auto;
    border-bottom-color: var(--app-line);
  }

  body.app-shell .home-page-toc__label,
  body.app-shell .home-hero-toc-item__num {
    display: none !important;
  }

  body.app-shell .home-page-toc__row {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding: 0 16px;
    scroll-padding-inline: 16px;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  body.app-shell .home-page-toc__row::-webkit-scrollbar {
    display: none;
  }

  body.app-shell.app-shell .homepage-matchmaking nav.home-page-toc a.home-hero-toc-item {
    flex: 0 0 auto;
    min-width: 0;
    min-height: 36px;
    padding: 6px 14px;
    gap: 6px;
    border-radius: 999px;
    font-size: 14px;
    scroll-snap-align: start;
    background: #ffffff !important;
    border: 1px solid rgba(159, 18, 57, 0.16) !important;
    box-shadow: none !important;
    transform: none;
    color: #1c1917 !important;
    -webkit-text-fill-color: #1c1917 !important;
  }

  body.app-shell.app-shell .homepage-matchmaking nav.home-page-toc a.home-hero-toc-item.is-active {
    background: var(--app-rose) !important;
    border-color: var(--app-rose) !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
  }

  body.app-shell .homepage-matchmaking.is-edge-nav-open .homepage-body-sections {
    padding-right: 0;
  }

  /* ---------- Events list ---------- */
  body.app-shell .events-list-header {
    padding-top: 12px;
  }

  /* ---------- Event detail ---------- */
  body.app-shell .ed-page-container {
    padding-bottom: 8px !important;
  }

  body.app-shell .ed-poster {
    color: var(--app-ink);
    -webkit-text-fill-color: var(--app-ink);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(28, 25, 23, 0.06), 0 6px 18px rgba(28, 25, 23, 0.06);
  }

  body.app-shell .ed-poster .ed-poster__img {
    height: auto;
    max-height: 72vh;
    min-height: 120px;
    object-fit: contain;
  }

  /* Bottom action bar */
  body.app-shell--has-action .detail-cta-float {
    color: var(--app-ink);
    -webkit-text-fill-color: var(--app-ink);
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 1150;
    display: flex;
    gap: 10px;
    padding: 10px max(16px, env(safe-area-inset-right, 0px)) calc(10px + var(--app-safe-bottom)) max(16px, env(safe-area-inset-left, 0px));
    background: var(--app-surface);
    -webkit-backdrop-filter: saturate(1.8) blur(18px);
    backdrop-filter: saturate(1.8) blur(18px);
    border-top: 1px solid var(--app-line);
    pointer-events: auto;
    view-transition-name: app-tabbar;
  }

  body.app-shell--has-action .detail-cta-float .detail-cta-float-btn,
  body.app-shell--has-action .detail-cta-float .detail-cta-float-btn:hover {
    flex: 1 1 auto;
    width: 100%;
    height: 50px;
    border-radius: 14px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.06em;
    opacity: 1;
    transform: none;
    background: linear-gradient(180deg, #e11d48 0%, #be123c 100%) !important;
    box-shadow: 0 6px 16px rgba(190, 18, 60, 0.28);
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
  }

  body.app-shell--has-action .detail-cta-float .detail-cta-float-btn:active {
    transform: scale(0.98);
    background: #9f1239 !important;
    color: #ffffff !important;
    -webkit-text-fill-color: #ffffff !important;
  }

  body.app-shell--has-action.app-kb-open .detail-cta-float {
    display: none;
  }
}
