/* ─── Reader experience (INCIDENTS #179) ─────────────────────────────────────
   A «شاهدته» mark on shows already opened,
   a «جديد» mark on what arrived since the last visit, a back-to-top button
   that shows how far down you are, and a circular theme switch. */

/* «شاهدته» and «جديد» marks on cards */
.xp-badge { position: absolute; top: 10px; inset-inline-start: 10px; z-index: 4; display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font: 800 11px/1.4 'Cairo', sans-serif; pointer-events: none; }
.xp-badge.seen { background: rgba(8,12,14,.72); color: #9ff0e6; backdrop-filter: blur(6px); }
.xp-badge.new { background: #2fc7b8; color: #04201d; box-shadow: 0 6px 16px -6px rgba(47,199,184,.8); animation: xp-pop .5s cubic-bezier(.34,1.56,.64,1) both; }
@keyframes xp-pop { from { transform: scale(.4); opacity: 0; } }
.show-card, .news-card { position: relative; }

/* Back to top, with a ring that fills as you read down */
.xp-top {
  position: fixed;
  inset-inline-start: 18px;
  bottom: calc(28px + env(safe-area-inset-bottom, 0px));
  z-index: 9995 !important;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid rgba(47,199,184,.35);
  cursor: pointer;
  background: color-mix(in srgb, var(--card, #12161b) 92%, transparent);
  color: #2fc7b8;
  box-shadow: 0 8px 24px -4px rgba(0,0,0,.6), 0 0 10px rgba(47,199,184,.22);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(16px) scale(.85);
  pointer-events: none;
  transition: opacity .35s cubic-bezier(.16,1,.3,1), transform .45s cubic-bezier(.34,1.56,.64,1), background-color .25s, border-color .25s, box-shadow .25s;
}
.xp-top.show {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}
.xp-top:hover {
  transform: translateY(-3px) scale(1.05);
  border-color: #2fc7b8;
  color: #5ef0e1;
  box-shadow: 0 12px 28px -4px rgba(0,0,0,.7), 0 0 16px rgba(47,199,184,.45);
}
.xp-top:active {
  transform: scale(0.92);
}
.xp-top svg.ring {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  transform: rotate(90deg);
  pointer-events: none;
}
.xp-top svg.ring circle {
  fill: none;
  stroke-width: 3.2;
}
.xp-top svg.ring .bg {
  stroke: rgba(47,199,184,.18);
}
.xp-top svg.ring .fg {
  stroke: #2fc7b8;
  stroke-linecap: round;
  stroke-dasharray: 138.2;
  stroke-dashoffset: 138.2;
  transition: stroke-dashoffset .15s linear;
}
.xp-top svg:not(.ring) {
  width: 18px;
  height: 18px;
  stroke-width: 2.8;
  transition: transform .2s ease;
  pointer-events: none;
}
.xp-top:hover svg:not(.ring) {
  transform: translateY(-2px);
}
.xp-top:focus-visible {
  outline: 2px solid #2fc7b8;
  outline-offset: 3px;
}

/* Whenever the bottom nav is active on mobile portrait */
@media (max-width: 768px) {
  .xp-top {
    inset-inline-start: 16px;
    bottom: calc(88px + env(safe-area-inset-bottom, 0px)) !important;
    width: 44px;
    height: 44px;
  }
}

/* When rotating phone sideways to landscape mode: always elevate above bottom nav bar */
@media (orientation: landscape) and (max-height: 650px), (orientation: landscape) and (max-width: 1024px) {
  .xp-top {
    inset-inline-start: 16px;
    bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
    width: 40px;
    height: 40px;
  }
  body.post-layout .xp-top {
    bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important;
  }
}

/* Fallback: if bottom nav exists on the page */
body.arw-has-bottom-nav .xp-top {
  bottom: calc(78px + env(safe-area-inset-bottom, 0px)) !important;
}

/* Switching the theme (experience.js): no element eases on its own (they finished one by one after the fade) … */
html.theme-switching, html.theme-switching *, html.theme-switching *::before, html.theme-switching *::after { transition: none !important; }
/* … and one cross-fade of the whole page, old picture into new, all at once */
html.theme-vt::view-transition-old(root), html.theme-vt::view-transition-new(root) {
  animation-duration: .45s; animation-timing-function: cubic-bezier(.4, 0, .2, 1); mix-blend-mode: normal;
}
/* the old picture stays as it is under the new one, which fades in on top: no dimming halfway */
html.theme-vt::view-transition-old(root) { animation: none; }
html.theme-vt::view-transition-new(root) { animation-name: theme-vt-in; }
@keyframes theme-vt-in { from { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .xp-top, .xp-badge.new { transition: none !important; animation: none !important; }
}
