/* Motionary micro-interactions: motion on every button, search box and text.
   No external libraries. All animations gated behind prefers-reduced-motion. */

/* ---------- Shared easing ---------- */
:root { --mi-ease: cubic-bezier(0.22, 1, 0.36, 1); --mi-pop: cubic-bezier(0.34, 1.56, 0.64, 1); }


/* Hero search dropdown: same panel styling as the nav dropdown (was unstyled) */
#g-results,#hero-results{max-height:60vh;overflow-y:auto;overscroll-behavior:contain}
#hero-results{position:absolute;top:calc(100% + 6px);right:0;left:0;background:var(--surface-container);border:var(--hairline-strong);border-radius:var(--rounded-lg);overflow:hidden;display:none;box-shadow:0 18px 40px rgba(0,0,0,.5);z-index:60;text-align:start}
#hero-results a{display:grid;gap:2px;padding:10px 14px;color:var(--on-surface);text-decoration:none;border-bottom:var(--hairline)}
#hero-results a:hover{background:var(--surface-container-high)}
#hero-results small{color:var(--on-surface-variant);direction:ltr;text-align:end}
#hero-results .all{color:var(--primary);font-weight:800}

@media (prefers-reduced-motion: no-preference) {

/* ---------- Buttons: lift, glow, press, shine ---------- */
.btn-primary, .btn-secondary, .btn-ghost, .btn-xs, .copy-mini,
.search-clear, .fx-replay-btn, .filter-pill, .lang-btn {
  position: relative;
  overflow: hidden;
  transition: transform 0.25s var(--mi-ease), box-shadow 0.25s var(--mi-ease),
    background-color 0.2s var(--mi-ease), color 0.2s var(--mi-ease),
    border-color 0.25s var(--mi-ease), filter 0.2s var(--mi-ease);
  will-change: transform;
}
.btn-primary:hover, .btn-secondary:hover, .btn-ghost:hover, .btn-xs:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 22px rgba(255, 94, 26, 0.22);
}
.btn-primary:hover { box-shadow: 0 8px 26px rgba(255, 94, 26, 0.4); }
.btn-primary:active, .btn-secondary:active, .btn-ghost:active, .btn-xs:active,
.copy-mini:active, .search-clear:active, .fx-replay-btn:active,
.filter-pill:active, .lang-btn:active {
  transform: translateY(0) scale(0.94);
  transition-duration: 0.08s;
}
/* Shine sweep across primary buttons */
.btn-primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 30%, rgba(255, 255, 255, 0.35) 50%, transparent 70%);
  transform: translateX(-130%);
  pointer-events: none;
}
.btn-primary:hover::after { animation: mi-shine 0.7s var(--mi-ease); }
@keyframes mi-shine { to { transform: translateX(130%); } }

/* Copy + replay icon buttons: spring pop */
.copy-mini, .fx-replay-btn { transition: transform 0.3s var(--mi-pop), background-color 0.2s, border-color 0.2s; }
.copy-mini:hover, .fx-replay-btn:hover { transform: scale(1.12) rotate(-4deg); }
.copy-mini:active, .fx-replay-btn:active { transform: scale(0.88); }

/* Filter pills: soft bounce on hover, pulse when toggled */
.filter-pill:hover { transform: translateY(-2px) scale(1.04); }
.filter-pill[aria-pressed="true"] { animation: mi-pillpop 0.35s var(--mi-pop); }
@keyframes mi-pillpop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }

/* Language button: playful tilt + glow */
.lang-btn:hover { transform: translateY(-2px) rotate(-6deg); box-shadow: 0 6px 18px rgba(255, 94, 26, 0.3); }

/* Focus ring: gentle breathing pulse on keyboard focus */
.btn-primary:focus-visible, .btn-secondary:focus-visible, .btn-ghost:focus-visible,
.btn-xs:focus-visible, .copy-mini:focus-visible, .search-clear:focus-visible,
.fx-replay-btn:focus-visible, .filter-pill:focus-visible, .lang-btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  animation: mi-ring 1.4s ease-in-out infinite;
}
@keyframes mi-ring {
  0%, 100% { outline-color: var(--primary); }
  50% { outline-color: rgba(255, 94, 26, 0.35); }
}

/* ---------- Nav links: underline that grows in the reading direction ---------- */
.nav-links a, .nav-links summary, .crumbs a, .sec-title a, footer a {
  background-image: linear-gradient(var(--primary), var(--primary));
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0% 2px;
  transition: color 0.2s var(--mi-ease), background-size 0.3s var(--mi-ease);
}
[dir="ltr"] .nav-links a, [dir="ltr"] .nav-links summary, [dir="ltr"] .crumbs a,
[dir="ltr"] .sec-title a, [dir="ltr"] footer a { background-position: 0 100%; }
[dir="rtl"] .nav-links a, [dir="rtl"] .nav-links summary, [dir="rtl"] .crumbs a,
[dir="rtl"] .sec-title a, [dir="rtl"] footer a { background-position: 100% 100%; }
.nav-links a:hover, .nav-links summary:hover, .nav-links a.on,
.crumbs a:hover, .sec-title a:hover, footer a:hover { background-size: 100% 2px; }

/* Brand: letters light up on hover */
.brand { transition: transform 0.3s var(--mi-ease), text-shadow 0.3s var(--mi-ease); display: inline-block; }
.brand:hover { transform: translateY(-1px) scale(1.03); text-shadow: 0 0 18px rgba(255, 94, 26, 0.55); }
.brand span { transition: color 0.3s var(--mi-ease); }

/* Categories dropdown items: slide in when opened */
.nav-cats[open] .dd a { animation: mi-ddin 0.3s var(--mi-ease) both; }
.nav-cats[open] .dd a:nth-child(1) { animation-delay: 0.00s; }
.nav-cats[open] .dd a:nth-child(2) { animation-delay: 0.03s; }
.nav-cats[open] .dd a:nth-child(3) { animation-delay: 0.06s; }
.nav-cats[open] .dd a:nth-child(4) { animation-delay: 0.09s; }
.nav-cats[open] .dd a:nth-child(5) { animation-delay: 0.12s; }
.nav-cats[open] .dd a:nth-child(6) { animation-delay: 0.15s; }
.nav-cats[open] .dd a:nth-child(7) { animation-delay: 0.18s; }
.nav-cats[open] .dd a:nth-child(8) { animation-delay: 0.21s; }
.nav-cats[open] .dd a:nth-child(9) { animation-delay: 0.24s; }
.nav-cats[open] .dd a:nth-child(10) { animation-delay: 0.27s; }
@keyframes mi-ddin { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.nav-cats .dd a { transition: background-color 0.18s var(--mi-ease), transform 0.18s var(--mi-ease); border-radius: var(--rounded); }
.nav-cats .dd a:hover { background-color: var(--surface-container-high); transform: translateX(3px); }
[dir="rtl"] .nav-cats .dd a:hover { transform: translateX(-3px); }

/* ---------- Search boxes: focus glow, breathing ring, typing shimmer ---------- */
.g-search input, .hero-search input, .search-input {
  caret-color: var(--primary);
  transition: border-color 0.25s var(--mi-ease), box-shadow 0.3s var(--mi-ease), transform 0.25s var(--mi-ease);
}
.g-search input:focus, .hero-search input:focus, .search-input:focus {
  animation: mi-breathe 2.2s ease-in-out infinite;
  transform: scale(1.015);
}
@keyframes mi-breathe {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 94, 26, 0); }
  50% { box-shadow: 0 0 0 5px rgba(255, 94, 26, 0.14); }
}
/* While the user types, the field shimmers softly */
.g-search input.typing, .hero-search input.typing, .search-input.typing {
  border-color: var(--primary);
  animation: mi-typing 0.9s ease-in-out infinite;
}
@keyframes mi-typing {
  0%, 100% { box-shadow: 0 0 0 3px rgba(255, 94, 26, 0.18); }
  50% { box-shadow: 0 0 14px 3px rgba(255, 94, 26, 0.32); }
}
/* Clear button: spins */
.search-clear { transition: transform 0.3s var(--mi-pop), color 0.2s; }
.search-clear:hover { transform: rotate(90deg) scale(1.1); color: var(--primary); }

/* Search results: staggered cascade + hover slide */
#g-results a, #hero-results a {
  animation: mi-resin 0.28s var(--mi-ease) both;
  animation-delay: calc(var(--i, 0) * 0.045s);
  transition: background-color 0.18s var(--mi-ease), transform 0.18s var(--mi-ease), color 0.18s;
}
@keyframes mi-resin { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
#g-results a:hover, #hero-results a:hover { transform: translateX(4px); }
[dir="rtl"] #g-results a:hover, [dir="rtl"] #hero-results a:hover { transform: translateX(-4px); }

/* ---------- Headings and text: entrance + hover shimmer ---------- */
.cat-hero h1, .cat-hero p, .crumbs { animation: mi-rise 0.55s var(--mi-ease) both; }
.cat-hero p { animation-delay: 0.12s; }
.cat-hero .crumbs ~ .crumbs { animation-delay: 0.22s; }
@keyframes mi-rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

.sec-title h2, .cat-hero h1, .hero h1 {
  background-image: linear-gradient(100deg, currentColor 42%, var(--primary) 50%, currentColor 58%);
  background-size: 280% 100%;
  background-position: 100% 0;
  -webkit-background-clip: text;
  background-clip: text;
  transition: background-position 0.9s var(--mi-ease);
}
.sec-title h2:hover, .cat-hero h1:hover, .hero h1:hover { background-position: 0 0; }
@supports (-webkit-background-clip: text) {
  .sec-title h2:hover, .cat-hero h1:hover, .hero h1:hover { -webkit-text-fill-color: transparent; }
  .sec-title h2, .cat-hero h1, .hero h1 { -webkit-text-fill-color: currentColor; }
  .sec-title h2:hover, .cat-hero h1:hover, .hero h1:hover { -webkit-text-fill-color: transparent; color: transparent; }
}

/* Card titles: color sweep on card hover */
.fx-card { transition: transform 0.3s var(--mi-ease), box-shadow 0.3s var(--mi-ease), border-color 0.3s var(--mi-ease); }
.fx-card:hover { transform: translateY(-4px); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 94, 26, 0.35); }
.fx-card .fx-ar, .fx-card .fx-en, .fx-card .fxn { transition: color 0.3s var(--mi-ease); }
.fx-card:hover .fx-ar, .fx-card:hover .fxn { color: var(--primary); }

/* Cards cascade in when (re)rendered */
.fx-card.mi-in { animation: mi-cardin 0.4s var(--mi-ease) both; animation-delay: var(--d, 0s); }
@keyframes mi-cardin { from { opacity: 0; transform: translateY(16px) scale(0.97); } to { opacity: 1; transform: none; } }

/* Category tiles on the home page: lift + number pop */
.cat-tile { transition: transform 0.3s var(--mi-ease), border-color 0.3s var(--mi-ease), box-shadow 0.3s var(--mi-ease); }
.cat-tile:hover { transform: translateY(-5px) scale(1.015); box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 94, 26, 0.4); }
.cat-tile .n { display: inline-block; transition: transform 0.35s var(--mi-pop); }
.cat-tile:hover .n { transform: scale(1.18) rotate(-3deg); }

/* Modal: panel springs in */
.modal-backdrop .modal-panel { animation: mi-modal 0.35s var(--mi-pop); }
@keyframes mi-modal { from { opacity: 0; transform: translateY(22px) scale(0.96); } to { opacity: 1; transform: none; } }

/* Click ripple */
.mi-ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 94, 26, 0.35);
  transform: scale(0);
  animation: mi-ripple 0.55s var(--mi-ease) forwards;
  pointer-events: none;
}
.btn-primary .mi-ripple { background: rgba(255, 255, 255, 0.4); }
@keyframes mi-ripple { to { transform: scale(2.6); opacity: 0; } }

/* Copied confirmation pulse (JS adds .copied briefly) */
.copied { animation: mi-copied 0.5s var(--mi-pop); border-color: var(--primary) !important; }
@keyframes mi-copied { 0% { transform: scale(0.9); } 55% { transform: scale(1.12); } 100% { transform: scale(1); } }

/* Footer byline: subtle glow on hover */
.by { transition: text-shadow 0.3s var(--mi-ease); }
.by:hover { text-shadow: 0 0 14px rgba(255, 94, 26, 0.45); }

} /* end no-preference */

/* Reduced motion: strip every micro-interaction */
@media (prefers-reduced-motion: reduce) {
  .btn-primary, .btn-secondary, .btn-ghost, .btn-xs, .copy-mini, .search-clear,
  .fx-replay-btn, .filter-pill, .lang-btn, .brand, .cat-tile, .fx-card,
  .g-search input, .hero-search input, .search-input, .nav-links a, .nav-links summary,
  .crumbs a, .sec-title a, footer a, .by, .cat-tile .n { transition: none !important; }
  *, *::before, *::after { animation-duration: 0.001s !important; animation-iteration-count: 1 !important; }
}
