/* Adventist Media — native app shell (mobile + installed app). Loaded after app.css. */
:root {
  --appbar-h: 52px;
  --tabbar-h: 60px;
  --mini-h: 62px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --glass: rgba(255, 255, 255, .86);
}

/* ------------------------------------------------------------------ App-wide native behaviour */
html, body { overscroll-behavior-y: contain; }
body { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; text-rendering: optimizeLegibility; }
a, button, .btn, [role="button"], label, select { touch-action: manipulation; }
.app-bar, .tab-bar, .am-player, .now-playing, .app-sheet, .btn, .chip, .tile, .tab-item, .track-row, .video-card,
.sheet-tile, .stat-card, .nav-link, .hymn-keypad, .verse-num, .album-card {
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
html.is-standalone body { -webkit-user-select: none; user-select: none; }
html.is-standalone :is(.article-body, .article-title, .article-lead, .reader-verses, .hymn-lyrics, .lyrics-body, input, textarea, .program-card p) {
  -webkit-user-select: text; user-select: text;
}
img { -webkit-user-drag: none; }
.am-main { min-height: 70vh; }
.am-player-track { display: flex; align-items: center; gap: .65rem; min-width: 0; border: 0; background: none; padding: 0; color: inherit; text-align: left; }

/* ------------------------------------------------------------------ Launch splash */
.am-splash { display: none; }
html.show-splash .am-splash {
  display: flex; position: fixed; inset: 0; z-index: 3000; background: #fff; flex-direction: column;
  align-items: center; justify-content: center; gap: 1rem; transition: opacity .35s ease, visibility .35s;
}
html.show-splash .am-splash img { animation: am-pop .5s var(--ease-out) both; border-radius: 24px; box-shadow: 0 12px 30px rgba(22, 50, 92, .2); }
.am-splash-name { font-weight: 800; font-size: 1.35rem; color: var(--am-navy); letter-spacing: -.02em; animation: am-fade-in .5s .1s both; }
.am-splash-name span { color: var(--am-teal); }
html.splash-done .am-splash { opacity: 0; visibility: hidden; pointer-events: none; }

/* ------------------------------------------------------------------ Navigation progress */
.nav-progress {
  position: fixed; top: var(--safe-top); left: 0; height: 2.5px; width: 0; z-index: 1100; opacity: 0;
  background: linear-gradient(90deg, var(--am-teal), var(--am-gold)); transition: width .45s var(--ease-out), opacity .2s;
  border-radius: 0 2px 2px 0; pointer-events: none;
}
.nav-progress.active { opacity: 1; }
.nav-progress.done { transition: width .15s ease, opacity .3s .1s; opacity: 0; }

/* ------------------------------------------------------------------ Toasts → snackbars */
.app-toasts { position: fixed; z-index: 1090; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); width: min(92vw, 420px); padding: 0; }
body.has-player .app-toasts { bottom: calc(var(--tabbar-h) + var(--mini-h) + var(--safe-bottom) + 18px); }
.app-toasts .toast { width: 100%; background: #1f2a37; color: #fff; border-radius: 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.app-toasts .toast.is-success { background: #0d6e70; }
.app-toasts .toast.is-error { background: #b42318; }
.app-toasts .toast-body { font-weight: 500; }

/* ------------------------------------------------------------------ Sheets */
.app-sheet.offcanvas-bottom { height: auto; max-height: 88vh; border-top-left-radius: 22px; border-top-right-radius: 22px; border: 0; padding-bottom: var(--safe-bottom); box-shadow: 0 -10px 40px rgba(0, 0, 0, .12); }
.app-sheet.lyrics-drawer { height: 72vh; }
.sheet-handle { width: 38px; height: 5px; border-radius: 3px; background: #d5d9df; margin: 8px auto 0; flex-shrink: 0; }
.sheet-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; }
.sheet-tile { display: flex; flex-direction: column; align-items: center; gap: .35rem; text-decoration: none; color: var(--am-text); font-size: .78rem; font-weight: 600; text-align: center; padding: .6rem .2rem; border-radius: 14px; }
.sheet-tile .bi { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-size: 1.4rem; background: var(--am-teal-50); color: var(--am-teal); }
.sheet-tile:active { background: #f2f4f6; }
.sheet-list .list-group-item { border: 0; padding: .85rem .5rem; font-weight: 500; display: flex; gap: .8rem; align-items: center; background: transparent; }
.sheet-list .list-group-item .bi { font-size: 1.2rem; color: var(--am-teal); }
.install-icon { border-radius: 18px; box-shadow: 0 8px 20px rgba(22, 50, 92, .2); }
.install-steps { background: #f6f7f9; border-radius: 14px; padding: 1rem 1rem 1rem 2.2rem; font-size: .92rem; }
.install-steps li { margin-bottom: .4rem; }

/* ------------------------------------------------------------------ Pull-to-refresh & edge back */
.ptr-indicator, .edge-back { display: none; }

/* ------------------------------------------------------------------ Page transitions */
@keyframes am-in-right { from { transform: translateX(28%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes am-out-left { from { transform: none; opacity: 1; } to { transform: translateX(-18%); opacity: 0; } }
@keyframes am-in-left { from { transform: translateX(-22%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes am-out-right { from { transform: none; opacity: 1; } to { transform: translateX(28%); opacity: 0; } }
@keyframes am-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes am-fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes am-pop { from { transform: scale(.8); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes am-spin { to { transform: rotate(360deg); } }

.am-main { view-transition-name: page; }
.app-bar { view-transition-name: appbar; }
.tab-bar { view-transition-name: tabbar; }
.am-player { view-transition-name: miniplayer; }
::view-transition-group(page) { animation-duration: .3s; }
html[data-nav-dir="forward"]::view-transition-old(page) { animation: .28s var(--ease-out) both am-out-left; }
html[data-nav-dir="forward"]::view-transition-new(page) { animation: .3s var(--ease-out) both am-in-right; }
html[data-nav-dir="back"]::view-transition-old(page) { animation: .28s var(--ease-out) both am-out-right; }
html[data-nav-dir="back"]::view-transition-new(page) { animation: .3s var(--ease-out) both am-in-left; }
html[data-nav-dir="fade"]::view-transition-old(page) { animation: .12s ease both am-fade-out; }
html[data-nav-dir="fade"]::view-transition-new(page) { animation: .2s ease both am-fade-in; }
.page-enter-forward { animation: .3s var(--ease-out) both am-in-right; }
.page-enter-back { animation: .3s var(--ease-out) both am-in-left; }
.page-enter-fade { animation: .2s ease both am-fade-in; }
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
  .page-enter { animation: none !important; }
}

/* ------------------------------------------------------------------ Desktop keeps the website layout */
@media (min-width: 992px) {
  .app-bar, .tab-bar, .now-playing { display: none !important; }
  .app-toasts { left: auto; right: 1.25rem; transform: none; top: 1rem; bottom: auto; }
  body.has-player .app-toasts { bottom: auto; }
  .offline-banner { position: sticky; top: 0; z-index: 1031; }
}

/* ------------------------------------------------------------------ Mobile app shell */
@media (max-width: 991.98px) {
  body {
    background: #f6f5f1;
    padding-top: calc(var(--appbar-h) + var(--safe-top));
    padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  }
  body.has-player { padding-bottom: calc(var(--tabbar-h) + var(--mini-h) + var(--safe-bottom) + 16px); }
  .desktop-nav, .am-footer, .skip-link { display: none !important; }
  .container { padding-left: max(16px, var(--safe-left)); padding-right: max(16px, var(--safe-right)); }

  /* App bar */
  .app-bar {
    position: fixed; top: 0; left: 0; right: 0; z-index: 1035;
    height: calc(var(--appbar-h) + var(--safe-top)); padding: var(--safe-top) max(6px, var(--safe-right)) 0 max(6px, var(--safe-left));
    display: flex; align-items: center; gap: 2px;
    background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-bottom: .5px solid rgba(0, 0, 0, .09);
  }
  .app-bar-title {
    flex: 1; min-width: 0; padding: 0 .35rem; font-weight: 700; font-size: 1.06rem; color: var(--am-navy);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.01em;
    transition: opacity .2s ease, transform .2s ease;
  }
  html.is-ios .app-bar-title { text-align: center; }
  .app-bar.title-hidden .app-bar-title { opacity: 0; transform: translateY(6px); }
  .app-bar-brand { display: inline-flex; padding: 0 .35rem 0 .5rem; }
  .app-bar-brand img { border-radius: 9px; }
  .app-bar-actions { display: flex; align-items: center; gap: 2px; }
  .app-bar-actions .live-pill { font-size: .68rem; padding: .32rem .5rem; }
  .app-bar-btn {
    width: 44px; height: 44px; border: 0; border-radius: 50%; background: none; color: var(--am-navy);
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.35rem; text-decoration: none; flex-shrink: 0;
  }
  .app-bar-btn:active { background: rgba(22, 50, 92, .09); }
  .app-back { font-size: 1.5rem; margin-left: -4px; }

  .offline-banner {
    position: fixed; z-index: 1034; top: calc(var(--appbar-h) + var(--safe-top) + 8px); left: 50%; transform: translateX(-50%);
    border: 0; border-radius: 30px; padding: .3rem .9rem; font-size: .8rem; font-weight: 600; white-space: nowrap;
    background: #fff4d6; color: #6b4e00; box-shadow: 0 4px 14px rgba(0, 0, 0, .08);
  }

  /* Tab bar */
  .tab-bar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 1035;
    height: calc(var(--tabbar-h) + var(--safe-bottom)); padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--glass); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border-top: .5px solid rgba(0, 0, 0, .09);
  }
  .tab-item { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: #7b8696; font-size: .68rem; font-weight: 600; letter-spacing: .01em; }
  .tab-icon { position: relative; width: 58px; height: 30px; border-radius: 16px; display: grid; place-items: center; font-size: 1.28rem; transition: background .25s var(--ease-out), transform .12s ease; }
  .tab-icon .i-on { display: none; }
  .tab-item.active { color: var(--am-navy); }
  .tab-item.active .tab-icon { background: var(--am-teal-50); color: var(--am-teal); }
  .tab-item.active .i-on { display: inline; }
  .tab-item.active .i-off { display: none; }
  .tab-item:active .tab-icon { transform: scale(.88); }
  .tab-live-dot { position: absolute; top: 3px; right: 13px; width: 9px; height: 9px; border-radius: 50%; background: var(--am-live); border: 2px solid #fff; animation: pulse 1.4s infinite; }

  /* Large titles */
  .page-header { background: transparent; border: 0; padding: .6rem 0 .3rem; }
  .page-header h1 { font-size: 2rem; letter-spacing: -.03em; margin-bottom: .1rem; }
  .page-header h1 > .bi { display: none; }
  .page-header p { font-size: .9rem; }
  .page-header .offline-status { font-size: .78rem; }
  .article-title { font-size: 1.65rem; }

  /* Content density */
  .hero { padding-top: .75rem; }
  .hero-card { min-height: 230px; padding: 1.4rem; border-radius: 20px; }
  .quick-tiles { grid-template-columns: repeat(3, 1fr); gap: .6rem; }
  .tile { border-radius: 16px; padding: .85rem .4rem; font-size: .82rem; }
  .section-head h2 { font-size: 1.2rem; }
  .my-5 { margin-top: 2rem !important; margin-bottom: 2rem !important; }
  .card, .reader-card, .admin-panel, .offline-summary, .sabbath-card { border-radius: 18px; }
  .news-card .card-body { padding: .9rem 1rem; }
  .filter-chips { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-left: -16px; margin-right: -16px; padding: 0 16px 2px; scroll-snap-type: x proximity; }
  .filter-chips::-webkit-scrollbar { display: none; }
  .chip { white-space: nowrap; scroll-snap-align: start; }
  .video-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .video-tabs::-webkit-scrollbar { display: none; }
  .video-tabs .nav-link { white-space: nowrap; }
  .form-control, .form-select { font-size: 16px; min-height: 44px; border-radius: 12px; }
  .btn { border-radius: 12px; }
  .pagination { --bs-pagination-padding-x: .9rem; --bs-pagination-padding-y: .55rem; }
  .modal-fullscreen-md-down .modal-content { padding-top: var(--safe-top); padding-bottom: var(--safe-bottom); }

  /* Press feedback */
  :is(.tile, .news-card, .track-row, .chip, .list-group-item-action, .video-card, .event-mini, .album-card, .related-item, .sheet-tile, .offline-shortcut, .btn):active {
    transform: scale(.97); transition: transform .08s ease;
  }
  .news-card:hover { transform: none; box-shadow: none; }

  /* Mini player */
  .am-player {
    left: max(8px, var(--safe-left)); right: max(8px, var(--safe-right)); bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 6px);
    border-radius: 16px; border: 0; overflow: hidden; padding-bottom: 0; z-index: 1036;
    background: rgba(255, 255, 255, .94); -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    box-shadow: 0 8px 28px rgba(16, 40, 75, .18), 0 0 0 .5px rgba(0, 0, 0, .06);
  }
  .am-player-inner { display: flex; height: var(--mini-h); padding: 0 .4rem 0 .5rem; gap: .25rem; align-items: center; grid-template-areas: none; }
  .am-player-track { flex: 1; }
  .am-player-track img { width: 44px; height: 44px; border-radius: 10px; }
  .am-player-extra { display: none !important; }
  .am-player .btn-play { width: 44px; height: 44px; background: transparent; color: var(--am-navy); font-size: 1.9rem; }
  .am-player .btn-icon { width: 42px; height: 42px; font-size: 1.45rem; }
  .am-player-progress { position: absolute; left: 12px; right: 12px; bottom: 0; }
  .am-player-progress input { height: 2.5px; pointer-events: none; border-radius: 2px; }
  .am-player-progress input::-webkit-slider-thumb { opacity: 0; }
  .am-player-progress input::-moz-range-thumb { opacity: 0; }

  /* Now Playing */
  .now-playing {
    position: fixed; inset: 0; z-index: 1060; background: #fff; overflow: hidden;
    transform: translateY(100%); transition: transform .38s var(--ease-out); visibility: hidden;
  }
  .now-playing.open { transform: none; visibility: visible; }
  html.np-open { overflow: hidden; }
  .np-bg { position: absolute; inset: -60px; background-size: cover; background-position: center; filter: blur(50px) saturate(1.5); opacity: .35; }
  .np-bg::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 255, 255, .2) 0%, rgba(255, 255, 255, .85) 70%); }
  .np-inner {
    position: relative; height: 100%; display: flex; flex-direction: column;
    padding: calc(var(--safe-top) + 6px) max(22px, var(--safe-right)) calc(var(--safe-bottom) + 22px) max(22px, var(--safe-left));
  }
  .np-top { display: flex; align-items: center; justify-content: space-between; }
  .np-top-label { text-align: center; line-height: 1.15; min-width: 0; }
  .np-top-label small { display: block; font-size: .62rem; font-weight: 700; letter-spacing: .1em; color: var(--am-muted); }
  .np-top-label span { font-size: .85rem; font-weight: 600; color: var(--am-navy); }
  .np-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; }
  .np-art img {
    width: min(80vw, 46vh); aspect-ratio: 1; object-fit: cover; border-radius: 18px; display: block;
    box-shadow: 0 20px 50px rgba(16, 40, 75, .28); transform: scale(.86); transition: transform .45s var(--ease-out);
  }
  .now-playing.is-playing .np-art img { transform: none; }
  .np-lyrics { display: none; position: absolute; inset: 0; overflow-y: auto; padding: 2rem 0 40%; text-align: left; font-size: 1.35rem; font-weight: 700; line-height: 1.45; -webkit-mask-image: linear-gradient(transparent, #000 12%, #000 80%, transparent); mask-image: linear-gradient(transparent, #000 12%, #000 80%, transparent); }
  .np-lyrics p { margin-bottom: 1rem; }
  .np-lyrics.is-synced p { color: rgba(30, 39, 51, .32); transform: none !important; }
  .np-lyrics.is-synced p.active { color: var(--am-navy); }
  .np-lyrics .lyrics-empty { font-size: 1rem; font-weight: 500; color: var(--am-muted); text-align: center; margin-top: 30%; }
  .now-playing.show-lyrics .np-art { display: none; }
  .now-playing.show-lyrics .np-lyrics { display: block; }
  .np-meta { margin-top: 1rem; }
  .np-title { font-size: 1.45rem; font-weight: 800; color: var(--am-navy); letter-spacing: -.02em; }
  .np-artist { font-size: 1.02rem; color: var(--am-muted); }
  .np-seek { margin-top: 1.1rem; }
  .np-seek input { width: 100%; -webkit-appearance: none; appearance: none; height: 5px; border-radius: 3px; background: linear-gradient(to right, var(--am-navy) var(--pct, 0%), rgba(22, 50, 92, .15) var(--pct, 0%)); }
  .np-seek input::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--am-navy); box-shadow: 0 2px 6px rgba(0, 0, 0, .2); }
  .np-seek input::-moz-range-thumb { width: 16px; height: 16px; border: 0; border-radius: 50%; background: var(--am-navy); }
  .np-times { display: flex; justify-content: space-between; font-size: .75rem; color: var(--am-muted); font-variant-numeric: tabular-nums; margin-top: .35rem; }
  .np-controls { display: flex; align-items: center; justify-content: space-between; margin-top: 1.2rem; }
  .np-btn { border: 0; background: none; color: var(--am-navy); width: 60px; height: 60px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 2.3rem; }
  .np-btn:active { background: rgba(22, 50, 92, .08); transform: scale(.92); }
  .np-btn.np-small { width: 46px; height: 46px; font-size: 1.25rem; font-weight: 700; color: var(--am-muted); }
  .np-btn.np-small.active { color: var(--am-teal); background: var(--am-teal-50); }
  .np-play { width: 76px; height: 76px; background: var(--am-navy); color: #fff; font-size: 2.6rem; box-shadow: 0 10px 24px rgba(22, 50, 92, .3); }
  .np-play:active { background: var(--am-navy-700); }

  /* Pull-to-refresh */
  .ptr-indicator {
    display: grid; place-items: center; position: fixed; z-index: 1034; left: 50%; top: calc(var(--appbar-h) + var(--safe-top) - 44px);
    width: 40px; height: 40px; border-radius: 50%; background: #fff; color: var(--am-muted); font-size: 1.15rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .14); opacity: 0; transform: translate(-50%, 0); pointer-events: none;
    transition: opacity .15s ease;
  }
  .ptr-indicator.visible { opacity: 1; }
  .ptr-indicator.ready { color: var(--am-teal); }
  .ptr-indicator.spinning { transition: transform .2s ease; }
  .ptr-indicator.spinning i { animation: am-spin .7s linear infinite; }

  /* Edge-swipe back */
  .edge-back {
    display: grid; place-items: center; position: fixed; z-index: 1040; top: 50%; left: -44px; width: 40px; height: 40px;
    border-radius: 50%; background: #fff; color: var(--am-muted); font-size: 1.2rem; box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
    opacity: 0; transform: translate(0, -50%); pointer-events: none;
  }
  .edge-back.visible { opacity: 1; }
  .edge-back.ready { color: #fff; background: var(--am-navy); }
  .am-main { transition: transform .2s var(--ease-out); }

  /* Track rows feel like a music app */
  .track-list .list-group-item { border-left: 0; border-right: 0; background: transparent; }
  .track-list { border-radius: 0; margin: 0 -16px; }
  .track-row { padding: .5rem 16px; }
  .track-row.is-playing { background: rgba(15, 139, 141, .07); }

  /* App-style detail pages */
  .article-wrap .breadcrumb { display: none; }
  .article-cover img { border-radius: 18px; max-height: 240px; }
  .program-poster { min-height: 0; max-height: 190px; }
  .program-card .card-body { padding: 1rem; }

  /* Hymn keypad: bigger targets */
  .hymn-keypad .btn { min-height: 48px; }
}

/* Installed app on large screens (tablets/desktop window): hide the browser-ish install affordances */
html.is-standalone [data-install] { display: none !important; }
