/* ==========================================================================
   مشهد التحويل لثيم Sakura (النسخة 3) — theme-switch-fx.js
   شعار العين ← سائل أخضر بمسارات إلكترونية ← إنذار ← غمضة ← وردة ← إعصار يبني الصفحة ← خيط ذهبي
   ========================================================================== */

.tsfx { position: fixed; inset: 0; z-index: 2147483600; overflow: hidden; --tsfx-from: #FF3B5C; --green: #4DFFA0; --red: #FF2D3D; }
.tsfx.tsfx-out { animation: tsfx-fade .42s ease forwards; }
html.tsfx-on { overflow: hidden; }
@keyframes tsfx-fade { to { opacity: 0; } }

/* الخلفية: ليل غامق بشبكة خفيفة */
.tsfx-bg {
  position: absolute; inset: 0; opacity: 0; animation: tsfx-in .35s ease forwards;
  background:
    linear-gradient(rgba(255, 255, 255, .035) 1px, transparent 1px) 0 0 / 44px 44px,
    linear-gradient(90deg, rgba(255, 255, 255, .035) 1px, transparent 1px) 0 0 / 44px 44px,
    radial-gradient(circle at 50% 46%, #170B12 0%, #07040A 72%);
}
@keyframes tsfx-in { to { opacity: 1; } }

/* ---------- المسارات الإلكترونية ---------- */
.tsfx-netbox, .tsfx-net { position: absolute; inset: 0; width: 100%; height: 100%; }
.tsfx-trace {
  fill: none; stroke: rgba(255, 255, 255, .09); stroke-width: 2; stroke-linejoin: round;
  stroke-dasharray: 1000; stroke-dashoffset: 1000; transition: stroke .5s ease;
}
.tsfx.p-open .tsfx-trace { animation: tsfx-draw-line .9s cubic-bezier(.4, 0, .2, 1) forwards; animation-delay: calc(var(--i) * 30ms + .25s); }
@keyframes tsfx-draw-line { to { stroke-dashoffset: 0; } }
.tsfx-flow {
  fill: none; stroke: var(--green); stroke-width: 3.2; stroke-linecap: round;
  stroke-dasharray: 70 1100; stroke-dashoffset: 70; opacity: 0;
  filter: drop-shadow(0 0 5px var(--green));
}
.tsfx.p-liquid .tsfx-trace { stroke: rgba(77, 255, 160, .42); }
.tsfx.p-liquid .tsfx-flow { opacity: 1; animation: tsfx-flow .85s linear infinite; animation-delay: calc(var(--i) * -61ms); }
@keyframes tsfx-flow { from { stroke-dashoffset: 70; } to { stroke-dashoffset: -1000; } }
.tsfx-via { fill: #07040A; stroke: rgba(255, 255, 255, .25); stroke-width: 1.4; opacity: 0; transition: opacity .3s ease, stroke .4s ease, fill .4s ease; }
.tsfx.p-open .tsfx-via { opacity: 1; transition: opacity .3s .9s ease, stroke .4s ease, fill .4s ease; }
.tsfx.p-liquid .tsfx-via { stroke: var(--green); fill: #0B2A1C; }
/* الإنذار: كل شي يحمر */
.tsfx.p-alarm .tsfx-trace { stroke: rgba(255, 45, 61, .55); }
.tsfx.p-alarm .tsfx-flow { stroke: var(--red); filter: drop-shadow(0 0 6px var(--red)); animation-duration: .45s; }
.tsfx.p-alarm .tsfx-via { stroke: var(--red); fill: #2A0A0E; }
.tsfx.p-shut .tsfx-netbox { opacity: 0; transition: opacity .35s ease; }

/* ---------- المسرح والعين ---------- */
.tsfx-stage { position: absolute; left: 50%; top: 45%; width: min(60vmin, 420px); aspect-ratio: 1; transform: translate(-50%, -50%); }
.tsfx-stage-in { position: relative; width: 100%; height: 100%; }
.tsfx-eye { position: relative; display: block; width: 100%; height: 100%; overflow: visible; }

.tsfx-hex-fill { fill: rgba(12, 6, 10, .92); opacity: 0; transition: opacity .6s .15s ease; }
.tsfx.p-open .tsfx-hex-fill { opacity: 1; }
.tsfx-hex {
  fill: none; stroke: var(--tsfx-from); stroke-width: 3; stroke-linejoin: round;
  stroke-dasharray: 100; stroke-dashoffset: 100; transition: stroke .6s ease;
  filter: drop-shadow(0 0 4px var(--tsfx-from));
}
.tsfx.p-open .tsfx-hex { animation: tsfx-hex-draw .7s cubic-bezier(.5, 0, .2, 1) forwards; }
@keyframes tsfx-hex-draw { to { stroke-dashoffset: 0; } }
.tsfx.p-liquid .tsfx-hex { stroke-dashoffset: 0; stroke: var(--green); filter: drop-shadow(0 0 7px var(--green)); }
.tsfx.p-alarm .tsfx-hex { stroke: var(--red); filter: drop-shadow(0 0 9px var(--red)); animation: tsfx-blink .3s steps(1) infinite; }
.tsfx.p-shut .tsfx-hex { animation: none; }
@keyframes tsfx-blink { 50% { opacity: .45; } }

.tsfx-white { fill: #F3EEF0; opacity: 0; transition: opacity .3s .35s ease; }
.tsfx.p-open .tsfx-white { opacity: 1; }
.tsfx-outline { fill: none; stroke: #20121A; stroke-width: 2.4; stroke-linejoin: round; opacity: 0; transition: opacity .3s .35s ease; }
.tsfx.p-open .tsfx-outline { opacity: 1; }
.tsfx-iris { fill: #2A0E18; transition: fill .6s ease; }
.tsfx.p-liquid .tsfx-iris { fill: #0F3A26; }
.tsfx-liquid { fill: #35C97C; transform: translateY(30px); transition: transform 1s .25s cubic-bezier(.4, 0, .2, 1); }
.tsfx.p-liquid .tsfx-liquid { transform: none; }
.tsfx.p-alarm .tsfx-liquid { animation: tsfx-liquid-alarm .3s steps(1) infinite; }
@keyframes tsfx-liquid-alarm { 0%, 49% { fill: #35C97C; } 50%, 100% { fill: var(--red); } }
.tsfx-ring { fill: none; stroke: rgba(255, 255, 255, .55); stroke-width: 1.1; stroke-dasharray: 3 2.4; }
.tsfx-pupil { fill: #07040A; transition: r .25s ease; }
.tsfx.p-alarm .tsfx-pupil { r: 3; }
.tsfx-glint { fill: rgba(255, 255, 255, .9); }

/* الجفون: مغمضة بالبداية، تنفتح، وبالإنذار تنطبق بقوة */
.tsfx-lid { fill: #20121A; transition: transform .45s .45s cubic-bezier(.3, .8, .3, 1); }
.tsfx.p-open .tsfx-lid-top { transform: translateY(-25px); }
.tsfx.p-open .tsfx-lid-bottom { transform: translateY(25px); }
.tsfx.p-shut .tsfx-lid-top, .tsfx.p-shut .tsfx-lid-bottom { transform: none; transition: transform .14s cubic-bezier(.7, 0, 1, .5); }
.tsfx-lash { fill: none; stroke: #F3EEF0; stroke-width: 2; stroke-linecap: round; opacity: 0; transition: opacity .12s ease; }
.tsfx.p-shut .tsfx-lash { opacity: 1; transition-delay: .12s; }

/* الإنذار: ضوء دوّار + حلقات + رجفة */
.tsfx-beacon {
  position: absolute; inset: -8%; border-radius: 50%; opacity: 0; pointer-events: none;
  background: conic-gradient(from 0deg, transparent 0deg, rgba(255, 45, 61, .55) 26deg, rgba(255, 45, 61, .0) 70deg, transparent 180deg, rgba(255, 45, 61, .45) 206deg, transparent 250deg);
  -webkit-mask: radial-gradient(circle, transparent 34%, #000 36%, #000 62%, transparent 72%);
  mask: radial-gradient(circle, transparent 34%, #000 36%, #000 62%, transparent 72%);
}
.tsfx.p-alarm .tsfx-beacon { opacity: 1; animation: tsfx-spin .7s linear infinite; }
.tsfx.p-shut .tsfx-beacon { opacity: 0; transition: opacity .2s ease; }
@keyframes tsfx-spin { to { transform: rotate(360deg); } }
.tsfx-rings circle { fill: none; stroke: var(--red); stroke-width: 2.2; opacity: 0; transform-origin: 0 0; }
.tsfx.p-alarm .tsfx-rings circle { animation: tsfx-ring 1s linear infinite; }
.tsfx.p-alarm .tsfx-rings circle:nth-child(2) { animation-delay: .33s; }
.tsfx.p-alarm .tsfx-rings circle:nth-child(3) { animation-delay: .66s; }
.tsfx.p-shut .tsfx-rings circle { animation: none; opacity: 0; }
@keyframes tsfx-ring { 0% { transform: scale(.8); opacity: .9; } 100% { transform: scale(1.6); opacity: 0; } }
.tsfx.p-alarm .tsfx-stage-in { animation: tsfx-shake .11s steps(2) infinite; }
.tsfx.p-shut .tsfx-stage-in { animation: tsfx-thump .34s cubic-bezier(.3, .7, .3, 1.4) 1; }
@keyframes tsfx-shake { 0% { transform: translate(-4px, 2px); } 50% { transform: translate(4px, -2px); } 100% { transform: translate(-2px, -3px); } }
@keyframes tsfx-thump { 0% { transform: scale(1); } 35% { transform: scale(.9); } 70% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* ---------- العين تتفتح وردة ---------- */
.tsfx-eyegroup { transform-origin: 0 0; transition: transform .45s cubic-bezier(.5, 0, .3, 1), opacity .22s ease; }
.tsfx.p-bloom .tsfx-eyegroup { transform: scale(.25) rotate(25deg); opacity: 0; }
.tsfx-bloom { opacity: 0; transform-origin: 0 0; }
.tsfx.p-bloom .tsfx-bloom { opacity: 1; animation: tsfx-bloom-spin 4s linear infinite; }
@keyframes tsfx-bloom-spin { to { transform: rotate(360deg); } }
.tsfx-petal { transform: scale(0) rotate(-50deg); transform-origin: 0 0; opacity: 0; stroke: #E36E9B; stroke-width: .5; }
.tsfx.p-bloom .tsfx-petal { animation: tsfx-petal .55s cubic-bezier(.3, 1.4, .5, 1) forwards; animation-delay: calc(var(--i) * 60ms + 140ms); }
@keyframes tsfx-petal { to { transform: none; opacity: 1; } }
.tsfx-core { transform: scale(0); transform-origin: 0 0; }
.tsfx.p-bloom .tsfx-core { animation: tsfx-petal .4s .42s ease forwards; }
.tsfx-glow {
  position: absolute; inset: -20%; border-radius: 50%; opacity: 0; pointer-events: none;
  background: radial-gradient(circle, rgba(255, 179, 206, .75) 0%, rgba(255, 179, 206, .25) 40%, transparent 68%);
  transition: opacity .5s ease;
}
.tsfx.p-bloom .tsfx-glow { opacity: 1; }

/* الكتابة تحت العين */
.tsfx-msg {
  position: absolute; left: 50%; top: calc(45% + min(30vmin, 210px) + 14px); transform: translateX(-50%); margin: 0;
  font: 700 clamp(15px, 2.4vmin, 21px)/1.3 "IBM Plex Sans Arabic", Tahoma, sans-serif; white-space: nowrap; text-align: center;
}
.tsfx-msg span { display: none; }
.tsfx.p-liquid .tsfx-msg .m-liquid { display: inline; color: var(--green); font-family: "JetBrains Mono", Consolas, "IBM Plex Sans Arabic", monospace; }
.tsfx.p-alarm .tsfx-msg .m-liquid { display: none; }
.tsfx.p-alarm .tsfx-msg .m-alarm { display: inline-block; color: #FF4D5E; animation: tsfx-glitch .16s steps(2) infinite; }
.tsfx.p-shut .tsfx-msg .m-alarm { display: none; }
.tsfx.p-bloom .tsfx-msg .m-bloom { display: inline-block; color: #FFC2D8; animation: tsfx-pop .45s cubic-bezier(.3, 1.5, .5, 1) both; }
@keyframes tsfx-glitch {
  0% { transform: translateX(0); text-shadow: 2px 0 #22E3FF, -2px 0 #FF2D3D; }
  50% { transform: translateX(2px); text-shadow: -2px 0 #22E3FF, 2px 0 #FF2D3D; }
  100% { transform: translateX(-1px); text-shadow: 1px 0 #22E3FF, -1px 0 #FF2D3D; }
}
@keyframes tsfx-pop { from { transform: scale(.6); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- الوردي يملي الشاشة من قلب الوردة ---------- */
.tsfx-wipe {
  position: absolute; width: 300vmax; height: 300vmax; margin: -150vmax 0 0 -150vmax; border-radius: 50%;
  background: radial-gradient(circle, #FFF7FA 0%, #FFE6EF 34%, #FFD0E0 55%, #FFB8D0 72%);
  transform: scale(0); pointer-events: none;
}
.tsfx.p-wipe .tsfx-wipe { animation: tsfx-wipe-in .5s cubic-bezier(.6, 0, .35, 1) forwards; }
.tsfx.p-storm .tsfx-wipe { transform: scale(1); animation: tsfx-wipe-out .75s .05s ease forwards; }
@keyframes tsfx-wipe-in { to { transform: scale(1); } }
@keyframes tsfx-wipe-out { from { opacity: 1; } to { opacity: 0; } }
.tsfx.p-storm :is(.tsfx-bg, .tsfx-netbox, .tsfx-stage, .tsfx-msg) { display: none; }

/* ---------- الإعصار والخيط الذهبي ---------- */
.tsfx-canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tsfx-gold { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.tsfx-gold rect {
  fill: none; stroke: #E9C46A; stroke-width: 3.5; stroke-dasharray: 100; stroke-dashoffset: 100;
  filter: drop-shadow(0 0 6px rgba(233, 196, 106, .95));
}
.tsfx.p-gold .tsfx-gold rect { animation: tsfx-gold .85s cubic-bezier(.5, 0, .3, 1) forwards; }
@keyframes tsfx-gold { to { stroke-dashoffset: 0; } }

/* زر التخطي */
.tsfx-skip {
  position: absolute; inset-inline-end: 18px; bottom: 18px; z-index: 2;
  padding: 7px 16px; border-radius: 999px; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, .14); color: #fff; font: 600 .85rem/1 "IBM Plex Sans Arabic", system-ui, sans-serif;
}
.tsfx-skip:hover { background: rgba(255, 255, 255, .26); }
.tsfx.p-storm .tsfx-skip { background: rgba(194, 54, 111, .16); color: #8A2A55; }

/* أجزاء الصفحة مخفية، وكل جزء يتجمع لمن يوصله ورق الإعصار (theme-switch-fx.js يضيف tsfx-shown) */
html.tsfx-build :is(.sidebar, .topbar-in, .bottomnav, .fab, .page > *) {
  opacity: 0; transform: translateY(16px) scale(.9);
  transition: opacity .45s ease, transform .6s cubic-bezier(.2, .9, .3, 1.2);
}
html.tsfx-build .tsfx-shown { opacity: 1 !important; transform: none !important; }

@media (prefers-reduced-motion: reduce) { .tsfx { display: none; } }
