/* ==========================================================================
   design-refresh.css — R354 final visual polish layer.
   Loaded last (after modern.css and mobile-responsive.css). Visual only: depth, colour, type, motion.
   It never changes display/position/size of layout containers, so existing responsive rules stay intact.
   Modern features (scroll-driven animation, view transitions, backdrop-filter) are progressive enhancements.
   ========================================================================== */

/* ---------- tokens ---------- */
:root {
  --rf-grad: linear-gradient(135deg, var(--lime) 0%, #6a5cff 55%, #8b5cf6 100%);
  --rf-glass: color-mix(in srgb, var(--surface) 80%, transparent);
  --rf-hair: color-mix(in srgb, var(--line) 75%, transparent);
  --rf-lift: 0 2px 4px rgb(15 23 42 / .05), 0 22px 40px -18px rgb(45 75 255 / .32);
  --rf-ease: cubic-bezier(.22, 1, .36, 1);
}
[data-bs-theme="dark"] {
  --rf-glass: color-mix(in srgb, var(--surface) 74%, transparent);
  --rf-lift: 0 2px 4px rgb(0 0 0 / .5), 0 24px 46px -18px rgb(0 0 0 / .9), 0 0 0 1px rgb(255 255 255 / .05);
}
html[data-contrast="high"] { --rf-grad: linear-gradient(var(--lime), var(--lime)); }

/* ---------- atmosphere: soft brand glow behind the page (depth without noise) ---------- */
body {
  background-image:
    radial-gradient(52rem 26rem at 88% -6rem, color-mix(in srgb, var(--lime) 8%, transparent), transparent 70%),
    radial-gradient(40rem 22rem at 6% 12rem, color-mix(in srgb, #8b5cf6 6%, transparent), transparent 70%);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
html[data-contrast="high"] body { background-image: none; }
::selection { background: color-mix(in srgb, var(--lime) 28%, transparent); }
html { scroll-behavior: smooth; scroll-padding-top: calc(var(--header-h, 74px) + 12px); }

/* ---------- typography: balanced Persian headings, no orphan last lines, relaxed long-form reading ---------- */
:where(h1, h2, h3, .hero-title) { text-wrap: balance; }
:where(p, li, figcaption, .lead) { text-wrap: pretty; }
:where(article p, .article-body p, .article-content p, .page-content p) { line-height: 1.95; }

/* ---------- header: hairline + frosted glass on desktop ---------- */
.site-header { border-block-end: 1px solid var(--rf-hair); }
@media (min-width: 992px) {
  @supports (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px)) {
    .site-header { background-color: var(--rf-glass); -webkit-backdrop-filter: saturate(1.5) blur(14px); backdrop-filter: saturate(1.5) blur(14px); }
    html[data-contrast="high"] .site-header { background-color: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
  }
}

/* ---------- buttons: tactile press, softer brand glow ---------- */
.btn { transition: transform .25s var(--rf-ease), box-shadow .25s var(--rf-ease), background-color .2s, border-color .2s, color .2s; }
.btn:active { transform: translateY(1px) scale(.985); }
@media (hover: hover) {
  .btn-lime:hover { box-shadow: 0 14px 28px -12px color-mix(in srgb, var(--lime) 75%, transparent); }
}

/* ---------- cards & tiles: one elevation language ---------- */
:where(.course-card, .article-card, .podcast-card, .h-path, .h-disc, .special-panel, .footer-pillar, .footer-tool-chip, .faq-item) {
  transition: transform .35s var(--rf-ease), box-shadow .35s var(--rf-ease), border-color .25s, background-color .25s;
}
:where(.course-card-media, .article-card-media) { background: var(--surface-2); }
@media (hover: hover) {
  :is(.course-card, .article-card, .podcast-card):hover {
    box-shadow: var(--rf-lift);
    border-color: color-mix(in srgb, var(--lime) 38%, var(--line));
  }
  :is(.h-path, .h-disc, .special-panel):hover { transform: translateY(-3px); box-shadow: var(--rf-lift); }
  :is(.footer-pillar, .footer-tool-chip):hover { transform: translateY(-2px); }
}
.faq-item[open] { border-color: color-mix(in srgb, var(--lime) 45%, var(--line)); box-shadow: var(--rf-lift); }
.form-control, .form-select { transition: border-color .2s, box-shadow .2s, background-color .2s; }
.form-control:hover:not(:focus):not(:disabled), .form-select:hover:not(:focus):not(:disabled) { border-color: color-mix(in srgb, var(--lime) 40%, var(--line)); }

/* ---------- motion (only when the person has not asked for reduced motion) ---------- */
@media (prefers-reduced-motion: no-preference) {
  /* smooth cross-fade between pages (multi-page view transitions) */
  @view-transition { navigation: auto; }
  ::view-transition-old(root), ::view-transition-new(root) { animation-duration: .22s; }

  @supports (animation-timeline: scroll()) {
    /* thin brand progress bar that follows the page scroll */
    html::before {
      content: ""; position: fixed; inset-block-start: 0; inset-inline: 0; block-size: 3px; z-index: 1040; pointer-events: none;
      background: var(--rf-grad); transform-origin: 100% 50%; scale: 0 1;
      animation: rf-progress linear both; animation-timeline: scroll(root block);
    }
    html[dir="ltr"]::before { transform-origin: 0 50%; }
    html[data-contrast="high"]::before { display: none; }
    @keyframes rf-progress { to { scale: 1 1; } }

    /* header gains depth once the page scrolls */
    .site-header { animation: rf-hdr linear both; animation-timeline: scroll(root block); animation-range: 0 96px; }
    @keyframes rf-hdr { to { box-shadow: 0 10px 28px -16px rgb(15 23 42 / .38); } }
  }

  @supports (animation-timeline: view()) {
    /* gentle rise-in as blocks enter the viewport (translate, so hover transforms are untouched) */
    :is(.section-head, .faq-item, .special-panel, .h-path, .h-disc, .footer-pillar) {
      animation: rf-rise linear both; animation-timeline: view(); animation-range: entry 0% entry 38%;
    }
    @keyframes rf-rise { from { opacity: 0; translate: 0 18px; } to { opacity: 1; translate: 0 0; } }
  }
}
